-
Notifications
You must be signed in to change notification settings - Fork 11
/
makefile
66 lines (50 loc) · 1.93 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Expect to be invoked either as:
# "make <targets>"
# or as
# "make -f .../makefile <targets>"
# so: the first word in $(MAKEFILE_LIST) will be the top-level
# makefile and therefore the $(dir) function will give us the relative
# directory. If it is "./" assume we're building inside the source dir
# and don't need to fiddle with the vpaths, otherwise ./ assume we're
# outside the source dir and set the vpath to point to the sources
SRCDIR := $(patsubst %/,%,$(dir $(firstword $(MAKEFILE_LIST))))
SUBDIRS = src example/platform example/configs/p2p example/throughput example/roundtrip
vpath %.c $(SUBDIRS:%=$(SRCDIR)/%)
vpath %.h $(SUBDIRS:%=$(SRCDIR)/%)
TARGETS = bin/roundtrip bin/throughput bin/psrid
ZHE_PLATFORM := platform-udp.c
ZHE := $(notdir $(wildcard $(SRCDIR)/src/*.c)) $(ZHE_PLATFORM)
OPT = #-O2
CFLAGS = $(OPT) -std=c99 -pedantic -g -Wall $(SUBDIRS:%=-I$(SRCDIR)/%)
LDFLAGS = $(OPT)
SRC_roundtrip = roundtrip.c zhe-util.c $(ZHE)
SRC_throughput = throughput.c zhe-util.c $(ZHE)
SRC_psrid = psrid.c zhe-util.c $(ZHE)
.PHONY: all clean zz test-configs
.PRECIOUS: %.o %/.STAMP
.SECONDEXPANSION:
%: %.o
%: %.c
%.o: %.c
all: $(TARGETS)
$(TARGETS): $$(patsubst %.c, gen/%.o, $$(SRC_$$(notdir $$@)))
test-configs: $(addprefix test/build.configs/throughput-, $(notdir $(wildcard example/configs/*)))
%/.STAMP:
[ -d $* ] || mkdir -p $*
touch $@
test/build.configs/throughput-%: test/build.configs/.STAMP $(SRC_throughput)
$(CC) -Iexample/configs/$* $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(wordlist 2, 999, $^) -o $@
bin/%: | bin/.STAMP
$(CC) $(LDFLAGS) $^ -o $@
gen/%.o: %.c gen/.STAMP
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
gen/psrid.o: test/psrid.c gen/.STAMP
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
gen/%.d: %.c gen/.STAMP
$(CC) $(CPPFLAGS) $(CFLAGS) -M $< -o $@
clean: ; rm -rf $(TARGETS) gen
zz:
@echo $(ZHE)
ifneq ($(MAKECMDGOALS),clean)
-include $(patsubst %.c, gen/%.d, $(sort $(foreach x, $(TARGETS), $(SRC_$(notdir $x)))))
endif