-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
130 lines (88 loc) · 2.71 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
SOURCE_DIR := src
# COMPILER := icc
COMPILER := g++
# release
BINARY_DIR := bin/lrelease
CPPFLAGS := -Wall -g -O3 `raptor-config --cflags`
LIBS := -lpthread -L/usr/local/lib `raptor-config --libs`
# debug
# BINARY_DIR := bin/ldebug
# CPPFLAGS := -g -fPIC -DDEBUG
COMPILE.cpp = $(COMPILER) $(CFLAGS) $(CPPFLAGS) -c
LINK.cpp = $(COMPILER) $(LIBS)
%.o: %.cpp
#$(call make-depend,$<,$@,$(subst .o,.d,$@))
$(COMPILE.cpp) $< -o $@
# $(call source-dir-to-binary-dir, directory-list)
source-dir-to-binary-dir = $(addprefix $(BINARY_DIR)/,$1)
# $(call source-to-object, source-file-list)
source-to-object = $(call source-dir-to-binary-dir, $(subst .cpp,.o,$1))
# $(subdirectory)
subdirectory = $(patsubst %/module.mk,%, \
$(word \
$(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
# $(call make-depend,source-file,object-file,depend-file)
define make-depend
g++ -MM \
-MF$3 \
-MP \
-MT$2 \
$(CFLAGS) \
$(CPPFLAGS) \
$(TARGET_ARCH) \
$1
endef
# $(call make-library, library-name, source-file-list)
define make-library
libraries += $(BINARY_DIR)/$1
sources += $2
$(BINARY_DIR)/$1: $(call source-dir-to-binary-dir, $(subst .cpp,.o,$2))
$(AR) $(ARFLAGS) $$@ $$^
endef
# $(call make-program, program-name, library-list, source-file-list)
define make-program
programs += $(BINARY_DIR)/$1
sources += $3
$(BINARY_DIR)/$1: $(call source-dir-to-binary-dir, $(subst .cpp,.o,$3) $2 )
$(LINK.cpp) -o $$@ $$^ -lpthread
endef
# $(compile-rules)
define compile-rules
$(foreach f,$(local_src),$(call one-compile-rule,$(call source-to-object,$f),$f))
endef
# $(call one-compile-rule, binary-file, source-file)
define one-compile-rule
$1: $2
$(call make-depend,$2,$1,$(subst .o,.d,$1))
$(COMPILE.cpp) -o $1 $2
endef
modules := TripleBit TripleBitQuery BuildTripleBitFromN3
programs :=
libraries :=
sources :=
objects = $(call source-to-object,$(sources))
dependencies = $(subst .o,.d,$(objects))
include_dirs := TripleBit
CPPFLAGS += $(addprefix -I ,$(include_dirs))
MKDIR := mkdir -p
MV := mv -f
RM := rm -f
SED := sed
TEST := test
create-output-directories := \
$(shell for f in $(call source-dir-to-binary-dir,$(modules)); \
do \
$(TEST) -d $$f || $(MKDIR) $$f; \
done)
all:
include $(addsuffix /module.mk,$(modules))
.PHONY: all
all: $(programs)
.PHONY: libraries
libraries: $(libraries)
.PHONY: clean
clean:
$(RM) -r $(BINARY_DIR)
ifneq "$(MAKECMDGOALS)" "clean"
-include $(dependencies)
endif