Do with this what you will; here's a patch to the Makefile and to tinyxml.h to add a "make lib" rule for building a static library. Go into the same directory as the Makefile, copy the diff below to a file named makelib.diff, and "patch -p1 < makelib.diff" to apply. This is on tinyxml 2.5.2.
Couple of sketchy things, use your own judgement:
1) Bash script used in the Makefile. I don't know if make always uses bash/sh or if it just uses the user's current shell. If it's the latter, then that might cause problems for users that use, say, tcsh (in which case they should switch to bash >:). But I don't know, I've never used tcsh -- maybe the commands are the same.
2) Since this is in library format, if -DTIXML_USE_STL is in the compiler line, it won't be available to applications that use tinyxml.h. To that end, I've removed the -DTIXML_USE_STL thing. Instead, the Makefile generates a little header file named "tinyopt.h" that has the appropriate #define in it, and tinyxml.h now #includes that. That way, TIXML_USE_STL is available to applications. Erm... this is the simplest thing I could come up with that didn't involve using sed to replace text. There's probably a better way.
3) If TIXML_USE_STL is set, tinystr.h is not placed in the include directory. This seems like it's the right thing to do. Maybe it's not.
- JC
Diff begins on the line after this one and goes to the end of this post (crossing my fingers that it shows up correctly):
+lib: ${LIBNAME}
+# Put stuff in lib & include, let user do rest.
+ -mkdir -p ${OUTLIBDIR} ${OUTINCDIR}
+ @cp -v ${LIBNAME} ${OUTLIBDIR}
+ @cp -v ${LIBHDRS} ${OUTINCDIR}
+ @echo
+ @echo "To install, copy the contents of 'lib' and 'include' to"
+ @echo "a place that you know they will be happy."
Bah, the HTML broke all the spaces. You can view the HTML source of this post and use the diff info from that instead, or feel free to email me at b5901@hotttmail.com (change ttt to single t).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
*Sigh* liek zomg i r such a nub oh noes. After applying the above patch, make the following two modifications to the Makefile to prevent it from including xmltest.o in the compiled library :-/
Type "make lib" and out pops libtinyxml.a. Copy headers and lib from the directories it creates into your include/lib path.
I generally prefer code like this to be in library form; that way if a new version of TinyXML comes out, I don't have to make sure that I update multiple copies of the TinyXML source I have laying around; only the library.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do with this what you will; here's a patch to the Makefile and to tinyxml.h to add a "make lib" rule for building a static library. Go into the same directory as the Makefile, copy the diff below to a file named makelib.diff, and "patch -p1 < makelib.diff" to apply. This is on tinyxml 2.5.2.
Couple of sketchy things, use your own judgement:
1) Bash script used in the Makefile. I don't know if make always uses bash/sh or if it just uses the user's current shell. If it's the latter, then that might cause problems for users that use, say, tcsh (in which case they should switch to bash >:). But I don't know, I've never used tcsh -- maybe the commands are the same.
2) Since this is in library format, if -DTIXML_USE_STL is in the compiler line, it won't be available to applications that use tinyxml.h. To that end, I've removed the -DTIXML_USE_STL thing. Instead, the Makefile generates a little header file named "tinyopt.h" that has the appropriate #define in it, and tinyxml.h now #includes that. That way, TIXML_USE_STL is available to applications. Erm... this is the simplest thing I could come up with that didn't involve using sed to replace text. There's probably a better way.
3) If TIXML_USE_STL is set, tinystr.h is not placed in the include directory. This seems like it's the right thing to do. Maybe it's not.
- JC
Diff begins on the line after this one and goes to the end of this post (crossing my fingers that it shows up correctly):
diff -ur tinyxml-2.5.2/Makefile tinyxml-2.5.2.mod/Makefile
--- tinyxml-2.5.2/Makefile Tue Sep 19 22:04:36 2006
+++ tinyxml-2.5.2.mod/Makefile Sun Feb 11 03:21:19 2007
@@ -52,14 +52,18 @@
LDFLAGS := ${LDFLAGS} -pg
endif
+OPTHDR := tinyopt.h
+LIBNAME := libtinyxml.a
+LIBHDRS := tinyxml.h ${OPTHDR} # tinystr.h included if necessary below.
+OUTLIBDIR := lib
+OUTINCDIR := include
+
#****************************************************************************
# Preprocessor directives
#****************************************************************************
-ifeq (YES, ${TINYXML_USE_STL})
- DEFS := -DTIXML_USE_STL
-else
- DEFS :=
+ifneq (YES, ${TINYXML_USE_STL})
+ LIBHDRS := ${LIBHDRS} tinystr.h
endif
#****************************************************************************
@@ -83,8 +87,18 @@
OUTPUT := xmltest
+.PHONY: all lib
+
all: ${OUTPUT}
+lib: ${LIBNAME}
+# Put stuff in lib & include, let user do rest.
+ -mkdir -p ${OUTLIBDIR} ${OUTINCDIR}
+ @cp -v ${LIBNAME} ${OUTLIBDIR}
+ @cp -v ${LIBHDRS} ${OUTINCDIR}
+ @echo
+ @echo "To install, copy the contents of 'lib' and 'include' to"
+ @echo "a place that you know they will be happy."
#****************************************************************************
# Source files
@@ -101,13 +115,35 @@
# Output
#****************************************************************************
+# Test program
${OUTPUT}: ${OBJS}
${LD} -o $@ ${LDFLAGS} ${OBJS} ${LIBS} ${EXTRA_LIBS}
+# Library
+${LIBNAME}: ${OBJS}
+ ${AR} ${LIBNAME} ${OBJS}
+ ${RANLIB} ${LIBNAME}
+
+# Option header
+${OPTHDR}:
+ @echo "Creating ${OPTHDR}..."
+ @head tinyxml.h -n 24 > ${OPTHDR} # license
+ @echo "#ifndef TINYOPT_INCLUDED" >> ${OPTHDR}
+ @echo "#define TINYOPT_INCLUDED" >> ${OPTHDR}
+ @echo "#ifdef TIXML_USE_STL" >> ${OPTHDR}
+ @echo "# undef TIXML_USE_STL" >> ${OPTHDR}
+ @echo "#endif" >> ${OPTHDR}
+ifeq (YES, ${TINYXML_USE_STL})
+ @echo "#define TIXML_USE_STL" >> ${OPTHDR}
+endif
+ @echo "#endif" >> ${OPTHDR}
+
#****************************************************************************
# common rules
#****************************************************************************
+.PHONY: dist clean depend
+
# Rules for compiling source files to object files
%.o : %.cpp
${CXX} -c ${CXXFLAGS} ${INCS} $< -o $@
@@ -119,12 +155,20 @@
bash makedistlinux
clean:
- -rm -f core ${OBJS} ${OUTPUT}
+ -rm -f core ${OBJS} ${OUTPUT} ${LIBNAME} ${OPTHDR} ${OUTLIBDIR}/${LIBNAME}
+ -for fn in ${LIBHDRS} ; do \ + rm -f ${OUTINCDIR}/$$fn ; \ + done
+ -for dn in ${OUTINCDIR} ${OUTLIBDIR} ; do \ + if [ -d $$dn ] ; then \ + rmdir --ignore-fail-on-non-empty $$dn ; \ + fi ; \ + done
depend:
- #makedepend ${INCS} ${SRCS}
+# makedepend ${INCS} ${SRCS}
-tinyxml.o: tinyxml.h tinystr.h
-tinyxmlparser.o: tinyxml.h tinystr.h
-xmltest.o: tinyxml.h tinystr.h
-tinyxmlerror.o: tinyxml.h tinystr.h
+tinyxml.o: tinyxml.h tinystr.h ${OPTHDR}
+tinyxmlparser.o: tinyxml.h tinystr.h ${OPTHDR}
+xmltest.o: tinyxml.h tinystr.h ${OPTHDR}
+tinyxmlerror.o: tinyxml.h tinystr.h ${OPTHDR}
diff -ur tinyxml-2.5.2/tinyxml.h tinyxml-2.5.2.mod/tinyxml.h
--- tinyxml-2.5.2/tinyxml.h Tue Sep 19 22:04:36 2006
+++ tinyxml-2.5.2.mod/tinyxml.h Sun Feb 11 03:16:02 2007
@@ -37,6 +37,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include "tinyopt.h"
// Help out windows:
#if defined( _DEBUG ) && !defined( DEBUG )
diff -ur tinyxml-2.5.2/xmltest.cpp tinyxml-2.5.2.mod/xmltest.cpp
--- tinyxml-2.5.2/xmltest.cpp Tue Sep 19 22:04:36 2006
+++ tinyxml-2.5.2.mod/xmltest.cpp Sun Feb 11 03:17:20 2007
@@ -2,15 +2,6 @@
Test program for TinyXML.
*/
-
-#ifdef TIXML_USE_STL
- #include <iostream>
- #include <sstream>
- using namespace std;
-#else
- #include <stdio.h>
-#endif
-
#if defined( WIN32 ) && defined( TUNE )
#include <crtdbg.h>
_CrtMemState startMemState;
@@ -18,6 +9,12 @@
#endif
#include "tinyxml.h"
+
+#ifdef TIXML_USE_STL
+ using namespace std;
+#else
+ #include <stdio.h>
+#endif
static int gPass = 0;
static int gFail = 0;
Bah, the HTML broke all the spaces. You can view the HTML source of this post and use the diff info from that instead, or feel free to email me at b5901@hotttmail.com (change ttt to single t).
*Sigh* liek zomg i r such a nub oh noes. After applying the above patch, make the following two modifications to the Makefile to prevent it from including xmltest.o in the compiled library :-/
1) Replace the "Source files" section with:
#****************************************************************************
# Source files
#****************************************************************************
LIBSRCS := tinyxml.cpp tinyxmlparser.cpp tinyxmlerror.cpp tinystr.cpp
SRCS := ${LIBSRCS} xmltest.cpp
# Add on the sources for libraries
SRCS := ${SRCS}
LIBOBJS := $(addsuffix .o,$(basename ${LIBSRCS}))
OBJS := $(addsuffix .o,$(basename ${SRCS}))
2) Change the line "${LIBNAME}: ${OBJS}" to "{$LIBNAME}: ${LIBOBJS}".
:((( And change ${OBJS} -> ${LIBOBJS} in the {$AR} line as well! Forgot to mention that. That's it. I'm never using the internet -again-.
Thanks for your comments...
but I'm not really sure what specific problems you are solving?
It's a patch for building tinyxml as a library.
Type "make lib" and out pops libtinyxml.a. Copy headers and lib from the directories it creates into your include/lib path.
I generally prefer code like this to be in library form; that way if a new version of TinyXML comes out, I don't have to make sure that I update multiple copies of the TinyXML source I have laying around; only the library.
Go to http://miarn.sf.net i made that a sometime ago.
ok has someone the hole file for me??? i lost the plot
And another patch, to allow the option for creating/making a static library under linux or now: TINYXML_CREATE_LIB := YES.
The patches would be better posted in as a file attached to a new feature request in the tracker.
Thanks nonetheless.
Blessings