-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile.include
More file actions
269 lines (206 loc) · 7.04 KB
/
Makefile.include
File metadata and controls
269 lines (206 loc) · 7.04 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# global optimisation options
GCC_OPT_OPT = -finline-limit=1200 -ffast-math -W -Wall -Wextra -O3 -fomit-frame-pointer -fPIC
# GCC 3.3 optimisation options that are not included in -O3
GCC_33_OPT = -ftracer -fgcse-sm
# GCC 3.4 optimisation options that are not included in -O3
GCC_34_OPT = $(GCC_33_OPT) -fgcse-las -fpeel-loops
# GCC 4.0 optimisation options that are not included in -O3
GCC_40_OPT = $(GCC_34_OPT) -fmodulo-sched -ftree-loop-linear -ftree-loop-im -fweb\
-ftree-loop-ivcanon -fivopts -ftree-vectorize -fvariable-expansion-in-unroller
# GCC 4.1 optimisation options that are not included in -O3
GCC_41_OPT = $(GCC_40_OPT) -funsafe-loop-optimizations
# GCC 4.2 optimisation options that are not included in -O3
GCC_42_OPT = $(GCC_41_OPT)
# GCC 4.3 optimisation options that are not included in -O3
GCC_43_OPT = $(GCC_42_OPT) -fmodulo-sched-allow-regmoves -fipa-cp -fvect-cost-model
# GCC 4.4 optimisation options that are not included in -O3
GCC_44_OPT = $(GCC_43_OPT)
# define architecture; it will affect file extentions, dynamic flags.
# now LINUX, WINDOWS(untested), MACOSX are supported
OS = LINUX
# ALL_DEF is an external defines
GENERAL_DEFINES = $(GCC_OPT_OPT) $(GCC_42_OPT) $(ALL_DEF)
#---------------------------------------------------------
# please do not change following lines
#---------------------------------------------------------
# Set default goal immediatly, to make it possible to define rules
default_goal: all
ifdef INTERNAL_LIBRARY
override LIBRARY := $(INTERNAL_LIBRARY)
endif
# tune some parameters depends on OS
EXEEXT =
LIBEXT =
DLLEXT =
OS_DEF =
# define Linux flags
ifeq ($(OS),LINUX)
override EXEEXT :=
override LIBEXT := .a
override DLLEXT := .so
override OS_DEF :=
endif
#define Mc OS X flags
ifeq ($(OS),MACOSX)
override EXEEXT :=
override LIBEXT := .a
override DLLEXT := .jnilib
override OS_DEF := -mmacosx-version-min=10.4
endif
#define Windows flags (untested)
ifeq ($(OS),WINDOWS)
override EXEEXT := .exe
override LIBEXT := .lib
override DLLEXT := .dll
override OS_DEF :=
endif
# System variables definitions should be expanded immidiately,
# either user defines those or not
# (The following lines are written because of their ':=' operator)
# We can't set default values here: WIs' rules.cvslvk may use +=
override INCLUDES := $(INCLUDES)
override DEFINES := $(DEFINES) $(GENERAL_DEFINES)
override LDFLAGS := $(LDFLAGS)
override BUILD_DIR := obj
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Set C++ compilers and linker
override CXX := g++$(GCC_SUFFIX) $(OS_DEF)
# Library building tools
ifdef LIBRARY
# If LTYPE is 'shared', gcc -shared is used
# $(LIBRARY) is library name.
ifeq ($(LTYPE),shared)
override LIBRARY_NAME := lib$(LIBRARY)$(DLLEXT)
endif
ifeq ($(LTYPE),static)
override LIBRARY_NAME := lib$(LIBRARY)$(LIBEXT)
endif
endif # ifdef LIBRARY
# Split LDFLAGS into -L..., -l... and others
override CL_LDFLAGS_DIRS := $(filter -L%,$(LDFLAGS))
override CL_LDFLAGS_LIBS := $(filter -l%,$(LDFLAGS))
override CL_LDFLAGS_OTHER := $(filter-out $(CL_LDFLAGS_DIRS) $(CL_LDFLAGS_LIBS),$(LDFLAGS))
# Internal library variables
#
# Executable may use some internal libraries (libraries from the same module).
# The subdirs should be in USE_IL variable
# Current restrictions:
# each library should be in a subdir;
# subdir name and library name should be the same
# The subdirs of the used internal libraries should be in CL_USE_IL variable
# When internal libraries are used, executable is linked separately during build
# and during installation.
# During build, rpaths to the build directories of the shared libraries are
# set, and during install - rpaths for the install directory is set
ifneq ($(USE_IL),)
# includes may be just added to $(INCLUDES)
override INCLUDES += $(USE_IL:%=-I%)
# -l flags also may be just added to $(CL_LDFLAGS_LIBS)
override CL_LDFLAGS_LIBS += $(patsubst %,-l%,$(notdir $(USE_IL)))
# -L flags can't be just added because of rpath logic, so we use $(CL_LDFLAGS_OTHER)
override CL_IL_DIRS := $(USE_IL:%=-L%)
endif
#update LD_FLAGS wrt DEFINES
ifneq ($(filter -g,$(DEFINES)),)
override CL_LDFLAGS_OTHER += -g
else
override CL_LDFLAGS_OTHER += -s
endif
ifneq ($(filter -m64,$(DEFINES)),)
override CL_LDFLAGS_OTHER += -m64
endif
ifneq ($(filter -m32,$(DEFINES)),)
override CL_LDFLAGS_OTHER += -m32
endif
ifneq ($(filter -pg,$(DEFINES)),)
override CL_LDFLAGS_OTHER += -pg
endif
ifneq ($(filter -fprofile-generate,$(DEFINES)),)
override CL_LDFLAGS_OTHER += -fprofile-generate
endif
# Compute the final LDFLAGS
override LDFLAGS := $(CL_IL_DIRS) $(CL_LDFLAGS_DIRS) $(CL_LDFLAGS_LIBS) $(CL_LDFLAGS_OTHER)
# Add $(INCLUDES) and $(DEFINES) to $(CXXFLAGS)
override CXXFLAGS += $(INCLUDES) $(DEFINES)
# make object files based on sources
override OBJECTS := $(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(basename $(notdir $(SOURCES)))))
# Rules for building object files
override CXX_COMPILE_COMMAND = $(CXX) -c $(CXXFLAGS) -o $@ $<
$(BUILD_DIR)/%.o: %.cpp
$(CXX_COMPILE_COMMAND)
# Make things like "make file.o" work
%: $(BUILD_DIR)/%
ifdef SUBDIRS
all_subdirs clean_subdirs dep_subdirs:
for dir in $(SUBDIRS); do \
(cd $$dir && $(MAKE) `echo $@ | cut -d_ -f1`) || exit 1; \
done
ifeq ($(EXECUTABLE)$(LIBRARY),)
all: all_subdirs
endif
else # No SUBDIRS
all_subdirs clean_subdirs dep_subdirs:
endif # SUBDIRS
# defining "dep" rule
ifeq ($(EXECUTABLE)$(LIBRARY),)
dep: dep_subdirs
else
dep: dep_subdirs .deps
#create .deps file that contains dependencies for all *.c[pp] files
.deps: $(SOURCES)
rm -f .deps
touch .deps
for file in $(SOURCES); do \
$(CXX) $(CXXFLAGS) -MM $$file > .deps.tmp ; \
sed '1 s/^\(.*\)/$(BUILD_DIR)\/\1/' .deps.tmp > .deps.tmp2 ; \
cat .deps.tmp2 >> .deps ; \
echo >> .deps ; \
done
rm -f .deps.tmp .deps.tmp2
# use this file to remember dependencies
include .deps
# now make libs/executables dependant on the libs they uses
# here we have all libraries of which current goal depends
override LIB_DEPS := $(filter -l%, $(LDFLAGS))
# make sure that goals for those libraries that are NOT from the project still exists
ifneq ($(LIB_DEPS),)
$(LIB_DEPS) :
endif
endif # deps for non-empty dirs
# main rule
ifdef EXECUTABLE
all: all_subdirs $(EXECUTABLE)
$(EXECUTABLE): $(BUILD_DIR) $(BUILD_DIR)/$(EXECUTABLE)
rm -f $(EXECUTABLE) && ln -s $(BUILD_DIR)/$(EXECUTABLE) $(EXECUTABLE)
$(BUILD_DIR)/$(EXECUTABLE): $(OBJECTS) $(LIB_DEPS)
$(CXX) $(OBJECTS) $(LDFLAGS) -o $@
endif # EXECUTABLE
ifdef LIBRARY
all: all_subdirs $(LIBRARY_NAME)
$(LIBRARY_NAME): $(BUILD_DIR) $(BUILD_DIR)/$(LIBRARY_NAME)
rm -f $@ && ln -s $(BUILD_DIR)/$@ .
# define shared flags
SHARED_FLAGS =
ifeq ($(OS),LINUX)
override SHARED_FLAGS := -shared -Wl,-h,$(LIBRARY_NAME)
endif
ifeq ($(OS),MACOSX)
override SHARED_FLAGS := -dynamiclib
endif
ifeq ($(OS),WINDOWS)
override SHARED_FLAGS :=
endif
ifeq ($(LTYPE),shared)
$(BUILD_DIR)/$(LIBRARY_NAME): $(OBJECTS) $(LIB_DEPS)
$(CXX) $(SHARED_FLAGS) -o $@ $(OBJECTS) $(LDFLAGS)
endif
ifeq ($(LTYPE),static)
$(BUILD_DIR)/$(LIBRARY_NAME): $(OBJECTS)
ar cr $@ $(OBJECTS)
ranlib $(BUILD_DIR)/$(LIBRARY_NAME)
endif
endif
# The generic "clean" rule
clean: clean_subdirs
rm -rf $(BUILD_DIR) $(LIBRARY_NAME) $(EXECUTABLE) .deps