add memset(buf, -5, 10) test
[libc-test.git] / Makefile
blob822fb526f6e8d82f3df8956d82a1b7177a372dbf
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:=-Isrc/common -I$(B)/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 - <$< | sed -e '1,/optiongroups_unistd_end/d' -e '/^#/d' -e '/^[[:space:]]*$$/d' -e 's/^/#define /' >$@
107 $(B)/common/mtest.o: src/common/mtest.h
108 $(math.OBJS): src/common/mtest.h
110 $(B)/api/main.exe: $(api.OBJS)
111 api/main.OBJS:=$(api.OBJS)
112 $(api.OBJS):$(B)/common/options.h
113 $(api.OBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700
115 all:$(B)/REPORT
116 run:$(B)/REPORT
117 clean:
118 rm -f $(OBJS) $(BINS) $(LIBS) $(B)/common/libtest.a $(B)/common/runtest.exe $(B)/common/options.h $(B)/*/*.err
119 cleanall: clean
120 rm -f $(B)/REPORT $(B)/*/REPORT
121 $(B)/REPORT:
122 cat $^ |tee $@
124 $(B)/%.o:: src/%.c
125 $(CC) $(CFLAGS) $($*.CFLAGS) -c -o $@ $< 2>$@.err || echo BUILDERROR $@
126 $(B)/%.s:: src/%.c
127 $(CC) $(CFLAGS) $($*.CFLAGS) -S -o $@ $< || echo BUILDERROR $@
128 $(B)/%.lo:: src/%.c
129 $(CC) $(CFLAGS) $($*.CFLAGS) -fPIC -DSHARED -c -o $@ $< 2>$@.err || echo BUILDERROR $@
130 $(B)/%.so: $(B)/%.lo
131 $(CC) -shared $(LDFLAGS) $($*.so.LDFLAGS) -o $@ $< $($*.so.LOBJS) $(LDLIBS) $($*.so.LDLIBS) 2>$@.err || echo BUILDERROR $@
132 $(B)/%-static.exe: $(B)/%.o
133 $(CC) -static $(LDFLAGS) $($*-static.LDFLAGS) -o $@ $< $($*-static.OBJS) $(LDLIBS) $($*-static.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@
134 $(B)/%.exe: $(B)/%.o
135 $(CC) $(LDFLAGS) $($*.LDFLAGS) -o $@ $< $($*.OBJS) $(LDLIBS) $($*.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@
137 %.o.err: %.o
138 touch $@
139 %.lo.err: %.lo
140 touch $@
141 %.so.err: %.so
142 touch $@
143 %.ld.err: %.exe
144 touch $@
145 %.err: %.exe
146 $(RUN_TEST) ./$< >$@ || true
148 .PHONY: all run clean cleanall