1#!/usr/bin/make -f
2# Makefile for DPF #
3# ---------------- #
4# Created by falkTX
5#
6
7AR  ?= ar
8CC  ?= gcc
9CXX ?= g++
10
11# ---------------------------------------------------------------------------------------------------------------------
12# Auto-detect OS if not defined
13
14TARGET_MACHINE := $(shell $(CC) -dumpmachine)
15
16ifneq ($(BSD),true)
17ifneq ($(HAIKU),true)
18ifneq ($(HURD),true)
19ifneq ($(LINUX),true)
20ifneq ($(MACOS),true)
21ifneq ($(WINDOWS),true)
22
23ifneq (,$(findstring bsd,$(TARGET_MACHINE)))
24BSD=true
25endif
26ifneq (,$(findstring haiku,$(TARGET_MACHINE)))
27HAIKU=true
28endif
29ifneq (,$(findstring gnu,$(TARGET_MACHINE)))
30HURD=true
31endif
32ifneq (,$(findstring linux,$(TARGET_MACHINE)))
33LINUX=true
34endif
35ifneq (,$(findstring apple,$(TARGET_MACHINE)))
36MACOS=true
37endif
38ifneq (,$(findstring mingw,$(TARGET_MACHINE)))
39WINDOWS=true
40endif
41
42endif
43endif
44endif
45endif
46endif
47endif
48
49# ---------------------------------------------------------------------------------------------------------------------
50# Auto-detect the processor
51
52TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE)))
53
54ifneq (,$(filter i%86,$(TARGET_PROCESSOR)))
55CPU_I386=true
56CPU_I386_OR_X86_64=true
57endif
58ifneq (,$(filter x86_64,$(TARGET_PROCESSOR)))
59CPU_X86_64=true
60CPU_I386_OR_X86_64=true
61endif
62ifneq (,$(filter arm%,$(TARGET_PROCESSOR)))
63CPU_ARM=true
64CPU_ARM_OR_AARCH64=true
65endif
66ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR)))
67CPU_AARCH64=true
68CPU_ARM_OR_AARCH64=true
69endif
70
71# ---------------------------------------------------------------------------------------------------------------------
72# Set PKG_CONFIG (can be overridden by environment variable)
73
74ifeq ($(WINDOWS),true)
75# Build statically on Windows by default
76PKG_CONFIG ?= pkg-config --static
77else
78PKG_CONFIG ?= pkg-config
79endif
80
81# ---------------------------------------------------------------------------------------------------------------------
82# Set LINUX_OR_MACOS
83
84ifeq ($(LINUX),true)
85LINUX_OR_MACOS=true
86endif
87
88ifeq ($(MACOS),true)
89LINUX_OR_MACOS=true
90endif
91
92# ---------------------------------------------------------------------------------------------------------------------
93# Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS
94
95ifeq ($(HAIKU),true)
96HAIKU_OR_MACOS_OR_WINDOWS=true
97endif
98
99ifeq ($(MACOS),true)
100MACOS_OR_WINDOWS=true
101HAIKU_OR_MACOS_OR_WINDOWS=true
102endif
103
104ifeq ($(WINDOWS),true)
105MACOS_OR_WINDOWS=true
106HAIKU_OR_MACOS_OR_WINDOWS=true
107endif
108
109# ---------------------------------------------------------------------------------------------------------------------
110# Set UNIX
111
112ifeq ($(BSD),true)
113UNIX=true
114endif
115
116ifeq ($(HURD),true)
117UNIX=true
118endif
119
120ifeq ($(LINUX),true)
121UNIX=true
122endif
123
124ifeq ($(MACOS),true)
125UNIX=true
126endif
127
128# ---------------------------------------------------------------------------------------------------------------------
129# Set build and link flags
130
131BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
132BASE_OPTS  = -O3 -ffast-math -fdata-sections -ffunction-sections
133
134ifeq ($(CPU_I386_OR_X86_64),true)
135BASE_OPTS += -mtune=generic -msse -msse2
136endif
137
138ifeq ($(CPU_ARM),true)
139BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard
140endif
141
142ifeq ($(MACOS),true)
143# MacOS linker flags
144LINK_OPTS  = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
145else
146# Common linker flags
147LINK_OPTS  = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
148ifneq ($(SKIP_STRIPPING),true)
149LINK_OPTS += -Wl,--strip-all
150endif
151endif
152
153ifeq ($(NOOPT),true)
154# No CPU-specific optimization flags
155BASE_OPTS  = -O2 -ffast-math -fdata-sections -ffunction-sections
156endif
157
158ifeq ($(WINDOWS),true)
159# mingw has issues with this specific optimization
160# See https://github.com/falkTX/Carla/issues/696
161BASE_OPTS  += -fno-rerun-cse-after-loop
162# See https://github.com/falkTX/Carla/issues/855
163BASE_OPTS  += -mstackrealign
164ifeq ($(BUILDING_FOR_WINDOWS),true)
165BASE_FLAGS += -DBUILDING_CARLA_FOR_WINDOWS
166endif
167else
168# Not needed for Windows
169BASE_FLAGS += -fPIC -DPIC
170endif
171
172ifeq ($(DEBUG),true)
173BASE_FLAGS += -DDEBUG -O0 -g
174LINK_OPTS   =
175else
176BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
177CXXFLAGS   += -fvisibility-inlines-hidden
178endif
179
180BUILD_C_FLAGS   = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
181BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
182LINK_FLAGS      = $(LINK_OPTS) $(LDFLAGS)
183
184ifneq ($(MACOS),true)
185# Not available on MacOS
186LINK_FLAGS     += -Wl,--no-undefined
187endif
188
189ifeq ($(MACOS_OLD),true)
190BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
191endif
192
193ifeq ($(WINDOWS),true)
194# Always build statically on windows
195LINK_FLAGS     += -static
196endif
197
198# ---------------------------------------------------------------------------------------------------------------------
199# Strict test build
200
201ifeq ($(TESTBUILD),true)
202BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
203BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5
204# BASE_FLAGS += -Wfloat-equal
205ifeq ($(CC),clang)
206BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
207BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
208else
209BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
210endif
211ifneq ($(MACOS),true)
212BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
213ifneq ($(CC),clang)
214BASE_FLAGS += -Wlogical-op
215endif
216endif
217CFLAGS     += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
218CXXFLAGS   += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
219endif
220
221# ---------------------------------------------------------------------------------------------------------------------
222# Check for required libraries
223
224HAVE_CAIRO  = $(shell $(PKG_CONFIG) --exists cairo && echo true)
225
226ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
227HAVE_OPENGL = true
228else
229HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
230HAVE_X11    = $(shell $(PKG_CONFIG) --exists x11 && echo true)
231endif
232
233# ---------------------------------------------------------------------------------------------------------------------
234# Check for optional libraries
235
236HAVE_JACK  = $(shell $(PKG_CONFIG) --exists jack && echo true)
237HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
238
239# ---------------------------------------------------------------------------------------------------------------------
240# Set Generic DGL stuff
241
242ifeq ($(HAIKU),true)
243DGL_SYSTEM_LIBS += -lbe
244endif
245
246ifeq ($(MACOS),true)
247DGL_SYSTEM_LIBS += -framework Cocoa
248endif
249
250ifeq ($(WINDOWS),true)
251DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
252endif
253
254ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
255ifeq ($(HAVE_X11),true)
256DGL_FLAGS       += $(shell $(PKG_CONFIG) --cflags x11)
257DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
258endif
259endif
260
261# ---------------------------------------------------------------------------------------------------------------------
262# Set Cairo specific stuff
263
264ifeq ($(HAVE_CAIRO),true)
265
266DGL_FLAGS   += -DHAVE_CAIRO
267
268CAIRO_FLAGS  = $(shell $(PKG_CONFIG) --cflags cairo)
269CAIRO_LIBS   = $(shell $(PKG_CONFIG) --libs cairo)
270
271HAVE_CAIRO_OR_OPENGL = true
272
273endif
274
275# ---------------------------------------------------------------------------------------------------------------------
276# Set OpenGL specific stuff
277
278ifeq ($(HAVE_OPENGL),true)
279
280DGL_FLAGS   += -DHAVE_OPENGL
281
282ifeq ($(HAIKU),true)
283OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
284OPENGL_LIBS  = $(shell $(PKG_CONFIG) --libs gl)
285endif
286
287ifeq ($(MACOS),true)
288OPENGL_LIBS  = -framework OpenGL
289endif
290
291ifeq ($(WINDOWS),true)
292OPENGL_LIBS  = -lopengl32
293endif
294
295ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
296OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
297OPENGL_LIBS  = $(shell $(PKG_CONFIG) --libs gl x11)
298endif
299
300HAVE_CAIRO_OR_OPENGL = true
301
302endif
303
304# ---------------------------------------------------------------------------------------------------------------------
305# Set app extension
306
307ifeq ($(WINDOWS),true)
308APP_EXT = .exe
309endif
310
311# ---------------------------------------------------------------------------------------------------------------------
312# Set shared lib extension
313
314LIB_EXT = .so
315
316ifeq ($(MACOS),true)
317LIB_EXT = .dylib
318endif
319
320ifeq ($(WINDOWS),true)
321LIB_EXT = .dll
322endif
323
324# ---------------------------------------------------------------------------------------------------------------------
325# Set shared library CLI arg
326
327ifeq ($(MACOS),true)
328SHARED = -dynamiclib
329else
330SHARED = -shared
331endif
332
333# ---------------------------------------------------------------------------------------------------------------------
334# Handle the verbosity switch
335
336ifeq ($(VERBOSE),true)
337SILENT =
338else
339SILENT = @
340endif
341
342# ---------------------------------------------------------------------------------------------------------------------
343