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)'
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
- <$< | 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
118 rm -f
$(OBJS
) $(BINS
) $(LIBS
) $(B
)/common
/libtest.a
$(B
)/common
/runtest.exe
$(B
)/common
/options.h
$(B
)/*/*.err
120 rm -f
$(B
)/REPORT
$(B
)/*/REPORT
125 $(CC
) $(CFLAGS
) $($*.CFLAGS
) -c
-o
$@
$< 2>$@.err || echo BUILDERROR
$@
; cat
$@.err
127 $(CC
) $(CFLAGS
) $($*.CFLAGS
) -S
-o
$@
$< || echo BUILDERROR
$@
; cat
$@.err
129 $(CC
) $(CFLAGS
) $($*.CFLAGS
) -fPIC
-DSHARED
-c
-o
$@
$< 2>$@.err || echo BUILDERROR
$@
; cat
$@.err
131 $(CC
) -shared
$(LDFLAGS
) $($*.so.LDFLAGS
) -o
$@
$< $($*.so.LOBJS
) $(LDLIBS
) $($*.so.LDLIBS
) 2>$@.err || echo BUILDERROR
$@
; cat
$@.err
132 $(B
)/%-static.exe
: $(B
)/%.o
133 $(CC
) -static
$(LDFLAGS
) $($*-static.LDFLAGS
) -o
$@
$< $($*-static.OBJS
) $(LDLIBS
) $($*-static.LDLIBS
) 2>$@.
ld.err || echo BUILDERROR
$@
; cat
$@.
ld.err
135 $(CC
) $(LDFLAGS
) $($*.LDFLAGS
) -o
$@
$< $($*.OBJS
) $(LDLIBS
) $($*.LDLIBS
) 2>$@.
ld.err || echo BUILDERROR
$@
; cat
$@.
ld.err
146 $(RUN_TEST
) .
/$< >$@ || true
148 .PHONY
: all run
clean cleanall