Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

548 lines
14KB

  1. #!/usr/bin/make -f
  2. # Makefile for Carla C++ code #
  3. # --------------------------- #
  4. # Created by falkTX
  5. #
  6. # ---------------------------------------------------------------------------------------------------------------------
  7. # Modify to enable/disable specific features
  8. # Build external plugins (if debug is disabled)
  9. ifneq ($(DEBUG),true)
  10. EXTERNAL_PLUGINS = true
  11. endif
  12. # ---------------------------------------------------------------------------------------------------------------------
  13. # DO NOT MODIFY PAST THIS POINT!
  14. AR ?= ar
  15. CC ?= gcc
  16. CXX ?= g++
  17. # ---------------------------------------------------------------------------------------------------------------------
  18. # Auto-detect OS if not defined
  19. ifneq ($(BSD),true)
  20. ifneq ($(HAIKU),true)
  21. ifneq ($(HURD),true)
  22. ifneq ($(LINUX),true)
  23. ifneq ($(MACOS),true)
  24. ifneq ($(WIN32),true)
  25. TARGET_MACHINE := $(shell $(CC) -dumpmachine)
  26. ifneq (,$(findstring bsd,$(TARGET_MACHINE)))
  27. BSD=true
  28. endif
  29. ifneq (,$(findstring haiku,$(TARGET_MACHINE)))
  30. HAIKU=true
  31. endif
  32. ifneq (,$(findstring gnu,$(TARGET_MACHINE)))
  33. HURD=true
  34. endif
  35. ifneq (,$(findstring linux,$(TARGET_MACHINE)))
  36. LINUX=true
  37. endif
  38. ifneq (,$(findstring apple,$(TARGET_MACHINE)))
  39. MACOS=true
  40. endif
  41. ifneq (,$(findstring mingw,$(TARGET_MACHINE)))
  42. WIN32=true
  43. endif
  44. endif
  45. endif
  46. endif
  47. endif
  48. endif
  49. endif
  50. # ---------------------------------------------------------------------------------------------------------------------
  51. # Set LINUX_OR_MACOS
  52. ifeq ($(LINUX),true)
  53. LINUX_OR_MACOS=true
  54. endif
  55. ifeq ($(MACOS),true)
  56. LINUX_OR_MACOS=true
  57. endif
  58. # ---------------------------------------------------------------------------------------------------------------------
  59. # Set MACOS_OR_WIN32
  60. ifeq ($(MACOS),true)
  61. MACOS_OR_WIN32=true
  62. endif
  63. ifeq ($(WIN32),true)
  64. MACOS_OR_WIN32=true
  65. endif
  66. # ---------------------------------------------------------------------------------------------------------------------
  67. # Set UNIX
  68. ifeq ($(BSD),true)
  69. UNIX=true
  70. endif
  71. ifeq ($(HURD),true)
  72. UNIX=true
  73. endif
  74. ifeq ($(LINUX),true)
  75. UNIX=true
  76. endif
  77. ifeq ($(MACOS),true)
  78. UNIX=true
  79. endif
  80. # ---------------------------------------------------------------------------------------------------------------------
  81. # Set build and link flags
  82. BASE_FLAGS = -Wall -Wextra -pipe -DBUILDING_CARLA -DREAL_BUILD -MD -MP
  83. BASE_OPTS = -O3 -ffast-math -mtune=generic -msse -msse2 -mfpmath=sse -fdata-sections -ffunction-sections
  84. ifeq ($(MACOS),true)
  85. # MacOS linker flags
  86. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
  87. else
  88. # Common linker flags
  89. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
  90. ifneq ($(SKIP_STRIPPING),true)
  91. LINK_OPTS += -Wl,--strip-all
  92. endif
  93. endif
  94. ifeq ($(RASPPI),true)
  95. # Raspberry-Pi optimization flags
  96. BASE_OPTS = -O3 -ffast-math -march=armv6 -mfpu=vfp -mfloat-abi=hard
  97. LINK_OPTS = -Wl,-O1 -Wl,--as-needed -Wl,--strip-all
  98. endif
  99. ifeq ($(NOOPT),true)
  100. # No CPU-specific optimization flags
  101. BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
  102. endif
  103. ifneq ($(WIN32),true)
  104. # Not needed for Windows
  105. BASE_FLAGS += -fPIC -DPIC
  106. endif
  107. ifeq ($(CLANG),true)
  108. BASE_FLAGS += -Wabsolute-value
  109. endif
  110. ifeq ($(STOAT),true)
  111. CC = clang
  112. CXX = clang++
  113. BASE_FLAGS += -emit-llvm
  114. BASE_OPTS += -O0
  115. endif
  116. ifeq ($(DEBUG),true)
  117. BASE_FLAGS += -DDEBUG -O0 -g
  118. ifeq ($(WIN32),true)
  119. BASE_FLAGS += -msse -msse2
  120. endif
  121. LINK_OPTS =
  122. else
  123. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  124. CXXFLAGS += -fvisibility-inlines-hidden
  125. endif
  126. 32BIT_FLAGS = -m32
  127. 64BIT_FLAGS = -m64
  128. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  129. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
  130. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  131. ifneq ($(MACOS),true)
  132. # Not available on MacOS
  133. LINK_FLAGS += -Wl,--no-undefined
  134. endif
  135. ifeq ($(MACOS_OLD),true)
  136. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  137. endif
  138. # ---------------------------------------------------------------------------------------------------------------------
  139. # Strict test build
  140. ifeq ($(TESTBUILD),true)
  141. BASE_FLAGS += -Werror -Wabi -Wcast-qual -Wclobbered -Wconversion -Wdisabled-optimization -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-declarations
  142. BASE_FLAGS += -Woverlength-strings -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-conversion -Wundef -Wuninitialized -Wunused
  143. BASE_FLAGS += -Wstrict-aliasing -fstrict-aliasing
  144. BASE_FLAGS += -Wstrict-overflow -fstrict-overflow
  145. CFLAGS += -Wnested-externs -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings
  146. CXXFLAGS += -Wc++0x-compat -Wc++11-compat -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual -Wzero-as-null-pointer-constant
  147. ifeq ($(LINUX),true)
  148. BASE_FLAGS += -isystem /opt/kxstudio/include
  149. CXXFLAGS += -isystem /usr/include/glib-2.0
  150. CXXFLAGS += -isystem /usr/include/glib-2.0/glib
  151. CXXFLAGS += -isystem /usr/include/gtk-2.0
  152. CXXFLAGS += -isystem /usr/include/gtk-2.0/gio
  153. ifeq ($(DEFAULT_QT),4)
  154. CXXFLAGS += -isystem /usr/include/qt4
  155. else
  156. CXXFLAGS += -isystem /usr/include/qt5
  157. endif
  158. endif
  159. ifeq ($(MACOS),true)
  160. BASE_FLAGS += -isystem /opt/kxstudio/include
  161. CXXFLAGS += -isystem /System/Library/Frameworks
  162. endif
  163. ifeq ($(WIN64),true)
  164. BASE_FLAGS += -isystem /opt/mingw64/include
  165. else
  166. ifeq ($(WIN32),true)
  167. BASE_FLAGS += -isystem /opt/mingw32/include
  168. endif
  169. endif
  170. endif
  171. # ---------------------------------------------------------------------------------------------------------------------
  172. # Check for optional libs (required by backend or bridges)
  173. ifeq ($(LINUX),true)
  174. HAVE_ALSA = $(shell pkg-config --exists alsa && echo true)
  175. HAVE_HYLIA = true
  176. endif
  177. ifeq ($(MACOS),true)
  178. ifneq ($(MACOS_OLD),true)
  179. HAVE_HYLIA = true
  180. endif
  181. endif
  182. ifneq ($(MACOS_OR_WIN32),true)
  183. HAVE_GTK2 = $(shell pkg-config --exists gtk+-2.0 && echo true)
  184. HAVE_GTK3 = $(shell pkg-config --exists gtk+-3.0 && echo true)
  185. HAVE_X11 = $(shell pkg-config --exists x11 && echo true)
  186. endif
  187. ifeq ($(UNIX),true)
  188. ifneq ($(MACOS),true)
  189. HAVE_PULSEAUDIO = $(shell pkg-config --exists libpulse-simple && echo true)
  190. endif
  191. endif
  192. HAVE_FFMPEG = $(shell pkg-config --exists libavcodec libavformat libavutil && echo true)
  193. HAVE_FLUIDSYNTH = $(shell pkg-config --exists fluidsynth && echo true)
  194. HAVE_LIBLO = $(shell pkg-config --exists liblo && echo true)
  195. HAVE_LINUXSAMPLER = $(shell pkg-config --atleast-version=1.0.0.svn41 linuxsampler && echo true)
  196. HAVE_QT4 = $(shell pkg-config --exists QtCore QtGui && echo true)
  197. HAVE_QT5 = $(shell pkg-config --exists Qt5Core Qt5Gui Qt5Widgets && echo true)
  198. HAVE_SNDFILE = $(shell pkg-config --exists sndfile && echo true)
  199. # ---------------------------------------------------------------------------------------------------------------------
  200. # Check for optional libs (special non-pkgconfig tests)
  201. ifneq ($(WIN32),true)
  202. # libmagic doesn't have a pkg-config file, so we need to call the compiler to test it
  203. HAVE_LIBMAGIC = $(shell echo '\#include <magic.h>' | $(CC) $(CFLAGS) -x c -w -c - -o .libmagic-tmp 2>/dev/null && echo true)
  204. endif
  205. # ---------------------------------------------------------------------------------------------------------------------
  206. # Set Qt tools
  207. ifeq ($(HAVE_QT4),true)
  208. MOC_QT4 ?= $(shell pkg-config --variable=moc_location QtCore)
  209. RCC_QT4 ?= $(shell pkg-config --variable=rcc_location QtCore)
  210. ifeq (,$(wildcard $(MOC_QT4)))
  211. HAVE_QT4=false
  212. endif
  213. ifeq (,$(wildcard $(RCC_QT4)))
  214. HAVE_QT4=false
  215. endif
  216. endif
  217. ifeq ($(HAVE_QT5),true)
  218. QT5_HOSTBINS = $(shell pkg-config --variable=host_bins Qt5Core)
  219. MOC_QT5 ?= $(QT5_HOSTBINS)/moc
  220. RCC_QT5 ?= $(QT5_HOSTBINS)/rcc
  221. ifeq (,$(wildcard $(MOC_QT5)))
  222. HAVE_QT5=false
  223. endif
  224. ifeq (,$(wildcard $(RCC_QT5)))
  225. HAVE_QT5=false
  226. endif
  227. endif
  228. ifeq ($(HAVE_QT4),true)
  229. HAVE_QT=true
  230. endif
  231. ifeq ($(HAVE_QT5),true)
  232. HAVE_QT=true
  233. endif
  234. ifeq ($(WIN32),true)
  235. HAVE_QT=true
  236. endif
  237. # ---------------------------------------------------------------------------------------------------------------------
  238. # Set PyQt tools
  239. PYRCC4 ?= $(shell which pyrcc4 2>/dev/null)
  240. PYUIC4 ?= $(shell which pyuic4 2>/dev/null)
  241. PYRCC5 ?= $(shell which pyrcc5 2>/dev/null)
  242. PYUIC5 ?= $(shell which pyuic5 2>/dev/null)
  243. HAVE_PYQT4=false
  244. HAVE_PYQT5=false
  245. ifneq ($(PYUIC4),)
  246. ifneq ($(PYRCC4),)
  247. HAVE_PYQT=true
  248. HAVE_PYQT4=true
  249. endif
  250. endif
  251. ifneq ($(PYUIC5),)
  252. ifneq ($(PYRCC5),)
  253. HAVE_PYQT=true
  254. HAVE_PYQT5=true
  255. endif
  256. endif
  257. # ---------------------------------------------------------------------------------------------------------------------
  258. # Set default Qt used in frontend
  259. ifeq ($(HAVE_PYQT5),true)
  260. DEFAULT_QT ?= 5
  261. else
  262. DEFAULT_QT ?= 4
  263. endif
  264. # ---------------------------------------------------------------------------------------------------------------------
  265. # Set base defines
  266. ifeq ($(HAVE_PYQT),true)
  267. BASE_FLAGS += -DHAVE_PYQT
  268. endif
  269. ifeq ($(HAVE_FLUIDSYNTH),true)
  270. BASE_FLAGS += -DHAVE_FLUIDSYNTH
  271. endif
  272. ifeq ($(HAVE_FFMPEG),true)
  273. BASE_FLAGS += -DHAVE_FFMPEG
  274. endif
  275. ifeq ($(HAVE_HYLIA),true)
  276. BASE_FLAGS += -DHAVE_HYLIA
  277. endif
  278. ifeq ($(HAVE_LIBLO),true)
  279. BASE_FLAGS += -DHAVE_LIBLO
  280. endif
  281. ifeq ($(HAVE_LIBMAGIC),true)
  282. BASE_FLAGS += -DHAVE_LIBMAGIC
  283. endif
  284. ifeq ($(HAVE_LINUXSAMPLER),true)
  285. BASE_FLAGS += -DHAVE_LINUXSAMPLER
  286. endif
  287. ifeq ($(HAVE_SNDFILE),true)
  288. BASE_FLAGS += -DHAVE_SNDFILE
  289. endif
  290. ifeq ($(HAVE_X11),true)
  291. BASE_FLAGS += -DHAVE_X11
  292. endif
  293. # ---------------------------------------------------------------------------------------------------------------------
  294. # Set libs stuff (part 1)
  295. ifeq ($(LINUX_OR_MACOS),true)
  296. LIBDL_LIBS = -ldl
  297. endif
  298. ifeq ($(HAVE_LIBLO),true)
  299. LIBLO_FLAGS = $(shell pkg-config --cflags liblo)
  300. LIBLO_LIBS = $(shell pkg-config --libs liblo)
  301. endif
  302. ifeq ($(HAVE_FFMPEG),true)
  303. FFMPEG_FLAGS = $(shell pkg-config --cflags libavcodec libavformat libavutil)
  304. FFMPEG_LIBS = $(shell pkg-config --libs libavcodec libavformat libavutil)
  305. endif
  306. ifeq ($(HAVE_FLUIDSYNTH),true)
  307. FLUIDSYNTH_FLAGS = $(shell pkg-config --cflags fluidsynth)
  308. FLUIDSYNTH_LIBS = $(shell pkg-config --libs fluidsynth)
  309. endif
  310. ifeq ($(HAVE_LINUXSAMPLER),true)
  311. LINUXSAMPLER_FLAGS = $(shell pkg-config --cflags linuxsampler) -DIS_CPP11=1 -Wno-non-virtual-dtor -Wno-shadow -Wno-unused-parameter
  312. ifeq ($(LINUX),true)
  313. LINUXSAMPLER_LIBS = -Wl,-rpath=$(shell pkg-config --variable=libdir gig):$(shell pkg-config --variable=libdir linuxsampler)
  314. endif
  315. LINUXSAMPLER_LIBS += $(shell pkg-config --libs linuxsampler)
  316. ifeq ($(WIN32),true)
  317. LINUXSAMPLER_LIBS += -lws2_32
  318. endif
  319. endif
  320. ifeq ($(HAVE_SNDFILE),true)
  321. SNDFILE_FLAGS = $(shell pkg-config --cflags sndfile)
  322. SNDFILE_LIBS = $(shell pkg-config --libs sndfile)
  323. endif
  324. ifeq ($(HAVE_X11),true)
  325. X11_FLAGS = $(shell pkg-config --cflags x11)
  326. X11_LIBS = $(shell pkg-config --libs x11)
  327. endif
  328. ifeq ($(HAVE_LIBMAGIC),true)
  329. MAGIC_LIBS += -lmagic
  330. ifeq ($(LINUX),true)
  331. MAGIC_LIBS += -lz
  332. endif
  333. endif
  334. # ---------------------------------------------------------------------------------------------------------------------
  335. # Set libs stuff (part 2)
  336. RTAUDIO_FLAGS = -DHAVE_GETTIMEOFDAY -D__RTAUDIO_DUMMY__
  337. RTMIDI_FLAGS = -D__RTMIDI_DUMMY__
  338. ifeq ($(DEBUG),true)
  339. RTAUDIO_FLAGS += -D__RTAUDIO_DEBUG__
  340. RTMIDI_FLAGS += -D__RTMIDI_DEBUG__
  341. endif
  342. ifeq ($(UNIX),true)
  343. RTAUDIO_FLAGS += -D__UNIX_JACK__
  344. ifeq ($(HAVE_PULSEAUDIO),true)
  345. RTAUDIO_FLAGS += $(shell pkg-config --cflags libpulse-simple) -D__UNIX_PULSE__
  346. RTAUDIO_LIBS += $(shell pkg-config --libs libpulse-simple)
  347. endif
  348. endif
  349. ifeq ($(BSD),true)
  350. JACKBRIDGE_LIBS = -lpthread -lrt
  351. LILV_LIBS = -lm -lrt
  352. RTMEMPOOL_LIBS = -lpthread
  353. WATER_LIBS = -lpthread -lrt
  354. endif
  355. ifneq ($(HAIKU),true)
  356. JACKBRIDGE_LIBS = -lpthread
  357. LILV_LIBS = -lm
  358. RTMEMPOOL_LIBS = -lpthread
  359. WATER_LIBS = -lpthread
  360. endif
  361. ifeq ($(HURD),true)
  362. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  363. LILV_LIBS = -ldl -lm -lrt
  364. RTMEMPOOL_LIBS = -lpthread -lrt
  365. WATER_LIBS = -ldl -lpthread -lrt
  366. endif
  367. ifeq ($(LINUX),true)
  368. HYLIA_FLAGS = -DLINK_PLATFORM_LINUX=1
  369. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  370. LILV_LIBS = -ldl -lm -lrt
  371. RTMEMPOOL_LIBS = -lpthread -lrt
  372. WATER_LIBS = -ldl -lpthread -lrt
  373. ifeq ($(HAVE_ALSA),true)
  374. RTAUDIO_FLAGS += $(shell pkg-config --cflags alsa) -D__LINUX_ALSA__
  375. RTAUDIO_LIBS += $(shell pkg-config --libs alsa) -lpthread
  376. RTMIDI_FLAGS += $(shell pkg-config --cflags alsa) -D__LINUX_ALSA__
  377. RTMIDI_LIBS += $(shell pkg-config --libs alsa)
  378. endif
  379. endif
  380. ifeq ($(MACOS),true)
  381. HYLIA_FLAGS = -DLINK_PLATFORM_MACOSX=1
  382. JACKBRIDGE_LIBS = -ldl -lpthread
  383. LILV_LIBS = -ldl -lm
  384. RTMEMPOOL_LIBS = -lpthread
  385. WATER_LIBS = -framework AppKit
  386. RTAUDIO_FLAGS += -D__MACOSX_CORE__
  387. RTAUDIO_LIBS += -framework CoreAudio
  388. RTMIDI_FLAGS += -D__MACOSX_CORE__
  389. RTMIDI_LIBS += -framework CoreMIDI
  390. endif
  391. ifeq ($(WIN32),true)
  392. HYLIA_FLAGS = -DLINK_PLATFORM_WINDOWS=1
  393. JACKBRIDGE_LIBS = -lpthread
  394. LILV_LIBS = -lm
  395. RTMEMPOOL_LIBS = -lpthread
  396. WATER_LIBS = -luuid -lwsock32 -lwininet -lversion -lole32 -lws2_32 -loleaut32 -limm32 -lcomdlg32 -lshlwapi -lrpcrt4 -lwinmm
  397. RTAUDIO_FLAGS += -D__WINDOWS_ASIO__ -D__WINDOWS_DS__ -D__WINDOWS_WASAPI__
  398. RTAUDIO_LIBS += -ldsound -luuid -lksuser -lwinmm
  399. RTMIDI_FLAGS += -D__WINDOWS_MM__
  400. endif
  401. # ---------------------------------------------------------------------------------------------------------------------
  402. NATIVE_PLUGINS_LIBS += $(FFMPEG_LIBS)
  403. NATIVE_PLUGINS_LIBS += $(SNDFILE_LIBS)
  404. # ---------------------------------------------------------------------------------------------------------------------
  405. # Set app extension
  406. ifeq ($(WIN32),true)
  407. APP_EXT = .exe
  408. endif
  409. # ---------------------------------------------------------------------------------------------------------------------
  410. # Set shared lib extension
  411. LIB_EXT = .so
  412. ifeq ($(MACOS),true)
  413. LIB_EXT = .dylib
  414. endif
  415. ifeq ($(WIN32),true)
  416. LIB_EXT = .dll
  417. endif
  418. BASE_FLAGS += -DCARLA_LIB_EXT=\"$(LIB_EXT)\"
  419. # ---------------------------------------------------------------------------------------------------------------------
  420. # Set static libs start & end
  421. ifneq ($(MACOS),true)
  422. LIBS_START = -Wl,--start-group
  423. LIBS_END = -Wl,--end-group
  424. endif
  425. # ---------------------------------------------------------------------------------------------------------------------
  426. # Set shared library CLI arg
  427. ifeq ($(MACOS),true)
  428. SHARED = -dynamiclib
  429. else
  430. SHARED = -shared
  431. endif
  432. # ---------------------------------------------------------------------------------------------------------------------
  433. # Set arguments used for inline 'sed'
  434. ifeq ($(BSD),true)
  435. SED_ARGS=-i '' -e
  436. else
  437. SED_ARGS=-i -e
  438. endif
  439. # ---------------------------------------------------------------------------------------------------------------------
  440. ifeq ($(EXTERNAL_PLUGINS),true)
  441. BASE_FLAGS += -DHAVE_EXTERNAL_PLUGINS
  442. include $(CWD)/native-plugins/external/Makefile.mk
  443. endif
  444. # ---------------------------------------------------------------------------------------------------------------------