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.

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