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.

567 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. 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_LIBDIR = $(shell pkg-config --variable=libdir Qt5Core)
  219. ifeq ($(BSD),true)
  220. MOC_QT5 ?= $(QT5_LIBDIR)/bin/moc
  221. RCC_QT5 ?= $(QT5_LIBDIR)/bin/rcc
  222. endif
  223. ifeq ($(HAIKU),true)
  224. MOC_QT5 ?= $(QT5_LIBDIR)/../../bin/moc
  225. RCC_QT5 ?= $(QT5_LIBDIR)/../../bin/rcc
  226. endif
  227. ifeq ($(MACOS),true)
  228. MOC_QT5 ?= $(QT5_LIBDIR)/../bin/moc
  229. RCC_QT5 ?= $(QT5_LIBDIR)/../bin/rcc
  230. endif
  231. ifeq ($(MOC_QT5),)
  232. ifneq (,$(wildcard $(QT5_LIBDIR)/qt5/bin/moc))
  233. MOC_QT5 ?= $(QT5_LIBDIR)/qt5/bin/moc
  234. RCC_QT5 ?= $(QT5_LIBDIR)/qt5/bin/rcc
  235. else
  236. MOC_QT5 ?= $(QT5_LIBDIR)/qt/bin/moc
  237. RCC_QT5 ?= $(QT5_LIBDIR)/qt/bin/rcc
  238. endif
  239. endif
  240. ifeq (,$(wildcard $(MOC_QT5)))
  241. HAVE_QT5=false
  242. endif
  243. ifeq (,$(wildcard $(RCC_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. ifeq ($(LINUX),true)
  350. MAGIC_LIBS += -lz
  351. endif
  352. endif
  353. # ---------------------------------------------------------------------------------------------------------------------
  354. # Set libs stuff (part 2)
  355. RTAUDIO_FLAGS = -DHAVE_GETTIMEOFDAY -D__RTAUDIO_DUMMY__
  356. RTMIDI_FLAGS = -D__RTMIDI_DUMMY__
  357. ifeq ($(DEBUG),true)
  358. RTAUDIO_FLAGS += -D__RTAUDIO_DEBUG__
  359. RTMIDI_FLAGS += -D__RTMIDI_DEBUG__
  360. endif
  361. ifeq ($(UNIX),true)
  362. RTAUDIO_FLAGS += -D__UNIX_JACK__
  363. ifeq ($(HAVE_PULSEAUDIO),true)
  364. RTAUDIO_FLAGS += $(shell pkg-config --cflags libpulse-simple) -D__UNIX_PULSE__
  365. RTAUDIO_LIBS += $(shell pkg-config --libs libpulse-simple)
  366. endif
  367. endif
  368. ifeq ($(BSD),true)
  369. JACKBRIDGE_LIBS = -lpthread -lrt
  370. LILV_LIBS = -lm -lrt
  371. RTMEMPOOL_LIBS = -lpthread
  372. WATER_LIBS = -lpthread -lrt
  373. endif
  374. ifneq ($(HAIKU),true)
  375. JACKBRIDGE_LIBS = -lpthread
  376. LILV_LIBS = -lm
  377. RTMEMPOOL_LIBS = -lpthread
  378. WATER_LIBS = -lpthread
  379. endif
  380. ifeq ($(HURD),true)
  381. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  382. LILV_LIBS = -ldl -lm -lrt
  383. RTMEMPOOL_LIBS = -lpthread -lrt
  384. WATER_LIBS = -ldl -lpthread -lrt
  385. endif
  386. ifeq ($(LINUX),true)
  387. HYLIA_FLAGS = -DLINK_PLATFORM_LINUX=1
  388. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  389. LILV_LIBS = -ldl -lm -lrt
  390. RTMEMPOOL_LIBS = -lpthread -lrt
  391. WATER_LIBS = -ldl -lpthread -lrt
  392. ifeq ($(HAVE_ALSA),true)
  393. RTAUDIO_FLAGS += $(shell pkg-config --cflags alsa) -D__LINUX_ALSA__
  394. RTAUDIO_LIBS += $(shell pkg-config --libs alsa) -lpthread
  395. RTMIDI_FLAGS += $(shell pkg-config --cflags alsa) -D__LINUX_ALSA__
  396. RTMIDI_LIBS += $(shell pkg-config --libs alsa)
  397. endif
  398. endif
  399. ifeq ($(MACOS),true)
  400. HYLIA_FLAGS = -DLINK_PLATFORM_MACOSX=1
  401. JACKBRIDGE_LIBS = -ldl -lpthread
  402. LILV_LIBS = -ldl -lm
  403. RTMEMPOOL_LIBS = -lpthread
  404. WATER_LIBS = -framework AppKit
  405. RTAUDIO_FLAGS += -D__MACOSX_CORE__
  406. RTAUDIO_LIBS += -framework CoreAudio
  407. RTMIDI_FLAGS += -D__MACOSX_CORE__
  408. RTMIDI_LIBS += -framework CoreMIDI
  409. endif
  410. ifeq ($(WIN32),true)
  411. HYLIA_FLAGS = -DLINK_PLATFORM_WINDOWS=1
  412. JACKBRIDGE_LIBS = -lpthread
  413. LILV_LIBS = -lm
  414. RTMEMPOOL_LIBS = -lpthread
  415. WATER_LIBS = -luuid -lwsock32 -lwininet -lversion -lole32 -lws2_32 -loleaut32 -limm32 -lcomdlg32 -lshlwapi -lrpcrt4 -lwinmm
  416. RTAUDIO_FLAGS += -D__WINDOWS_ASIO__ -D__WINDOWS_DS__ -D__WINDOWS_WASAPI__
  417. RTAUDIO_LIBS += -ldsound -luuid -lksuser -lwinmm
  418. RTMIDI_FLAGS += -D__WINDOWS_MM__
  419. endif
  420. # ---------------------------------------------------------------------------------------------------------------------
  421. NATIVE_PLUGINS_LIBS += $(FFMPEG_LIBS)
  422. NATIVE_PLUGINS_LIBS += $(SNDFILE_LIBS)
  423. # ---------------------------------------------------------------------------------------------------------------------
  424. # Set app extension
  425. ifeq ($(WIN32),true)
  426. APP_EXT = .exe
  427. endif
  428. # ---------------------------------------------------------------------------------------------------------------------
  429. # Set shared lib extension
  430. LIB_EXT = .so
  431. ifeq ($(MACOS),true)
  432. LIB_EXT = .dylib
  433. endif
  434. ifeq ($(WIN32),true)
  435. LIB_EXT = .dll
  436. endif
  437. BASE_FLAGS += -DCARLA_LIB_EXT=\"$(LIB_EXT)\"
  438. # ---------------------------------------------------------------------------------------------------------------------
  439. # Set static libs start & end
  440. ifneq ($(MACOS),true)
  441. LIBS_START = -Wl,--start-group
  442. LIBS_END = -Wl,--end-group
  443. endif
  444. # ---------------------------------------------------------------------------------------------------------------------
  445. # Set shared library CLI arg
  446. ifeq ($(MACOS),true)
  447. SHARED = -dynamiclib
  448. else
  449. SHARED = -shared
  450. endif
  451. # ---------------------------------------------------------------------------------------------------------------------
  452. # Set arguments used for inline 'sed'
  453. ifeq ($(BSD),true)
  454. SED_ARGS=-i '' -e
  455. else
  456. SED_ARGS=-i -e
  457. endif
  458. # ---------------------------------------------------------------------------------------------------------------------
  459. ifeq ($(EXTERNAL_PLUGINS),true)
  460. BASE_FLAGS += -DHAVE_EXTERNAL_PLUGINS
  461. include $(CWD)/native-plugins/external/Makefile.mk
  462. endif
  463. # ---------------------------------------------------------------------------------------------------------------------