A few more tweaks for AU hosting, WIP
[carla.git] / source / Makefile.mk
blob22aa5d319fafb30a492f375682ae9bddb0263a2b
1 #!/usr/bin/make -f
2 # Makefile for Carla C++ code #
3 # --------------------------- #
4 # Created by falkTX
7 # ---------------------------------------------------------------------------------------------------------------------
8 # Base environment vars
10 WINECC ?= winegcc
12 # ---------------------------------------------------------------------------------------------------------------------
13 # Internationalization
15 I18N_LANGUAGES :=
17 # ---------------------------------------------------------------------------------------------------------------------
18 # Base definitions for dependencies and system type
20 include $(CWD)/Makefile.deps.mk
22 # ---------------------------------------------------------------------------------------------------------------------
23 # Set build and link flags
25 BASE_FLAGS = -Wall -Wextra -pipe -DBUILDING_CARLA -MD -MP -fno-common
26 BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
28 ifeq ($(WASM),true)
29 BASE_OPTS += -msse -msse2 -msse3 -msimd128
30 else ifeq ($(CPU_ARM32),true)
31 BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard
32 else ifeq ($(CPU_I386_OR_X86_64),true)
33 BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse
34 endif
36 ifeq ($(MACOS),true)
37 # MacOS linker flags
38 BASE_FLAGS += -Wno-deprecated-declarations
39 LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip,-dead_strip_dylibs
40 ifneq ($(SKIP_STRIPPING),true)
41 LINK_OPTS += -Wl,-x
42 endif
43 else
44 # Common linker flags
45 LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-O1,--gc-sections
46 ifneq ($(WASM),true)
47 LINK_OPTS += -Wl,--as-needed
48 ifneq ($(SKIP_STRIPPING),true)
49 LINK_OPTS += -Wl,--strip-all
50 endif
51 endif
52 endif
54 ifeq ($(NOOPT),true)
55 # No CPU-specific optimization flags
56 BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections -DBUILDING_CARLA_NOOPT
57 endif
59 ifeq ($(WINDOWS),true)
60 # Assume we want posix
61 BASE_FLAGS += -posix
62 # Needed for windows, see https://github.com/falkTX/Carla/issues/855
63 BASE_FLAGS += -mstackrealign
64 ifeq ($(BUILDING_FOR_WINE),true)
65 BASE_FLAGS += -DBUILDING_CARLA_FOR_WINE
66 endif
67 else
68 # Not needed for Windows
69 BASE_FLAGS += -fPIC -DPIC
70 endif
72 ifeq ($(CLANG),true)
73 BASE_FLAGS += -Wabsolute-value
74 endif
76 ifeq ($(DEBUG),true)
77 BASE_FLAGS += -DDEBUG -O0 -g
78 LINK_OPTS =
79 ifeq ($(WASM),true)
80 LINK_OPTS += -sASSERTIONS=1
81 endif
82 else
83 BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
84 CXXFLAGS += -fvisibility-inlines-hidden
85 endif
87 ifneq ($(MACOS_OR_WASM_OR_WINDOWS),true)
88 ifneq ($(BSD),true)
89 BASE_FLAGS += -fno-gnu-unique
90 endif
91 endif
93 ifeq ($(WITH_LTO),true)
94 BASE_FLAGS += -fno-strict-aliasing -flto
95 LINK_OPTS += -fno-strict-aliasing -flto -Werror=odr -Werror=lto-type-mismatch
96 endif
98 32BIT_FLAGS = -m32
99 64BIT_FLAGS = -m64
100 ARM32_FLAGS = -mcpu=cortex-a7 -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -mvectorize-with-neon-quad
102 BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
103 BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++11 $(CXXFLAGS)
104 LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
106 ifeq ($(WASM),true)
107 # Special flag for emscripten
108 LINK_FLAGS += -sLLD_REPORT_UNDEFINED
109 else ifneq ($(MACOS),true)
110 # Not available on MacOS
111 LINK_FLAGS += -Wl,--no-undefined
112 endif
114 ifeq ($(WINDOWS),true)
115 # Always build static binaries on Windows
116 LINK_FLAGS += -static
117 endif
119 # ---------------------------------------------------------------------------------------------------------------------
120 # Strict test build
122 ifeq ($(TESTBUILD),true)
123 BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wdisabled-optimization
124 BASE_FLAGS += -Wdouble-promotion -Wfloat-equal -Wpointer-arith -Wsign-conversion
125 BASE_FLAGS += -Wformat=2 -Woverlength-strings
126 BASE_FLAGS += -Wmissing-declarations -Wredundant-decls
127 BASE_FLAGS += -Wshadow -Wundef -Wuninitialized -Wunused
128 BASE_FLAGS += -Wstrict-aliasing -fstrict-aliasing
129 BASE_FLAGS += -Wstrict-overflow -fstrict-overflow
130 BASE_FLAGS += -Wnull-dereference
131 ifneq ($(CLANG),true)
132 BASE_FLAGS += -Wabi=98 -Wclobbered -Wlogical-op
133 BASE_FLAGS += -Wformat-truncation=2 -Wformat-overflow=2
134 BASE_FLAGS += -Wstringop-overflow=4 -Wstringop-truncation
135 BASE_FLAGS += -Wduplicated-branches -Wduplicated-cond
136 endif
137 CFLAGS += -Winit-self -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes -Wwrite-strings
138 ifneq ($(CLANG),true)
139 CFLAGS += -Wjump-misses-init
140 endif
141 CXXFLAGS += -Wc++0x-compat -Wc++11-compat
142 CXXFLAGS += -Wnon-virtual-dtor -Woverloaded-virtual
143 # CXXFLAGS += -Wold-style-cast -Wuseless-cast
144 CXXFLAGS += -Wzero-as-null-pointer-constant
145 ifneq ($(DEBUG),true)
146 CXXFLAGS += -Weffc++
147 endif
148 ifeq ($(LINUX),true)
149 BASE_FLAGS += -isystem /opt/kxstudio/include
150 endif
151 ifeq ($(MACOS),true)
152 CXXFLAGS += -isystem /System/Library/Frameworks
153 endif
154 # TODO
155 ifeq ($(CLANG),true)
156 BASE_FLAGS += -Wno-double-promotion
157 BASE_FLAGS += -Wno-format-nonliteral
158 BASE_FLAGS += -Wno-tautological-pointer-compare
159 endif
160 endif
162 # ---------------------------------------------------------------------------------------------------------------------
163 # Set base defines
165 ifeq ($(JACKBRIDGE_DIRECT),true)
166 ifeq ($(HAVE_JACKLIB),true)
167 BASE_FLAGS += -DJACKBRIDGE_DIRECT
168 else
169 $(error jackbridge direct mode requested, but jack not available)
170 endif
171 endif
173 ifeq ($(HAVE_DGL),true)
174 BASE_FLAGS += -DHAVE_DGL
175 BASE_FLAGS += -DHAVE_OPENGL
176 BASE_FLAGS += -DDGL_OPENGL
177 BASE_FLAGS += -DDONT_SET_USING_DGL_NAMESPACE
178 ifeq ($(USING_CUSTOM_DPF),true)
179 BASE_FLAGS += -DDISTRHO_UI_FILE_BROWSER=0
180 endif
181 ifneq ($(DGL_NAMESPACE),)
182 BASE_FLAGS += -DDGL_NAMESPACE=$(DGL_NAMESPACE)
183 else
184 BASE_FLAGS += -DDGL_NAMESPACE=CarlaDGL
185 endif
186 endif
188 ifneq ($(USING_CUSTOM_DPF),true)
189 BASE_FLAGS += -DDGL_FILE_BROWSER_DISABLED
190 BASE_FLAGS += -DDGL_NO_SHARED_RESOURCES
191 endif
193 ifeq ($(HAVE_FLUIDSYNTH),true)
194 BASE_FLAGS += -DHAVE_FLUIDSYNTH
195 ifeq ($(HAVE_FLUIDSYNTH_INSTPATCH),true)
196 BASE_FLAGS += -DHAVE_FLUIDSYNTH_INSTPATCH
197 endif
198 endif
200 ifeq ($(HAVE_FFMPEG),true)
201 BASE_FLAGS += -DHAVE_FFMPEG
202 endif
204 ifeq ($(HAVE_HYLIA),true)
205 BASE_FLAGS += -DHAVE_HYLIA
206 endif
208 ifeq ($(HAVE_JACK),true)
209 BASE_FLAGS += -DHAVE_JACK
210 endif
212 ifeq ($(HAVE_LIBLO),true)
213 BASE_FLAGS += -DHAVE_LIBLO
214 endif
216 ifeq ($(HAVE_LIBMAGIC),true)
217 BASE_FLAGS += -DHAVE_LIBMAGIC
218 endif
220 ifeq ($(HAVE_PYQT),true)
221 BASE_FLAGS += -DHAVE_PYQT
222 endif
224 ifeq ($(HAVE_SDL2),true)
225 BASE_FLAGS += -DHAVE_SDL -DHAVE_SDL2
226 else ifeq ($(HAVE_SDL1),true)
227 BASE_FLAGS += -DHAVE_SDL -DHAVE_SDL1
228 endif
230 ifeq ($(HAVE_SNDFILE),true)
231 BASE_FLAGS += -DHAVE_SNDFILE
232 endif
234 ifeq ($(HAVE_X11),true)
235 BASE_FLAGS += -DHAVE_X11
236 endif
238 ifeq ($(HAVE_YSFX),true)
239 BASE_FLAGS += -DHAVE_YSFX
240 endif
242 ifeq ($(USING_RTAUDIO),true)
243 BASE_FLAGS += -DUSING_RTAUDIO
244 endif
246 ifeq ($(STATIC_PLUGIN_TARGET),true)
247 BASE_FLAGS += -DSTATIC_PLUGIN_TARGET
248 endif
250 # ---------------------------------------------------------------------------------------------------------------------
251 # Allow custom namespace
253 ifneq ($(CARLA_BACKEND_NAMESPACE),)
254 BASE_FLAGS += -DCARLA_BACKEND_NAMESPACE=$(CARLA_BACKEND_NAMESPACE)
255 endif
257 # ---------------------------------------------------------------------------------------------------------------------
258 # Set app extension
260 ifeq ($(WASM),true)
261 APP_EXT = .html
262 else ifeq ($(WINDOWS),true)
263 APP_EXT = .exe
264 endif
266 # ---------------------------------------------------------------------------------------------------------------------
267 # Set shared lib extension
269 ifeq ($(MACOS),true)
270 LIB_EXT = .dylib
271 else ifeq ($(WASM),true)
272 LIB_EXT = .js
273 else ifeq ($(WINDOWS),true)
274 LIB_EXT = .dll
275 else
276 LIB_EXT = .so
277 endif
279 BASE_FLAGS += -DCARLA_LIB_EXT=\"$(LIB_EXT)\"
281 # ---------------------------------------------------------------------------------------------------------------------
282 # Set static libs start & end
284 ifneq ($(MACOS),true)
285 LIBS_START = -Wl,--start-group -Wl,--whole-archive
286 LIBS_END = -Wl,--no-whole-archive -Wl,--end-group
287 endif
289 # ---------------------------------------------------------------------------------------------------------------------
290 # Handle the verbosity switch
292 SILENT =
294 ifeq ($(VERBOSE),1)
295 else ifeq ($(VERBOSE),y)
296 else ifeq ($(VERBOSE),yes)
297 else ifeq ($(VERBOSE),true)
298 else
299 SILENT = @
300 endif
302 # ---------------------------------------------------------------------------------------------------------------------
303 # Set shared library CLI arg
305 ifeq ($(MACOS),true)
306 SHARED = -dynamiclib
307 else ifeq ($(WASM),true)
308 SHARED = -sMAIN_MODULE=2
309 else
310 SHARED = -shared
311 endif
313 # ---------------------------------------------------------------------------------------------------------------------
314 # Set arguments used for inline 'sed'
316 ifeq ($(BSD),true)
317 SED_ARGS=-i '' -e
318 else
319 SED_ARGS=-i -e
320 endif
322 # ---------------------------------------------------------------------------------------------------------------------
323 # Set command used for file symlinking
325 LINK := ln -sf
327 # ---------------------------------------------------------------------------------------------------------------------
328 # Check if we can generate ttl files
330 ifneq ($(BUILDING_FOR_WINE),true)
331 ifeq ($(CROSS_COMPILING),true)
332 ifeq ($(WINDOWS),true)
333 NEEDS_WINE = true
334 endif
335 endif
336 endif
338 ifneq ($(CROSS_COMPILING),true)
339 CAN_GENERATE_LV2_TTL = true
340 else ifeq ($(NEEDS_WINE),true)
341 ifneq ($(EXE_WRAPPER),)
342 CAN_GENERATE_LV2_TTL = true
343 endif
344 endif
346 # ---------------------------------------------------------------------------------------------------------------------
347 # Check if we should build the external plugins
349 ifeq ($(EXTERNAL_PLUGINS),true)
350 ifneq ($(DEBUG),true)
351 ifneq ($(TESTBUILD),true)
352 ifneq (,$(wildcard $(CWD)/native-plugins/external/Makefile.mk))
353 BASE_FLAGS += -DHAVE_EXTERNAL_PLUGINS
354 include $(CWD)/native-plugins/external/Makefile.mk
355 endif
356 endif
357 endif
358 endif
360 # ---------------------------------------------------------------------------------------------------------------------