memset test: fix padding size
[libc-test.git] / Makefile
blobcf2ab2b2c8ebef0a9eab8cb06efc7bb5d989cc83
1 B:=src
2 SRCS:=$(sort $(wildcard src/*/*.c))
3 OBJS:=$(SRCS:src/%.c=$(B)/%.o)
4 LOBJS:=$(SRCS:src/%.c=$(B)/%.lo)
5 DIRS:=$(patsubst src/%/,%,$(sort $(dir $(SRCS))))
6 BDIRS:=$(DIRS:%=$(B)/%)
7 NAMES:=$(SRCS:src/%.c=%)
8 CFLAGS:=-I$(B)/common -Isrc/common
9 LDLIBS:=$(B)/common/libtest.a
10 AR = $(CROSS_COMPILE)ar
11 RANLIB = $(CROSS_COMPILE)ranlib
12 RUN_TEST = $(RUN_WRAP) $(B)/common/runtest.exe -w '$(RUN_WRAP)'
14 all:
15 %.mk:
16 # turn off evil implicit rules
17 .SUFFIXES:
18 %: %.o
19 %: %.c
20 %: %.cc
21 %: %.C
22 %: %.cpp
23 %: %.p
24 %: %.f
25 %: %.F
26 %: %.r
27 %: %.s
28 %: %.S
29 %: %.mod
30 %: %.sh
31 %: %,v
32 %: RCS/%,v
33 %: RCS/%
34 %: s.%
35 %: SCCS/s.%
37 config.mak:
38 cp config.mak.def $@
39 -include config.mak
41 define default_template
42 $(1).BINS_TEMPL:=bin.exe bin-static.exe
43 $(1).NAMES:=$$(filter $(1)/%,$$(NAMES))
44 $(1).OBJS:=$$($(1).NAMES:%=$(B)/%.o)
45 endef
46 $(foreach d,$(DIRS),$(eval $(call default_template,$(d))))
47 common.BINS_TEMPL:=
48 api.BINS_TEMPL:=
49 math.BINS_TEMPL:=bin.exe
51 define template
52 D:=$$(patsubst %/,%,$$(dir $(1)))
53 N:=$(1)
54 $(1).BINS := $$($$(D).BINS_TEMPL:bin%=$(B)/$(1)%)
55 -include src/$(1).mk
56 #$$(warning D $$(D) N $$(N) B $$($(1).BINS))
57 $(B)/$(1).exe $(B)/$(1)-static.exe: $$($(1).OBJS)
58 $(B)/$(1).so: $$($(1).LOBJS)
59 # make sure dynamic and static binaries are not run parallel (matters for some tests eg ipc)
60 $(B)/$(1)-static.err: $(B)/$(1).err
61 endef
62 $(foreach n,$(NAMES),$(eval $(call template,$(n))))
64 BINS:=$(foreach n,$(NAMES),$($(n).BINS)) $(B)/api/main.exe
65 LIBS:=$(foreach n,$(NAMES),$($(n).LIBS)) $(B)/common/runtest.exe
66 ERRS:=$(BINS:%.exe=%.err)
68 debug:
69 @echo NAMES $(NAMES)
70 @echo BINS $(BINS)
71 @echo LIBS $(LIBS)
72 @echo ERRS $(ERRS)
73 @echo DIRS $(DIRS)
75 define target_template
76 $(1).ERRS:=$$(filter $(B)/$(1)/%,$$(ERRS))
77 $(B)/$(1)/all: $(B)/$(1)/REPORT
78 $(B)/$(1)/run: $(B)/$(1)/cleanerr $(B)/$(1)/REPORT
79 $(B)/$(1)/cleanerr:
80 rm -f $$(filter-out $(B)/$(1)/%-static.err,$$($(1).ERRS))
81 $(B)/$(1)/clean:
82 rm -f $$(filter $(B)/$(1)/%,$$(OBJS) $$(LOBJS) $$(BINS) $$(LIBS)) $(B)/$(1)/*.err
83 $(B)/$(1)/REPORT: $$($(1).ERRS)
84 cat $(B)/$(1)/*.err >$$@
85 run: $(B)/$(1)/run
86 $(B)/REPORT: $(B)/$(1)/REPORT
87 .PHONY: $(B)/$(1)/all $(B)/$(1)/clean
88 endef
89 $(foreach d,$(DIRS),$(eval $(call target_template,$(d))))
91 $(B)/common/libtest.a: $(common.OBJS)
92 rm -f $@
93 $(AR) rc $@ $^
94 $(RANLIB) $@
96 $(B)/common/all: $(B)/common/runtest.exe
98 $(ERRS): $(B)/common/runtest.exe | $(BDIRS)
99 $(BINS) $(LIBS): $(B)/common/libtest.a
100 $(OBJS): src/common/test.h | $(BDIRS)
101 $(BDIRS):
102 mkdir -p $@
104 $(B)/common/options.h: src/common/options.h.in
105 $(CC) -E - <$< | awk ' \
106 /optiongroups_unistd_end/ {s=1; next} \
107 !s || !NF || /^#/ {next} \
108 !a {a=$$1; if(NF==1)next} \
109 {print "#define "a" "$$NF; a=""}' >$@.tmp
110 mv $@.tmp $@
112 $(B)/common/mtest.o: src/common/mtest.h
113 $(math.OBJS): src/common/mtest.h
115 $(B)/api/main.exe: $(api.OBJS)
116 api/main.OBJS:=$(api.OBJS)
117 $(api.OBJS):$(B)/common/options.h
118 $(api.OBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700
120 all run: $(B)/REPORT
121 grep FAIL $< || echo PASS
122 clean:
123 rm -f $(OBJS) $(BINS) $(LIBS) $(B)/common/libtest.a $(B)/common/runtest.exe $(B)/common/options.h $(B)/*/*.err
124 cleanall: clean
125 rm -f $(B)/REPORT $(B)/*/REPORT
126 $(B)/REPORT:
127 cat $^ >$@
129 $(B)/%.o:: src/%.c
130 $(CC) $(CFLAGS) $($*.CFLAGS) -c -o $@ $< 2>$@.err || echo BUILDERROR $@; cat $@.err
131 $(B)/%.s:: src/%.c
132 $(CC) $(CFLAGS) $($*.CFLAGS) -S -o $@ $< || echo BUILDERROR $@; cat $@.err
133 $(B)/%.lo:: src/%.c
134 $(CC) $(CFLAGS) $($*.CFLAGS) -fPIC -DSHARED -c -o $@ $< 2>$@.err || echo BUILDERROR $@; cat $@.err
135 $(B)/%.so: $(B)/%.lo
136 $(CC) -shared $(LDFLAGS) $($*.so.LDFLAGS) -o $@ $(sort $< $($*.so.LOBJS)) $(LDLIBS) $($*.so.LDLIBS) 2>$@.err || echo BUILDERROR $@; cat $@.err
137 $(B)/%-static.exe: $(B)/%.o
138 $(CC) -static $(LDFLAGS) $($*-static.LDFLAGS) -o $@ $(sort $< $($*-static.OBJS)) $(LDLIBS) $($*-static.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@; cat $@.ld.err
139 $(B)/%.exe: $(B)/%.o
140 $(CC) $(LDFLAGS) $($*.LDFLAGS) -o $@ $(sort $< $($*.OBJS)) $(LDLIBS) $($*.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@; cat $@.ld.err
142 %.o.err: %.o
143 touch $@
144 %.lo.err: %.lo
145 touch $@
146 %.so.err: %.so
147 touch $@
148 %.ld.err: %.exe
149 touch $@
150 %.err: %.exe
151 $(RUN_TEST) $< >$@ || true
153 .PHONY: all run clean cleanall