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.

538 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. CXXFLAGS += -isystem /usr/include/qt5
  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 --atleast-version=1.1.7 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. PYRCC5 ?= $(shell which pyrcc5 2>/dev/null)
  232. PYUIC5 ?= $(shell which pyuic5 2>/dev/null)
  233. ifneq ($(PYUIC5),)
  234. ifneq ($(PYRCC5),)
  235. HAVE_PYQT=true
  236. endif
  237. endif
  238. # ---------------------------------------------------------------------------------------------------------------------
  239. # Set PyQt tools, part2
  240. PYUIC ?= pyuic5
  241. PYRCC ?= pyrcc5
  242. ifeq ($(HAVE_QT5),true)
  243. HAVE_THEME = true
  244. endif
  245. # ---------------------------------------------------------------------------------------------------------------------
  246. # Set base defines
  247. ifeq ($(HAVE_DGL),true)
  248. BASE_FLAGS += -DHAVE_DGL
  249. BASE_FLAGS += -DDGL_NAMESPACE=CarlaDGL -DDGL_FILE_BROWSER_DISABLED -DDGL_NO_SHARED_RESOURCES
  250. endif
  251. ifeq ($(HAVE_FLUIDSYNTH),true)
  252. BASE_FLAGS += -DHAVE_FLUIDSYNTH
  253. endif
  254. ifeq ($(HAVE_FFMPEG),true)
  255. BASE_FLAGS += -DHAVE_FFMPEG
  256. endif
  257. ifeq ($(HAVE_HYLIA),true)
  258. BASE_FLAGS += -DHAVE_HYLIA
  259. endif
  260. ifeq ($(HAVE_LIBLO),true)
  261. BASE_FLAGS += -DHAVE_LIBLO
  262. endif
  263. ifeq ($(HAVE_LIBMAGIC),true)
  264. BASE_FLAGS += -DHAVE_LIBMAGIC
  265. endif
  266. ifeq ($(HAVE_PYQT),true)
  267. BASE_FLAGS += -DHAVE_PYQT
  268. endif
  269. ifeq ($(HAVE_SNDFILE),true)
  270. BASE_FLAGS += -DHAVE_SNDFILE
  271. endif
  272. ifeq ($(HAVE_X11),true)
  273. BASE_FLAGS += -DHAVE_X11
  274. endif
  275. # ---------------------------------------------------------------------------------------------------------------------
  276. # Set libs stuff (part 1)
  277. ifeq ($(LINUX_OR_MACOS),true)
  278. LIBDL_LIBS = -ldl
  279. endif
  280. ifeq ($(WIN32),true)
  281. PKG_CONFIG_FLAGS = --static
  282. endif
  283. ifeq ($(HAVE_DGL),true)
  284. ifeq ($(MACOS),true)
  285. DGL_LIBS = -framework OpenGL -framework Cocoa
  286. endif
  287. ifeq ($(WIN32),true)
  288. DGL_LIBS = -lopengl32 -lgdi32
  289. endif
  290. ifneq ($(MACOS_OR_WIN32),true)
  291. DGL_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags gl x11)
  292. DGL_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs gl x11)
  293. endif
  294. endif
  295. ifeq ($(HAVE_LIBLO),true)
  296. LIBLO_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags liblo)
  297. LIBLO_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs liblo)
  298. endif
  299. ifeq ($(HAVE_LIBMAGIC),true)
  300. MAGIC_LIBS += -lmagic
  301. ifeq ($(LINUX_OR_MACOS),true)
  302. MAGIC_LIBS += -lz
  303. endif
  304. endif
  305. ifeq ($(HAVE_FFMPEG),true)
  306. FFMPEG_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags libavcodec libavformat libavutil)
  307. FFMPEG_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs libavcodec libavformat libavutil)
  308. endif
  309. ifeq ($(HAVE_FLUIDSYNTH),true)
  310. FLUIDSYNTH_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags fluidsynth)
  311. FLUIDSYNTH_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs fluidsynth)
  312. endif
  313. ifeq ($(HAVE_SNDFILE),true)
  314. SNDFILE_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags sndfile)
  315. SNDFILE_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs sndfile)
  316. endif
  317. ifeq ($(HAVE_X11),true)
  318. X11_FLAGS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags x11)
  319. X11_LIBS = $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs x11)
  320. endif
  321. # ---------------------------------------------------------------------------------------------------------------------
  322. # Set libs stuff (part 2)
  323. RTAUDIO_FLAGS = -DHAVE_GETTIMEOFDAY
  324. RTMIDI_FLAGS =
  325. ifeq ($(DEBUG),true)
  326. RTAUDIO_FLAGS += -D__RTAUDIO_DEBUG__
  327. RTMIDI_FLAGS += -D__RTMIDI_DEBUG__
  328. endif
  329. ifeq ($(UNIX),true)
  330. RTAUDIO_FLAGS += -D__UNIX_JACK__
  331. ifeq ($(HAVE_PULSEAUDIO),true)
  332. RTAUDIO_FLAGS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags libpulse-simple) -D__UNIX_PULSE__
  333. RTAUDIO_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs libpulse-simple)
  334. endif
  335. endif
  336. ifeq ($(BSD),true)
  337. JACKBRIDGE_LIBS = -lpthread -lrt
  338. LILV_LIBS = -lm -lrt
  339. RTMEMPOOL_LIBS = -lpthread
  340. WATER_LIBS = -lpthread -lrt
  341. endif
  342. ifeq ($(HAIKU),true)
  343. JACKBRIDGE_LIBS = -lpthread
  344. LILV_LIBS = -lm
  345. RTMEMPOOL_LIBS = -lpthread
  346. WATER_LIBS = -lpthread
  347. endif
  348. ifeq ($(HURD),true)
  349. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  350. LILV_LIBS = -ldl -lm -lrt
  351. RTMEMPOOL_LIBS = -lpthread -lrt
  352. WATER_LIBS = -ldl -lpthread -lrt
  353. endif
  354. ifeq ($(LINUX),true)
  355. HYLIA_FLAGS = -DLINK_PLATFORM_LINUX=1
  356. JACKBRIDGE_LIBS = -ldl -lpthread -lrt
  357. LILV_LIBS = -ldl -lm -lrt
  358. RTMEMPOOL_LIBS = -lpthread -lrt
  359. WATER_LIBS = -ldl -lpthread -lrt
  360. ifeq ($(HAVE_ALSA),true)
  361. RTAUDIO_FLAGS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags alsa) -D__LINUX_ALSA__
  362. RTAUDIO_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs alsa) -lpthread
  363. RTMIDI_FLAGS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --cflags alsa) -D__LINUX_ALSA__
  364. RTMIDI_LIBS += $(shell pkg-config $(PKG_CONFIG_FLAGS) --libs alsa)
  365. endif
  366. endif
  367. ifeq ($(MACOS),true)
  368. HYLIA_FLAGS = -DLINK_PLATFORM_MACOSX=1
  369. JACKBRIDGE_LIBS = -ldl -lpthread
  370. LILV_LIBS = -ldl -lm
  371. RTMEMPOOL_LIBS = -lpthread
  372. WATER_LIBS = -framework AppKit
  373. RTAUDIO_FLAGS += -D__MACOSX_CORE__
  374. RTAUDIO_LIBS += -framework CoreAudio
  375. RTMIDI_FLAGS += -D__MACOSX_CORE__
  376. RTMIDI_LIBS += -framework CoreMIDI
  377. endif
  378. ifeq ($(WIN32),true)
  379. HYLIA_FLAGS = -DLINK_PLATFORM_WINDOWS=1
  380. JACKBRIDGE_LIBS = -lpthread
  381. LILV_LIBS = -lm
  382. RTMEMPOOL_LIBS = -lpthread
  383. WATER_LIBS = -luuid -lwsock32 -lwininet -lversion -lole32 -lws2_32 -loleaut32 -limm32 -lcomdlg32 -lshlwapi -lrpcrt4 -lwinmm
  384. RTAUDIO_FLAGS += -D__WINDOWS_ASIO__ -D__WINDOWS_DS__ -D__WINDOWS_WASAPI__
  385. RTAUDIO_LIBS += -ldsound -luuid -lksuser -lwinmm
  386. RTMIDI_FLAGS += -D__WINDOWS_MM__
  387. endif
  388. # ---------------------------------------------------------------------------------------------------------------------
  389. NATIVE_PLUGINS_LIBS += $(DGL_LIBS)
  390. NATIVE_PLUGINS_LIBS += $(FFMPEG_LIBS)
  391. NATIVE_PLUGINS_LIBS += $(SNDFILE_LIBS)
  392. # ---------------------------------------------------------------------------------------------------------------------
  393. # Set app extension
  394. ifeq ($(WIN32),true)
  395. APP_EXT = .exe
  396. endif
  397. # ---------------------------------------------------------------------------------------------------------------------
  398. # Set shared lib extension
  399. LIB_EXT = .so
  400. ifeq ($(MACOS),true)
  401. LIB_EXT = .dylib
  402. endif
  403. ifeq ($(WIN32),true)
  404. LIB_EXT = .dll
  405. endif
  406. BASE_FLAGS += -DCARLA_LIB_EXT=\"$(LIB_EXT)\"
  407. # ---------------------------------------------------------------------------------------------------------------------
  408. # Set static libs start & end
  409. ifneq ($(MACOS),true)
  410. LIBS_START = -Wl,--start-group
  411. LIBS_END = -Wl,--end-group
  412. endif
  413. # ---------------------------------------------------------------------------------------------------------------------
  414. # Set shared library CLI arg
  415. ifeq ($(MACOS),true)
  416. SHARED = -dynamiclib
  417. else
  418. SHARED = -shared
  419. endif
  420. # ---------------------------------------------------------------------------------------------------------------------
  421. # Set arguments used for inline 'sed'
  422. ifeq ($(BSD),true)
  423. SED_ARGS=-i '' -e
  424. else
  425. SED_ARGS=-i -e
  426. endif
  427. # ---------------------------------------------------------------------------------------------------------------------
  428. # Set command used for file symlinking
  429. LINK := ln -sf
  430. # ---------------------------------------------------------------------------------------------------------------------
  431. ifneq (,$(wildcard $(CWD)/native-plugins/external/Makefile.mk))
  432. EXTERNAL_PLUGINS = true
  433. BASE_FLAGS += -DHAVE_EXTERNAL_PLUGINS
  434. include $(CWD)/native-plugins/external/Makefile.mk
  435. endif
  436. # ---------------------------------------------------------------------------------------------------------------------