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.

550 lines
15KB

  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. ifeq ($(WINDOWS),true)
  142. # Assume we want posix
  143. BASE_FLAGS += -posix -D__STDC_FORMAT_MACROS
  144. # Needed for windows, see https://github.com/falkTX/Carla/issues/855
  145. BASE_FLAGS += -mstackrealign
  146. else
  147. # Not needed for Windows
  148. BASE_FLAGS += -fPIC -DPIC
  149. endif
  150. ifeq ($(DEBUG),true)
  151. BASE_FLAGS += -DDEBUG -O0 -g
  152. LINK_OPTS =
  153. else
  154. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  155. CXXFLAGS += -fvisibility-inlines-hidden
  156. endif
  157. ifeq ($(WITH_LTO),true)
  158. BASE_FLAGS += -fno-strict-aliasing -flto
  159. LINK_FLAGS += -fno-strict-aliasing -flto -Werror=odr -Werror=lto-type-mismatch
  160. endif
  161. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  162. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++11 $(CXXFLAGS)
  163. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  164. ifneq ($(MACOS),true)
  165. # Not available on MacOS
  166. LINK_FLAGS += -Wl,--no-undefined
  167. endif
  168. ifeq ($(MACOS_OLD),true)
  169. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  170. endif
  171. ifeq ($(WINDOWS),true)
  172. # Always build statically on windows
  173. LINK_FLAGS += -static -static-libgcc -static-libstdc++
  174. endif
  175. # ---------------------------------------------------------------------------------------------------------------------
  176. # Strict test build
  177. ifeq ($(TESTBUILD),true)
  178. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  179. BASE_FLAGS += -Wpointer-arith -Wabi=98 -Winit-self -Wuninitialized -Wstrict-overflow=5
  180. # BASE_FLAGS += -Wfloat-equal
  181. ifeq ($(CC),clang)
  182. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  183. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  184. else
  185. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  186. endif
  187. ifneq ($(MACOS),true)
  188. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  189. ifneq ($(CC),clang)
  190. BASE_FLAGS += -Wlogical-op
  191. endif
  192. endif
  193. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  194. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  195. endif
  196. # ---------------------------------------------------------------------------------------------------------------------
  197. # Check for required libraries
  198. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  199. # Vulkan is not supported yet
  200. # HAVE_VULKAN = $(shell $(PKG_CONFIG) --exists vulkan && echo true)
  201. ifeq ($(MACOS_OR_WINDOWS),true)
  202. HAVE_OPENGL = true
  203. else
  204. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  205. ifneq ($(HAIKU),true)
  206. HAVE_DBUS = $(shell $(PKG_CONFIG) --exists dbus-1 && echo true)
  207. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  208. HAVE_XCURSOR = $(shell $(PKG_CONFIG) --exists xcursor && echo true)
  209. HAVE_XEXT = $(shell $(PKG_CONFIG) --exists xext && echo true)
  210. HAVE_XRANDR = $(shell $(PKG_CONFIG) --exists xrandr && echo true)
  211. endif
  212. endif
  213. # ---------------------------------------------------------------------------------------------------------------------
  214. # Check for optional libraries
  215. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  216. ifeq ($(SKIP_RTAUDIO_FALLBACK),true)
  217. CXXFLAGS += -DDPF_JACK_STANDALONE_SKIP_RTAUDIO_FALLBACK
  218. else
  219. ifeq ($(MACOS),true)
  220. HAVE_RTAUDIO = true
  221. else ifeq ($(WINDOWS),true)
  222. HAVE_RTAUDIO = true
  223. else ifneq ($(HAIKU),true)
  224. HAVE_ALSA = $(shell $(PKG_CONFIG) --exists alsa && echo true)
  225. HAVE_PULSEAUDIO = $(shell $(PKG_CONFIG) --exists libpulse-simple && echo true)
  226. ifeq ($(HAVE_ALSA),true)
  227. HAVE_RTAUDIO = true
  228. else ifeq ($(HAVE_PULSEAUDIO),true)
  229. HAVE_RTAUDIO = true
  230. endif
  231. endif
  232. endif
  233. # backwards compat
  234. HAVE_JACK = true
  235. # ---------------------------------------------------------------------------------------------------------------------
  236. # Set Generic DGL stuff
  237. ifeq ($(HAIKU),true)
  238. DGL_SYSTEM_LIBS += -lbe
  239. endif
  240. ifeq ($(MACOS),true)
  241. DGL_SYSTEM_LIBS += -framework Cocoa -framework CoreVideo
  242. endif
  243. ifeq ($(WINDOWS),true)
  244. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  245. # -lole32
  246. endif
  247. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  248. ifeq ($(HAVE_DBUS),true)
  249. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags dbus-1) -DHAVE_DBUS
  250. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs dbus-1)
  251. endif
  252. ifeq ($(HAVE_X11),true)
  253. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11
  254. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  255. ifeq ($(HAVE_XCURSOR),true)
  256. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor) -DHAVE_XCURSOR
  257. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor)
  258. endif
  259. ifeq ($(HAVE_XEXT),true)
  260. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xext) -DHAVE_XEXT -DHAVE_XSYNC
  261. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xext)
  262. endif
  263. ifeq ($(HAVE_XRANDR),true)
  264. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR
  265. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr)
  266. endif
  267. endif
  268. endif
  269. # ---------------------------------------------------------------------------------------------------------------------
  270. # Set Cairo specific stuff
  271. ifeq ($(HAVE_CAIRO),true)
  272. DGL_FLAGS += -DHAVE_CAIRO
  273. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  274. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  275. HAVE_CAIRO_OR_OPENGL = true
  276. endif
  277. # ---------------------------------------------------------------------------------------------------------------------
  278. # Set OpenGL specific stuff
  279. ifeq ($(HAVE_OPENGL),true)
  280. DGL_FLAGS += -DHAVE_OPENGL
  281. ifeq ($(HAIKU),true)
  282. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  283. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  284. endif
  285. ifeq ($(MACOS),true)
  286. OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1 -Wno-deprecated-declarations
  287. OPENGL_LIBS = -framework OpenGL
  288. endif
  289. ifeq ($(WINDOWS),true)
  290. OPENGL_LIBS = -lopengl32
  291. endif
  292. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  293. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  294. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  295. endif
  296. HAVE_CAIRO_OR_OPENGL = true
  297. endif
  298. # ---------------------------------------------------------------------------------------------------------------------
  299. # Set Stub specific stuff
  300. ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  301. HAVE_STUB = true
  302. else
  303. HAVE_STUB = $(HAVE_X11)
  304. endif
  305. # ---------------------------------------------------------------------------------------------------------------------
  306. # Set Vulkan specific stuff
  307. ifeq ($(HAVE_VULKAN),true)
  308. DGL_FLAGS += -DHAVE_VULKAN
  309. VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan)
  310. VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan)
  311. ifneq ($(WINDOWS),true)
  312. VULKAN_LIBS += -ldl
  313. endif
  314. endif
  315. # ---------------------------------------------------------------------------------------------------------------------
  316. # Set optional libraries specific stuff
  317. ifeq ($(HAVE_ALSA),true)
  318. ALSA_FLAGS = $(shell $(PKG_CONFIG) --cflags alsa)
  319. ALSA_LIBS = $(shell $(PKG_CONFIG) --libs alsa)
  320. endif
  321. ifeq ($(HAVE_LIBLO),true)
  322. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  323. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  324. endif
  325. ifeq ($(HAVE_PULSEAUDIO),true)
  326. PULSEAUDIO_FLAGS = $(shell $(PKG_CONFIG) --cflags libpulse-simple)
  327. PULSEAUDIO_LIBS = $(shell $(PKG_CONFIG) --libs libpulse-simple)
  328. endif
  329. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  330. SHARED_MEMORY_LIBS = -lrt
  331. endif
  332. # ---------------------------------------------------------------------------------------------------------------------
  333. # Backwards-compatible HAVE_DGL
  334. ifeq ($(MACOS_OR_WINDOWS),true)
  335. HAVE_DGL = true
  336. else ifeq ($(HAVE_OPENGL),true)
  337. ifeq ($(HAIKU),true)
  338. HAVE_DGL = true
  339. else
  340. HAVE_DGL = $(HAVE_X11)
  341. endif
  342. endif
  343. # ---------------------------------------------------------------------------------------------------------------------
  344. # Optional flags
  345. ifeq ($(NVG_DISABLE_SKIPPING_WHITESPACE),true)
  346. BUILD_CXX_FLAGS += -DNVG_DISABLE_SKIPPING_WHITESPACE
  347. endif
  348. ifneq ($(NVG_FONT_TEXTURE_FLAGS),)
  349. BUILD_CXX_FLAGS += -DNVG_FONT_TEXTURE_FLAGS=$(NVG_FONT_TEXTURE_FLAGS)
  350. endif
  351. ifeq ($(FILE_BROWSER_DISABLED),true)
  352. BUILD_CXX_FLAGS += -DDGL_FILE_BROWSER_DISABLED
  353. endif
  354. ifeq ($(USE_OPENGL3),true)
  355. BUILD_CXX_FLAGS += -DDGL_USE_OPENGL3
  356. endif
  357. ifeq ($(USE_NANOVG_FBO),true)
  358. BUILD_CXX_FLAGS += -DDGL_USE_NANOVG_FBO
  359. endif
  360. ifeq ($(USE_NANOVG_FREETYPE),true)
  361. BUILD_CXX_FLAGS += -DFONS_USE_FREETYPE $(shell $(PKG_CONFIG) --cflags freetype2)
  362. endif
  363. ifeq ($(USE_RGBA),true)
  364. BUILD_CXX_FLAGS += -DDGL_USE_RGBA
  365. endif
  366. # ---------------------------------------------------------------------------------------------------------------------
  367. # Set app extension
  368. ifeq ($(WINDOWS),true)
  369. APP_EXT = .exe
  370. endif
  371. # ---------------------------------------------------------------------------------------------------------------------
  372. # Set shared lib extension
  373. LIB_EXT = .so
  374. ifeq ($(MACOS),true)
  375. LIB_EXT = .dylib
  376. endif
  377. ifeq ($(WINDOWS),true)
  378. LIB_EXT = .dll
  379. endif
  380. # ---------------------------------------------------------------------------------------------------------------------
  381. # Set shared library CLI arg
  382. ifeq ($(MACOS),true)
  383. SHARED = -dynamiclib
  384. else
  385. SHARED = -shared
  386. endif
  387. # ---------------------------------------------------------------------------------------------------------------------
  388. # Handle the verbosity switch
  389. ifeq ($(VERBOSE),true)
  390. SILENT =
  391. else
  392. SILENT = @
  393. endif
  394. # ---------------------------------------------------------------------------------------------------------------------
  395. # all needs to be first
  396. all:
  397. # ---------------------------------------------------------------------------------------------------------------------
  398. # helper to print what is available/possible to build
  399. print_available = @echo $(1): $(shell echo $($(1)) | grep -q true && echo Yes || echo No)
  400. features:
  401. @echo === Detected CPU
  402. $(call print_available,CPU_AARCH64)
  403. $(call print_available,CPU_ARM)
  404. $(call print_available,CPU_ARM64)
  405. $(call print_available,CPU_ARM_OR_AARCH64)
  406. $(call print_available,CPU_I386)
  407. $(call print_available,CPU_I386_OR_X86_64)
  408. @echo === Detected OS
  409. $(call print_available,BSD)
  410. $(call print_available,HAIKU)
  411. $(call print_available,HURD)
  412. $(call print_available,LINUX)
  413. $(call print_available,MACOS)
  414. $(call print_available,WINDOWS)
  415. $(call print_available,HAIKU_OR_MACOS_OR_WINDOWS)
  416. $(call print_available,LINUX_OR_MACOS)
  417. $(call print_available,MACOS_OR_WINDOWS)
  418. $(call print_available,UNIX)
  419. @echo === Detected features
  420. $(call print_available,HAVE_ALSA)
  421. $(call print_available,HAVE_DBUS)
  422. $(call print_available,HAVE_CAIRO)
  423. $(call print_available,HAVE_DGL)
  424. $(call print_available,HAVE_LIBLO)
  425. $(call print_available,HAVE_OPENGL)
  426. $(call print_available,HAVE_PULSEAUDIO)
  427. $(call print_available,HAVE_RTAUDIO)
  428. $(call print_available,HAVE_STUB)
  429. $(call print_available,HAVE_VULKAN)
  430. $(call print_available,HAVE_X11)
  431. $(call print_available,HAVE_XCURSOR)
  432. $(call print_available,HAVE_XEXT)
  433. $(call print_available,HAVE_XRANDR)
  434. # ---------------------------------------------------------------------------------------------------------------------
  435. # Protect against multiple inclusion
  436. endif # DPF_MAKEFILE_BASE_INCLUDED
  437. # ---------------------------------------------------------------------------------------------------------------------