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.

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