-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.std
340 lines (281 loc) · 9.14 KB
/
Makefile.std
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
##################################################
# Makefile.std
# Aaron Stump, Spring 1998
# Modified by Clark Barrett, Spring 2005
##################################################
##################################################
#
# This Makefile can be included by other Makefiles
# to get certain rules defined. This Makefile
# assumes the following (items marked with
# '**' cannot be left undefined, but all others
# can be). Note that you should define at most one
# of LIBRARY or EXECUTABLE
#
# ** 1. $(SRC) gives the names of all the
# source (*.cpp) files for your target.
# 2. $(OTHER_OBJ) gives the names of any
# object files that should be linked in
# with the executable or library but
# not themselves built.
# 3. $(HEADERS) gives the names of all
# the header files for your target.
# 4. $(EXECUTABLE) gives the name of the
# executable you're trying to compile,
# if you're trying to compile an
# executable.
# 5. $(LIBRARY) gives the name of the
# library you're trying to compile,
# if you're trying to compile a library.
# 6. if $(OPTIMIZED) is defined, an optimized
# target is built. Otherwise, a debug
# target is built.
# 7. The options listed below have defaults
# that you may want to override.
##################################################
#
# To review:
#
# What rule should delete the dynamic cvc3 binary? clean or spotty
# What rule should delete the dynamic libs? clean or spotty
# What rule should delete the dynamic link libcvc3.dylib in libs? clean or spotty
# What rule should delete logs? (regressions.log) clean or distclean
# What rule should delete autoconf-generated files? distclean
# (config.log, config.status, configure, autom4ta.cache)
# What rule should delete configure-generated files? distclean
# (those derived from *.in:
# ./bin/cvc2smt.in ./bin/libmerge.in ./bin/run_tests.in ./doc/Doxyfile.in
# ./doc/Makefile.in ./LICENSE.in ./Makefile.local.in)
# test/Makefile's clean should delete test/obj/**/*.o, test/bin/**/test
# testc/Makefile's clean ...
# cleaning test1.cvc?
# How about library version information?
##################################################
# Force shell to Bash so we can rely on some process management
# tricks like ${PIPESTATUS[0]} and <( ... ) for process redirection
SHELL = /bin/bash
##################################################
# Special versions of dir/notdir built-ins that
# can handle paths with spaces
# Note that, unlike dir/notdir, these functions
# take a *single* path and assume that any spaces
# are part of the path (they need not be escaped).
##################################################
s? = $(subst $(empty) ,?,$(1))
?s = $(subst ?, ,$(1))
notdirx = $(call ?s,$(notdir $(call s?,$(1))))
dirx = $(call ?s,$(dir $(call s?,$(1))))
##################################################
# Compute flags and platform based on options
##################################################
#Default platform is generic
ifndef PLATFORM
PLATFORM := generic
endif
ifeq ($(SMTCOMP),1)
LOCAL_CXXFLAGS = -O9 -funroll-all-loops -fexpensive-optimizations -DSMTCOMP
DEBUG_PLATFORM =-smtcomp
else
ifeq ($(OPTGDB),1)
LOCAL_CXXFLAGS = -g
DEBUG_PLATFORM = -optgdb
else
ifeq ($(OPTDEBUG),1)
LOCAL_CXXFLAGS = -O2 -D_CVC3_DEBUG_MODE
DEBUG_PLATFORM = -optdbg
else
ifeq ($(OPTIMIZED),1)
LOCAL_CXXFLAGS = -O2
DEBUG_PLATFORM =
else
LOCAL_CXXFLAGS = -D_CVC3_DEBUG_MODE -g -O0
DEBUG_PLATFORM = -debug
endif
endif
endif
endif
ifeq ($(GCOV),1)
LOCAL_CXXFLAGS += -fprofile-arcs -ftest-coverage
GTOOLS_PLATFORM = -gcov
else
ifeq ($(GPROF),1)
LOCAL_CXXFLAGS += -pg
GTOOLS_PLATFORM = -gprof
endif
endif
PLATFORM_WITH_OPTIONS = $(PLATFORM)$(DEBUG_PLATFORM)$(GTOOLS_PLATFORM)
##################################################
# Set variables to defaults if not already set
##################################################
ifdef BASE_DIR
SRC_DIR = $(BASE_DIR)
OBJ_DIR = $(BASE_DIR)/obj/$(PLATFORM_WITH_OPTIONS)
else
BASE_DIR=$(TOP)
endif
ifndef SRC_DIR
SRC_DIR = $(TOP)/src/$(MODULE)
endif
ifndef OBJ_DIR
OBJ_DIR = $(TOP)/obj/$(MODULE)/$(PLATFORM_WITH_OPTIONS)
endif
ifndef EXE_DIR
EXE_DIR=$(BASE_DIR)/bin/$(PLATFORM_WITH_OPTIONS)
endif
ifndef LIB_DIR
LIB_DIR = $(TOP)/lib/$(PLATFORM_WITH_OPTIONS)
endif
#Default C++ suffix is cpp
ifndef CPPSUFFIX
CPPSUFFIX = cpp
endif
#Default compiler/linker is g++
ifndef CXX
CXX = g++
endif
#Default linker is same as CXX
ifndef LD
LD = $(CXX)
endif
#Default include directory is current directory
ifndef INCLUDE_DIR
INCLUDE_DIR=-I.
endif
#Default directory for link libraries is current directory
ifndef LD_LIB_DIR
LD_LIB_DIR=-L.
endif
#If TRANSIENT is defined, clean will remove those files
#automatically. By default, no transient files.
ifndef TRANSIENT
TRANSIENT=
endif
#Default is to build individual shared libraries
ifndef BUILD_SHARED_LIB
BUILD_SHARED_LIB=1
endif
LOCAL_CXXFLAGS += -Wall $(INCLUDE_DIR)
ifdef EXTRAFLAGS
LOCAL_CXXFLAGS += $(EXTRAFLAGS)
endif
##################################################
# Objects from Sources
##################################################
OBJ = $(patsubst %.$(CPPSUFFIX), $(OBJ_DIR)/%.o, $(SRC))
$(OBJ_DIR)/%.o : %.$(CPPSUFFIX)
@mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) $(LOCAL_CXXFLAGS) $(CPPFLAGS) -c $< -o '$@'
##################################################
# executables and libraries
##################################################
.PHONY: all depend clean real_clean spotty print_src
ifeq ($(STATIC),1)
STATIC_FLAG_TARGET = $(STATIC_FLAG)
LIB_SUFFIX = $(STATIC_LIB_SUFFIX)
EXE_DIR_STATIC_OR_DYNAMIC = $(EXE_DIR)/static
else
STATIC_FLAG_TARGET =
LIB_SUFFIX = $(SHARED_LIB_SUFFIX)
EXE_DIR_STATIC_OR_DYNAMIC = $(EXE_DIR)
endif
ifdef EXECUTABLE
# Compile executable
BUILD_SPECIFIC_TARGET = $(EXE_DIR_STATIC_OR_DYNAMIC)/$(EXECUTABLE)$(EXEEXT)
BUILD_INDEPENDENT_TARGET = $(BASE_DIR)/bin/$(EXECUTABLE)$(EXEEXT)
all:
$(MAKE) $(BUILD_SPECIFIC_TARGET)
@rm -f $(BUILD_INDEPENDENT_TARGET)
ln -sf $(BUILD_SPECIFIC_TARGET) $(BUILD_INDEPENDENT_TARGET)
$(BUILD_SPECIFIC_TARGET): $(OBJ) $(OTHER_OBJ) $(OTHER_DEPENDENCIES)
@mkdir -p $(EXE_DIR_STATIC_OR_DYNAMIC)
$(LD) $(STATIC_FLAG_TARGET) $(CXXFLAGS) $(LOCAL_CXXFLAGS) $(LDFLAGS) -o '$@' $(OBJ) \
$(OTHER_OBJ) $(LD_LIB_DIR) $(LD_LIBS)
else
ifdef LIBRARY
# Compile library
SHARED_LIBRARY = $(patsubst %.$(STATIC_LIB_SUFFIX),%.$(SHARED_LIB_SUFFIX),$(LIBRARY))
STATIC_LIB_TARGET = $(LIB_DIR)/$(LIBRARY)
SHARED_LIB_TARGET = $(LIB_DIR)/$(SHARED_LIBRARY)
BUILD_SPECIFIC_TARGET = $(STATIC_LIB_TARGET)
ifneq ($(STATIC),1)
ifeq ($(BUILD_SHARED_LIB),1)
BUILD_SPECIFIC_TARGET += $(SHARED_LIB_TARGET)
endif
endif
all: $(BUILD_SPECIFIC_TARGET)
$(SHARED_LIB_TARGET): $(OBJ) $(OTHER_OBJ)
@mkdir -p $(LIB_DIR)
$(CXX) $(SHARED) -o '$@' $(OBJ) $(OTHER_OBJ)
$(STATIC_LIB_TARGET): $(OBJ) $(OTHER_OBJ)
@mkdir -p $(LIB_DIR)
ar ruvs '$@' $(OBJ) $(OTHER_OBJ)
@#ranlib '$@'
else
LIB_OR_EXE = 0
endif
endif
ifeq ($(LIB_OR_EXE),0)
else
##################################################
# depend
##################################################
MAKEFILE_DEPS=$(OBJ_DIR)/Makefile.deps
MAKEFILE_DEPS_TMP=$(OBJ_DIR)/Makefile.tmp
MAKEFILE_DEPS_TMP2=$(OBJ_DIR)/Makefile.tmp2
ifndef MY_DEPEND
depend: $(SRC) $(HEADERS) $(OTHER_DEPEND)
@mkdir -p $(OBJ_DIR)
@-rm -f $(MAKEFILE_DEPS) $(MAKEFILE_DEPS_TMP) $(MAKEFILE_DEPS_TMP2)
@echo '# Dependencies for C++ files' >> $(MAKEFILE_DEPS_TMP)
@echo >> $(MAKEFILE_DEPS_TMP)
@echo "Making dependencies for $(SRC)"
$(CXX) -M $(CXXFLAGS) $(LOCAL_CXXFLAGS) $(CPPFLAGS) $(SRC) >> $(MAKEFILE_DEPS_TMP)
@echo >> $(MAKEFILE_DEPS_TMP)
@sed -e '/^.*:/ s#^#$(OBJ_DIR)/#' < $(MAKEFILE_DEPS_TMP) > $(MAKEFILE_DEPS_TMP2)
@cat $(MAKEFILE_DEPS_TMP2) > $(MAKEFILE_DEPS)
@rm -f $(MAKEFILE_DEPS_TMP) $(MAKEFILE_DEPS_TMP2)
endif
$(MAKEFILE_DEPS): $(SRC) $(HEADERS) $(OTHER_DEPENDENCY_MAKEFILES)
@mkdir -p $(OBJ_DIR)
@touch $(MAKEFILE_DEPS)
@$(MAKE) --no-print-directory depend
##################################################
# clean
#
# Remove all generated files.
##################################################
clean: $(MAKEFILE_DEPS)
rm -f $(OBJ) $(BUILD_SPECIFIC_TARGET) $(TRANSIENT) $(MAKEFILE_DEPS) \
$(MAKEFILE_DEPS_TMP) $(MAKEFILE_DEPS_TMP2) $(BUILD_INDEPENDENT_TARGET)
distclean:
rm -f $(TRANSIENT)
##################################################
# spotty
#
# Remove just the executable or library
##################################################
spotty:
rm -f $(BUILD_SPECIFIC_TARGET) $(BUILD_INDEPENDENT_TARGET)
##################################################
# print_src
#
# Print all the source files (*.cpp and *.h) for the module
##################################################
ifndef FILELIST
FILELIST = /dev/null
endif
# Normally, *.cpp files are the sources. However, if SRC includes
# dynamically generated files (e.g. parser files from *.lex and
# *.yacc), then SRC_ORIG must be defined to include the true source
# files.
ifndef SRC_ORIG
SRC_ORIG = $(SRC)
endif
print_src:
echo "Collecting files from " src/$(MODULE)
@echo $(patsubst %, src/$(MODULE)/%, $(SRC_ORIG)) \
$(patsubst %, src/$(MODULE)/%, $(HEADERS)) \
src/$(MODULE)/Makefile \
>> $(FILELIST)
-include $(MAKEFILE_DEPS)
endif