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.

504 lines
14KB

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