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.

554 lines
15KB

  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. ifeq ($(MACOS_OR_WIN32),true)
  171. HAVE_DGL = true
  172. else
  173. HAVE_DGL = $(shell pkg-config --exists gl x11 && echo true)
  174. HAVE_GTK2 = $(shell pkg-config --exists gtk+-2.0 && echo true)
  175. HAVE_GTK3 = $(shell pkg-config --exists gtk+-3.0 && echo true)
  176. HAVE_X11 = $(shell pkg-config --exists x11 && echo true)
  177. endif
  178. ifeq ($(UNIX),true)
  179. ifneq ($(MACOS),true)
  180. HAVE_PULSEAUDIO = $(shell pkg-config --exists libpulse-simple && echo true)
  181. endif
  182. endif
  183. HAVE_FFMPEG = $(shell pkg-config --exists libavcodec libavformat libavutil && echo true)
  184. HAVE_FLUIDSYNTH = $(shell pkg-config --exists fluidsynth && echo true)
  185. HAVE_LIBLO = $(shell pkg-config --exists liblo && echo true)
  186. HAVE_QT4 = $(shell pkg-config --exists QtCore QtGui && echo true)
  187. HAVE_QT5 = $(shell pkg-config --exists Qt5Core Qt5Gui Qt5Widgets && echo true)
  188. HAVE_SNDFILE = $(shell pkg-config --exists sndfile && echo true)
  189. # ---------------------------------------------------------------------------------------------------------------------
  190. # Check for optional libs (special non-pkgconfig tests)
  191. ifneq ($(WIN32),true)
  192. # libmagic doesn't have a pkg-config file, so we need to call the compiler to test it
  193. HAVE_LIBMAGIC = $(shell echo '\#include <magic.h>' | $(CC) $(CFLAGS) -x c -w -c - -o .libmagic-tmp 2>/dev/null && echo true)
  194. endif
  195. # ---------------------------------------------------------------------------------------------------------------------
  196. # Set Qt tools
  197. ifeq ($(HAVE_QT4),true)
  198. MOC_QT4 ?= $(shell pkg-config --variable=moc_location QtCore)
  199. RCC_QT4 ?= $(shell pkg-config --variable=rcc_location QtCore)
  200. UIC_QT4 ?= $(shell pkg-config --variable=uic_location QtCore)
  201. ifeq (,$(wildcard $(MOC_QT4)))
  202. HAVE_QT4=false
  203. endif
  204. ifeq (,$(wildcard $(RCC_QT4)))
  205. HAVE_QT4=false
  206. endif
  207. endif
  208. ifeq ($(HAVE_QT5),true)
  209. QT5_HOSTBINS = $(shell pkg-config --variable=host_bins Qt5Core)
  210. MOC_QT5 ?= $(QT5_HOSTBINS)/moc
  211. RCC_QT5 ?= $(QT5_HOSTBINS)/rcc
  212. UIC_QT5 ?= $(QT5_HOSTBINS)/uic
  213. ifeq (,$(wildcard $(MOC_QT5)))
  214. HAVE_QT5=false
  215. endif
  216. ifeq (,$(wildcard $(RCC_QT5)))
  217. HAVE_QT5=false
  218. endif
  219. endif
  220. ifeq ($(HAVE_QT4),true)
  221. HAVE_QT=true
  222. endif
  223. ifeq ($(HAVE_QT5),true)
  224. HAVE_QT=true
  225. endif
  226. ifeq ($(WIN32),true)
  227. HAVE_QT=true
  228. endif
  229. # ---------------------------------------------------------------------------------------------------------------------
  230. # Set PyQt tools
  231. PYRCC4 ?= $(shell which pyrcc4 2>/dev/null)
  232. PYUIC4 ?= $(shell which pyuic4 2>/dev/null)
  233. PYRCC5 ?= $(shell which pyrcc5 2>/dev/null)
  234. PYUIC5 ?= $(shell which pyuic5 2>/dev/null)
  235. HAVE_PYQT4=false
  236. HAVE_PYQT5=false
  237. ifneq ($(PYUIC4),)
  238. ifneq ($(PYRCC4),)
  239. HAVE_PYQT=true
  240. HAVE_PYQT4=true
  241. endif
  242. endif
  243. ifneq ($(PYUIC5),)
  244. ifneq ($(PYRCC5),)
  245. HAVE_PYQT=true
  246. HAVE_PYQT5=true
  247. endif
  248. endif
  249. # ---------------------------------------------------------------------------------------------------------------------
  250. # Set default Qt used in frontend
  251. ifeq ($(HAVE_PYQT5),true)
  252. DEFAULT_QT ?= 5
  253. else
  254. DEFAULT_QT ?= 4
  255. endif
  256. # ---------------------------------------------------------------------------------------------------------------------
  257. # Set base defines
  258. ifeq ($(HAVE_DGL),true)
  259. BASE_FLAGS += -DHAVE_DGL
  260. BASE_FLAGS += -DDGL_NAMESPACE=CarlaDGL -DDGL_FILE_BROWSER_DISABLED -DDGL_NO_SHARED_RESOURCES
  261. endif
  262. ifeq ($(HAVE_FLUIDSYNTH),true)
  263. BASE_FLAGS += -DHAVE_FLUIDSYNTH
  264. endif
  265. ifeq ($(HAVE_FFMPEG),true)
  266. BASE_FLAGS += -DHAVE_FFMPEG
  267. endif
  268. ifeq ($(HAVE_HYLIA),true)
  269. BASE_FLAGS += -DHAVE_HYLIA
  270. endif
  271. ifeq ($(HAVE_LIBLO),true)
  272. BASE_FLAGS += -DHAVE_LIBLO
  273. endif
  274. ifeq ($(HAVE_LIBMAGIC),true)
  275. BASE_FLAGS += -DHAVE_LIBMAGIC
  276. endif
  277. ifeq ($(HAVE_PYQT),true)
  278. BASE_FLAGS += -DHAVE_PYQT
  279. endif
  280. ifeq ($(HAVE_SNDFILE),true)
  281. BASE_FLAGS += -DHAVE_SNDFILE
  282. endif
  283. ifeq ($(HAVE_X11),true)
  284. BASE_FLAGS += -DHAVE_X11
  285. endif
  286. # ---------------------------------------------------------------------------------------------------------------------
  287. # Set libs stuff (part 1)
  288. ifeq ($(LINUX_OR_MACOS),true)
  289. LIBDL_LIBS = -ldl
  290. endif
  291. ifeq ($(WIN32),true)
  292. PKG_CONFIG_FLAGS = --static
  293. endif
  294. ifeq ($(HAVE_DGL),true)
  295. ifeq ($(MACOS),true)
  296. DGL_LIBS = -framework OpenGL -framework Cocoa
  297. endif
  298. ifeq ($(WIN32),true)
  299. DGL_LIBS = -lopengl32 -lgdi32
  300. endif
  301. ifneq ($(MACOS_OR_WIN32),true)
  302. DGL_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags gl x11)
  303. DGL_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs gl x11)
  304. endif
  305. endif
  306. ifeq ($(HAVE_LIBLO),true)
  307. LIBLO_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags liblo)
  308. LIBLO_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs liblo)
  309. endif
  310. ifeq ($(HAVE_LIBMAGIC),true)
  311. MAGIC_LIBS += -lmagic
  312. ifeq ($(LINUX_OR_MACOS),true)
  313. MAGIC_LIBS += -lz
  314. endif
  315. endif
  316. ifeq ($(HAVE_FFMPEG),true)
  317. FFMPEG_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags libavcodec libavformat libavutil)
  318. FFMPEG_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs libavcodec libavformat libavutil)
  319. endif
  320. ifeq ($(HAVE_FLUIDSYNTH),true)
  321. FLUIDSYNTH_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags fluidsynth)
  322. FLUIDSYNTH_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs fluidsynth)
  323. endif
  324. ifeq ($(HAVE_SNDFILE),true)
  325. SNDFILE_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags sndfile)
  326. SNDFILE_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs sndfile)
  327. endif
  328. ifeq ($(HAVE_X11),true)
  329. X11_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags x11)
  330. X11_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs x11)
  331. endif
  332. # ---------------------------------------------------------------------------------------------------------------------
  333. # Set libs stuff (part 2)
  334. RTAUDIO_FLAGS = -DHAVE_GETTIMEOFDAY
  335. RTMIDI_FLAGS =
  336. ifeq ($(DEBUG),true)
  337. RTAUDIO_FLAGS += -D__RTAUDIO_DEBUG__
  338. RTMIDI_FLAGS += -D__RTMIDI_DEBUG__
  339. endif
  340. ifeq ($(UNIX),true)
  341. RTAUDIO_FLAGS += -D__UNIX_JACK__
  342. ifeq ($(HAVE_PULSEAUDIO),true)
  343. RTAUDIO_FLAGS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags libpulse-simple) -D__UNIX_PULSE__
  344. RTAUDIO_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs libpulse-simple)
  345. endif
  346. endif
  347. ifeq ($(BSD),true)
  348. JACKBRIDGE_LIBS = -lpthread -lrt
  349. LILV_LIBS = -lm -lrt
  350. RTMEMPOOL_LIBS = -lpthread
  351. WATER_LIBS = -lpthread -lrt
  352. endif
  353. ifneq ($(HAIKU),true)
  354. JACKBRIDGE_LIBS = -lpthread
  355. LILV_LIBS = -lm
  356. RTMEMPOOL_LIBS = -lpthread
  357. WATER_LIBS = -lpthread
  358. RTAUDIO_FLAGS += -D__RTAUDIO_DUMMY__
  359. RTMIDI_FLAGS += -D__RTMIDI_DUMMY__
  360. endif
  361. ifeq ($(HURD),true)
  362. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  363. LILV_LIBS = -ldl -lm -lrt
  364. RTMEMPOOL_LIBS = -lpthread -lrt
  365. WATER_LIBS = -ldl -lpthread -lrt
  366. endif
  367. ifeq ($(LINUX),true)
  368. HYLIA_FLAGS = -DLINK_PLATFORM_LINUX=1
  369. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  370. LILV_LIBS = -ldl -lm -lrt
  371. RTMEMPOOL_LIBS = -lpthread -lrt
  372. WATER_LIBS = -ldl -lpthread -lrt
  373. ifeq ($(HAVE_ALSA),true)
  374. RTAUDIO_FLAGS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags alsa) -D__LINUX_ALSA__
  375. RTAUDIO_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs alsa) -lpthread
  376. RTMIDI_FLAGS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags alsa) -D__LINUX_ALSA__
  377. RTMIDI_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs alsa)
  378. endif
  379. endif
  380. ifeq ($(MACOS),true)
  381. HYLIA_FLAGS = -DLINK_PLATFORM_MACOSX=1
  382. JACKBRIDGE_LIBS = -ldl -lpthread
  383. LILV_LIBS = -ldl -lm
  384. RTMEMPOOL_LIBS = -lpthread
  385. WATER_LIBS = -framework AppKit
  386. RTAUDIO_FLAGS += -D__MACOSX_CORE__
  387. RTAUDIO_LIBS += -framework CoreAudio
  388. RTMIDI_FLAGS += -D__MACOSX_CORE__
  389. RTMIDI_LIBS += -framework CoreMIDI
  390. endif
  391. ifeq ($(WIN32),true)
  392. HYLIA_FLAGS = -DLINK_PLATFORM_WINDOWS=1
  393. JACKBRIDGE_LIBS = -lpthread
  394. LILV_LIBS = -lm
  395. RTMEMPOOL_LIBS = -lpthread
  396. WATER_LIBS = -luuid -lwsock32 -lwininet -lversion -lole32 -lws2_32 -loleaut32 -limm32 -lcomdlg32 -lshlwapi -lrpcrt4 -lwinmm
  397. RTAUDIO_FLAGS += -D__WINDOWS_ASIO__ -D__WINDOWS_DS__ -D__WINDOWS_WASAPI__
  398. RTAUDIO_LIBS += -ldsound -luuid -lksuser -lwinmm
  399. RTMIDI_FLAGS += -D__WINDOWS_MM__
  400. ifeq ($(HAVE_FLUIDSYNTH),true)
  401. ifeq ($(HAVE_SNDFILE),true)
  402. FLUIDSYNTH_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs sndfile)
  403. endif
  404. FLUIDSYNTH_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs glib-2.0 gthread-2.0) -ldsound -lole32 -lwinmm -lws2_32
  405. endif
  406. endif
  407. # ---------------------------------------------------------------------------------------------------------------------
  408. NATIVE_PLUGINS_LIBS += $(DGL_LIBS)
  409. NATIVE_PLUGINS_LIBS += $(FFMPEG_LIBS)
  410. NATIVE_PLUGINS_LIBS += $(SNDFILE_LIBS)
  411. # ---------------------------------------------------------------------------------------------------------------------
  412. # Set app extension
  413. ifeq ($(WIN32),true)
  414. APP_EXT = .exe
  415. endif
  416. # ---------------------------------------------------------------------------------------------------------------------
  417. # Set shared lib extension
  418. LIB_EXT = .so
  419. ifeq ($(MACOS),true)
  420. LIB_EXT = .dylib
  421. endif
  422. ifeq ($(WIN32),true)
  423. LIB_EXT = .dll
  424. endif
  425. BASE_FLAGS += -DCARLA_LIB_EXT=\"$(LIB_EXT)\"
  426. # ---------------------------------------------------------------------------------------------------------------------
  427. # Set static libs start & end
  428. ifneq ($(MACOS),true)
  429. LIBS_START = -Wl,--start-group
  430. LIBS_END = -Wl,--end-group
  431. endif
  432. # ---------------------------------------------------------------------------------------------------------------------
  433. # Set shared library CLI arg
  434. ifeq ($(MACOS),true)
  435. SHARED = -dynamiclib
  436. else
  437. SHARED = -shared
  438. endif
  439. # ---------------------------------------------------------------------------------------------------------------------
  440. # Set arguments used for inline 'sed'
  441. ifeq ($(BSD),true)
  442. SED_ARGS=-i '' -e
  443. else
  444. SED_ARGS=-i -e
  445. endif
  446. # ---------------------------------------------------------------------------------------------------------------------
  447. ifneq (,$(wildcard $(CWD)/native-plugins/external/Makefile.mk))
  448. EXTERNAL_PLUGINS = true
  449. BASE_FLAGS += -DHAVE_EXTERNAL_PLUGINS
  450. include $(CWD)/native-plugins/external/Makefile.mk
  451. endif
  452. # ---------------------------------------------------------------------------------------------------------------------