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.

528 lines
14KB

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