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.

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