forked from cloudwu/pbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (57 loc) · 1.63 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
CC = gcc
CFLAGS = -O2 -fPIC -Wall
AR = ar rc
BUILD = build
.PHONY : all lib clean tool
LIBSRCS = context.c varint.c array.c pattern.c register.c proto.c map.c alloc.c rmessage.c wmessage.c bootstrap.c stringpool.c decode.c
LIBNAME = libpbc.a
TESTSRCS = addressbook.c pattern.c pbc.c float.c map.c test.c decode.c
PROTOSRCS = addressbook.proto descriptor.proto float.proto test.proto
BUILD_O = $(BUILD)/o
all : lib test
lib : $(LIBNAME)
clean :
rm -rf $(BUILD)
$(BUILD) : $(BUILD_O)
$(BUILD_O) :
mkdir -p $@
TOOL := $(BUILD)/dump
tool : $(TOOL)
$(TOOL) : | $(BUILD)
$(TOOL) : $(LIBNAME)
$(TOOL) : tool/dump.c
cd $(BUILD) && $(CC) $(CFLAGS) -I.. -L. -o dump ../$< -lpbc
LIB_O :=
define BUILD_temp
TAR := $(BUILD_O)/$(notdir $(basename $(1)))
LIB_O := $(LIB_O) $$(TAR).o
$$(TAR).o : | $(BUILD_O)
-include $$(TAR).d
$$(TAR).o : src/$(1)
$(CC) $(CFLAGS) -c -Isrc -I. -o $$@ -MMD $$<
endef
$(foreach s,$(LIBSRCS),$(eval $(call BUILD_temp,$(s))))
$(LIBNAME) : $(LIB_O)
cd $(BUILD) && $(AR) $(LIBNAME) $(addprefix ../,$^)
TEST :=
define TEST_temp
TAR := $(BUILD)/$(notdir $(basename $(1)))
TEST := $(TEST) $$(TAR)
$$(TAR) : | $(BUILD)
$$(TAR) : $(LIBNAME)
$$(TAR) : test/$(1)
cd $(BUILD) && $(CC) $(CFLAGS) -I.. -L. -o $$(notdir $$@) ../$$< -lpbc
endef
$(foreach s,$(TESTSRCS),$(eval $(call TEST_temp,$(s))))
test : $(TEST) proto
PROTO :=
define PROTO_temp
TAR := $(BUILD)/$(notdir $(basename $(1)))
PROTO := $(PROTO) $$(TAR).pb
$$(TAR).pb : | $(BUILD)
$$(TAR).pb : test/$(1)
protoc -o$$@ $$<
endef
$(foreach s,$(PROTOSRCS),$(eval $(call PROTO_temp,$(s))))
proto : $(PROTO)
.PHONY : all lib test proto clean