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.

557 lines
15KB

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