-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
187 lines (142 loc) · 4.91 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Compiler / strip
CC:=gcc
CFLAGS:=-O0
override CFLAGS+=-g -Wall -Wextra
# -fPIC
#CFLAGS+=-fno-unswitch-loops
override CFLAGS+=-DTBS_LOG_DISABLE
#CFLAGS+=-DTBS_LOG_DISABLETBS_LOG_MUTEX_T
#CFLAGS+=-DTBS_BINCR_DISABLE
# -O3 -std=c++11 -stdlib=libc++
LDFLAGS:=-lm
#-std=c++11 -stdlib=libc++
STRIP:=strip
AR=ar
# Doxygen
DOXYGEN:=doxygen
DOXYGEN_FLAGS:=
DOXYGEN_CONF:=doxygen.conf
# Dirs / files-extensions
ARCHD:=arch
SRC:=src
INC:=include
BIN:=bin
BIN_EXT:=
SO_EXT:=.so
SL_EXT:=.a
OBJ:=obj
OBJ_EXT:=.o
DEP:=dep
DEP_EXT:=.dep
C_EXT:=.c
TEST=test
PREFIX:=/usr/local
# Kdevelop
KDEV=kdevelop
KDEV_INC=.kdev_include_paths
KDEV_FILES=$(shell find $(SRC) -name '*.cpp' -type f; find $(SRC) $(INC) -name '*.h' -type f)
# Edit the flags
override CFLAGS+=-I$(INC) -I$(SRC)
LDFLAGS+=-L$(BIN)
# Autogenerated flags
FFLAGSD:=flags
# Include arch-files
ifeq ($(ARCH),)
ARCH:=local
endif
ifeq ($(ARCH),win64)
CXXFLAGS+=-Dwin64
endif
-include $(ARCHD)/$(ARCH)
# Add now the optional c flags
CC_TARGET:=$(shell cd scripts; ./gcc_target.sh $(CC))
CC_VERSION:=$(shell cd scripts; ./gcc_version.sh $(CC))
CC_FLAGS:=$(CC)_$(CC_TARGET)_$(CC_VERSION)
OPT:=$(shell cat flags/$(CC_FLAGS) 2>/dev/null)
CFLAGS+=$(OPT)
export
# The targets
TARGETS= $(BIN)/tbs/bincr/libtbs-bincr-minimal$(SL_EXT) $(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT) $(BIN)/tbs/bincr/example$(BIN_EXT)
TARGETS+=$(BIN)/tbs/bincr/example2$(BIN_EXT) $(BIN)/tbs/bincr/example3$(BIN_EXT) $(BIN)/tbs/bincr/optimization_test$(BIN_EXT)
#$(BIN)/tbs/bincr/encrypt$(BIN_EXT) $(BIN)/tbs/bincr/decrypt$(BIN_EXT)
TARGETS+=$(BIN)/tbs/bincr/crypt$(BIN_EXT)
TARGETS+=$(BIN)/tbs/log/libtbs-log$(SL_EXT) $(BIN)/tbs/log/example$(BIN_EXT)
#TARGETS=$(BIN)/test$(BIN_EXT) $(BIN)/libtest$(SL_EXT) $(BIN)/libtest$(SO_EXT)
.PHONY: all clean mrproper $(FFLAGSD) show_flags install uninstall docs kdev
.SECONDARY:
all: $(TARGETS)
# Load dependencies.
# The dependency logic is based on the following two links:
# http://stackoverflow.com/questions/8025766/makefile-auto-dependency-generation
# http://stackoverflow.com/questions/313778/generate-dependencies-for-a-makefile-for-a-project-in-c-c
DEP_FILES:=$(shell [ -d '$(DEP)' ] && find $(DEP) -name '*$(DEP_EXT)')
-include $(DEP_FILES)
clean:
@echo "CLEAN..."
@$(RM) -R $(BIN) $(OBJ) $(DEP) $(KDEV_INC) $(TEST) docs
mrproper: clean
@echo "MRPROPER..."
@$(RM) -R $(FFLAGSD) scripts/.cache_*
install: all
@echo "INSTALL..."
@mkdir -p $(PREFIX)/bin $(PREFIX)/lib
@cp $(BIN)/test$(BIN_EXT) $(PREFIX)/bin/test$(BIN_EXT)
@cp $(BIN)/libtest$(SO_EXT) $(PREFIX)/lib/libtest$(SO_EXT)
uninstall:
@echo "UNINSTALL..."
@$(RM) $(PREFIX)/bin/test$(BIN_EXT) $(PREFIX)/lib/libtest$(SO_EXT)
docs:
@echo "DOXYGEN..."
@$(DOXYGEN) $(DOXYGEN_FLAGS) $(DOXYGEN_CONF)
kdev: $(KDEV_INC)
@$(KDEV) $(KDEV_FILES)
$(FFLAGSD):
@mkdir -p $(FFLAGSD)
(cd scripts; ./gcc_test.sh $(CC) "CC=$(CC) ARCH=$(ARCH) STRIP=$(STRIP) BIN_EXT=$(BIN_EXT)" $(BIN_EXT)) > $@/$(CC_FLAGS)
show_flags:
@echo $(OPT)
$(KDEV_INC):
@echo $(shell pwd)/$(SRC) > $@; echo $(shell pwd)/$(INC) >> $@
$(OBJ)/%$(OBJ_EXT): $(SRC)/%$(C_EXT)
@mkdir -p $(DEP)/$(dir $*)
@echo "DEP $(DEP)/$*$(DEP_EXT)..."
@$(CC) $(CFLAGS) -MM -MT '$(patsubst $(SRC)/%$(C_EXT),$(OBJ)/%$(OBJ_EXT),$<)' $< > $(DEP)/$*$(DEP_EXT)
@mkdir -p $(@D)
@echo "CC $@..."
$(CC) $(CFLAGS) -o $@ -c $<
$(BIN)/%$(SO_EXT):
@mkdir -p $(@D)
@echo "LD $@..."
$(CC) -fPIC -shared -o $@ $^ $(LDFLAGS)
$(BIN)/%$(SL_EXT):
@mkdir -p $(@D)
@echo "AR $@..."
$(AR) crfsT $@ $^
$(BIN)/%$(BIN_EXT): $(OBJ)/%$(OBJ_EXT)
@mkdir -p $(@D)
@echo "LD $@..."
$(CC) -o $@ $^ $(LDFLAGS)
@if [ ! -z '$(STRIP)' ]; then echo "STRIP $@..."; $(STRIP) -s $@; fi
$(TEST)/%$(SO_EXT): $(OBJ)/gtest/gtest-all$(OBJ_EXT)
@mkdir -p $(@D)
@echo "LD $@..."
$(CC) -fPIC -shared -o $@ $^ $(LDFLAGS) -lpthread
$(TEST)/%$(SL_EXT): $(OBJ)/gtest/gtest-all$(OBJ_EXT)
@mkdir -p $(@D)
@echo "AR $@..."
$(AR) crfsT $@ $^
$(TEST)/%$(BIN_EXT): $(OBJ)/gtest/gtest-all$(OBJ_EXT) $(OBJ)/$(TEST)/%$(OBJ_EXT)
@mkdir -p $(@D)
@echo "LD $@..."
$(CC) -o $@ $^ $(LDFLAGS) -lpthread
$(BIN)/tbs/bincr/libtbs-bincr-minimal$(SL_EXT): $(OBJ)/tbs/log/core$(OBJ_EXT) $(OBJ)/tbs/bincr/minimal$(OBJ_EXT)
$(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT): $(OBJ)/tbs/log/core$(OBJ_EXT) $(OBJ)/tbs/bincr/minimal$(OBJ_EXT) $(OBJ)/tbs/bincr/keygen$(OBJ_EXT) $(OBJ)/tbs/bincr/core$(OBJ_EXT)
$(BIN)/tbs/bincr/example$(BIN_EXT): $(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT)
$(BIN)/tbs/bincr/example2$(BIN_EXT): $(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT)
$(BIN)/tbs/bincr/example3$(BIN_EXT): $(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT)
$(BIN)/tbs/bincr/optimization_test$(BIN_EXT): $(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT)
#$(BIN)/tbs/bincr/encrypt$(BIN_EXT): $(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT)
#$(BIN)/tbs/bincr/decrypt$(BIN_EXT): $(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT)
$(BIN)/tbs/bincr/crypt$(BIN_EXT): $(BIN)/tbs/bincr/libtbs-bincr$(SL_EXT)
$(BIN)/tbs/log/libtbs-log$(SL_EXT): $(OBJ)/tbs/log/core$(OBJ_EXT)
$(BIN)/tbs/log/example$(BIN_EXT): $(BIN)/tbs/log/libtbs-log$(SL_EXT)