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.

502 lines
13KB

  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. endif
  25. ifneq (,$(findstring haiku,$(TARGET_MACHINE)))
  26. HAIKU=true
  27. endif
  28. ifneq (,$(findstring linux,$(TARGET_MACHINE)))
  29. LINUX=true
  30. else ifneq (,$(findstring gnu,$(TARGET_MACHINE)))
  31. HURD=true
  32. endif
  33. ifneq (,$(findstring apple,$(TARGET_MACHINE)))
  34. MACOS=true
  35. endif
  36. ifneq (,$(findstring mingw,$(TARGET_MACHINE)))
  37. WINDOWS=true
  38. endif
  39. ifneq (,$(findstring windows,$(TARGET_MACHINE)))
  40. WINDOWS=true
  41. endif
  42. endif
  43. endif
  44. endif
  45. endif
  46. endif
  47. endif
  48. # ---------------------------------------------------------------------------------------------------------------------
  49. # Auto-detect the processor
  50. TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE)))
  51. ifneq (,$(filter i%86,$(TARGET_PROCESSOR)))
  52. CPU_I386=true
  53. CPU_I386_OR_X86_64=true
  54. endif
  55. ifneq (,$(filter x86_64,$(TARGET_PROCESSOR)))
  56. CPU_X86_64=true
  57. CPU_I386_OR_X86_64=true
  58. endif
  59. ifneq (,$(filter arm%,$(TARGET_PROCESSOR)))
  60. CPU_ARM=true
  61. CPU_ARM_OR_AARCH64=true
  62. endif
  63. ifneq (,$(filter arm64%,$(TARGET_PROCESSOR)))
  64. CPU_ARM64=true
  65. CPU_ARM_OR_AARCH64=true
  66. endif
  67. ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR)))
  68. CPU_AARCH64=true
  69. CPU_ARM_OR_AARCH64=true
  70. endif
  71. # ---------------------------------------------------------------------------------------------------------------------
  72. # Set PKG_CONFIG (can be overridden by environment variable)
  73. ifeq ($(WINDOWS),true)
  74. # Build statically on Windows by default
  75. PKG_CONFIG ?= pkg-config --static
  76. else
  77. PKG_CONFIG ?= pkg-config
  78. endif
  79. # ---------------------------------------------------------------------------------------------------------------------
  80. # Set LINUX_OR_MACOS
  81. ifeq ($(LINUX),true)
  82. LINUX_OR_MACOS=true
  83. endif
  84. ifeq ($(MACOS),true)
  85. LINUX_OR_MACOS=true
  86. endif
  87. # ---------------------------------------------------------------------------------------------------------------------
  88. # Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS
  89. ifeq ($(HAIKU),true)
  90. HAIKU_OR_MACOS_OR_WINDOWS=true
  91. endif
  92. ifeq ($(MACOS),true)
  93. MACOS_OR_WINDOWS=true
  94. HAIKU_OR_MACOS_OR_WINDOWS=true
  95. endif
  96. ifeq ($(WINDOWS),true)
  97. MACOS_OR_WINDOWS=true
  98. HAIKU_OR_MACOS_OR_WINDOWS=true
  99. endif
  100. # ---------------------------------------------------------------------------------------------------------------------
  101. # Set UNIX
  102. ifeq ($(BSD),true)
  103. UNIX=true
  104. endif
  105. ifeq ($(HURD),true)
  106. UNIX=true
  107. endif
  108. ifeq ($(LINUX),true)
  109. UNIX=true
  110. endif
  111. ifeq ($(MACOS),true)
  112. UNIX=true
  113. endif
  114. # ---------------------------------------------------------------------------------------------------------------------
  115. # Set build and link flags
  116. BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
  117. BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
  118. ifeq ($(CPU_I386_OR_X86_64),true)
  119. BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse
  120. endif
  121. ifeq ($(CPU_ARM),true)
  122. ifneq ($(CPU_ARM64),true)
  123. BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard
  124. endif
  125. endif
  126. ifeq ($(MACOS),true)
  127. # MacOS linker flags
  128. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
  129. ifneq ($(SKIP_STRIPPING),true)
  130. LINK_OPTS += -Wl,-x
  131. endif
  132. else
  133. # Common linker flags
  134. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
  135. ifneq ($(SKIP_STRIPPING),true)
  136. LINK_OPTS += -Wl,--strip-all
  137. endif
  138. endif
  139. ifeq ($(NOOPT),true)
  140. # Non-CPU-specific optimization flags
  141. BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections
  142. endif
  143. ifeq ($(WINDOWS),true)
  144. # Needed for windows, see https://github.com/falkTX/Carla/issues/855
  145. BASE_OPTS += -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. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  158. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++11 $(CXXFLAGS)
  159. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  160. ifneq ($(MACOS),true)
  161. # Not available on MacOS
  162. LINK_FLAGS += -Wl,--no-undefined
  163. endif
  164. ifeq ($(MACOS_OLD),true)
  165. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  166. endif
  167. ifeq ($(WINDOWS),true)
  168. # Always build statically on windows
  169. LINK_FLAGS += -static -static-libgcc -static-libstdc++
  170. endif
  171. # ---------------------------------------------------------------------------------------------------------------------
  172. # Strict test build
  173. ifeq ($(TESTBUILD),true)
  174. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  175. BASE_FLAGS += -Wpointer-arith -Wabi=98 -Winit-self -Wuninitialized -Wstrict-overflow=5
  176. # BASE_FLAGS += -Wfloat-equal
  177. ifeq ($(CC),clang)
  178. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  179. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  180. else
  181. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  182. endif
  183. ifneq ($(MACOS),true)
  184. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  185. ifneq ($(CC),clang)
  186. BASE_FLAGS += -Wlogical-op
  187. endif
  188. endif
  189. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  190. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  191. endif
  192. # ---------------------------------------------------------------------------------------------------------------------
  193. # Check for required libraries
  194. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  195. # Vulkan is not supported yet
  196. # HAVE_VULKAN = $(shell $(PKG_CONFIG) --exists vulkan && echo true)
  197. ifeq ($(MACOS_OR_WINDOWS),true)
  198. HAVE_OPENGL = true
  199. else
  200. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  201. ifneq ($(HAIKU),true)
  202. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  203. HAVE_XCURSOR = $(shell $(PKG_CONFIG) --exists xcursor && echo true)
  204. HAVE_XEXT = $(shell $(PKG_CONFIG) --exists xext && echo true)
  205. HAVE_XRANDR = $(shell $(PKG_CONFIG) --exists xrandr && echo true)
  206. endif
  207. endif
  208. # ---------------------------------------------------------------------------------------------------------------------
  209. # Check for optional libraries
  210. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  211. ifeq ($(MACOS),true)
  212. HAVE_RTAUDIO = true
  213. else ifeq ($(WINDOWS),true)
  214. HAVE_RTAUDIO = true
  215. else ifneq ($(HAIKU),true)
  216. HAVE_ALSA = $(shell $(PKG_CONFIG) --exists alsa && echo true)
  217. HAVE_PULSEAUDIO = $(shell $(PKG_CONFIG) --exists libpulse-simple && echo true)
  218. ifeq ($(HAVE_ALSA),true)
  219. HAVE_RTAUDIO = true
  220. else ifeq ($(HAVE_PULSEAUDIO),true)
  221. HAVE_RTAUDIO = true
  222. endif
  223. endif
  224. # backwards compat
  225. HAVE_JACK = true
  226. # ---------------------------------------------------------------------------------------------------------------------
  227. # Set Generic DGL stuff
  228. ifeq ($(HAIKU),true)
  229. DGL_SYSTEM_LIBS += -lbe
  230. endif
  231. ifeq ($(MACOS),true)
  232. DGL_SYSTEM_LIBS += -framework Cocoa -framework CoreVideo
  233. endif
  234. ifeq ($(WINDOWS),true)
  235. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  236. endif
  237. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  238. ifeq ($(HAVE_X11),true)
  239. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11
  240. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  241. ifeq ($(HAVE_XCURSOR),true)
  242. # TODO -DHAVE_XCURSOR
  243. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor)
  244. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor)
  245. endif
  246. ifeq ($(HAVE_XEXT),true)
  247. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xext) -DHAVE_XEXT -DHAVE_XSYNC
  248. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xext)
  249. endif
  250. ifeq ($(HAVE_XRANDR),true)
  251. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR
  252. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr)
  253. endif
  254. endif
  255. endif
  256. # ---------------------------------------------------------------------------------------------------------------------
  257. # Set Cairo specific stuff
  258. ifeq ($(HAVE_CAIRO),true)
  259. DGL_FLAGS += -DHAVE_CAIRO
  260. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  261. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  262. HAVE_CAIRO_OR_OPENGL = true
  263. endif
  264. # ---------------------------------------------------------------------------------------------------------------------
  265. # Set OpenGL specific stuff
  266. ifeq ($(HAVE_OPENGL),true)
  267. DGL_FLAGS += -DHAVE_OPENGL
  268. ifeq ($(HAIKU),true)
  269. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  270. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  271. endif
  272. ifeq ($(MACOS),true)
  273. OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1 -Wno-deprecated-declarations
  274. OPENGL_LIBS = -framework OpenGL
  275. endif
  276. ifeq ($(WINDOWS),true)
  277. OPENGL_LIBS = -lopengl32
  278. endif
  279. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  280. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  281. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  282. endif
  283. HAVE_CAIRO_OR_OPENGL = true
  284. endif
  285. # ---------------------------------------------------------------------------------------------------------------------
  286. # Set Stub specific stuff
  287. ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  288. HAVE_STUB = true
  289. else
  290. HAVE_STUB = $(HAVE_X11)
  291. endif
  292. # ---------------------------------------------------------------------------------------------------------------------
  293. # Set Vulkan specific stuff
  294. ifeq ($(HAVE_VULKAN),true)
  295. DGL_FLAGS += -DHAVE_VULKAN
  296. VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan)
  297. VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan)
  298. ifneq ($(WINDOWS),true)
  299. VULKAN_LIBS += -ldl
  300. endif
  301. endif
  302. # ---------------------------------------------------------------------------------------------------------------------
  303. # Set optional libraries specific stuff
  304. ifeq ($(HAVE_ALSA),true)
  305. ALSA_FLAGS = $(shell $(PKG_CONFIG) --cflags alsa)
  306. ALSA_LIBS = $(shell $(PKG_CONFIG) --libs alsa)
  307. endif
  308. ifeq ($(HAVE_LIBLO),true)
  309. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  310. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  311. endif
  312. ifeq ($(HAVE_PULSEAUDIO),true)
  313. PULSEAUDIO_FLAGS = $(shell $(PKG_CONFIG) --cflags libpulse-simple)
  314. PULSEAUDIO_LIBS = $(shell $(PKG_CONFIG) --libs libpulse-simple)
  315. endif
  316. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  317. SHARED_MEMORY_LIBS = -lrt
  318. endif
  319. # ---------------------------------------------------------------------------------------------------------------------
  320. # Backwards-compatible HAVE_DGL
  321. ifeq ($(MACOS_OR_WINDOWS),true)
  322. HAVE_DGL = true
  323. else ifeq ($(HAVE_OPENGL),true)
  324. ifeq ($(HAIKU),true)
  325. HAVE_DGL = true
  326. else
  327. HAVE_DGL = $(HAVE_X11)
  328. endif
  329. endif
  330. # ---------------------------------------------------------------------------------------------------------------------
  331. # Set app extension
  332. ifeq ($(WINDOWS),true)
  333. APP_EXT = .exe
  334. endif
  335. # ---------------------------------------------------------------------------------------------------------------------
  336. # Set shared lib extension
  337. LIB_EXT = .so
  338. ifeq ($(MACOS),true)
  339. LIB_EXT = .dylib
  340. endif
  341. ifeq ($(WINDOWS),true)
  342. LIB_EXT = .dll
  343. endif
  344. # ---------------------------------------------------------------------------------------------------------------------
  345. # Set shared library CLI arg
  346. ifeq ($(MACOS),true)
  347. SHARED = -dynamiclib
  348. else
  349. SHARED = -shared
  350. endif
  351. # ---------------------------------------------------------------------------------------------------------------------
  352. # Handle the verbosity switch
  353. ifeq ($(VERBOSE),true)
  354. SILENT =
  355. else
  356. SILENT = @
  357. endif
  358. # ---------------------------------------------------------------------------------------------------------------------
  359. # all needs to be first
  360. all:
  361. # ---------------------------------------------------------------------------------------------------------------------
  362. # helper to print what is available/possible to build
  363. print_available = @echo $(1): $(shell echo $($(1)) | grep -q true && echo Yes || echo No)
  364. features:
  365. @echo === Detected CPU
  366. $(call print_available,CPU_AARCH64)
  367. $(call print_available,CPU_ARM)
  368. $(call print_available,CPU_ARM64)
  369. $(call print_available,CPU_ARM_OR_AARCH64)
  370. $(call print_available,CPU_I386)
  371. $(call print_available,CPU_I386_OR_X86_64)
  372. @echo === Detected OS
  373. $(call print_available,BSD)
  374. $(call print_available,HAIKU)
  375. $(call print_available,HURD)
  376. $(call print_available,LINUX)
  377. $(call print_available,MACOS)
  378. $(call print_available,WINDOWS)
  379. $(call print_available,HAIKU_OR_MACOS_OR_WINDOWS)
  380. $(call print_available,LINUX_OR_MACOS)
  381. $(call print_available,MACOS_OR_WINDOWS)
  382. $(call print_available,UNIX)
  383. @echo === Detected features
  384. $(call print_available,HAVE_ALSA)
  385. $(call print_available,HAVE_CAIRO)
  386. $(call print_available,HAVE_DGL)
  387. $(call print_available,HAVE_LIBLO)
  388. $(call print_available,HAVE_OPENGL)
  389. $(call print_available,HAVE_PULSEAUDIO)
  390. $(call print_available,HAVE_RTAUDIO)
  391. $(call print_available,HAVE_STUB)
  392. $(call print_available,HAVE_VULKAN)
  393. $(call print_available,HAVE_X11)
  394. $(call print_available,HAVE_XCURSOR)
  395. $(call print_available,HAVE_XEXT)
  396. $(call print_available,HAVE_XRANDR)
  397. # ---------------------------------------------------------------------------------------------------------------------
  398. # Protect against multiple inclusion
  399. endif # DPF_MAKEFILE_BASE_INCLUDED
  400. # ---------------------------------------------------------------------------------------------------------------------