Debian Codegraph @

Makefile-options

raw
1 ########## fre:ac options makefile ##########
2
3 VERSION = 1.1
4 REVISION = 0
5
6 SMOOTHVER = 0.9
7 BOCAVER = 1.0
8
9 # Find source folder and set vpath
10 SRCDIR = $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
11
12 vpath %.c "$(SRCDIR)"
13 vpath %.cc "$(SRCDIR)"
14 vpath %.cpp "$(SRCDIR)"
15 vpath %.m "$(SRCDIR)"
16 vpath %.mm "$(SRCDIR)"
17 vpath %.rc "$(SRCDIR)"
18 vpath %.ico "$(SRCDIR)"
19
20 # Define makein and cleanin macros
21 ifeq ("$(SRCDIR)","$(CURDIR)")
22 makein = cd $(1) && $(MAKE) $(2) && cd ..
23 cleanin = cd $(1) && $(MAKE) clean && cd ..
24 else
25 makein = mkdir -p $(1) && cd $(1) && $(MAKE) -f "$(SRCDIR)"/$(1)/Makefile $(2) && cd ..
26 cleanin = mkdir -p $(1) && cd $(1) && $(MAKE) -f "$(SRCDIR)"/$(1)/Makefile clean && cd .. && (rmdir $(1) || true)
27 endif
28
29 # Find architecture and system
30 UNAME = $(shell uname)
31 MACHINE = $(shell $(CC) -dumpmachine)
32
33 ifneq ($(findstring arm,$(MACHINE)),)
34 ifneq ($(BUILD_ARM),False)
35 BUILD_ARM = True
36 endif
37 else ifneq ($(findstring aarch64,$(MACHINE)),)
38 ifneq ($(BUILD_ARM64),False)
39 BUILD_ARM64 = True
40 endif
41 else ifneq ($(findstring mips,$(MACHINE)),)
42 ifneq ($(BUILD_MIPS),False)
43 BUILD_MIPS = True
44 endif
45 else ifneq ($(findstring powerpc64,$(MACHINE)),)
46 ifneq ($(BUILD_PPC64),False)
47 BUILD_PPC64 = True
48 endif
49 else ifneq ($(findstring powerpc,$(MACHINE)),)
50 ifneq ($(BUILD_PPC),False)
51 BUILD_PPC = True
52 endif
53 else ifneq ($(findstring riscv64,$(MACHINE)),)
54 ifneq ($(BUILD_RISCV64),False)
55 BUILD_RISCV64 = True
56 endif
57 else ifneq ($(findstring x86_64,$(MACHINE)),)
58 ifneq ($(BUILD_ARM64),True)
59 ifneq ($(BUILD_X86),True)
60 ifneq ($(BUILD_X86_64),False)
61 BUILD_X86_64 = True
62 endif
63 endif
64 endif
65 else ifneq ($(findstring amd64,$(MACHINE)),)
66 ifneq ($(BUILD_ARM64),True)
67 ifneq ($(BUILD_X86),True)
68 ifneq ($(BUILD_X86_64),False)
69 BUILD_X86_64 = True
70 endif
71 endif
72 endif
73 else ifneq ($(findstring i586,$(MACHINE))$(findstring i686,$(MACHINE)),)
74 ifneq ($(BUILD_ARM64),True)
75 ifneq ($(BUILD_X86),False)
76 ifneq ($(BUILD_X86_64),True)
77 BUILD_X86 = True
78 endif
79 endif
80 endif
81 endif
82
83 # Treat MSYS and MinGW the same
84 ifneq ($(findstring MSYS,$(UNAME)),)
85 UNAME = MINGW
86 endif
87
88 ifneq ($(findstring MINGW,$(UNAME)),)
89 # Set executable and shared object extensions
90 EXECUTABLE = .exe
91 SHARED = .dll
92
93 # Build on Win32
94 BUILD_WIN32 = True
95 else
96 # Set executable and shared object extensions
97 EXECUTABLE =
98 SHARED = .so
99
100 BUILD_UNIX = True
101
102 ifeq ($(UNAME),Linux)
103 BUILD_LINUX = True
104 else ifeq ($(UNAME),FreeBSD)
105 BUILD_FREEBSD = True
106 else ifeq ($(UNAME),OpenBSD)
107 BUILD_OPENBSD = True
108 else ifeq ($(UNAME),NetBSD)
109 BUILD_NETBSD = True
110 else ifeq ($(UNAME),SunOS)
111 BUILD_SOLARIS = True
112 else ifeq ($(UNAME),Haiku)
113 BUILD_HAIKU = True
114 else ifeq ($(UNAME),GNU)
115 BUILD_GNU = True
116 else ifeq ($(UNAME),Darwin)
117 # Set shared object extension
118 SHARED = .dylib
119
120 BUILD_OSX = True
121 endif
122 endif
123
124 # Set default commands
125 ifndef OBJC
126 OBJC = $(CC)
127 endif
128
129 ifndef OBJCXX
130 OBJCXX = $(CXX)
131 endif
132
133 ifeq ($(LD),ld)
134 LD = $(CXX)
135 endif
136
137 LDCONFIG = /sbin/ldconfig
138
139 INSTALL = install
140
141 ifeq ($(BUILD_SOLARIS),True)
142 INSTALL = ginstall
143 endif
144
145 INSTALL_PROGRAM = $(INSTALL)
146 INSTALL_DATA = $(INSTALL) -m 644
147
148 # Set output folders
149 BINDIR = bin
150 LIBDIR = lib
151
152 ifeq ($(BUILD_WIN32),True)
153 ifeq ($(BUILD_X86_64),True)
154 BINDIR = bin64
155 LIBDIR = lib64
156 endif
157 endif
158
159 # Set install folders
160 ifndef prefix
161 prefix = /usr/local
162
163 ifeq ($(BUILD_HAIKU),True)
164 prefix = /system/non-packaged
165 endif
166 endif
167
168 bindir = $(prefix)/bin
169 libdir = $(prefix)/lib
170 includedir = $(prefix)/include
171 datadir = $(prefix)/share
172
173 ifeq ($(BUILD_HAIKU),True)
174 includedir = $(prefix)/develop/headers
175 datadir = $(prefix)/data
176 endif
177
178 # Set release specific options
179 ifeq ($(findstring release,$(config)),release)
180 ifeq ($(BUILD_FREEBSD),True)
181 override CC = clang
182 override CXX = clang++
183 override OBJC = clang
184 override OBJCXX = clang++
185
186 override LD = clang++
187 else ifeq ($(BUILD_OSX),True)
188 override CC = gcc
189 override CXX = g++
190 override OBJC = gcc
191 override OBJCXX = g++
192
193 override LD = g++
194 endif
195
196 override CFLAGS = -pipe -g0 -Wall -Os -DFREAC_DATE=\"$(shell date +"%Y%m%d")\"
197 override CXXFLAGS =
198 override OBJCFLAGS =
199 override OBJCXXFLAGS =
200 override LDFLAGS = -pipe
201
202 ifneq ($(RTTI),True)
203 ifneq ($(BUILD_HAIKU),True)
204 override CXXFLAGS += -fno-rtti
205 override OBJCXXFLAGS += -fno-rtti
206 endif
207 endif
208
209 ifneq ($(EXCEPTION),True)
210 override CXXFLAGS += -fno-exceptions
211 override OBJCXXFLAGS += -fno-exceptions
212 endif
213
214 ifeq ($(BUILD_OSX),True)
215 # Find macOS and Xcode version
216 XCODEVERSION = $(shell xcodebuild -version | head -n1)
217 MACOSVERSION = $(MACOSX_DEPLOYMENT_TARGET)
218
219 ifeq ($(MACOSVERSION),)
220 MACOSVERSION = $(shell sw_vers | awk '$$1 == "ProductVersion:" { print $$2 }')
221 endif
222
223 XCODE_LE3 = $(shell bash -c "v='$(XCODEVERSION)'; v=\$${v\#\#* }; if [ \$${v%%.*} -le 3 ]; then echo True; fi")
224 XCODE_LE9 = $(shell bash -c "v='$(XCODEVERSION)'; v=\$${v\#\#* }; if [ \$${v%%.*} -le 9 ]; then echo True; fi")
225 XCODE_EQ12 = $(shell bash -c "v='$(XCODEVERSION)'; v=\$${v\#\#* }; if [ \$${v%%.*} -eq 12 ]; then echo True; fi")
226 XCODE_GE13 = $(shell bash -c "v='$(XCODEVERSION)'; v=\$${v\#\#* }; if [ \$${v%%.*} -ge 13 ]; then echo True; fi")
227 XCODE_N_GE2 = $(shell bash -c "v='$(XCODEVERSION)'; v=\$${v\#*.}; if [ \$${v%%.*} -ge 2 ]; then echo True; fi")
228
229 MACOS_GE11 = $(shell bash -c "v='$(MACOSVERSION)'; if [ \$${v%%.*} -ge 11 ]; then echo True; fi")
230
231 # Build universal binaries
232 ifneq ($(BUILD_X86_64),False)
233 BUILD_X86_64 = True
234 endif
235 ifeq ($(XCODE_LE9),True)
236 ifneq ($(BUILD_X86),False)
237 BUILD_X86 = True
238 endif
239
240 ifeq ($(XCODE_LE3),True)
241 ifneq ($(BUILD_PPC),False)
242 BUILD_PPC = True
243 endif
244 endif
245 else ifeq ($(XCODE_EQ12),True)
246 ifeq ($(XCODE_N_GE2),True)
247 ifeq ($(MACOS_GE11),True)
248 ifneq ($(BUILD_ARM64),False)
249 BUILD_ARM64 = True
250 endif
251 endif
252 endif
253 else ifeq ($(XCODE_GE13),True)
254 ifeq ($(MACOS_GE11),True)
255 ifneq ($(BUILD_ARM64),False)
256 BUILD_ARM64 = True
257 endif
258 endif
259 endif
260
261 # Set build flags
262 override LDFLAGS += -Wl,-x
263
264 ifeq ($(BUILD_X86),True)
265 override CFLAGS += -arch i386 -Xarch_i386 -march=prescott
266 override LDFLAGS += -arch i386
267 endif
268 ifeq ($(BUILD_X86_64),True)
269 ifeq ($(MACOS_GE11),True)
270 override CFLAGS += -arch x86_64 -Xarch_x86_64 -march=haswell
271 else
272 override CFLAGS += -arch x86_64 -Xarch_x86_64 -march=core2
273 endif
274
275 override LDFLAGS += -arch x86_64
276 endif
277 ifeq ($(BUILD_PPC),True)
278 override CFLAGS += -arch ppc -Xarch_ppc -mcpu=G4
279 override LDFLAGS += -arch ppc
280 endif
281 ifeq ($(BUILD_PPC64),True)
282 override CFLAGS += -arch ppc64 -Xarch_ppc64 -mcpu=G5
283 override LDFLAGS += -arch ppc64
284 endif
285 ifeq ($(BUILD_ARM64),True)
286 override CFLAGS += -arch arm64
287 override LDFLAGS += -arch arm64
288 endif
289 else
290 override LDFLAGS += -s
291
292 ifeq ($(BUILD_X86),True)
293 override CFLAGS += -m32
294 override LDFLAGS += -m32
295 else ifeq ($(BUILD_X86_64),True)
296 override CFLAGS += -m64
297 override LDFLAGS += -m64
298 endif
299 endif
300
301 override CXXFLAGS += $(CFLAGS)
302 override OBJCFLAGS += $(CFLAGS)
303 override OBJCXXFLAGS += $(CFLAGS)
304
305 ifneq ($(BUILD_WIN32),True)
306 ifneq ($(BUILD_OSX),True)
307 override LDFLAGS += -Wl,-rpath,.
308 endif
309 endif
310 endif
311
312 # Set debug specific options
313 ifeq ($(findstring debug,$(config)),debug)
314 override CFLAGS = -pipe -g -Wall -DDEBUG
315 override CXXFLAGS =
316 override OBJCFLAGS =
317 override OBJCXXFLAGS =
318 override LDFLAGS = -pipe
319
320 ifneq ($(RTTI),True)
321 ifneq ($(BUILD_HAIKU),True)
322 override CXXFLAGS += -fno-rtti
323 override OBJCXXFLAGS += -fno-rtti
324 endif
325 endif
326
327 ifneq ($(EXCEPTION),True)
328 override CXXFLAGS += -fno-exceptions
329 override OBJCXXFLAGS += -fno-exceptions
330 endif
331
332 override CXXFLAGS += $(CFLAGS)
333 override OBJCFLAGS += $(CFLAGS)
334 override OBJCXXFLAGS += $(CFLAGS)
335
336 ifneq ($(BUILD_WIN32),True)
337 ifneq ($(BUILD_OSX),True)
338 override LDFLAGS += -Wl,-rpath,.
339 endif
340 endif
341 endif
342
343 # Flags needed for Windows ARM64 toolchain
344 ifeq ($(BUILD_WIN32),True)
345 ifeq ($(BUILD_ARM64),True)
346 override CFLAGS += -target aarch64-w64-mingw32
347 override LDFLAGS += -target aarch64-w64-mingw32
348 endif
349 endif
350
351 # Clear config variable
352 config =