Makefile changes, run target only reruns dynamic tests
authorSzabolcs Nagy <nsz@port70.net>
Wed, 24 Jul 2013 02:41:25 +0000 (02:41 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Wed, 24 Jul 2013 02:41:25 +0000 (02:41 +0000)
Makefile
README

index b65c4d7..55e0a32 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,7 @@
 SRCS:=$(sort $(wildcard src/*/*.c))
 OBJS:=$(SRCS:%.c=%.o)
-DIRS:=$(filter-out src/common,$(sort $(wildcard src/*)))
+DIRS:=$(sort $(wildcard src/*))
 NAMES:=$(OBJS:.o=)
-SPEC_PATTERNS:=src/common/% src/api/% src/math/%
 CFLAGS:=-Isrc/common
 LDLIBS:=src/common/libtest.a
 
@@ -13,74 +12,82 @@ config.mak:
        cp config.mak.def $@
 -include config.mak
 
+define default_template
+$(1).BINS_TEMPL:=bin bin-static
+$(1).NAMES:=$$(filter $(1)/%,$$(NAMES))
+$(1).OBJS:=$$($(1).NAMES:%=%.o)
+endef
+$(foreach d,$(DIRS),$(eval $(call default_template,$(d))))
+src/common.BINS_TEMPL:=
+src/api.BINS_TEMPL:=
+src/math.BINS_TEMPL:=bin
+
 define template
-$(1).BINS := $(1) $(1)-static
-D:=$$(dir $(1))
+D:=$$(patsubst %/,%,$$(dir $(1)))
 N:=$(1)
+$(1).BINS := $$($$(D).BINS_TEMPL:bin%=$(1)%)
 -include $(1).mk
+#$$(warning D $$(D) T $$($$(D).BINS_TEMPL) B $$($(1).BINS))
 $(1) $(1)-static: $$($(1).OBJS)
 $(1).so: $$($(1).LOBJS)
 # make sure dynamic and static binaries are not run parallel (matters for some tests eg ipc)
 $(1)-static.err: $(1).err
 endef
+$(foreach n,$(NAMES),$(eval $(call template,$(n))))
 
-$(foreach n,$(filter-out $(SPEC_PATTERNS),$(NAMES)),$(eval $(call template,$(n))))
-
-MBINS:=$(filter src/math/%,$(NAMES))
-BINS:=$(foreach n,$(NAMES),$($(n).BINS)) src/api/main $(MBINS)
-LIBS:=$(foreach n,$(NAMES),$($(n).LIBS))
+BINS:=$(foreach n,$(NAMES),$($(n).BINS)) src/api/main
+LIBS:=$(foreach n,$(NAMES),$($(n).LIBS)) src/common/run
 ERRS:=$(BINS:%=%.err)
 
 debug:
-       @echo MBINS $(MBINS)
+       @echo NAMES $(NAMES)
        @echo BINS $(BINS)
        @echo LIBS $(LIBS)
        @echo ERRS $(ERRS)
        @echo DIRS $(DIRS)
 
 define target_template
+$(1).ERRS:=$$(filter $(1)/%,$$(ERRS))
 $(1)/all: $(1)/REPORT
+# TODO: src/common/run collides with the run binary target
+$(1)/run: $(1)/cleanerr $(1)/REPORT
+$(1)/cleanerr:
+       rm -f $$(filter-out $(1)/%-static.err,$$($(1).ERRS))
 $(1)/clean:
        rm -f $$(filter $(1)/%,$$(OBJS) $$(BINS) $$(LIBS)) $(1)/*.err
-$(1)/REPORT: $$(filter $(1)/%,$$(ERRS))
+$(1)/REPORT: $$($(1).ERRS)
        cat $(1)/*.err >$$@
+run: $(1)/run
 REPORT: $(1)/REPORT
 .PHONY: $(1)/all $(1)/clean
 endef
-
 $(foreach d,$(DIRS),$(eval $(call target_template,$(d))))
 
-src/common/all: src/common/REPORT
-src/common/REPORT: src/common/run
-       cat src/common/*.err >$@
-REPORT: src/common/REPORT
-src/common/run: src/common/run.o src/common/libtest.a
-$(ERRS): src/common/run
-
-all:REPORT
-clean:
-       rm -f $(OBJS) $(BINS) $(LIBS) src/common/libtest.a src/common/run src/*/*.err
-cleanall: clean
-       rm -f REPORT src/*/REPORT
-REPORT:
-       cat $^ |tee $@
-
-src/common/libtest.a: $(filter src/common/%,$(OBJS))
+src/common/libtest.a: $(src/common.OBJS)
        rm -f $@
        $(AR) rc $@ $^
        $(RANLIB) $@
 
+$(ERRS): src/common/run
 $(BINS) $(LIBS): src/common/libtest.a
 $(OBJS): src/common/test.h
 
 src/common/mtest.o: src/common/mtest.h
-$(MBINS:%=%.o): src/common/mtest.h
+$(src/math.OBJS): src/common/mtest.h
 
-IOBJS:=$(filter src/api/%,$(OBJS))
-src/api/main: $(IOBJS)
-src/api/main.OBJS:=$(IOBJS)
-$(IOBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700
-$(IOBJS):CFLAGS+=-DX_PS -DX_TPS -DX_SS
+src/api/main: $(src/api.OBJS)
+src/api/main.OBJS:=$(src/api.OBJS)
+$(src/api.OBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700
+$(src/api.OBJS):CFLAGS+=-DX_PS -DX_TPS -DX_SS
+
+all:REPORT
+run:REPORT
+clean:
+       rm -f $(OBJS) $(BINS) $(LIBS) src/common/libtest.a src/common/run src/*/*.err
+cleanall: clean
+       rm -f REPORT src/*/REPORT
+REPORT:
+       cat $^ |tee $@
 
 %.o: %.c
        $(CC) $(CFLAGS) $($*.CFLAGS) -c -o $@ $< 2>$@.err || echo BUILDERROR $@
@@ -102,8 +109,7 @@ $(IOBJS):CFLAGS+=-DX_PS -DX_TPS -DX_SS
 %.so.err: %.so
        touch $@
 %.err: %
-# TODO: proper wrapping that records exit status
        src/common/run ./$< 2>/dev/null >$@ || true
 
-.PHONY: all clean cleanall
+.PHONY: all run clean cleanall
 
diff --git a/README b/README
index c4ece08..ccf9fda 100644 (file)
--- a/README
+++ b/README
@@ -48,6 +48,11 @@ may be used to simplify the code like
 #define T1(a,b) (check(a,b) || (t_error("check(%s,%s) failed\n", a, b),0))
 #define T2(f,w) (result=(f), result==(w) || (t_error("%s failed: got %s, want %s\n", #f, result, w),0))
 
+binaries should be possible to run from arbitrary directory.
+the build system runs the tests using the src/common/run tool which
+kills the test process after a timeout and reports the exit status
+in case of failure
+
 directories:
 
 src/api: interface tests, build time include header tests
@@ -62,8 +67,13 @@ Rich Felker, regression tests should contain reference of the bug
 
 build system:
 
-the targets src/directory/all and src/directory/clean build and clean
-only the specified directory, each directory has its own Makefile that
+the main non-file make targets are all, run, clean and cleanall.
+(cleanall removes the reports as well, run reruns the dynamically
+linked executables)
+
+for each directory under src there are targets like src/directory/all,
+src/directory/run and src/directory/clean to make only the contents
+of that directory, each directory has its own Makefile set up so it
 invokes the top level make with src/directory/foo for the foo target,
 so it is possible to work only under a specific test directory