forked from AlloSphere-Research-Group/AlloSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
308 lines (251 loc) · 7.97 KB
/
Makefile.common
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
###########################################################################
# Standard Make variable definitions
#
# These are the common variable definitions used across different projects.
# This will usually be included at the top of a separate project specific
# Makefile using 'include Makefile.common'.
###########################################################################
#==========================================================================
# Command-line options
# Modify for your system -or- use command-line argument OPTION=string
#==========================================================================
#--------------------------------------------------------------------------
# Operating system variables
#--------------------------------------------------------------------------
# Operating system: 'macosx', 'linux', or 'windows'
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
PLATFORM = linux
else ifeq ($(UNAME), Darwin)
PLATFORM = macosx
# Mac OS X version
UNAMER := $(shell uname -r)
UNAMER := $(firstword $(subst ., , $(UNAMER)))
ifeq ($(UNAMER), 12)
OSX_VERSION = 10_8
else ifeq ($(UNAMER), 11)
OSX_VERSION = 10_7
else ifeq ($(UNAMER), 10)
OSX_VERSION = 10_6
else ifeq ($(UNAMER), 9)
OSX_VERSION = 10_5
else ifeq ($(UNAMER), 8)
OSX_VERSION = 10_4
endif
else
PLATFORM = windows
endif
# Architecture: '32' or '64'
ifeq ($(shell which getconf 2>/dev/null),)
UNAMEM := $(shell uname -m)
ifeq ($(UNAMEM), $(findstring $(UNAMEM), x86_64 ia86 amd64))
ARCH = 64
else
ARCH = 32
endif
else
# Set equal to number of bits in a type long int
ARCH := $(shell getconf LONG_BIT)
endif
#
USING_PUREDYNE = 0
#--------------------------------------------------------------------------
# Build settings
#--------------------------------------------------------------------------
# Name of the library
# This should be defined prior to including this file
LIB_NAME ?=
# Dynamic library major/minor version numbers
DLIB_MAJ = 1
DLIB_MIN = 0
# Build configuration: 'Release' or 'Debug'
# 'Release' aggressively optimizes for speed at the expense of greater
# compile times and program size. 'Debug' generates code suitable for a
# debugging tool.
BUILD_CONFIG = Release
# Whether to build a dynamic library versus a static library
DYNAMIC = 0
# Whether to show verbose output
VERBOSE = 0
# Whether Make should determine the dependencies of each C or C++ file as
# it compiles it. This will be automatically disabled for universal builds
# on Mac OSX.
DEP_TRACK = 1
# Whether to enable strict warnings
STRICT_WARNINGS = 1
# Whether to automatically run executables after building
AUTORUN = 1
# Platform-specific library file extensions
SLIB_EXT = a
DLIB_EXT = so
DLIB_OPT = shared
# Flags required for including and linking against library
LINK_CPPFLAGS ?=
LINK_LDFLAGS ?=
# Flags handed to 'ar' command
SLIB_FLAGS ?=
DLIB_FLAGS ?=
#--------------------------------------------------------------------------
# Default paths
#--------------------------------------------------------------------------
PREFIX = /usr/local/
CONFPREFIX = $(PREFIX)/etc/
MANPREFIX = $(PREFIX)/share/man/
# Locations of built objects
BUILD_DIR ?= build/
BIN_DIR = $(BUILD_DIR)bin/
OBJ_DIR = $(BUILD_DIR)obj/
# Location of library installation
DESTDIR = $(PREFIX)
# Check for some common shared library directories
ifneq ($(wildcard /usr/local/),)
HAS_USR_LOCAL = 1
endif
ifneq ($(wildcard /opt/local/),)
HAS_OPT_LOCAL = 1
endif
ifneq ($(wildcard /usr/X11/),)
HAS_USR_X11 = 1
endif
# Platform-dependent directory
PLATFORM_DIR ?=
#--------------------------------------------------------------------------
# Default tools/commands
#--------------------------------------------------------------------------
# NOTE: ar -s is completely equivalent to running ranlib
AR = ar crs
INSTALL = install
RANLIB = ranlib
RM = rm -f
# Let user override variables
-include Makefile.user
#--------------------------------------------------------------------------
# Finalize variables
#--------------------------------------------------------------------------
# Dependency tracking doesn't work with universal libraries, so disable it
ifeq ($(ARCH), 32_64)
DEP_TRACK = 0
endif
# Linux:
ifeq ($(PLATFORM), linux)
PLATFORM_DIR = linux/
ifneq ($(USING_PUREDYNE), 0)
CXX = gcc
endif
ifeq ($(ARCH), 32)
CFLAGS += -m32
else ifeq ($(ARCH), 64)
CFLAGS += -m64
else ifeq ($(ARCH), 32_64)
CFLAGS += -m32 -m64
endif
CPPFLAGS += -D__LINUX__ -DLINUX
CPPFLAGS += -I/usr/local/include/ -I/usr/include/
LDFLAGS += -lm -lstdc++
DLIB_FLAGS += -shared
DLIB_FLAGS += -Wl,-soname,$(DLIB_MAJ_FILE)
# Mac OSX:
else ifeq ($(PLATFORM), macosx)
PLATFORM_DIR = osx/
ifeq ($(ARCH), 32)
CFLAGS += -arch i386
else ifeq ($(ARCH), 64)
CFLAGS += -arch x86_64
else ifeq ($(ARCH), 32_64)
CFLAGS += -arch i386 -arch x86_64
endif
# Oh where, oh where have my SDKs gone?
ifeq ($(wildcard /Applications/Xcode.app),)
OSX_SDK_PATH := /Developer/SDKs/
else
OSX_SDK_PATH := /Applications/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
endif
# Set system root directory for stdc++ etc.
ifeq ($(OSX_VERSION), 10_8)
CFLAGS += -isysroot $(OSX_SDK_PATH)MacOSX10.8.sdk -mmacosx-version-min=10.8
else ifeq ($(OSX_VERSION), 10_7)
CFLAGS += -isysroot $(OSX_SDK_PATH)MacOSX10.7.sdk -mmacosx-version-min=10.7
else ifeq ($(OSX_VERSION), 10_6)
CFLAGS += -isysroot $(OSX_SDK_PATH)MacOSX10.6.sdk -mmacosx-version-min=10.6
else ifeq ($(OSX_VERSION), 10_5)
CFLAGS += -isysroot $(OSX_SDK_PATH)MacOSX10.5.sdk -mmacosx-version-min=10.5
else ifeq ($(OSX_VERSION), 10_4)
CFLAGS += -isysroot $(OSX_SDK_PATH)MacOSX10.4u.sdk -mmacosx-version-min=10.4
endif
# Needed to link to libraries installed through MacPorts
ifdef HAS_OPT_LOCAL
LDFLAGS += -L/opt/local/lib/
CPPFLAGS += -I/opt/local/include/
endif
# Needed to link to libraries installed through homebrew or by user
ifneq ($(wildcard /usr/local/lib),)
LDFLAGS += -L/usr/local/lib/
endif
ifneq ($(wildcard /usr/local/include),)
CPPFLAGS += -I/usr/local/include/
endif
LDFLAGS += -lm -lstdc++
DLIB_EXT = dylib
DLIB_OPT = dynamiclib
DLIB_FLAGS += -dynamiclib
DLIB_FLAGS += -current_version $(DLIB_MAJ).$(DLIB_MIN) -compatibility_version $(DLIB_MAJ).$(DLIB_MIN)
# Windows:
else ifeq ($(PLATFORM), windows)
PLATFORM_DIR = windows/
# Needed for MinGW libs...
LDFLAGS += -L/mingw/lib/
CPPFLAGS += -I/mingw/include/
# Needed for MSYS libs...
LDFLAGS += -L/local/lib/
CPPFLAGS += -I/local/include/
CPPFLAGS += -I`pwd`
# SLIB_EXT = lib
# DLIB_EXT = dll
endif
# Whether to echo commands to the terminal...
ifeq ($(VERBOSE), 0)
AR := @$(AR)
CC := @$(CC)
CXX := @$(CXX)
endif
# Append optimization flags
ifeq ($(BUILD_CONFIG), Release)
CFLAGS += -O3 -fpeel-loops
else
CFLAGS += -g -O0 -fno-inline
endif
# Append warning flags
ifneq ($(STRICT_WARNINGS), 0)
CFLAGS += \
-Wreturn-type \
-Wformat -Wmissing-braces -Wparentheses -Wswitch \
-Wunused-variable -Wsign-compare -Wno-unknown-pragmas \
-Wuninitialized -Winit-self
CXXFLAGS += -Wnon-virtual-dtor -Woverloaded-virtual
endif
SLIB_FILE = lib$(LIB_NAME).$(SLIB_EXT)
DLIB_FILE = lib$(LIB_NAME).$(DLIB_EXT)
DLIB_MAJ_FILE = lib$(LIB_NAME).$(DLIB_MAJ).$(DLIB_EXT)
DLIB_MIN_FILE = lib$(LIB_NAME).$(DLIB_MAJ).$(DLIB_MIN).$(DLIB_EXT)
DLIB_PATH = $(addprefix $(BUILD_DIR)lib/, $(DLIB_MIN_FILE))
SLIB_PATH = $(addprefix $(BUILD_DIR)lib/, $(SLIB_FILE))
# Set file directory/name of specified library type
ifneq ($(DYNAMIC), 0)
CFLAGS += -fPIC
LIB_FILE = $(DLIB_MIN_FILE)
LIB_PATH = $(DLIB_PATH)
else
LIB_FILE = $(SLIB_FILE)
LIB_PATH = $(SLIB_PATH)
endif
#--------------------------------------------------------------------------
# Utility functions
#--------------------------------------------------------------------------
RemoveDir = @if test -d $(1); then $(RM) $(1)* && rmdir $(1); fi
define RemoveBuildDir
$(call RemoveDir, $(BUILD_DIR)include/)
$(call RemoveDir, $(BUILD_DIR)lib/)
$(call RemoveDir, $(BIN_DIR))
$(call RemoveDir, $(OBJ_DIR))
$(call RemoveDir, $(BUILD_DIR))
endef