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)'
16 # turn off evil implicit rules
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
)
46 $(foreach d
,$(DIRS
),$(eval
$(call default_template
,$(d
))))
49 math.BINS_TEMPL
:=bin.exe
52 D
:=$$(patsubst %/,%,$$(dir $(1)))
54 $(1).BINS
:= $$($$(D
).BINS_TEMPL
:bin
%=$(B
)/$(1)%)
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
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
)
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
80 rm -f
$$(filter-out $(B
)/$(1)/%-static.err
,$$($(1).ERRS
))
82 rm -f
$$(filter $(B
)/$(1)/%,$$(OBJS
) $$(LOBJS
) $$(BINS
) $$(LIBS
)) $(B
)/$(1)/*.err
83 $(B
)/$(1)/REPORT
: $$($(1).ERRS
)
84 cat
$(B
)/$(1)/*.err
>$$@
86 $(B
)/REPORT
: $(B
)/$(1)/REPORT
87 .PHONY
: $(B
)/$(1)/all $(B
)/$(1)/clean
89 $(foreach d
,$(DIRS
),$(eval
$(call target_template
,$(d
))))
91 $(B
)/common
/libtest.a
: $(common.OBJS
)
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
)
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
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
121 grep FAIL
$< || echo PASS
123 rm -f
$(OBJS
) $(BINS
) $(LIBS
) $(B
)/common
/libtest.a
$(B
)/common
/runtest.exe
$(B
)/common
/options.h
$(B
)/*/*.err
125 rm -f
$(B
)/REPORT
$(B
)/*/REPORT
130 $(CC
) $(CFLAGS
) $($*.CFLAGS
) -c
-o
$@
$< 2>$@.err || echo BUILDERROR
$@
; cat
$@.err
132 $(CC
) $(CFLAGS
) $($*.CFLAGS
) -S
-o
$@
$< || echo BUILDERROR
$@
; cat
$@.err
134 $(CC
) $(CFLAGS
) $($*.CFLAGS
) -fPIC
-DSHARED
-c
-o
$@
$< 2>$@.err || echo BUILDERROR
$@
; cat
$@.err
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
140 $(CC
) $(LDFLAGS
) $($*.LDFLAGS
) -o
$@
$(sort $< $($*.OBJS
)) $(LDLIBS
) $($*.LDLIBS
) 2>$@.
ld.err || echo BUILDERROR
$@
; cat
$@.
ld.err
151 $(RUN_TEST
) $< >$@ || true
153 .PHONY
: all run
clean cleanall