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.

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