DISTRHO Plugin Framework
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.

580 lines
16KB

  1. #!/usr/bin/make -f
  2. # Makefile for DPF #
  3. # ---------------- #
  4. # Created by falkTX
  5. #
  6. AR ?= ar
  7. CC ?= gcc
  8. CXX ?= g++
  9. # ---------------------------------------------------------------------------------------------------------------------
  10. # Protect against multiple inclusion
  11. ifneq ($(DPF_MAKEFILE_BASE_INCLUDED),true)
  12. DPF_MAKEFILE_BASE_INCLUDED = true
  13. # ---------------------------------------------------------------------------------------------------------------------
  14. # Auto-detect OS if not defined
  15. TARGET_MACHINE := $(shell $(CC) -dumpmachine)
  16. ifneq ($(BSD),true)
  17. ifneq ($(HAIKU),true)
  18. ifneq ($(HURD),true)
  19. ifneq ($(LINUX),true)
  20. ifneq ($(MACOS),true)
  21. ifneq ($(WINDOWS),true)
  22. ifneq (,$(findstring bsd,$(TARGET_MACHINE)))
  23. BSD=true
  24. else ifneq (,$(findstring haiku,$(TARGET_MACHINE)))
  25. HAIKU=true
  26. else ifneq (,$(findstring linux,$(TARGET_MACHINE)))
  27. LINUX=true
  28. else ifneq (,$(findstring gnu,$(TARGET_MACHINE)))
  29. HURD=true
  30. else ifneq (,$(findstring apple,$(TARGET_MACHINE)))
  31. MACOS=true
  32. else ifneq (,$(findstring mingw,$(TARGET_MACHINE)))
  33. WINDOWS=true
  34. else ifneq (,$(findstring windows,$(TARGET_MACHINE)))
  35. WINDOWS=true
  36. endif
  37. endif
  38. endif
  39. endif
  40. endif
  41. endif
  42. endif
  43. # ---------------------------------------------------------------------------------------------------------------------
  44. # Auto-detect the processor
  45. TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE)))
  46. ifneq (,$(filter i%86,$(TARGET_PROCESSOR)))
  47. CPU_I386=true
  48. CPU_I386_OR_X86_64=true
  49. endif
  50. ifneq (,$(filter x86_64,$(TARGET_PROCESSOR)))
  51. CPU_X86_64=true
  52. CPU_I386_OR_X86_64=true
  53. endif
  54. ifneq (,$(filter arm%,$(TARGET_PROCESSOR)))
  55. CPU_ARM=true
  56. CPU_ARM_OR_AARCH64=true
  57. endif
  58. ifneq (,$(filter arm64%,$(TARGET_PROCESSOR)))
  59. CPU_ARM64=true
  60. CPU_ARM_OR_AARCH64=true
  61. endif
  62. ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR)))
  63. CPU_AARCH64=true
  64. CPU_ARM_OR_AARCH64=true
  65. endif
  66. # ---------------------------------------------------------------------------------------------------------------------
  67. # Set PKG_CONFIG (can be overridden by environment variable)
  68. ifeq ($(WINDOWS),true)
  69. # Build statically on Windows by default
  70. PKG_CONFIG ?= pkg-config --static
  71. else
  72. PKG_CONFIG ?= pkg-config
  73. endif
  74. # ---------------------------------------------------------------------------------------------------------------------
  75. # Set LINUX_OR_MACOS
  76. ifeq ($(LINUX),true)
  77. LINUX_OR_MACOS=true
  78. endif
  79. ifeq ($(MACOS),true)
  80. LINUX_OR_MACOS=true
  81. endif
  82. # ---------------------------------------------------------------------------------------------------------------------
  83. # Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS
  84. ifeq ($(HAIKU),true)
  85. HAIKU_OR_MACOS_OR_WINDOWS=true
  86. endif
  87. ifeq ($(MACOS),true)
  88. MACOS_OR_WINDOWS=true
  89. HAIKU_OR_MACOS_OR_WINDOWS=true
  90. endif
  91. ifeq ($(WINDOWS),true)
  92. MACOS_OR_WINDOWS=true
  93. HAIKU_OR_MACOS_OR_WINDOWS=true
  94. endif
  95. # ---------------------------------------------------------------------------------------------------------------------
  96. # Set UNIX
  97. ifeq ($(BSD),true)
  98. UNIX=true
  99. endif
  100. ifeq ($(HURD),true)
  101. UNIX=true
  102. endif
  103. ifeq ($(LINUX),true)
  104. UNIX=true
  105. endif
  106. ifeq ($(MACOS),true)
  107. UNIX=true
  108. endif
  109. # ---------------------------------------------------------------------------------------------------------------------
  110. # Set build and link flags
  111. BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
  112. BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
  113. ifeq ($(CPU_I386_OR_X86_64),true)
  114. BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse
  115. endif
  116. ifeq ($(CPU_ARM),true)
  117. ifneq ($(CPU_ARM64),true)
  118. BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard
  119. endif
  120. endif
  121. ifeq ($(MACOS),true)
  122. # MacOS linker flags
  123. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
  124. ifneq ($(SKIP_STRIPPING),true)
  125. LINK_OPTS += -Wl,-x
  126. endif
  127. else
  128. # Common linker flags
  129. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
  130. ifneq ($(SKIP_STRIPPING),true)
  131. LINK_OPTS += -Wl,--strip-all
  132. endif
  133. endif
  134. ifeq ($(SKIP_STRIPPING),true)
  135. BASE_FLAGS += -g
  136. endif
  137. ifeq ($(NOOPT),true)
  138. # Non-CPU-specific optimization flags
  139. BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections
  140. endif
  141. ifneq ($(MACOS_OR_WINDOWS),true)
  142. ifneq ($(BSD),true)
  143. BASE_FLAGS += -fno-gnu-unique
  144. endif
  145. endif
  146. ifeq ($(WINDOWS),true)
  147. # Assume we want posix
  148. BASE_FLAGS += -posix -D__STDC_FORMAT_MACROS=1 -D__USE_MINGW_ANSI_STDIO=1
  149. # Needed for windows, see https://github.com/falkTX/Carla/issues/855
  150. BASE_FLAGS += -mstackrealign
  151. else
  152. # Not needed for Windows
  153. BASE_FLAGS += -fPIC -DPIC
  154. endif
  155. ifeq ($(DEBUG),true)
  156. BASE_FLAGS += -DDEBUG -O0 -g
  157. LINK_OPTS =
  158. else
  159. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  160. CXXFLAGS += -fvisibility-inlines-hidden
  161. endif
  162. ifeq ($(STATIC_BUILD),true)
  163. BASE_FLAGS += -DSTATIC_BUILD
  164. # LINK_OPTS += -static
  165. endif
  166. ifeq ($(WITH_LTO),true)
  167. BASE_FLAGS += -fno-strict-aliasing -flto
  168. LINK_OPTS += -fno-strict-aliasing -flto -Werror=odr -Werror=lto-type-mismatch
  169. endif
  170. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  171. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++11 $(CXXFLAGS)
  172. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  173. ifneq ($(MACOS),true)
  174. # Not available on MacOS
  175. LINK_FLAGS += -Wl,--no-undefined
  176. endif
  177. ifeq ($(MACOS_OLD),true)
  178. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  179. endif
  180. ifeq ($(WINDOWS),true)
  181. # Always build statically on windows
  182. LINK_FLAGS += -static -static-libgcc -static-libstdc++
  183. endif
  184. # ---------------------------------------------------------------------------------------------------------------------
  185. # Strict test build
  186. ifeq ($(TESTBUILD),true)
  187. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  188. BASE_FLAGS += -Wpointer-arith -Wabi=98 -Winit-self -Wuninitialized -Wstrict-overflow=5
  189. # BASE_FLAGS += -Wfloat-equal
  190. ifeq ($(CC),clang)
  191. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  192. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  193. else
  194. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  195. endif
  196. ifneq ($(MACOS),true)
  197. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  198. ifneq ($(CC),clang)
  199. BASE_FLAGS += -Wlogical-op
  200. endif
  201. endif
  202. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  203. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  204. endif
  205. # ---------------------------------------------------------------------------------------------------------------------
  206. # Check for required libraries
  207. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  208. ifeq ($(MACOS_OR_WINDOWS),true)
  209. HAVE_OPENGL = true
  210. else
  211. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  212. HAVE_DBUS = $(shell $(PKG_CONFIG) --exists dbus-1 && echo true)
  213. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  214. HAVE_XCURSOR = $(shell $(PKG_CONFIG) --exists xcursor && echo true)
  215. HAVE_XEXT = $(shell $(PKG_CONFIG) --exists xext && echo true)
  216. HAVE_XRANDR = $(shell $(PKG_CONFIG) --exists xrandr && echo true)
  217. endif
  218. # Vulkan is not supported yet
  219. # HAVE_VULKAN = $(shell $(PKG_CONFIG) --exists vulkan && echo true)
  220. # ---------------------------------------------------------------------------------------------------------------------
  221. # Check for optional libraries
  222. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  223. ifeq ($(SKIP_RTAUDIO_FALLBACK),true)
  224. CXXFLAGS += -DDPF_JACK_STANDALONE_SKIP_RTAUDIO_FALLBACK
  225. else
  226. ifeq ($(MACOS),true)
  227. HAVE_RTAUDIO = true
  228. else ifeq ($(WINDOWS),true)
  229. HAVE_RTAUDIO = true
  230. else
  231. HAVE_ALSA = $(shell $(PKG_CONFIG) --exists alsa && echo true)
  232. HAVE_PULSEAUDIO = $(shell $(PKG_CONFIG) --exists libpulse-simple && echo true)
  233. ifeq ($(HAVE_ALSA),true)
  234. HAVE_RTAUDIO = true
  235. else ifeq ($(HAVE_PULSEAUDIO),true)
  236. HAVE_RTAUDIO = true
  237. endif
  238. endif
  239. endif
  240. # backwards compat, always available/enabled
  241. HAVE_JACK = true
  242. # ---------------------------------------------------------------------------------------------------------------------
  243. # Set Generic DGL stuff
  244. ifeq ($(HAIKU),true)
  245. DGL_SYSTEM_LIBS += -lbe
  246. endif
  247. ifeq ($(MACOS),true)
  248. DGL_SYSTEM_LIBS += -framework Cocoa -framework CoreVideo
  249. endif
  250. ifeq ($(WINDOWS),true)
  251. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  252. # -lole32
  253. endif
  254. ifneq ($(MACOS_OR_WINDOWS),true)
  255. ifeq ($(HAVE_DBUS),true)
  256. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags dbus-1) -DHAVE_DBUS
  257. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs dbus-1)
  258. endif
  259. ifeq ($(HAVE_X11),true)
  260. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11
  261. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  262. ifeq ($(HAVE_XCURSOR),true)
  263. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor) -DHAVE_XCURSOR
  264. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor)
  265. endif
  266. ifeq ($(HAVE_XEXT),true)
  267. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xext) -DHAVE_XEXT -DHAVE_XSYNC
  268. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xext)
  269. endif
  270. ifeq ($(HAVE_XRANDR),true)
  271. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR
  272. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr)
  273. endif
  274. endif
  275. endif
  276. # ---------------------------------------------------------------------------------------------------------------------
  277. # Set Cairo specific stuff
  278. ifeq ($(HAVE_CAIRO),true)
  279. DGL_FLAGS += -DHAVE_CAIRO
  280. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  281. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  282. HAVE_CAIRO_OR_OPENGL = true
  283. endif
  284. # ---------------------------------------------------------------------------------------------------------------------
  285. # Set OpenGL specific stuff
  286. ifeq ($(HAVE_OPENGL),true)
  287. DGL_FLAGS += -DHAVE_OPENGL
  288. ifeq ($(HAIKU),true)
  289. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  290. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  291. endif
  292. ifeq ($(MACOS),true)
  293. OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1 -Wno-deprecated-declarations
  294. OPENGL_LIBS = -framework OpenGL
  295. endif
  296. ifeq ($(WINDOWS),true)
  297. OPENGL_LIBS = -lopengl32
  298. endif
  299. ifneq ($(MACOS_OR_WINDOWS),true)
  300. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  301. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  302. endif
  303. HAVE_CAIRO_OR_OPENGL = true
  304. endif
  305. # ---------------------------------------------------------------------------------------------------------------------
  306. # Set Stub specific stuff
  307. ifeq ($(MACOS_OR_WINDOWS),true)
  308. HAVE_STUB = true
  309. else
  310. HAVE_STUB = $(HAVE_X11)
  311. endif
  312. # ---------------------------------------------------------------------------------------------------------------------
  313. # Set Vulkan specific stuff
  314. ifeq ($(HAVE_VULKAN),true)
  315. DGL_FLAGS += -DHAVE_VULKAN
  316. VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan)
  317. VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan)
  318. ifneq ($(WINDOWS),true)
  319. VULKAN_LIBS += -ldl
  320. endif
  321. endif
  322. # ---------------------------------------------------------------------------------------------------------------------
  323. # Set optional libraries specific stuff
  324. ifeq ($(HAVE_ALSA),true)
  325. ALSA_FLAGS = $(shell $(PKG_CONFIG) --cflags alsa)
  326. ALSA_LIBS = $(shell $(PKG_CONFIG) --libs alsa)
  327. endif
  328. ifeq ($(HAVE_LIBLO),true)
  329. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  330. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  331. endif
  332. ifeq ($(HAVE_PULSEAUDIO),true)
  333. PULSEAUDIO_FLAGS = $(shell $(PKG_CONFIG) --cflags libpulse-simple)
  334. PULSEAUDIO_LIBS = $(shell $(PKG_CONFIG) --libs libpulse-simple)
  335. endif
  336. ifeq ($(HAVE_JACK),true)
  337. ifeq ($(STATIC_BUILD),true)
  338. JACK_FLAGS = $(shell $(PKG_CONFIG) --cflags jack)
  339. JACK_LIBS = $(shell $(PKG_CONFIG) --libs jack)
  340. endif
  341. endif
  342. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  343. SHARED_MEMORY_LIBS = -lrt
  344. endif
  345. # ---------------------------------------------------------------------------------------------------------------------
  346. # Backwards-compatible HAVE_DGL
  347. ifeq ($(MACOS_OR_WINDOWS),true)
  348. HAVE_DGL = true
  349. else ifeq ($(HAVE_OPENGL),true)
  350. HAVE_DGL = $(HAVE_X11)
  351. endif
  352. # ---------------------------------------------------------------------------------------------------------------------
  353. # Namespace flags
  354. ifneq ($(DISTRHO_NAMESPACE),)
  355. BUILD_CXX_FLAGS += -DDISTRHO_NAMESPACE=$(DISTRHO_NAMESPACE)
  356. endif
  357. ifneq ($(DGL_NAMESPACE),)
  358. BUILD_CXX_FLAGS += -DDGL_NAMESPACE=$(DGL_NAMESPACE)
  359. endif
  360. # ---------------------------------------------------------------------------------------------------------------------
  361. # Optional flags
  362. ifeq ($(NVG_DISABLE_SKIPPING_WHITESPACE),true)
  363. BUILD_CXX_FLAGS += -DNVG_DISABLE_SKIPPING_WHITESPACE
  364. endif
  365. ifneq ($(NVG_FONT_TEXTURE_FLAGS),)
  366. BUILD_CXX_FLAGS += -DNVG_FONT_TEXTURE_FLAGS=$(NVG_FONT_TEXTURE_FLAGS)
  367. endif
  368. ifeq ($(FILE_BROWSER_DISABLED),true)
  369. BUILD_CXX_FLAGS += -DDGL_FILE_BROWSER_DISABLED
  370. endif
  371. ifneq ($(WINDOWS_ICON_ID),)
  372. BUILD_CXX_FLAGS += -DDGL_WINDOWS_ICON_ID=$(WINDOWS_ICON_ID)
  373. endif
  374. ifeq ($(USE_OPENGL3),true)
  375. BUILD_CXX_FLAGS += -DDGL_USE_OPENGL3
  376. endif
  377. ifeq ($(USE_NANOVG_FBO),true)
  378. BUILD_CXX_FLAGS += -DDGL_USE_NANOVG_FBO
  379. endif
  380. ifeq ($(USE_NANOVG_FREETYPE),true)
  381. BUILD_CXX_FLAGS += -DFONS_USE_FREETYPE $(shell $(PKG_CONFIG) --cflags freetype2)
  382. endif
  383. ifeq ($(USE_RGBA),true)
  384. BUILD_CXX_FLAGS += -DDGL_USE_RGBA
  385. endif
  386. # ---------------------------------------------------------------------------------------------------------------------
  387. # Set app extension
  388. ifeq ($(WINDOWS),true)
  389. APP_EXT = .exe
  390. endif
  391. # ---------------------------------------------------------------------------------------------------------------------
  392. # Set shared lib extension
  393. LIB_EXT = .so
  394. ifeq ($(MACOS),true)
  395. LIB_EXT = .dylib
  396. endif
  397. ifeq ($(WINDOWS),true)
  398. LIB_EXT = .dll
  399. endif
  400. # ---------------------------------------------------------------------------------------------------------------------
  401. # Set shared library CLI arg
  402. ifeq ($(MACOS),true)
  403. SHARED = -dynamiclib
  404. else
  405. SHARED = -shared
  406. endif
  407. # ---------------------------------------------------------------------------------------------------------------------
  408. # Handle the verbosity switch
  409. SILENT =
  410. ifeq ($(VERBOSE),1)
  411. else ifeq ($(VERBOSE),y)
  412. else ifeq ($(VERBOSE),yes)
  413. else ifeq ($(VERBOSE),true)
  414. else
  415. SILENT = @
  416. endif
  417. # ---------------------------------------------------------------------------------------------------------------------
  418. # all needs to be first
  419. all:
  420. # ---------------------------------------------------------------------------------------------------------------------
  421. # helper to print what is available/possible to build
  422. print_available = @echo $(1): $(shell echo $($(1)) | grep -q true && echo Yes || echo No)
  423. features:
  424. @echo === Detected CPU
  425. $(call print_available,CPU_AARCH64)
  426. $(call print_available,CPU_ARM)
  427. $(call print_available,CPU_ARM64)
  428. $(call print_available,CPU_ARM_OR_AARCH64)
  429. $(call print_available,CPU_I386)
  430. $(call print_available,CPU_I386_OR_X86_64)
  431. @echo === Detected OS
  432. $(call print_available,BSD)
  433. $(call print_available,HAIKU)
  434. $(call print_available,HURD)
  435. $(call print_available,LINUX)
  436. $(call print_available,MACOS)
  437. $(call print_available,WINDOWS)
  438. $(call print_available,HAIKU_OR_MACOS_OR_WINDOWS)
  439. $(call print_available,LINUX_OR_MACOS)
  440. $(call print_available,MACOS_OR_WINDOWS)
  441. $(call print_available,UNIX)
  442. @echo === Detected features
  443. $(call print_available,HAVE_ALSA)
  444. $(call print_available,HAVE_DBUS)
  445. $(call print_available,HAVE_CAIRO)
  446. $(call print_available,HAVE_DGL)
  447. $(call print_available,HAVE_LIBLO)
  448. $(call print_available,HAVE_OPENGL)
  449. $(call print_available,HAVE_PULSEAUDIO)
  450. $(call print_available,HAVE_RTAUDIO)
  451. $(call print_available,HAVE_STUB)
  452. $(call print_available,HAVE_VULKAN)
  453. $(call print_available,HAVE_X11)
  454. $(call print_available,HAVE_XCURSOR)
  455. $(call print_available,HAVE_XEXT)
  456. $(call print_available,HAVE_XRANDR)
  457. # ---------------------------------------------------------------------------------------------------------------------
  458. # Protect against multiple inclusion
  459. endif # DPF_MAKEFILE_BASE_INCLUDED
  460. # ---------------------------------------------------------------------------------------------------------------------