more comment to the malloc(0) test
[libc-test] / Makefile
index 3383bad..55e0a32 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,84 +1,93 @@
 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
 
--include config.mak
-
 all:
 %.mk:
 
+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
+
+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
 
-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
+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 $@
@@ -100,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