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.

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