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