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.

963 lines
28KB

  1. #!/usr/bin/make -f
  2. # Makefile for DPF #
  3. # ---------------- #
  4. # Created by falkTX
  5. #
  6. # Before including this file, a few variables can be set in order to tweak build behaviour:
  7. # DEBUG=true
  8. # Building in debug mode
  9. # Implies SKIP_STRIPPING=true as well
  10. # NOOPT=true
  11. # Do not automatically set optimization flags
  12. # SKIP_STRIPPING=true
  13. # Do not strip output binaries
  14. # NVG_DISABLE_SKIPPING_WHITESPACE=true
  15. # Tweak `nvgTextBreakLines` to allow space characters
  16. # FIXME proper details
  17. # NVG_FONT_TEXTURE_FLAGS=0
  18. # FILE_BROWSER_DISABLED=true
  19. # WINDOWS_ICON_ID=0
  20. # USE_GLES2=true
  21. # USE_GLES3=true
  22. # USE_OPENGL3=true
  23. # USE_NANOVG_FBO=true
  24. # USE_NANOVG_FREETYPE=true
  25. # USE_FILE_BROWSER=true
  26. # USE_WEB_VIEW=true
  27. # STATIC_BUILD=true
  28. # Tweak build to be able to generate fully static builds (e.g. skip use of libdl)
  29. # Experimental, use only if you know what you are doing
  30. # FORCE_NATIVE_AUDIO_FALLBACK=true
  31. # Do not use JACK for the standalone, only native audio
  32. # SKIP_NATIVE_AUDIO_FALLBACK=true
  33. # Do not use native audio for the standalone, only use JACK
  34. # ---------------------------------------------------------------------------------------------------------------------
  35. # Read target compiler from environment
  36. AR ?= ar
  37. CC ?= gcc
  38. CXX ?= g++
  39. # ---------------------------------------------------------------------------------------------------------------------
  40. # Protect against multiple inclusion
  41. ifneq ($(DPF_MAKEFILE_BASE_INCLUDED),true)
  42. DPF_MAKEFILE_BASE_INCLUDED = true
  43. # ---------------------------------------------------------------------------------------------------------------------
  44. # Auto-detect target compiler if not defined
  45. ifneq ($(shell echo -e escaped-by-default | grep -- '-e escaped-by-default'),-e escaped-by-default)
  46. TARGET_COMPILER = $(shell echo -e '#ifdef __clang__\nclang\n#else\ngcc\n#endif' | $(CC) -E -P -x c - 2>/dev/null)
  47. else ifeq ($(shell echo '\#escaped-by-default' | grep -- '\#escaped-by-default'),\#escaped-by-default)
  48. TARGET_COMPILER = $(shell echo '\#ifdef __clang__\nclang\n\#else\ngcc\n\#endif' | $(CC) -E -P -x c - 2>/dev/null)
  49. else
  50. TARGET_COMPILER = $(shell echo '#ifdef __clang__\nclang\n#else\ngcc\n#endif' | $(CC) -E -P -x c - 2>/dev/null)
  51. endif
  52. ifneq ($(CLANG),true)
  53. ifneq ($(GCC),true)
  54. ifneq (,$(findstring clang,$(TARGET_COMPILER)))
  55. CLANG = true
  56. else
  57. GCC = true
  58. endif
  59. endif
  60. endif
  61. # ---------------------------------------------------------------------------------------------------------------------
  62. # Auto-detect target OS if not defined
  63. TARGET_MACHINE := $(shell $(CC) -dumpmachine)
  64. ifneq ($(BSD),true)
  65. ifneq ($(HAIKU),true)
  66. ifneq ($(HURD),true)
  67. ifneq ($(LINUX),true)
  68. ifneq ($(MACOS),true)
  69. ifneq ($(WASM),true)
  70. ifneq ($(WINDOWS),true)
  71. ifneq (,$(findstring bsd,$(TARGET_MACHINE)))
  72. BSD = true
  73. else ifneq (,$(findstring haiku,$(TARGET_MACHINE)))
  74. HAIKU = true
  75. else ifneq (,$(findstring linux,$(TARGET_MACHINE)))
  76. LINUX = true
  77. else ifneq (,$(findstring gnu,$(TARGET_MACHINE)))
  78. HURD = true
  79. else ifneq (,$(findstring apple,$(TARGET_MACHINE)))
  80. MACOS = true
  81. else ifneq (,$(findstring mingw,$(TARGET_MACHINE)))
  82. WINDOWS = true
  83. else ifneq (,$(findstring msys,$(TARGET_MACHINE)))
  84. WINDOWS = true
  85. else ifneq (,$(findstring wasm,$(TARGET_MACHINE)))
  86. WASM = true
  87. else ifneq (,$(findstring windows,$(TARGET_MACHINE)))
  88. WINDOWS = true
  89. endif
  90. endif # WINDOWS
  91. endif # WASM
  92. endif # MACOS
  93. endif # LINUX
  94. endif # HURD
  95. endif # HAIKU
  96. endif # BSD
  97. # ---------------------------------------------------------------------------------------------------------------------
  98. # Auto-detect target processor
  99. TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE)))
  100. ifneq (,$(filter i%86,$(TARGET_PROCESSOR)))
  101. CPU_I386 = true
  102. CPU_I386_OR_X86_64 = true
  103. endif
  104. ifneq (,$(filter wasm32,$(TARGET_PROCESSOR)))
  105. CPU_I386 = true
  106. CPU_I386_OR_X86_64 = true
  107. endif
  108. ifneq (,$(filter x86_64,$(TARGET_PROCESSOR)))
  109. CPU_X86_64 = true
  110. CPU_I386_OR_X86_64 = true
  111. endif
  112. ifneq (,$(filter arm%,$(TARGET_PROCESSOR)))
  113. CPU_ARM = true
  114. CPU_ARM_OR_ARM64 = true
  115. endif
  116. ifneq (,$(filter arm64%,$(TARGET_PROCESSOR)))
  117. CPU_ARM64 = true
  118. CPU_ARM_OR_ARM64 = true
  119. endif
  120. ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR)))
  121. CPU_ARM64 = true
  122. CPU_ARM_OR_ARM64 = true
  123. endif
  124. ifneq (,$(filter riscv64%,$(TARGET_PROCESSOR)))
  125. CPU_RISCV64 = true
  126. endif
  127. ifeq ($(CPU_ARM),true)
  128. ifneq ($(CPU_ARM64),true)
  129. CPU_ARM32 = true
  130. endif
  131. endif
  132. # ---------------------------------------------------------------------------------------------------------------------
  133. # Set PKG_CONFIG (can be overridden by environment variable)
  134. ifeq ($(WASM),true)
  135. # Skip on wasm by default
  136. PKG_CONFIG ?= false
  137. else ifeq ($(WINDOWS),true)
  138. # Build statically on Windows by default
  139. PKG_CONFIG ?= pkg-config --static
  140. else
  141. PKG_CONFIG ?= pkg-config
  142. endif
  143. # ---------------------------------------------------------------------------------------------------------------------
  144. # Set cross compiling flag
  145. ifeq ($(WASM),true)
  146. CROSS_COMPILING = true
  147. endif
  148. # ---------------------------------------------------------------------------------------------------------------------
  149. # Set LINUX_OR_MACOS
  150. ifeq ($(LINUX),true)
  151. LINUX_OR_MACOS = true
  152. endif
  153. ifeq ($(MACOS),true)
  154. LINUX_OR_MACOS = true
  155. endif
  156. # ---------------------------------------------------------------------------------------------------------------------
  157. # Set MACOS_OR_WINDOWS, MACOS_OR_WASM_OR_WINDOWS, HAIKU_OR_MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS
  158. ifeq ($(HAIKU),true)
  159. HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS = true
  160. HAIKU_OR_MACOS_OR_WINDOWS = true
  161. endif
  162. ifeq ($(MACOS),true)
  163. HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS = true
  164. HAIKU_OR_MACOS_OR_WINDOWS = true
  165. MACOS_OR_WASM_OR_WINDOWS = true
  166. MACOS_OR_WINDOWS = true
  167. endif
  168. ifeq ($(WASM),true)
  169. HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS = true
  170. MACOS_OR_WASM_OR_WINDOWS = true
  171. endif
  172. ifeq ($(WINDOWS),true)
  173. HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS = true
  174. HAIKU_OR_MACOS_OR_WINDOWS = true
  175. MACOS_OR_WASM_OR_WINDOWS = true
  176. MACOS_OR_WINDOWS = true
  177. endif
  178. # ---------------------------------------------------------------------------------------------------------------------
  179. # Set UNIX
  180. ifeq ($(BSD),true)
  181. UNIX = true
  182. endif
  183. ifeq ($(HURD),true)
  184. UNIX = true
  185. endif
  186. ifeq ($(LINUX),true)
  187. UNIX = true
  188. endif
  189. ifeq ($(MACOS),true)
  190. UNIX = true
  191. endif
  192. # ---------------------------------------------------------------------------------------------------------------------
  193. # Compatibility checks
  194. ifeq ($(FILE_BROWSER_DISABLED),true)
  195. $(error FILE_BROWSER_DISABLED has been replaced by USE_FILE_BROWSER (opt-in vs opt-out))
  196. endif
  197. ifeq ($(USE_FILEBROWSER),true)
  198. $(error typo detected use USE_FILE_BROWSER instead of USE_FILEBROWSER)
  199. endif
  200. ifeq ($(USE_WEBVIEW),true)
  201. $(error typo detected use USE_WEB_VIEW instead of USE_WEBVIEW)
  202. endif
  203. # ---------------------------------------------------------------------------------------------------------------------
  204. # Set optional flags
  205. USE_FILE_BROWSER ?= true
  206. USE_WEB_VIEW ?= false
  207. # ---------------------------------------------------------------------------------------------------------------------
  208. # Set build and link flags
  209. BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
  210. BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
  211. LINK_OPTS = -fdata-sections -ffunction-sections
  212. ifeq ($(GCC),true)
  213. BASE_FLAGS += -fno-gnu-unique
  214. endif
  215. ifeq ($(SKIP_STRIPPING),true)
  216. BASE_FLAGS += -g
  217. endif
  218. ifeq ($(STATIC_BUILD),true)
  219. BASE_FLAGS += -DSTATIC_BUILD
  220. endif
  221. ifeq ($(WINDOWS),true)
  222. # Assume we want posix
  223. BASE_FLAGS += -posix -D__STDC_FORMAT_MACROS=1 -D__USE_MINGW_ANSI_STDIO=1
  224. # Needed for windows, see https://github.com/falkTX/Carla/issues/855
  225. BASE_FLAGS += -mstackrealign
  226. else
  227. # Not needed for Windows
  228. BASE_FLAGS += -fPIC -DPIC
  229. endif
  230. ifeq ($(WASM),true)
  231. BASE_OPTS += -msse -msse2 -msse3 -msimd128
  232. else ifeq ($(CPU_ARM32),true)
  233. BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard
  234. else ifeq ($(CPU_I386_OR_X86_64),true)
  235. BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse
  236. endif
  237. ifeq ($(MACOS),true)
  238. ifneq ($(MACOS_NO_DEAD_STRIP),true)
  239. LINK_OPTS += -Wl,-dead_strip,-dead_strip_dylibs
  240. endif
  241. else ifeq ($(WASM),true)
  242. LINK_OPTS += -O3
  243. LINK_OPTS += -Wl,--gc-sections
  244. else
  245. LINK_OPTS += -Wl,-O1,--as-needed,--gc-sections
  246. endif
  247. ifneq ($(SKIP_STRIPPING),true)
  248. ifeq ($(MACOS),true)
  249. LINK_OPTS += -Wl,-x
  250. else ifeq ($(WASM),true)
  251. LINK_OPTS += -sAGGRESSIVE_VARIABLE_ELIMINATION=1
  252. else
  253. LINK_OPTS += -Wl,--strip-all
  254. endif
  255. endif
  256. ifeq ($(NOOPT),true)
  257. # Non-CPU-specific optimization flags
  258. BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections
  259. endif
  260. ifeq ($(DEBUG),true)
  261. BASE_FLAGS += -DDEBUG -DDPF_DEBUG -O0 -g
  262. # ifneq ($(HAIKU),true)
  263. # BASE_FLAGS += -fsanitize=address
  264. # endif
  265. LINK_OPTS =
  266. ifeq ($(WASM),true)
  267. LINK_OPTS += -sASSERTIONS=1
  268. endif
  269. else
  270. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  271. CXXFLAGS += -fvisibility-inlines-hidden
  272. endif
  273. ifeq ($(WITH_LTO),true)
  274. BASE_FLAGS += -fno-strict-aliasing -flto
  275. LINK_OPTS += -fno-strict-aliasing -flto -Werror=odr
  276. ifeq ($(GCC),true)
  277. LINK_OPTS += -Werror=lto-type-mismatch
  278. endif
  279. endif
  280. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  281. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++11 $(CXXFLAGS)
  282. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  283. ifeq ($(WASM),true)
  284. # Special flag for emscripten
  285. LINK_FLAGS += -sENVIRONMENT=web -sLLD_REPORT_UNDEFINED
  286. else ifneq ($(MACOS),true)
  287. # Not available on MacOS
  288. LINK_FLAGS += -Wl,--no-undefined
  289. endif
  290. ifeq ($(MACOS_OLD),true)
  291. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  292. endif
  293. ifeq ($(WASM_CLIPBOARD),true)
  294. BUILD_CXX_FLAGS += -DPUGL_WASM_ASYNC_CLIPBOARD
  295. LINK_FLAGS += -sASYNCIFY -sASYNCIFY_IMPORTS=puglGetAsyncClipboardData
  296. endif
  297. ifeq ($(WASM_EXCEPTIONS),true)
  298. BUILD_CXX_FLAGS += -fexceptions
  299. LINK_FLAGS += -fexceptions
  300. endif
  301. ifeq ($(WINDOWS),true)
  302. # Always build statically on windows
  303. LINK_FLAGS += -static -static-libgcc -static-libstdc++
  304. endif
  305. # ---------------------------------------------------------------------------------------------------------------------
  306. # Strict test build
  307. ifeq ($(TESTBUILD),true)
  308. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  309. BASE_FLAGS += -Wpointer-arith -Wabi=98 -Winit-self -Wuninitialized -Wstrict-overflow=5
  310. # BASE_FLAGS += -Wfloat-equal
  311. ifeq ($(CLANG),true)
  312. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  313. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  314. else
  315. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  316. endif
  317. ifneq ($(MACOS),true)
  318. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  319. ifeq ($(GCC),true)
  320. BASE_FLAGS += -Wlogical-op
  321. endif
  322. endif
  323. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  324. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  325. endif
  326. # ---------------------------------------------------------------------------------------------------------------------
  327. # Check for required libraries
  328. ifneq ($(HAIKU)$(WASM),true)
  329. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  330. endif
  331. ifeq ($(HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS),true)
  332. HAVE_OPENGL = true
  333. else
  334. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  335. HAVE_DBUS = $(shell $(PKG_CONFIG) --exists dbus-1 && echo true)
  336. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  337. HAVE_XCURSOR = $(shell $(PKG_CONFIG) --exists xcursor && echo true)
  338. HAVE_XEXT = $(shell $(PKG_CONFIG) --exists xext && echo true)
  339. HAVE_XRANDR = $(shell $(PKG_CONFIG) --exists xrandr && echo true)
  340. endif
  341. # Vulkan is not supported yet
  342. # HAVE_VULKAN = $(shell $(PKG_CONFIG) --exists vulkan && echo true)
  343. # ---------------------------------------------------------------------------------------------------------------------
  344. # Check for optional libraries
  345. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  346. ifneq ($(SKIP_NATIVE_AUDIO_FALLBACK),true)
  347. ifneq ($(SKIP_RTAUDIO_FALLBACK),true)
  348. ifeq ($(MACOS),true)
  349. HAVE_RTAUDIO = true
  350. else ifeq ($(WINDOWS),true)
  351. HAVE_RTAUDIO = true
  352. else
  353. HAVE_ALSA = $(shell $(PKG_CONFIG) --exists alsa && echo true)
  354. HAVE_PULSEAUDIO = $(shell $(PKG_CONFIG) --exists libpulse-simple && echo true)
  355. HAVE_SDL2 = $(shell $(PKG_CONFIG) --exists sdl2 && echo true)
  356. ifeq ($(HAVE_ALSA),true)
  357. HAVE_RTAUDIO = true
  358. else ifeq ($(HAVE_PULSEAUDIO),true)
  359. HAVE_RTAUDIO = true
  360. endif
  361. endif
  362. endif
  363. endif
  364. # backwards compat, always available/enabled
  365. ifneq ($(FORCE_NATIVE_AUDIO_FALLBACK),true)
  366. ifeq ($(STATIC_BUILD),true)
  367. HAVE_JACK = $(shell $(PKG_CONFIG) --exists jack && echo true)
  368. else
  369. HAVE_JACK = true
  370. endif
  371. endif
  372. # ---------------------------------------------------------------------------------------------------------------------
  373. # Set Generic DGL stuff
  374. ifeq ($(HAIKU),true)
  375. DGL_SYSTEM_LIBS += -lbe
  376. else ifeq ($(MACOS),true)
  377. DGL_SYSTEM_LIBS += -framework Cocoa
  378. DGL_SYSTEM_LIBS += -framework CoreVideo
  379. ifeq ($(USE_WEB_VIEW),true)
  380. DGL_SYSTEM_LIBS += -framework WebKit
  381. endif
  382. else ifeq ($(WASM),true)
  383. # wasm builds cannot work using regular desktop OpenGL
  384. ifeq (,$(USE_GLES2)$(USE_GLES3))
  385. USE_GLES2 = true
  386. endif
  387. else ifeq ($(WINDOWS),true)
  388. DGL_SYSTEM_LIBS += -lcomdlg32
  389. DGL_SYSTEM_LIBS += -ldwmapi
  390. DGL_SYSTEM_LIBS += -lgdi32
  391. # DGL_SYSTEM_LIBS += -lole32
  392. ifeq ($(USE_WEB_VIEW),true)
  393. DGL_SYSTEM_LIBS += -lole32
  394. DGL_SYSTEM_LIBS += -luuid
  395. endif
  396. else
  397. ifneq ($(FILE_BROWSER_DISABLED),true)
  398. ifeq ($(HAVE_DBUS),true)
  399. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags dbus-1) -DHAVE_DBUS
  400. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs dbus-1)
  401. endif
  402. endif
  403. ifeq ($(HAVE_X11),true)
  404. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11
  405. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  406. ifeq ($(HAVE_XCURSOR),true)
  407. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor) -DHAVE_XCURSOR
  408. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor)
  409. endif
  410. ifeq ($(HAVE_XEXT),true)
  411. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xext) -DHAVE_XEXT -DHAVE_XSYNC
  412. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xext)
  413. endif
  414. ifeq ($(HAVE_XRANDR),true)
  415. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR
  416. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr)
  417. endif
  418. ifeq ($(USE_WEB_VIEW),true)
  419. DGL_FLAGS += -pthread
  420. DGL_SYSTEM_LIBS += -pthread -lrt
  421. endif
  422. endif # HAVE_X11
  423. endif
  424. # ---------------------------------------------------------------------------------------------------------------------
  425. # Set Cairo specific stuff
  426. ifeq ($(HAVE_CAIRO),true)
  427. DGL_FLAGS += -DHAVE_CAIRO
  428. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  429. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  430. HAVE_CAIRO_OR_OPENGL = true
  431. endif # HAVE_CAIRO
  432. # ---------------------------------------------------------------------------------------------------------------------
  433. # Set OpenGL specific stuff
  434. ifeq ($(HAVE_OPENGL),true)
  435. DGL_FLAGS += -DHAVE_OPENGL
  436. ifeq ($(HAIKU),true)
  437. OPENGL_FLAGS =
  438. OPENGL_LIBS = -lGL
  439. else ifeq ($(MACOS),true)
  440. OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1 -Wno-deprecated-declarations
  441. OPENGL_LIBS = -framework OpenGL
  442. else ifeq ($(WASM),true)
  443. ifeq ($(USE_GLES2),true)
  444. OPENGL_LIBS = -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2
  445. else
  446. ifneq ($(USE_GLES3),true)
  447. OPENGL_LIBS = -sLEGACY_GL_EMULATION -sGL_UNSAFE_OPTS=0
  448. endif
  449. endif
  450. else ifeq ($(WINDOWS),true)
  451. OPENGL_LIBS = -lopengl32
  452. else
  453. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  454. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  455. endif
  456. HAVE_CAIRO_OR_OPENGL = true
  457. endif # HAVE_OPENGL
  458. # ---------------------------------------------------------------------------------------------------------------------
  459. # Set Stub specific stuff
  460. ifeq ($(HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS),true)
  461. HAVE_STUB = true
  462. else
  463. HAVE_STUB = $(HAVE_X11)
  464. endif
  465. # ---------------------------------------------------------------------------------------------------------------------
  466. # Set Vulkan specific stuff
  467. ifeq ($(HAVE_VULKAN),true)
  468. DGL_FLAGS += -DHAVE_VULKAN
  469. VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan)
  470. VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan)
  471. ifneq ($(WINDOWS),true)
  472. VULKAN_LIBS += -ldl
  473. endif
  474. endif
  475. # ---------------------------------------------------------------------------------------------------------------------
  476. # Set optional libraries specific stuff
  477. ifeq ($(HAVE_ALSA),true)
  478. ALSA_FLAGS = $(shell $(PKG_CONFIG) --cflags alsa)
  479. ALSA_LIBS = $(shell $(PKG_CONFIG) --libs alsa)
  480. endif
  481. ifeq ($(HAVE_LIBLO),true)
  482. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  483. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  484. endif
  485. ifeq ($(HAVE_PULSEAUDIO),true)
  486. PULSEAUDIO_FLAGS = $(shell $(PKG_CONFIG) --cflags libpulse-simple)
  487. PULSEAUDIO_LIBS = $(shell $(PKG_CONFIG) --libs libpulse-simple)
  488. endif
  489. ifeq ($(HAVE_SDL2),true)
  490. SDL2_FLAGS = $(shell $(PKG_CONFIG) --cflags sdl2)
  491. SDL2_LIBS = $(shell $(PKG_CONFIG) --libs sdl2)
  492. endif
  493. ifeq ($(HAVE_JACK),true)
  494. ifeq ($(STATIC_BUILD),true)
  495. JACK_FLAGS = $(shell $(PKG_CONFIG) --cflags jack)
  496. JACK_LIBS = $(shell $(PKG_CONFIG) --libs jack)
  497. endif
  498. endif
  499. ifneq ($(HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS),true)
  500. SHARED_MEMORY_LIBS = -lrt
  501. endif
  502. # ---------------------------------------------------------------------------------------------------------------------
  503. # Generic HAVE_DGL
  504. ifeq ($(HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS),true)
  505. HAVE_DGL = true
  506. else
  507. HAVE_DGL = $(HAVE_X11)
  508. endif
  509. # ---------------------------------------------------------------------------------------------------------------------
  510. # Namespace flags
  511. ifneq ($(DISTRHO_NAMESPACE),)
  512. BUILD_CXX_FLAGS += -DDISTRHO_NAMESPACE=$(DISTRHO_NAMESPACE)
  513. endif
  514. ifneq ($(DGL_NAMESPACE),)
  515. BUILD_CXX_FLAGS += -DDGL_NAMESPACE=$(DGL_NAMESPACE)
  516. endif
  517. # ---------------------------------------------------------------------------------------------------------------------
  518. # Optional flags
  519. ifeq ($(NVG_DISABLE_SKIPPING_WHITESPACE),true)
  520. BUILD_CXX_FLAGS += -DNVG_DISABLE_SKIPPING_WHITESPACE
  521. endif
  522. ifneq ($(NVG_FONT_TEXTURE_FLAGS),)
  523. BUILD_CXX_FLAGS += -DNVG_FONT_TEXTURE_FLAGS=$(NVG_FONT_TEXTURE_FLAGS)
  524. endif
  525. ifneq ($(WINDOWS_ICON_ID),)
  526. BUILD_CXX_FLAGS += -DDGL_WINDOWS_ICON_ID=$(WINDOWS_ICON_ID)
  527. endif
  528. ifneq ($(X11_WINDOW_ICON_NAME),)
  529. BUILD_CXX_FLAGS += -DDGL_X11_WINDOW_ICON_NAME=$(X11_WINDOW_ICON_NAME)
  530. endif
  531. ifneq ($(X11_WINDOW_ICON_SIZE),)
  532. BUILD_CXX_FLAGS += -DDGL_X11_WINDOW_ICON_SIZE=$(X11_WINDOW_ICON_SIZE)
  533. endif
  534. ifeq ($(USE_GLES2),true)
  535. BUILD_CXX_FLAGS += -DDGL_USE_OPENGL3 -DDGL_USE_GLES -DDGL_USE_GLES2
  536. endif
  537. ifeq ($(USE_GLES3),true)
  538. BUILD_CXX_FLAGS += -DDGL_USE_OPENGL3 -DDGL_USE_GLES -DDGL_USE_GLES3
  539. endif
  540. ifeq ($(USE_OPENGL3),true)
  541. BUILD_CXX_FLAGS += -DDGL_USE_OPENGL3
  542. endif
  543. ifeq ($(USE_NANOVG_FBO),true)
  544. BUILD_CXX_FLAGS += -DDGL_USE_NANOVG_FBO
  545. endif
  546. ifeq ($(USE_NANOVG_FREETYPE),true)
  547. BUILD_CXX_FLAGS += -DFONS_USE_FREETYPE $(shell $(PKG_CONFIG) --cflags freetype2)
  548. endif
  549. ifeq ($(USE_RGBA),true)
  550. BUILD_CXX_FLAGS += -DDGL_USE_RGBA
  551. endif
  552. ifeq ($(USE_FILE_BROWSER),true)
  553. BUILD_CXX_FLAGS += -DDGL_USE_FILE_BROWSER
  554. endif
  555. ifeq ($(USE_WEB_VIEW),true)
  556. BUILD_CXX_FLAGS += -DDGL_USE_WEB_VIEW
  557. endif
  558. # ---------------------------------------------------------------------------------------------------------------------
  559. # Set app extension
  560. ifeq ($(WASM),true)
  561. APP_EXT = .html
  562. else ifeq ($(WINDOWS),true)
  563. APP_EXT = .exe
  564. endif
  565. # ---------------------------------------------------------------------------------------------------------------------
  566. # Set shared lib extension
  567. ifeq ($(MACOS),true)
  568. LIB_EXT = .dylib
  569. else ifeq ($(WASM),true)
  570. LIB_EXT = .wasm
  571. else ifeq ($(WINDOWS),true)
  572. LIB_EXT = .dll
  573. else
  574. LIB_EXT = .so
  575. endif
  576. # ---------------------------------------------------------------------------------------------------------------------
  577. # Set shared library CLI arg
  578. ifeq ($(MACOS),true)
  579. SHARED = -dynamiclib
  580. else ifeq ($(WASM),true)
  581. SHARED = -sSIDE_MODULE=2
  582. else
  583. SHARED = -shared
  584. endif
  585. # ---------------------------------------------------------------------------------------------------------------------
  586. # Set CLAP binary directory
  587. ifeq ($(MACOS),true)
  588. CLAP_BINARY_DIR = Contents/MacOS
  589. else
  590. CLAP_BINARY_DIR =
  591. endif
  592. # ---------------------------------------------------------------------------------------------------------------------
  593. # Set VST2 binary directory
  594. ifeq ($(MACOS),true)
  595. VST2_BINARY_DIR = Contents/MacOS
  596. else
  597. VST2_BINARY_DIR =
  598. endif
  599. # ---------------------------------------------------------------------------------------------------------------------
  600. # Set VST3 binary directory, see https://vst3sdk-doc.diatonic.jp/doc/vstinterfaces/vst3loc.html
  601. ifeq ($(LINUX),true)
  602. # This must match `uname -m`, which differs from `gcc -dumpmachine` on PowerPC.
  603. VST3_ARCHITECTURE := $(patsubst powerpc%,ppc%,$(TARGET_PROCESSOR))
  604. VST3_BINARY_DIR = Contents/$(VST3_ARCHITECTURE)-linux
  605. else ifeq ($(MACOS),true)
  606. VST3_BINARY_DIR = Contents/MacOS
  607. else ifeq ($(WASM),true)
  608. VST3_BINARY_DIR = Contents/wasm
  609. else ifeq ($(WINDOWS)$(CPU_I386),truetrue)
  610. VST3_BINARY_DIR = Contents/x86-win
  611. else ifeq ($(WINDOWS)$(CPU_X86_64),truetrue)
  612. VST3_BINARY_DIR = Contents/x86_64-win
  613. else
  614. VST3_BINARY_DIR =
  615. endif
  616. # ---------------------------------------------------------------------------------------------------------------------
  617. # Handle the verbosity switch
  618. SILENT =
  619. ifeq ($(VERBOSE),1)
  620. else ifeq ($(VERBOSE),y)
  621. else ifeq ($(VERBOSE),yes)
  622. else ifeq ($(VERBOSE),true)
  623. else
  624. SILENT = @
  625. endif
  626. # ---------------------------------------------------------------------------------------------------------------------
  627. # all needs to be first
  628. all:
  629. # ---------------------------------------------------------------------------------------------------------------------
  630. # helper to print what is available/possible to build
  631. print_available = @echo $(1): $(shell echo $($(1)) | grep -q true && echo Yes || echo No)
  632. features:
  633. @echo === Detected Compiler
  634. $(call print_available,CLANG)
  635. $(call print_available,GCC)
  636. @echo === Detected CPU
  637. $(call print_available,CPU_ARM)
  638. $(call print_available,CPU_ARM32)
  639. $(call print_available,CPU_ARM64)
  640. $(call print_available,CPU_ARM_OR_ARM64)
  641. $(call print_available,CPU_I386)
  642. $(call print_available,CPU_I386_OR_X86_64)
  643. $(call print_available,CPU_RISCV64)
  644. $(call print_available,CPU_X86_64)
  645. @echo === Detected OS
  646. $(call print_available,BSD)
  647. $(call print_available,HAIKU)
  648. $(call print_available,HURD)
  649. $(call print_available,LINUX)
  650. $(call print_available,MACOS)
  651. $(call print_available,WASM)
  652. $(call print_available,WINDOWS)
  653. $(call print_available,HAIKU_OR_MACOS_OR_WASM_OR_WINDOWS)
  654. $(call print_available,HAIKU_OR_MACOS_OR_WINDOWS)
  655. $(call print_available,LINUX_OR_MACOS)
  656. $(call print_available,MACOS_OR_WASM_OR_WINDOWS)
  657. $(call print_available,MACOS_OR_WINDOWS)
  658. $(call print_available,UNIX)
  659. @echo === Detected features
  660. $(call print_available,HAVE_ALSA)
  661. $(call print_available,HAVE_DBUS)
  662. $(call print_available,HAVE_CAIRO)
  663. $(call print_available,HAVE_DGL)
  664. $(call print_available,HAVE_JACK)
  665. $(call print_available,HAVE_LIBLO)
  666. $(call print_available,HAVE_OPENGL)
  667. $(call print_available,HAVE_PULSEAUDIO)
  668. $(call print_available,HAVE_RTAUDIO)
  669. $(call print_available,HAVE_SDL2)
  670. $(call print_available,HAVE_STUB)
  671. $(call print_available,HAVE_VULKAN)
  672. $(call print_available,HAVE_X11)
  673. $(call print_available,HAVE_XCURSOR)
  674. $(call print_available,HAVE_XEXT)
  675. $(call print_available,HAVE_XRANDR)
  676. # ---------------------------------------------------------------------------------------------------------------------
  677. # Extra rules for MOD Audio stuff
  678. # NOTE: path must be absolute
  679. MOD_WORKDIR ?= $(HOME)/mod-workdir
  680. MOD_ENVIRONMENT = \
  681. AR=${1}/host/usr/bin/${2}-gcc-ar \
  682. CC=${1}/host/usr/bin/${2}-gcc \
  683. CPP=${1}/host/usr/bin/${2}-cpp \
  684. CXX=${1}/host/usr/bin/${2}-g++ \
  685. LD=${1}/host/usr/bin/${2}-ld \
  686. PKG_CONFIG=${1}/host/usr/bin/pkg-config \
  687. PKG_CONFIG_PATH="${1}/staging/usr/lib/pkgconfig" \
  688. STRIP=${1}/host/usr/bin/${2}-strip \
  689. CFLAGS="-I${1}/staging/usr/include $(EXTRA_MOD_FLAGS)" \
  690. CPPFLAGS= \
  691. CXXFLAGS="-I${1}/staging/usr/include $(EXTRA_MOD_FLAGS)" \
  692. LDFLAGS="-L${1}/staging/usr/lib $(EXTRA_MOD_FLAGS)" \
  693. EXE_WRAPPER="qemu-${3}-static -L ${1}/target" \
  694. HAVE_CAIRO=false \
  695. HAVE_OPENGL=false \
  696. MOD_BUILD=true \
  697. NOOPT=true
  698. modduo:
  699. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/modduo-static,arm-mod-linux-gnueabihf.static,arm)
  700. modduo-new:
  701. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/modduo-new,arm-modaudio-linux-gnueabihf,arm)
  702. modduox:
  703. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/modduox-static,aarch64-mod-linux-gnueabi.static,aarch64)
  704. modduox-new:
  705. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/modduox-new,aarch64-modaudio-linux-gnueabi,aarch64)
  706. moddwarf:
  707. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/moddwarf,aarch64-mod-linux-gnu,aarch64)
  708. moddwarf-new:
  709. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/moddwarf-new,aarch64-modaudio-linux-gnu,aarch64)
  710. modpush:
  711. tar -C bin -chz $(subst bin/,,$(wildcard bin/*.lv2)) | base64 | curl -F 'package=@-' http://192.168.51.1/sdk/install && echo
  712. ifneq (,$(findstring modduo-new-,$(MAKECMDGOALS)))
  713. $(MAKECMDGOALS):
  714. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/modduo-new,arm-modaudio-linux-gnueabihf,arm) $(subst modduo-new-,,$(MAKECMDGOALS))
  715. else ifneq (,$(findstring modduo-,$(filter-out modduo-new,$(MAKECMDGOALS))))
  716. $(MAKECMDGOALS):
  717. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/modduo-static,arm-mod-linux-gnueabihf.static,arm) $(subst modduo-,,$(MAKECMDGOALS))
  718. endif
  719. ifneq (,$(findstring modduox-new-,$(MAKECMDGOALS)))
  720. $(MAKECMDGOALS):
  721. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/modduox-new,aarch64-modaudio-linux-gnueabi,aarch64) $(subst modduox-new-,,$(MAKECMDGOALS))
  722. else ifneq (,$(findstring modduox-,$(filter-out modduox-new,$(MAKECMDGOALS))))
  723. $(MAKECMDGOALS):
  724. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/modduox-static,aarch64-mod-linux-gnueabi.static,aarch64) $(subst modduox-,,$(MAKECMDGOALS))
  725. endif
  726. ifneq (,$(findstring moddwarf-new-,$(MAKECMDGOALS)))
  727. $(MAKECMDGOALS):
  728. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/moddwarf-new,aarch64-modaudio-linux-gnu,aarch64) $(subst moddwarf-new-,,$(MAKECMDGOALS))
  729. else ifneq (,$(findstring moddwarf-,$(filter-out moddwarf-new,$(MAKECMDGOALS))))
  730. $(MAKECMDGOALS):
  731. $(MAKE) $(call MOD_ENVIRONMENT,$(MOD_WORKDIR)/moddwarf,aarch64-mod-linux-gnu,aarch64) $(subst moddwarf-,,$(MAKECMDGOALS))
  732. endif
  733. # ---------------------------------------------------------------------------------------------------------------------
  734. # Convenience rules for common builds
  735. macos-intel-10.8:
  736. $(MAKE) \
  737. CFLAGS="$(CFLAGS) -arch x86_64 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_8 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_8 -mmacosx-version-min=10.8" \
  738. CXXFLAGS="$(CXXFLAGS) -arch x86_64 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_8 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_8 -mmacosx-version-min=10.8 -stdlib=libc++" \
  739. LDFLAGS="$(LDFLAGS) -stdlib=libc++" \
  740. PKG_CONFIG=/usr/bin/false \
  741. PKG_CONFIG_PATH=/NOT
  742. macos-universal-10.8:
  743. $(MAKE) \
  744. CFLAGS="$(CFLAGS) -arch x86_64 -arch arm64 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_8 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_8 -mmacosx-version-min=10.15" \
  745. CXXFLAGS="$(CXXFLAGS) -arch x86_64 -arch arm64 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_8 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_8 -mmacosx-version-min=10.15 -stdlib=libc++" \
  746. LDFLAGS="$(LDFLAGS) -stdlib=libc++" \
  747. PKG_CONFIG=/usr/bin/false \
  748. PKG_CONFIG_PATH=/NOT
  749. macos-intel-10.15:
  750. $(MAKE) \
  751. CFLAGS="$(CFLAGS) -arch x86_64 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_15 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_15 -mmacosx-version-min=10.15" \
  752. CXXFLAGS="$(CXXFLAGS) -arch x86_64 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_15 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_15 -mmacosx-version-min=10.15" \
  753. PKG_CONFIG=/usr/bin/false \
  754. PKG_CONFIG_PATH=/NOT
  755. macos-universal-10.15:
  756. $(MAKE) \
  757. CFLAGS="$(CFLAGS) -arch x86_64 -arch arm64 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_15 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_15 -mmacosx-version-min=10.15" \
  758. CXXFLAGS="$(CXXFLAGS) -arch x86_64 -arch arm64 -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_15 -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_15 -mmacosx-version-min=10.15" \
  759. PKG_CONFIG=/usr/bin/false \
  760. PKG_CONFIG_PATH=/NOT
  761. mingw32:
  762. $(MAKE) \
  763. AR=i686-w64-mingw32-ar \
  764. CC=i686-w64-mingw32-gcc \
  765. CXX=i686-w64-mingw32-g++ \
  766. EXE_WRAPPER=wine \
  767. PKG_CONFIG=/usr/bin/false \
  768. PKG_CONFIG_PATH=/NOT
  769. mingw64:
  770. $(MAKE) \
  771. AR=x86_64-w64-mingw32-ar \
  772. CC=x86_64-w64-mingw32-gcc \
  773. CXX=x86_64-w64-mingw32-g++ \
  774. EXE_WRAPPER=wine \
  775. PKG_CONFIG=/usr/bin/false \
  776. PKG_CONFIG_PATH=/NOT
  777. # ---------------------------------------------------------------------------------------------------------------------
  778. # Protect against multiple inclusion
  779. endif # DPF_MAKEFILE_BASE_INCLUDED
  780. # ---------------------------------------------------------------------------------------------------------------------