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.

564 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 (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 = -O2 -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 = -O2 -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 optimization flags
  101. BASE_OPTS = -O2 -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. UIC_QT4 ?= $(shell pkg-config --variable=uic_location QtCore)
  211. ifeq (,$(wildcard $(MOC_QT4)))
  212. HAVE_QT4=false
  213. endif
  214. endif
  215. ifeq ($(HAVE_QT5),true)
  216. QT5_LIBDIR = $(shell pkg-config --variable=libdir Qt5Core)
  217. ifeq ($(BSD),true)
  218. MOC_QT5 ?= $(QT5_LIBDIR)/bin/moc
  219. RCC_QT5 ?= $(QT5_LIBDIR)/bin/rcc
  220. UIC_QT5 ?= $(QT5_LIBDIR)/bin/uic
  221. endif
  222. ifeq ($(HAIKU),true)
  223. MOC_QT5 ?= $(QT5_LIBDIR)/../../bin/moc
  224. RCC_QT5 ?= $(QT5_LIBDIR)/../../bin/rcc
  225. UIC_QT5 ?= $(QT5_LIBDIR)/../../bin/uic
  226. endif
  227. ifeq ($(MACOS),true)
  228. MOC_QT5 ?= $(QT5_LIBDIR)/../bin/moc
  229. RCC_QT5 ?= $(QT5_LIBDIR)/../bin/rcc
  230. UIC_QT5 ?= $(QT5_LIBDIR)/../bin/uic
  231. endif
  232. ifeq ($(MOC_QT5),)
  233. ifneq (,$(wildcard $(QT5_LIBDIR)/qt5/bin/moc))
  234. MOC_QT5 ?= $(QT5_LIBDIR)/qt5/bin/moc
  235. RCC_QT5 ?= $(QT5_LIBDIR)/qt5/bin/rcc
  236. UIC_QT5 ?= $(QT5_LIBDIR)/qt5/bin/uic
  237. else
  238. MOC_QT5 ?= $(QT5_LIBDIR)/qt/bin/moc
  239. RCC_QT5 ?= $(QT5_LIBDIR)/qt/bin/rcc
  240. UIC_QT5 ?= $(QT5_LIBDIR)/qt/bin/uic
  241. endif
  242. endif
  243. ifeq (,$(wildcard $(MOC_QT5)))
  244. HAVE_QT5=false
  245. endif
  246. endif
  247. ifeq ($(HAVE_QT4),true)
  248. HAVE_QT=true
  249. endif
  250. ifeq ($(HAVE_QT5),true)
  251. HAVE_QT=true
  252. endif
  253. ifeq ($(WIN32),true)
  254. HAVE_QT=true
  255. endif
  256. # ---------------------------------------------------------------------------------------------------------------------
  257. # Set PyQt tools
  258. PYRCC4 ?= $(shell which pyrcc4 2>/dev/null)
  259. PYUIC4 ?= $(shell which pyuic4 2>/dev/null)
  260. PYRCC5 ?= $(shell which pyrcc5 2>/dev/null)
  261. PYUIC5 ?= $(shell which pyuic5 2>/dev/null)
  262. HAVE_PYQT4=false
  263. HAVE_PYQT5=false
  264. ifneq ($(PYUIC4),)
  265. ifneq ($(PYRCC4),)
  266. HAVE_PYQT=true
  267. HAVE_PYQT4=true
  268. endif
  269. endif
  270. ifneq ($(PYUIC5),)
  271. ifneq ($(PYRCC5),)
  272. HAVE_PYQT=true
  273. HAVE_PYQT5=true
  274. endif
  275. endif
  276. # ---------------------------------------------------------------------------------------------------------------------
  277. # Set default Qt used in frontend
  278. ifeq ($(HAVE_PYQT5),true)
  279. DEFAULT_QT ?= 5
  280. else
  281. DEFAULT_QT ?= 4
  282. endif
  283. # ---------------------------------------------------------------------------------------------------------------------
  284. # Set base defines
  285. ifeq ($(HAVE_PYQT),true)
  286. BASE_FLAGS += -DHAVE_PYQT
  287. endif
  288. ifeq ($(HAVE_FLUIDSYNTH),true)
  289. BASE_FLAGS += -DHAVE_FLUIDSYNTH
  290. endif
  291. ifeq ($(HAVE_FFMPEG),true)
  292. BASE_FLAGS += -DHAVE_FFMPEG
  293. endif
  294. ifeq ($(HAVE_HYLIA),true)
  295. BASE_FLAGS += -DHAVE_HYLIA
  296. endif
  297. ifeq ($(HAVE_LIBLO),true)
  298. BASE_FLAGS += -DHAVE_LIBLO
  299. endif
  300. ifeq ($(HAVE_LIBMAGIC),true)
  301. BASE_FLAGS += -DHAVE_LIBMAGIC
  302. endif
  303. ifeq ($(HAVE_LINUXSAMPLER),true)
  304. BASE_FLAGS += -DHAVE_LINUXSAMPLER
  305. endif
  306. ifeq ($(HAVE_SNDFILE),true)
  307. BASE_FLAGS += -DHAVE_SNDFILE
  308. endif
  309. ifeq ($(HAVE_X11),true)
  310. BASE_FLAGS += -DHAVE_X11
  311. endif
  312. # ---------------------------------------------------------------------------------------------------------------------
  313. # Set libs stuff (part 1)
  314. ifeq ($(LINUX_OR_MACOS),true)
  315. LIBDL_LIBS = -ldl
  316. endif
  317. ifeq ($(HAVE_LIBLO),true)
  318. LIBLO_FLAGS = $(shell pkg-config --cflags liblo)
  319. LIBLO_LIBS = $(shell pkg-config --libs liblo)
  320. endif
  321. ifeq ($(HAVE_FFMPEG),true)
  322. FFMPEG_FLAGS = $(shell pkg-config --cflags libavcodec libavformat libavutil)
  323. FFMPEG_LIBS = $(shell pkg-config --libs libavcodec libavformat libavutil)
  324. endif
  325. ifeq ($(HAVE_FLUIDSYNTH),true)
  326. FLUIDSYNTH_FLAGS = $(shell pkg-config --cflags fluidsynth)
  327. FLUIDSYNTH_LIBS = $(shell pkg-config --libs fluidsynth)
  328. endif
  329. ifeq ($(HAVE_LINUXSAMPLER),true)
  330. LINUXSAMPLER_FLAGS = $(shell pkg-config --cflags linuxsampler) -DIS_CPP11=1 -Wno-non-virtual-dtor -Wno-shadow -Wno-unused-parameter
  331. ifeq ($(LINUX),true)
  332. LINUXSAMPLER_LIBS = -Wl,-rpath=$(shell pkg-config --variable=libdir gig):$(shell pkg-config --variable=libdir linuxsampler)
  333. endif
  334. LINUXSAMPLER_LIBS += $(shell pkg-config --libs linuxsampler)
  335. ifeq ($(WIN32),true)
  336. LINUXSAMPLER_LIBS += -lws2_32
  337. endif
  338. endif
  339. ifeq ($(HAVE_SNDFILE),true)
  340. SNDFILE_FLAGS = $(shell pkg-config --cflags sndfile)
  341. SNDFILE_LIBS = $(shell pkg-config --libs sndfile)
  342. endif
  343. ifeq ($(HAVE_X11),true)
  344. X11_FLAGS = $(shell pkg-config --cflags x11)
  345. X11_LIBS = $(shell pkg-config --libs x11)
  346. endif
  347. ifeq ($(HAVE_LIBMAGIC),true)
  348. MAGIC_LIBS += -lmagic
  349. endif
  350. # ---------------------------------------------------------------------------------------------------------------------
  351. # Set libs stuff (part 2)
  352. RTAUDIO_FLAGS = -DHAVE_GETTIMEOFDAY -D__RTAUDIO_DUMMY__
  353. RTMIDI_FLAGS = -D__RTMIDI_DUMMY__
  354. ifeq ($(DEBUG),true)
  355. RTAUDIO_FLAGS += -D__RTAUDIO_DEBUG__
  356. RTMIDI_FLAGS += -D__RTMIDI_DEBUG__
  357. endif
  358. ifeq ($(UNIX),true)
  359. RTAUDIO_FLAGS += -D__UNIX_JACK__
  360. ifeq ($(HAVE_PULSEAUDIO),true)
  361. RTAUDIO_FLAGS += $(shell pkg-config --cflags libpulse-simple) -D__UNIX_PULSE__
  362. RTAUDIO_LIBS += $(shell pkg-config --libs libpulse-simple)
  363. endif
  364. endif
  365. ifeq ($(BSD),true)
  366. JACKBRIDGE_LIBS = -lpthread -lrt
  367. LILV_LIBS = -lm -lrt
  368. RTMEMPOOL_LIBS = -lpthread
  369. WATER_LIBS = -lpthread -lrt
  370. endif
  371. ifneq ($(HAIKU),true)
  372. JACKBRIDGE_LIBS = -lpthread
  373. LILV_LIBS = -lm
  374. RTMEMPOOL_LIBS = -lpthread
  375. WATER_LIBS = -lpthread
  376. endif
  377. ifeq ($(HURD),true)
  378. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  379. LILV_LIBS = -ldl -lm -lrt
  380. RTMEMPOOL_LIBS = -lpthread -lrt
  381. WATER_LIBS = -ldl -lpthread -lrt
  382. endif
  383. ifeq ($(LINUX),true)
  384. HYLIA_FLAGS = -DLINK_PLATFORM_LINUX=1
  385. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  386. LILV_LIBS = -ldl -lm -lrt
  387. RTMEMPOOL_LIBS = -lpthread -lrt
  388. WATER_LIBS = -ldl -lpthread -lrt
  389. ifeq ($(HAVE_ALSA),true)
  390. RTAUDIO_FLAGS += $(shell pkg-config --cflags alsa) -D__LINUX_ALSA__
  391. RTAUDIO_LIBS += $(shell pkg-config --libs alsa) -lpthread
  392. RTMIDI_FLAGS += $(shell pkg-config --cflags alsa) -D__LINUX_ALSA__
  393. RTMIDI_LIBS += $(shell pkg-config --libs alsa)
  394. endif
  395. endif
  396. ifeq ($(MACOS),true)
  397. HYLIA_FLAGS = -DLINK_PLATFORM_MACOSX=1
  398. JACKBRIDGE_LIBS = -ldl -lpthread
  399. LILV_LIBS = -ldl -lm
  400. RTMEMPOOL_LIBS = -lpthread
  401. WATER_LIBS = -framework AppKit
  402. RTAUDIO_FLAGS += -D__MACOSX_CORE__
  403. RTAUDIO_LIBS += -framework CoreAudio
  404. RTMIDI_FLAGS += -D__MACOSX_CORE__
  405. RTMIDI_LIBS += -framework CoreMIDI
  406. endif
  407. ifeq ($(WIN32),true)
  408. HYLIA_FLAGS = -DLINK_PLATFORM_WINDOWS=1
  409. JACKBRIDGE_LIBS = -lpthread
  410. LILV_LIBS = -lm
  411. RTMEMPOOL_LIBS = -lpthread
  412. WATER_LIBS = -luuid -lwsock32 -lwininet -lversion -lole32 -lws2_32 -loleaut32 -limm32 -lcomdlg32 -lshlwapi -lrpcrt4 -lwinmm
  413. RTAUDIO_FLAGS += -D__WINDOWS_ASIO__ -D__WINDOWS_DS__ -D__WINDOWS_WASAPI__
  414. RTAUDIO_LIBS += -ldsound -luuid -lksuser -lwinmm
  415. RTMIDI_FLAGS += -D__WINDOWS_MM__
  416. endif
  417. # ---------------------------------------------------------------------------------------------------------------------
  418. NATIVE_PLUGINS_LIBS += $(FFMPEG_LIBS)
  419. NATIVE_PLUGINS_LIBS += $(SNDFILE_LIBS)
  420. # ---------------------------------------------------------------------------------------------------------------------
  421. # Set app extension
  422. ifeq ($(WIN32),true)
  423. APP_EXT = .exe
  424. endif
  425. # ---------------------------------------------------------------------------------------------------------------------
  426. # Set shared lib extension
  427. LIB_EXT = .so
  428. ifeq ($(MACOS),true)
  429. LIB_EXT = .dylib
  430. endif
  431. ifeq ($(WIN32),true)
  432. LIB_EXT = .dll
  433. endif
  434. BASE_FLAGS += -DCARLA_LIB_EXT=\"$(LIB_EXT)\"
  435. # ---------------------------------------------------------------------------------------------------------------------
  436. # Set static libs start & end
  437. ifneq ($(MACOS),true)
  438. LIBS_START = -Wl,--start-group
  439. LIBS_END = -Wl,--end-group
  440. endif
  441. # ---------------------------------------------------------------------------------------------------------------------
  442. # Set shared library CLI arg
  443. ifeq ($(MACOS),true)
  444. SHARED = -dynamiclib
  445. else
  446. SHARED = -shared
  447. endif
  448. # ---------------------------------------------------------------------------------------------------------------------
  449. # Set arguments used for inline 'sed'
  450. ifeq ($(BSD),true)
  451. SED_ARGS=-i '' -e
  452. else
  453. SED_ARGS=-i -e
  454. endif
  455. # ---------------------------------------------------------------------------------------------------------------------
  456. ifeq ($(EXTERNAL_PLUGINS),true)
  457. BASE_FLAGS += -DHAVE_EXTERNAL_PLUGINS
  458. include $(CWD)/native-plugins/external/Makefile.mk
  459. endif
  460. # ---------------------------------------------------------------------------------------------------------------------