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