|
Szabolcs Nagy |
cfa23c |
SRCS:=$(sort $(wildcard src/*/*.c))
|
|
Szabolcs Nagy |
cfa23c |
OBJS:=$(SRCS:%.c=%.o)
|
|
Szabolcs Nagy |
cfa23c |
DIRS:=$(sort $(wildcard src/*))
|
|
Szabolcs Nagy |
cfa23c |
NAMES:=$(OBJS:.o=)
|
|
Szabolcs Nagy |
cfa23c |
SPEC_PATTERNS:=src/common/% src/api/% src/math/%
|
|
Szabolcs Nagy |
cfa23c |
CFLAGS:=-Isrc/common
|
|
Szabolcs Nagy |
cfa23c |
LDLIBS:=src/common/libtest.a
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
-include config.mak
|
|
nsz |
7308b3 |
|
|
nsz |
8f27a3 |
all:
|
|
Szabolcs Nagy |
cfa23c |
%.mk:
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
define template
|
|
Szabolcs Nagy |
cfa23c |
$(1).BINS := $(1) $(1)-static
|
|
Szabolcs Nagy |
cfa23c |
D:=$$(dir $(1))
|
|
Szabolcs Nagy |
cfa23c |
N:=$(1)
|
|
Szabolcs Nagy |
cfa23c |
-include $(1).mk
|
|
Szabolcs Nagy |
cfa23c |
$(1) $(1)-static: $$($(1).OBJS)
|
|
Szabolcs Nagy |
cfa23c |
$(1).so: $$($(1).LOBJS)
|
|
Szabolcs Nagy |
cfa23c |
endef
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
$(foreach n,$(filter-out $(SPEC_PATTERNS),$(NAMES)),$(eval $(call template,$(n))))
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
MBINS:=$(filter src/math/%,$(NAMES))
|
|
Szabolcs Nagy |
cfa23c |
BINS:=$(foreach n,$(NAMES),$($(n).BINS)) src/api/main $(MBINS)
|
|
Szabolcs Nagy |
cfa23c |
LIBS:=$(foreach n,$(NAMES),$($(n).LIBS)) src/common/libtest.a
|
|
Szabolcs Nagy |
cfa23c |
ERRS:=$(BINS:%=%.err)
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
define target_template
|
|
Szabolcs Nagy |
cfa23c |
$(1)/all: $(1)/REPORT
|
|
Szabolcs Nagy |
cfa23c |
$(1)/clean:
|
|
Szabolcs Nagy |
cfa23c |
rm -f $$(filter $(1)/%,$$(OBJS) $$(BINS) $$(LIBS)) $(1)/*.err
|
|
Szabolcs Nagy |
cfa23c |
$(1)/REPORT: $$(filter $(1)/%,$$(ERRS))
|
|
Szabolcs Nagy |
cfa23c |
cat $(1)/*.err >$$@
|
|
Szabolcs Nagy |
cfa23c |
REPORT: $(1)/REPORT
|
|
Szabolcs Nagy |
cfa23c |
.PHONY: $(1)/all $(1)/clean
|
|
Szabolcs Nagy |
cfa23c |
endef
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
$(foreach d,$(DIRS),$(eval $(call target_template,$(d))))
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
all:REPORT
|
|
nsz |
8f27a3 |
clean:
|
|
Szabolcs Nagy |
cfa23c |
rm -f $(OBJS) $(BINS) $(LIBS) src/*/*.err
|
|
Szabolcs Nagy |
cfa23c |
cleanall: clean
|
|
Szabolcs Nagy |
cfa23c |
rm -f REPORT src/*/REPORT
|
|
Szabolcs Nagy |
cfa23c |
REPORT:
|
|
Szabolcs Nagy |
cfa23c |
cat $^ |tee $@
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
src/common/libtest.a: $(filter src/common/%,$(OBJS))
|
|
Szabolcs Nagy |
cfa23c |
rm -f $@
|
|
Szabolcs Nagy |
cfa23c |
$(AR) rc $@ $^
|
|
Szabolcs Nagy |
cfa23c |
$(RANLIB) $@
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
b95022 |
$(BINS) $(LIBS): src/common/libtest.a
|
|
Szabolcs Nagy |
cfa23c |
$(OBJS): src/common/test.h
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
src/common/mtest.o: src/common/mtest.h
|
|
Szabolcs Nagy |
cfa23c |
$(MBINS:%=%.o): src/common/mtest.h
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
IOBJS:=$(filter src/api/%,$(OBJS))
|
|
Szabolcs Nagy |
cfa23c |
src/api/main: $(IOBJS)
|
|
Szabolcs Nagy |
cfa23c |
src/api/main.OBJS:=$(IOBJS)
|
|
Szabolcs Nagy |
cfa23c |
$(IOBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700
|
|
Szabolcs Nagy |
cfa23c |
$(IOBJS):CFLAGS+=-DX_PS -DX_TPS -DX_SS
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
%.o: %.c
|
|
Szabolcs Nagy |
cfa23c |
$(CC) $(CFLAGS) $($*.CFLAGS) -c -o $@ $< 2>$@.err || echo BUILDERROR $@
|
|
Szabolcs Nagy |
cfa23c |
%.s: %.c
|
|
Szabolcs Nagy |
cfa23c |
$(CC) $(CFLAGS) $($*.CFLAGS) -S -o $@ $< || echo BUILDERROR $@
|
|
Szabolcs Nagy |
cfa23c |
%.lo: %.c
|
|
Szabolcs Nagy |
cfa23c |
$(CC) $(CFLAGS) $($*.CFLAGS) -fPIC -DSHARED -c -o $@ $< 2>$@.err || echo BUILDERROR $@
|
|
Szabolcs Nagy |
cfa23c |
%.so: %.lo
|
|
Szabolcs Nagy |
cfa23c |
$(CC) -shared $(LDFLAGS) $($@.LDFLAGS) -o $@ $< $($*.LOBJS) $(LDLIBS) $($@.LDLIBS) 2>$@.err || echo BUILDERROR $@
|
|
Szabolcs Nagy |
cfa23c |
%-static: %.o
|
|
Szabolcs Nagy |
cfa23c |
$(CC) -static $(LDFLAGS) $($@.LDFLAGS) -o $@ $< $($*.OBJS) $(LDLIBS) $($@.LDLIBS) 2>$@.err || echo BUILDERROR $@
|
|
Szabolcs Nagy |
cfa23c |
%: %.o
|
|
Szabolcs Nagy |
cfa23c |
$(CC) $(LDFLAGS) $($@.LDFLAGS) -o $@ $< $($@.OBJS) $(LDLIBS) $($@.LDLIBS) 2>$@.err || echo BUILDERROR $@
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
%.o.err: %.o
|
|
Szabolcs Nagy |
cfa23c |
touch $@
|
|
Szabolcs Nagy |
cfa23c |
%.lo.err: %.lo
|
|
Szabolcs Nagy |
cfa23c |
touch $@
|
|
Szabolcs Nagy |
cfa23c |
%.so.err: %.so
|
|
Szabolcs Nagy |
cfa23c |
touch $@
|
|
Szabolcs Nagy |
cfa23c |
%.err: %
|
|
Szabolcs Nagy |
cfa23c |
# TODO: proper wrapping that records exit status
|
|
Szabolcs Nagy |
cfa23c |
./$< 2>/dev/null >$@ || true
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
.PHONY: all clean cleanall
|
|
Szabolcs Nagy |
cfa23c |
|