diff options
-rw-r--r-- | docs/README.GenGetopt | 8 | ||||
-rw-r--r-- | include/wolf/port/string.h | 16 | ||||
-rw-r--r-- | makefiles/clean.mk | 13 | ||||
-rw-r--r-- | makefiles/compiler.mk | 8 | ||||
-rw-r--r-- | makefiles/depend.mk | 19 | ||||
-rw-r--r-- | makefiles/sub.mk | 4 | ||||
-rw-r--r-- | src/port/string.c | 16 | ||||
-rw-r--r-- | tests/GNUmakefile | 6 | ||||
-rw-r--r-- | tests/daemon/GNUmakefile | 13 | ||||
-rw-r--r-- | tests/daemon/README | 13 | ||||
-rw-r--r-- | tests/daemon/testd.c | 2 | ||||
-rw-r--r-- | tests/port/GNUmakefile | 4 | ||||
-rw-r--r-- | tests/port/test_strcasecmp.c | 8 | ||||
-rw-r--r-- | tests/port/test_strdup.c | 8 | ||||
-rw-r--r-- | tests/port/test_strerror_r.c | 9 | ||||
-rw-r--r-- | tests/port/test_strncasecmp.c | 8 |
16 files changed, 75 insertions, 80 deletions
diff --git a/docs/README.GenGetopt b/docs/README.GenGetopt deleted file mode 100644 index 1763029..0000000 --- a/docs/README.GenGetopt +++ /dev/null @@ -1,8 +0,0 @@ -gengetopt: generates plain C code using getopt_long/getopt and -has a local getopt_long replacement for Unixes which don't -support getopt_long properly - -popt is happily broken - -self-made ones are usually quite funny to use and we don't use -some getopt features (like the ones on Solaris)
\ No newline at end of file diff --git a/include/wolf/port/string.h b/include/wolf/port/string.h index 2b12952..2f5a049 100644 --- a/include/wolf/port/string.h +++ b/include/wolf/port/string.h @@ -41,23 +41,31 @@ #include <sys/types.h> /* for size_t */ -#if !defined HAVE_STRDUP +#if !defined HAVE_STRDUP || defined TEST_STRDUP extern char *wolf_port_strdup( const char *s ); +#endif +#if !defined HAVE_STRDUP #define strdup wolf_port_strdup #endif -#if !defined HAVE_STRERROR_R +#if !defined HAVE_STRERROR_R || defined TEST_STRERROR_R extern int wolf_port_strerror_r( int num, char *buf, size_t buflen ); +#endif +#if !defined HAVE_STRERROR_R #define strerror_r( errnum, buf, buflen ) wolf_port_strerror_r( errnum, buf, buflen ) #endif -#if !defined HAVE_STRCASECMP +#if !defined HAVE_STRCASECMP || defined TEST_STRCASECMP extern int wolf_port_strcasecmp( const char *s1, const char *s2 ); +#endif +#if !defined HAVE_STRCASECMP #define strcasecmp( s1, s2 ) wolf_port_strcasecmp( s1, s2 ) #endif -#if !defined HAVE_STRNCASECMP +#if !defined HAVE_STRNCASECMP || defined TEST_STRNCASECMP extern int wolf_port_strncasecmp( const char *s1, const char *s2, size_t n ); +#endif +#if !defined HAVE_STRNCASECMP #define strncasecmp( s1, s2, n ) wolf_port_strncasecmp( s1, s2, n ) #endif diff --git a/makefiles/clean.mk b/makefiles/clean.mk index c924fee..d416905 100644 --- a/makefiles/clean.mk +++ b/makefiles/clean.mk @@ -1,9 +1,12 @@ # cleans up directories # # requires: -# - BINS, OBJS, CPPOBJS, BIN_OBJS -# - CMODULES, CPPMODULES -# - SUBDIRS +# - SUBDIRS: for recursive cleaning +# - local_clean, local_distclean targets in local GNUmakefile +# - all artifacts to clean: +# - BINS, TEST_BINS, TEST_CPP_BINS, CPP_BINS +# - OBJS, CPPOBJS, BIN_OBJS, TEST_BIN_OBJS, CPP_BIN_OBJS, TEST_CPP_BIN_OBJS +# - CMODULES, CPPMODULES # # provides: # - target: clean @@ -19,8 +22,8 @@ clean: clean_recursive local_clean -@rm -f *.bak 2>/dev/null -@rm -f *~ 2>/dev/null -@rm -f *.d port/*.d 2>/dev/null - -@rm -f $(BINS) $(CPP_BINS) 2>/dev/null - -@rm -f $(OBJS) $(CPP_OBJS) $(BIN_OBJS) $(CPP_BIN_OBJS) 2>/dev/null + -@rm -f $(BINS) $(CPP_BINS) $(TEST_BINS) $(TEST_CPP_BINS) 2>/dev/null + -@rm -f $(OBJS) $(CPP_OBJS) $(BIN_OBJS) $(TEST_BIN_OBJS) $(CPP_BIN_OBJS) $(TEST_CPP_BIN_OBJS) 2>/dev/null -@rm -f exec/* -@rm -f *.core -@rm -f $(CMODULES) $(CPPMODULES) diff --git a/makefiles/compiler.mk b/makefiles/compiler.mk index 668a579..581f9c6 100644 --- a/makefiles/compiler.mk +++ b/makefiles/compiler.mk @@ -4,7 +4,11 @@ # - INCLUDE_DIRS # # provides: -# - BIN_OBJS: the object files we need for the binaries (containing the main) +# - BIN_OBJS: the object files we need for the binaries which we build always +# - CPP_BIN_OBJS: same for binaries which have C++ code in them +# - TEST_BIN_OBJS: same as BIN_OBJS but for test binaries compiled only when +# testing +# - TEST_CPP_BIN_OBJS: same for C++ tests # # start of gcc section @@ -218,4 +222,6 @@ CCPP_LINK = $(CCPP) $(CCPP_LINK) -shared -o $@ $(LDFLAGS) $(LIBS) $(OBJS) $(CPPOBJS) $< BIN_OBJS = $(BINS:$(EXE)=.o) +TEST_BIN_OBJS = $(TEST_BINS:$(EXE)=.o) CPP_BIN_OBJS = $(CPP_BINS:$(EXE)=.o) +TEST_CPP_BIN_OBJS = $(TEST_CPP_BINS:$(EXE)=.o) diff --git a/makefiles/depend.mk b/makefiles/depend.mk index 14e816b..bcdb5b2 100644 --- a/makefiles/depend.mk +++ b/makefiles/depend.mk @@ -4,7 +4,8 @@ # requires: # - compilers CC and CCPP # - INCLUDEDIRS -# - OBJS, CPP_OBJS and BIN_OBJS +# - OBJS, CPP_OBJS and BIN_OBJS, CPP_BIN_OBJS +# - TEST_BINS, TEST_BIN_OBJS, TEST_CPP_BINS, TEST_CPP_BIN_OBJS # # provides: # - included dependency files @@ -15,12 +16,12 @@ ifeq "$(COMPILER)" "gcc" %.d : %.c @echo Generating dependencies for $< - @$(CC) -MM -MT $@ $(CFLAGS) $< | \ + @$(CC) -DMAKE_DEPENDENCIES -MM -MT $@ $(CFLAGS) $< | \ sed "s,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\&\&\&\1 : \2,g" | tr -s '&' "\n" > $@ %.d : %.cpp @echo Generating dependencies for $< - @$(CCPP) -MM -MT $@ $(CCPPFLAGS) $< | \ + @$(CCPP) -DMAKE_DEPENDENCIES -MM -MT $@ $(CCPPFLAGS) $< | \ sed "s,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\&\&\&\1 : \2,g" | tr -s '&' "\n" > $@ endif @@ -29,7 +30,7 @@ ifeq "$(COMPILER)" "tcc" %.d : %.c @echo Generating dependencies for $< - @makedepend $(INCLUDE_DIRS) -I/usr/lib/tcc/include -f - $< > $@ + @makedepend -DMAKE_DEPENDENCIES $(INCLUDE_DIRS) -I/usr/lib/tcc/include -f - $< > $@ endif @@ -37,12 +38,12 @@ ifeq "$(COMPILER)" "icc" %.d : %.c @echo Generating dependencies for $< - @$(CC) -MM -MT $@ $(CFLAGS) $< | \ + @$(CC) -DMAKE_DEPENDENCIES -MM -MT $@ $(CFLAGS) $< | \ sed "s,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\&\&\&\1 : \2,g" | tr -s '&' "\n" > $@ %.d : %.cpp @echo Generating dependencies for $< - @$(CCPP) -MM -MT $@ $(CCPPFLAGS) $< | \ + @$(CCPP) -DMAKE_DEPENDENCIES -MM -MT $@ $(CCPPFLAGS) $< | \ sed "s,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\&\&\&\1 : \2,g" | tr -s '&' "\n" > $@ endif @@ -51,14 +52,16 @@ ifeq "$(COMPILER)" "spro" %.d : %.c @echo Generating dependencies for $< - @$(CC) -xM1 $(INCLUDE_DIRS) $< > $@ + @$(CC) -DMAKE_DEPENDENCIES -xM1 $(INCLUDE_DIRS) $< > $@ %.d : %.cpp @echo Generating dependencies for $< - @$(CCPP) -xM1 $(INCLUDE_DIRS) $< > $@ + @$(CCPP) -DMAKE_DEPENDENCIES -xM1 $(INCLUDE_DIRS) $< > $@ endif -include $(OBJS:.o=.d) -include $(CPP_OBJS:.o=.d) -include $(BIN_OBJS:.o=.d) -include $(CPP_BIN_OBJS:.o=.d) +-include $(TEST_BIN_OBJS:.o=.d) +-include $(TEST_CPP_BIN_OBJS:.o=.d) diff --git a/makefiles/sub.mk b/makefiles/sub.mk index 5a5d606..567e144 100644 --- a/makefiles/sub.mk +++ b/makefiles/sub.mk @@ -12,12 +12,12 @@ -include $(TOPDIR)/makefiles/compiler.mk .PHONY: all $(SUBDIRS) local_all -all: local_all $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(CPP_BIN_OBJS) $(BINS) $(CPP_BINS) $(CMODULES) $(CPPMODULES) +all: $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(CPP_BIN_OBJS) $(BINS) $(CPP_BINS) $(CMODULES) $(CPPMODULES) local_all @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ (set -e; $(MAKE) -C $$d all || exit 1); done) .PHONY: test local_test -test: local_test $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(BINS) $(CPP_BINS) $(CMODULES) $(CPPMODULES) +test: $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(BINS) $(CPP_BINS) $(TEST_BINS) $(TEST_CPP_BINS) $(CMODULES) $(CPPMODULES) local_test @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ (set -e; $(MAKE) -C $$d test || exit 1); done) diff --git a/src/port/string.c b/src/port/string.c index 01c5228..78c3685 100644 --- a/src/port/string.c +++ b/src/port/string.c @@ -22,7 +22,7 @@ * be set which would enable too many non-standard things. */ -#if !defined HAVE_STRDUP +#if !defined HAVE_STRDUP || defined TEST_STRDUP #include <stdlib.h> /* for malloc, NULL */ @@ -34,14 +34,14 @@ char *wolf_port_strdup( const char *s ) { return d; } -#endif /* !defined HAVE_STRDUP */ +#endif /* !defined HAVE_STRDUP || defined TEST_STRDUP */ /** * strerror_r exists in various fassions (XSI and GNU flavour in glibc). We stick to * the API of POSIX.1 of course (XSI-compliant).. */ -#if !defined HAVE_STRERROR_R +#if !defined HAVE_STRERROR_R || defined TEST_STRERROR_R #include "port/stdio.h" /* for snprintf */ #include <sys/types.h> /* for size_t */ @@ -68,7 +68,7 @@ int wolf_port_strerror_r( int num, char *buf, size_t buflen ) { return 0; } -#endif /* !defined HAVE_STRERROR_R */ +#endif /* !defined HAVE_STRERROR_R || defined TEST_STRERROR_R */ /** * str(n)casecmp is always around but on very old or strance C libraries. @@ -77,7 +77,7 @@ int wolf_port_strerror_r( int num, char *buf, size_t buflen ) { * anyway. */ -#if !defined HAVE_STRCASECMP +#if !defined HAVE_STRCASECMP || defined TEST_STRCASECMP #include <ctype.h> /* for tolower */ @@ -94,9 +94,9 @@ int wolf_port_strcasecmp( const char *s1, const char *s2 ) { return( c2 > c1 ? -1 : c1 > c2 ); } -#endif /* !defined HAVE_STRCASECMP */ +#endif /* !defined HAVE_STRCASECMP || defined TEST_STRCASECMP */ -#if !defined HAVE_STRNCASECMP +#if !defined HAVE_STRNCASECMP || defined TEST_STRNCASECMP #include <ctype.h> /* for tolower */ @@ -117,4 +117,4 @@ int wolf_port_strncasecmp( const char *s1, const char *s2, size_t n ) { return( c2 > c1 ? -1 : c1 > c2 ); } -#endif /* !defined HAVE_STRNCASECMP */ +#endif /* !defined HAVE_STRNCASECMP || defined TEST_STRNCASECMP */ diff --git a/tests/GNUmakefile b/tests/GNUmakefile index b61d985..3ffab88 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -2,12 +2,6 @@ TOPDIR = .. SUBDIRS = port daemon -INCLUDE_DIRS = -I. - -BINS = - -OBJS = - -include $(TOPDIR)/makefiles/sub.mk local_test: diff --git a/tests/daemon/GNUmakefile b/tests/daemon/GNUmakefile index 1c88a31..c2f9e91 100644 --- a/tests/daemon/GNUmakefile +++ b/tests/daemon/GNUmakefile @@ -7,17 +7,13 @@ INCLUDE_LIBS = \ INCLUDE_DIRS = -I$(TOPDIR)/include/wolf -I. -BINS = \ +TEST_BINS = \ testd$(EXE) -OBJS = \ - testd_cmdline.o - -include $(TOPDIR)/makefiles/sub.mk # ABa: currently a special rule for cmdline.c as gengetopt is not # completly fixed yet -testd.d : testd_cmdline.h testd_cmdline.h : testd.ggo gengetopt --file-name testd_cmdline --include-getopt --conf-parser -i $< testd_cmdline.c : testd.ggo @@ -26,14 +22,15 @@ testd_cmdline.c : testd.ggo testd_cmdline.o : testd_cmdline.c testd_cmdline.h $(CC) -c -o $@ $< -testd: $(TOPDIR)/src/libwolf.a +testd: $(TOPDIR)/src/libwolf.a testd_cmdline.o -local_all: testd_cmdline.h +local_all: local_clean: + -@rm -f testd_cmdline.o local_distclean: - -@rm testd_cmdline.c testd_cmdline.h + -@rm -f testd_cmdline.c testd_cmdline.h local_test: @fakeroot ./testd -d -c ./testd.conf && \ diff --git a/tests/daemon/README b/tests/daemon/README new file mode 100644 index 0000000..c706f38 --- /dev/null +++ b/tests/daemon/README @@ -0,0 +1,13 @@ +This example serves as a template for writting your own daemons. + +command line parser +------------------- + +This test needs 'gengetopt' to parse the command line arguments of the daemon. + +Get it from http://www.gnu.org/software/gengetopt/gengetopt.html (many +distributions package a far too old version!) when you encounter problems. + +This by no means implies that you are forced to use gengetopt together with +WolfBones, you can as well write your own parser, use getopt, getopt_long, +use popt or something different. diff --git a/tests/daemon/testd.c b/tests/daemon/testd.c index 0a9c45d..47dad8e 100644 --- a/tests/daemon/testd.c +++ b/tests/daemon/testd.c @@ -8,7 +8,9 @@ #include "daemon/daemon.h" /* Unix daemonizing code */ #include "daemon/signals.h" /* signal suspension */ +#ifndef MAKE_DEPENDENCIES #include "testd_cmdline.h" /* for command line and option parsing (gengetopt) */ +#endif #define DEFAULT_CONFIG_FILE "/etc/" CMDLINE_PARSER_PACKAGE ".conf" diff --git a/tests/port/GNUmakefile b/tests/port/GNUmakefile index 0e83dd8..8f2e455 100644 --- a/tests/port/GNUmakefile +++ b/tests/port/GNUmakefile @@ -6,7 +6,7 @@ INCLUDE_LIBS = \ INCLUDE_DIRS = \ -I$(TOPDIR)/include/wolf -I. -I$(TOPDIR)/src -BINS = \ +TEST_BINS = \ test_strdup$(EXE) \ test_strerror_r$(EXE) \ test_strcasecmp$(EXE) \ @@ -20,7 +20,7 @@ local_clean: local_distclean: -local_test: all +local_test: @echo "Testing strdup.." @./test_strdup >/dev/null @echo "Testing strerror_r..." diff --git a/tests/port/test_strcasecmp.c b/tests/port/test_strcasecmp.c index fb17eed..48b2ed1 100644 --- a/tests/port/test_strcasecmp.c +++ b/tests/port/test_strcasecmp.c @@ -1,13 +1,7 @@ #include "port/sys.h" -#ifdef HAVE_STRCASECMP -#define SAVE_HAVE_STRCASECMP -#undef HAVE_STRCASECMP -#endif +#define TEST_STRCASECMP #include "port/string.c" /* for strcasecmp */ -#ifdef SAVE_HAVE_STRCASECMP -#undef strcasecmp -#endif #include <stdlib.h> /* for EXIT_SUCCESS, EXIT_FAILURE */ diff --git a/tests/port/test_strdup.c b/tests/port/test_strdup.c index 8d08e1b..d8e5959 100644 --- a/tests/port/test_strdup.c +++ b/tests/port/test_strdup.c @@ -1,13 +1,7 @@ #include "port/sys.h" -#ifdef HAVE_STRDUP -#define SAVE_HAVE_STRDUP -#undef HAVE_STRDUP -#endif +#define TEST_STRDUP #include "port/string.c" /* for strdup */ -#ifdef SAVE_HAVE_STRDUP -#undef strdup -#endif #include <stdlib.h> /* for exit, EXIT_SUCCESS, free */ diff --git a/tests/port/test_strerror_r.c b/tests/port/test_strerror_r.c index 0ff53d6..4d5eb7b 100644 --- a/tests/port/test_strerror_r.c +++ b/tests/port/test_strerror_r.c @@ -1,16 +1,11 @@ #include "port/sys.h" -#ifdef HAVE_STRERROR_R -#define SAVE_HAVE_STRERROR_R -#undef HAVE_STRERROR_R -#endif +#define TEST_STRERROR_R #include "port/string.c" /* for strerror_r */ -#ifdef SAVE_HAVE_STRERROR_R -#undef strerror_r -#endif #include <stdlib.h> /* for exit, EXIT_SUCCESS, free */ #include <stdio.h> /* for printf */ +#include <errno.h> /* for errno */ int main( void ) { int i; diff --git a/tests/port/test_strncasecmp.c b/tests/port/test_strncasecmp.c index 0483c41..3700613 100644 --- a/tests/port/test_strncasecmp.c +++ b/tests/port/test_strncasecmp.c @@ -1,13 +1,7 @@ #include "port/sys.h" -#ifdef HAVE_STRNCASECMP -#define SAVE_HAVE_STRNCASECMP -#undef HAVE_STRNCASECMP -#endif +#define TEST_STRNCASECMP #include "port/string.c" /* for strcasecmp */ -#ifdef SAVE_HAVE_STRNCASECMP -#undef strncasecmp -#endif #include <stdlib.h> /* for EXIT_SUCCESS, EXIT_FAILURE */ |