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 ($(WIN32),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)))
38WIN32=true
39endif
40
41endif
42endif
43endif
44endif
45endif
46endif
47
48# ---------------------------------------------------------------------------------------------------------------------
49# Set LINUX_OR_MACOS
50
51ifeq ($(LINUX),true)
52LINUX_OR_MACOS=true
53endif
54
55ifeq ($(MACOS),true)
56LINUX_OR_MACOS=true
57endif
58
59# ---------------------------------------------------------------------------------------------------------------------
60# Set MACOS_OR_WIN32
61
62ifeq ($(MACOS),true)
63MACOS_OR_WIN32=true
64endif
65
66ifeq ($(WIN32),true)
67MACOS_OR_WIN32=true
68endif
69
70# ---------------------------------------------------------------------------------------------------------------------
71# Set UNIX
72
73ifeq ($(BSD),true)
74UNIX=true
75endif
76
77ifeq ($(HURD),true)
78UNIX=true
79endif
80
81ifeq ($(LINUX),true)
82UNIX=true
83endif
84
85ifeq ($(MACOS),true)
86UNIX=true
87endif
88
89# ---------------------------------------------------------------------------------------------------------------------
90# Set build and link flags
91
92BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
93BASE_OPTS  = -O3 -ffast-math -fdata-sections -ffunction-sections
94
95ifeq ($(MACOS),true)
96# MacOS linker flags
97LINK_OPTS  = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
98else
99# Common linker flags
100LINK_OPTS  = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
101ifneq ($(SKIP_STRIPPING),true)
102LINK_OPTS += -Wl,--strip-all
103endif
104endif
105
106ifeq ($(NOOPT),true)
107# No CPU-specific optimization flags
108BASE_OPTS  = -O2 -ffast-math -fdata-sections -ffunction-sections
109endif
110
111ifeq ($(WIN32),true)
112# mingw has issues with this specific optimization
113# See https://github.com/falkTX/Carla/issues/696
114BASE_OPTS  += -fno-rerun-cse-after-loop
115ifeq ($(BUILDING_FOR_WINDOWS),true)
116BASE_FLAGS += -DBUILDING_CARLA_FOR_WINDOWS
117endif
118else
119# Not needed for Windows
120BASE_FLAGS += -fPIC -DPIC
121endif
122
123ifeq ($(DEBUG),true)
124BASE_FLAGS += -DDEBUG -O0 -g
125LINK_OPTS   =
126else
127BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
128CXXFLAGS   += -fvisibility-inlines-hidden
129endif
130
131BUILD_C_FLAGS   = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
132BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
133LINK_FLAGS      = $(LINK_OPTS) $(LDFLAGS)
134
135ifneq ($(MACOS),true)
136# Not available on MacOS
137LINK_FLAGS     += -Wl,--no-undefined
138endif
139
140ifeq ($(MACOS_OLD),true)
141BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
142endif
143
144ifeq ($(WIN32),true)
145# Always build statically on windows
146LINK_FLAGS     += -static
147endif
148
149# ---------------------------------------------------------------------------------------------------------------------
150# Strict test build
151
152ifeq ($(TESTBUILD),true)
153BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
154BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5
155# BASE_FLAGS += -Wfloat-equal
156ifeq ($(CC),clang)
157BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
158BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
159else
160BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
161endif
162ifneq ($(MACOS),true)
163BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
164ifneq ($(CC),clang)
165BASE_FLAGS += -Wlogical-op
166endif
167endif
168CFLAGS     += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
169CXXFLAGS   += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
170endif
171
172# ---------------------------------------------------------------------------------------------------------------------
173# Check for optional libs
174
175ifeq ($(MACOS_OR_WIN32),true)
176HAVE_DGL   = true
177else
178HAVE_DGL   = $(shell pkg-config --exists gl x11 && echo true)
179HAVE_JACK  = $(shell pkg-config --exists jack   && echo true)
180HAVE_LIBLO = $(shell pkg-config --exists liblo  && echo true)
181endif
182
183ifneq ($(HAVE_DGL),true)
184$(error DGL missing 22)
185endif
186
187# ---------------------------------------------------------------------------------------------------------------------
188# Set libs stuff
189
190ifeq ($(HAVE_DGL),true)
191
192ifeq ($(MACOS),true)
193DGL_LIBS  = -framework OpenGL -framework Cocoa
194endif
195
196ifeq ($(WIN32),true)
197DGL_LIBS  = -lopengl32 -lgdi32
198endif
199
200ifneq ($(MACOS_OR_WIN32),true)
201DGL_FLAGS = $(shell pkg-config --cflags gl x11)
202DGL_LIBS  = $(shell pkg-config --libs gl x11)
203endif
204
205endif # HAVE_DGL
206
207# ---------------------------------------------------------------------------------------------------------------------
208# Set app extension
209
210ifeq ($(WIN32),true)
211APP_EXT = .exe
212endif
213
214# ---------------------------------------------------------------------------------------------------------------------
215# Set shared lib extension
216
217LIB_EXT = .so
218
219ifeq ($(MACOS),true)
220LIB_EXT = .dylib
221endif
222
223ifeq ($(WIN32),true)
224LIB_EXT = .dll
225endif
226
227# ---------------------------------------------------------------------------------------------------------------------
228# Set shared library CLI arg
229
230SHARED = -shared
231
232ifeq ($(MACOS),true)
233SHARED = -dynamiclib
234endif
235
236# ---------------------------------------------------------------------------------------------------------------------
237