diff --git a/Makefile b/Makefile index 55e0a32..77e85a1 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ +B:=src SRCS:=$(sort $(wildcard src/*/*.c)) -OBJS:=$(SRCS:%.c=%.o) -DIRS:=$(sort $(wildcard src/*)) -NAMES:=$(OBJS:.o=) +OBJS:=$(SRCS:src/%.c=$(B)/%.o) +DIRS:=$(patsubst src/%/,%,$(sort $(wildcard src/*/))) +BDIRS:=$(DIRS:%=$(B)/%) +NAMES:=$(SRCS:src/%.c=%) CFLAGS:=-Isrc/common -LDLIBS:=src/common/libtest.a +LDLIBS:=$(B)/common/libtest.a all: %.mk: @@ -15,28 +17,28 @@ config.mak: define default_template $(1).BINS_TEMPL:=bin bin-static $(1).NAMES:=$$(filter $(1)/%,$$(NAMES)) -$(1).OBJS:=$$($(1).NAMES:%=%.o) +$(1).OBJS:=$$($(1).NAMES:%=$(B)/%.o) endef $(foreach d,$(DIRS),$(eval $(call default_template,$(d)))) -src/common.BINS_TEMPL:= -src/api.BINS_TEMPL:= -src/math.BINS_TEMPL:=bin +common.BINS_TEMPL:= +api.BINS_TEMPL:= +math.BINS_TEMPL:=bin define template 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) +$(1).BINS := $$($$(D).BINS_TEMPL:bin%=$(B)/$(1)%) +-include src/$(1).mk +#$$(warning D $$(D) N $$(N) B $$($(1).BINS)) +$(B)/$(1) $(B)/$(1)-static: $$($(1).OBJS) +$(B)/$(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 +$(B)/$(1)-static.err: $(B)/$(1).err endef $(foreach n,$(NAMES),$(eval $(call template,$(n)))) -BINS:=$(foreach n,$(NAMES),$($(n).BINS)) src/api/main -LIBS:=$(foreach n,$(NAMES),$($(n).LIBS)) src/common/run +BINS:=$(foreach n,$(NAMES),$($(n).BINS)) $(B)/api/main +LIBS:=$(foreach n,$(NAMES),$($(n).LIBS)) $(B)/common/run ERRS:=$(BINS:%=%.err) debug: @@ -47,60 +49,62 @@ debug: @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: $$($(1).ERRS) - cat $(1)/*.err >$$@ -run: $(1)/run -REPORT: $(1)/REPORT -.PHONY: $(1)/all $(1)/clean +$(1).ERRS:=$$(filter $(B)/$(1)/%,$$(ERRS)) +$(B)/$(1)/all: $(B)/$(1)/REPORT +# TODO: $(B)/common/run collides with the run binary target +$(B)/$(1)/run: $(B)/$(1)/cleanerr $(B)/$(1)/REPORT +$(B)/$(1)/cleanerr: + rm -f $$(filter-out $(B)/$(1)/%-static.err,$$($(1).ERRS)) +$(B)/$(1)/clean: + rm -f $$(filter $(B)/$(1)/%,$$(OBJS) $$(BINS) $$(LIBS)) $(B)/$(1)/*.err +$(B)/$(1)/REPORT: $$($(1).ERRS) + cat $(B)/$(1)/*.err >$$@ +run: $(B)/$(1)/run +$(B)/REPORT: $(B)/$(1)/REPORT +.PHONY: $(B)/$(1)/all $(B)/$(1)/clean endef $(foreach d,$(DIRS),$(eval $(call target_template,$(d)))) -src/common/libtest.a: $(src/common.OBJS) +$(B)/common/libtest.a: $(common.OBJS) rm -f $@ $(AR) rc $@ $^ $(RANLIB) $@ -$(ERRS): src/common/run -$(BINS) $(LIBS): src/common/libtest.a -$(OBJS): src/common/test.h +$(ERRS): $(B)/common/run | $(BDIRS) +$(BINS) $(LIBS): $(B)/common/libtest.a +$(OBJS): src/common/test.h | $(BDIRS) +$(BDIRS): + mkdir -p $@ -src/common/mtest.o: src/common/mtest.h -$(src/math.OBJS): src/common/mtest.h +$(B)/common/mtest.o: src/common/mtest.h +$(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 +$(B)/api/main: $(api.OBJS) +api/main.OBJS:=$(api.OBJS) +$(api.OBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700 +$(api.OBJS):CFLAGS+=-DX_PS -DX_TPS -DX_SS -all:REPORT -run:REPORT +all:$(B)/REPORT +run:$(B)/REPORT clean: - rm -f $(OBJS) $(BINS) $(LIBS) src/common/libtest.a src/common/run src/*/*.err + rm -f $(OBJS) $(BINS) $(LIBS) $(B)/common/libtest.a $(B)/common/run $(B)/*/*.err cleanall: clean - rm -f REPORT src/*/REPORT -REPORT: + rm -f $(B)/REPORT $(B)/*/REPORT +$(B)/REPORT: cat $^ |tee $@ -%.o: %.c +$(B)/%.o: src/%.c $(CC) $(CFLAGS) $($*.CFLAGS) -c -o $@ $< 2>$@.err || echo BUILDERROR $@ -%.s: %.c +$(B)/%.s: src/%.c $(CC) $(CFLAGS) $($*.CFLAGS) -S -o $@ $< || echo BUILDERROR $@ -%.lo: %.c +$(B)/%.lo: src/%.c $(CC) $(CFLAGS) $($*.CFLAGS) -fPIC -DSHARED -c -o $@ $< 2>$@.err || echo BUILDERROR $@ -%.so: %.lo - $(CC) -shared $(LDFLAGS) $($@.LDFLAGS) -o $@ $< $($*.LOBJS) $(LDLIBS) $($@.LDLIBS) 2>$@.err || echo BUILDERROR $@ -%-static: %.o - $(CC) -static $(LDFLAGS) $($@.LDFLAGS) -o $@ $< $($*.OBJS) $(LDLIBS) $($@.LDLIBS) 2>$@.err || echo BUILDERROR $@ -%: %.o - $(CC) $(LDFLAGS) $($@.LDFLAGS) -o $@ $< $($@.OBJS) $(LDLIBS) $($@.LDLIBS) 2>$@.err || echo BUILDERROR $@ +$(B)/%.so: $(B)/%.lo + $(CC) -shared $(LDFLAGS) $($*.so.LDFLAGS) -o $@ $< $($*.so.LOBJS) $(LDLIBS) $($*.so.LDLIBS) 2>$@.err || echo BUILDERROR $@ +$(B)/%-static: $(B)/%.o + $(CC) -static $(LDFLAGS) $($*-static.LDFLAGS) -o $@ $< $($*-static.OBJS) $(LDLIBS) $($*-static.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@ +$(B)/%: $(B)/%.o + $(CC) $(LDFLAGS) $($*.LDFLAGS) -o $@ $< $($*.OBJS) $(LDLIBS) $($*.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@ %.o.err: %.o touch $@ @@ -108,8 +112,10 @@ REPORT: touch $@ %.so.err: %.so touch $@ +%.ld.err: % + touch $@ %.err: % - src/common/run ./$< 2>/dev/null >$@ || true + $(B)/common/run ./$< 2>/dev/null >$@ || true .PHONY: all run clean cleanall diff --git a/README b/README index ccf9fda..61b0722 100644 --- a/README +++ b/README @@ -68,14 +68,17 @@ Rich Felker, regression tests should contain reference of the bug build system: the main non-file make targets are all, run, clean and cleanall. -(cleanall removes the reports as well, run reruns the dynamically +(cleanall removes the reports unlike clean, 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 +make variable can be overridden from config.mak or the make command line, +the variable B sets the build directory which is src by default + +for each directory under src there are targets like $(B)/directory/all, +$(B)/directory/run and $(B)/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 +invokes the top level make with B=src src/directory/foo for the foo +target, so it is possible to work only under a specific test directory the build and runtime errors of each target are accumulated into a target.err file and in the end they are concatenated into a REPORT @@ -85,9 +88,9 @@ dynamic linked and a static linked executable test binary by default, this behaviour can be changed by a similarly named .mk file changing make variables and specifying additional rules: -$(N) is the name of the binary target (the file name without the .c) -$(N)-static is the name of the static binary target -$(D) is the directory +$(B)/$(N) is the name of the binary target (the file name without the .c) +$(B)/$(N)-static is the name of the static binary target +$(B)/$(D) is the build directory $(N).CFLAGS are added to the CFLAGS at compilation $(N).LDFLAGS are added to the LDFLAGS at linking $(N).LDLIBS are added to the LDLIBS at linking diff --git a/src/api/Makefile b/src/api/Makefile index c37b86a..cd1aa1f 100644 --- a/src/api/Makefile +++ b/src/api/Makefile @@ -1,4 +1,4 @@ all: %: - $(MAKE) -C ../.. src/api/$@ + $(MAKE) -C ../.. B=src src/api/$@ diff --git a/src/common/Makefile b/src/common/Makefile index 351583d..343df71 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -1,4 +1,4 @@ all: %: - $(MAKE) -C ../.. src/common/$@ + $(MAKE) -C ../.. B=src src/common/$@ diff --git a/src/functional/Makefile b/src/functional/Makefile index a6e5208..e0d02f9 100644 --- a/src/functional/Makefile +++ b/src/functional/Makefile @@ -1,4 +1,4 @@ all: %: - $(MAKE) -C ../.. src/functional/$@ + $(MAKE) -C ../.. B=src src/functional/$@ diff --git a/src/functional/dlopen.mk b/src/functional/dlopen.mk index 97d3bcc..a794074 100644 --- a/src/functional/dlopen.mk +++ b/src/functional/dlopen.mk @@ -1,3 +1,3 @@ -$(N).BINS:=$(N) +$(N).BINS:=$(B)/$(N) $(N).LDFLAGS:=-rdynamic -$(N).err: $(D)/dlopen_dso.so +$(B)/$(N).err: $(B)/$(D)/dlopen_dso.so diff --git a/src/functional/dlopen_dso.mk b/src/functional/dlopen_dso.mk index b691b45..2b1c25b 100644 --- a/src/functional/dlopen_dso.mk +++ b/src/functional/dlopen_dso.mk @@ -1,2 +1,2 @@ $(N).BINS:= -$(N).LIBS:=$(N).so +$(N).LIBS:=$(B)/$(N).so diff --git a/src/functional/tls_align.mk b/src/functional/tls_align.mk index 7058f68..654f7c9 100644 --- a/src/functional/tls_align.mk +++ b/src/functional/tls_align.mk @@ -1,6 +1,6 @@ -$(N).LDLIBS := $(D)/tls_align_dso.so -$(N)-static.LDLIBS := $(D)/tls_align_dso.o +$(N).LDLIBS := $(B)/$(D)/tls_align_dso.so +$(N)-static.LDLIBS := $(B)/$(D)/tls_align_dso.o -$(N): $(D)/tls_align_dso.so -$(N)-static: $(D)/tls_align_dso.o +$(B)/$(N): $(B)/$(D)/tls_align_dso.so +$(B)/$(N)-static: $(B)/$(D)/tls_align_dso.o diff --git a/src/functional/tls_align_dlopen.mk b/src/functional/tls_align_dlopen.mk index 72f9694..b462446 100644 --- a/src/functional/tls_align_dlopen.mk +++ b/src/functional/tls_align_dlopen.mk @@ -1,2 +1,2 @@ -$(N).BINS=$(N) -$(N).err: $(D)/tls_align_dso.so +$(N).BINS=$(B)/$(N) +$(B)/$(N).err: $(B)/$(D)/tls_align_dso.so diff --git a/src/functional/tls_align_dso.mk b/src/functional/tls_align_dso.mk index b691b45..2b1c25b 100644 --- a/src/functional/tls_align_dso.mk +++ b/src/functional/tls_align_dso.mk @@ -1,2 +1,2 @@ $(N).BINS:= -$(N).LIBS:=$(N).so +$(N).LIBS:=$(B)/$(N).so diff --git a/src/math/Makefile b/src/math/Makefile index 7be5f7a..44fb35b 100644 --- a/src/math/Makefile +++ b/src/math/Makefile @@ -1,4 +1,4 @@ all: %: - $(MAKE) -C ../.. src/math/$@ + $(MAKE) -C ../.. B=src src/math/$@ diff --git a/src/regression/Makefile b/src/regression/Makefile index ef9690b..d0ff541 100644 --- a/src/regression/Makefile +++ b/src/regression/Makefile @@ -1,4 +1,4 @@ all: %: - $(MAKE) -C ../.. src/regression/$@ + $(MAKE) -C ../.. B=src src/regression/$@