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.

490 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. # Vulkan is not supported yet
  192. # HAVE_VULKAN = $(shell $(PKG_CONFIG) --exists vulkan && echo true)
  193. ifeq ($(MACOS_OR_WINDOWS),true)
  194. HAVE_OPENGL = true
  195. else
  196. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  197. ifneq ($(HAIKU),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. endif
  233. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  234. ifeq ($(HAVE_X11),true)
  235. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11
  236. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  237. ifeq ($(HAVE_XCURSOR),true)
  238. # TODO -DHAVE_XCURSOR
  239. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor)
  240. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor)
  241. endif
  242. ifeq ($(HAVE_XEXT),true)
  243. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xext) -DHAVE_XEXT -DHAVE_XSYNC
  244. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xext)
  245. endif
  246. ifeq ($(HAVE_XRANDR),true)
  247. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR
  248. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr)
  249. endif
  250. endif
  251. endif
  252. # ---------------------------------------------------------------------------------------------------------------------
  253. # Set Cairo specific stuff
  254. ifeq ($(HAVE_CAIRO),true)
  255. DGL_FLAGS += -DHAVE_CAIRO
  256. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  257. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  258. HAVE_CAIRO_OR_OPENGL = true
  259. endif
  260. # ---------------------------------------------------------------------------------------------------------------------
  261. # Set OpenGL specific stuff
  262. ifeq ($(HAVE_OPENGL),true)
  263. DGL_FLAGS += -DHAVE_OPENGL
  264. ifeq ($(HAIKU),true)
  265. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  266. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  267. endif
  268. ifeq ($(MACOS),true)
  269. OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1 -Wno-deprecated-declarations
  270. OPENGL_LIBS = -framework OpenGL
  271. endif
  272. ifeq ($(WINDOWS),true)
  273. OPENGL_LIBS = -lopengl32
  274. endif
  275. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  276. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  277. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  278. endif
  279. HAVE_CAIRO_OR_OPENGL = true
  280. endif
  281. # ---------------------------------------------------------------------------------------------------------------------
  282. # Set Stub specific stuff
  283. ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  284. HAVE_STUB = true
  285. else
  286. HAVE_STUB = $(HAVE_X11)
  287. endif
  288. # ---------------------------------------------------------------------------------------------------------------------
  289. # Set Vulkan specific stuff
  290. ifeq ($(HAVE_VULKAN),true)
  291. DGL_FLAGS += -DHAVE_VULKAN
  292. VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan)
  293. VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan)
  294. ifneq ($(WINDOWS),true)
  295. VULKAN_LIBS += -ldl
  296. endif
  297. endif
  298. # ---------------------------------------------------------------------------------------------------------------------
  299. # Set optional libraries specific stuff
  300. ifeq ($(HAVE_ALSA),true)
  301. ALSA_FLAGS = $(shell $(PKG_CONFIG) --cflags alsa)
  302. ALSA_LIBS = $(shell $(PKG_CONFIG) --libs alsa)
  303. endif
  304. ifeq ($(HAVE_LIBLO),true)
  305. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  306. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  307. endif
  308. ifeq ($(HAVE_PULSEAUDIO),true)
  309. PULSEAUDIO_FLAGS = $(shell $(PKG_CONFIG) --cflags libpulse-simple)
  310. PULSEAUDIO_LIBS = $(shell $(PKG_CONFIG) --libs libpulse-simple)
  311. endif
  312. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  313. SHARED_MEMORY_LIBS = -lrt
  314. endif
  315. # ---------------------------------------------------------------------------------------------------------------------
  316. # Backwards-compatible HAVE_DGL
  317. ifeq ($(MACOS_OR_WINDOWS),true)
  318. HAVE_DGL = true
  319. else ifeq ($(HAVE_OPENGL),true)
  320. ifeq ($(HAIKU),true)
  321. HAVE_DGL = true
  322. else
  323. HAVE_DGL = $(HAVE_X11)
  324. endif
  325. endif
  326. # ---------------------------------------------------------------------------------------------------------------------
  327. # Set app extension
  328. ifeq ($(WINDOWS),true)
  329. APP_EXT = .exe
  330. endif
  331. # ---------------------------------------------------------------------------------------------------------------------
  332. # Set shared lib extension
  333. LIB_EXT = .so
  334. ifeq ($(MACOS),true)
  335. LIB_EXT = .dylib
  336. endif
  337. ifeq ($(WINDOWS),true)
  338. LIB_EXT = .dll
  339. endif
  340. # ---------------------------------------------------------------------------------------------------------------------
  341. # Set shared library CLI arg
  342. ifeq ($(MACOS),true)
  343. SHARED = -dynamiclib
  344. else
  345. SHARED = -shared
  346. endif
  347. # ---------------------------------------------------------------------------------------------------------------------
  348. # Handle the verbosity switch
  349. ifeq ($(VERBOSE),true)
  350. SILENT =
  351. else
  352. SILENT = @
  353. endif
  354. # ---------------------------------------------------------------------------------------------------------------------
  355. # all needs to be first
  356. all:
  357. # ---------------------------------------------------------------------------------------------------------------------
  358. # helper to print what is available/possible to build
  359. print_available = @echo $(1): $(shell echo $($(1)) | grep -q true && echo Yes || echo No)
  360. features:
  361. @echo === Detected CPU
  362. $(call print_available,CPU_AARCH64)
  363. $(call print_available,CPU_ARM)
  364. $(call print_available,CPU_ARM64)
  365. $(call print_available,CPU_ARM_OR_AARCH64)
  366. $(call print_available,CPU_I386)
  367. $(call print_available,CPU_I386_OR_X86_64)
  368. @echo === Detected OS
  369. $(call print_available,BSD)
  370. $(call print_available,HAIKU)
  371. $(call print_available,HURD)
  372. $(call print_available,LINUX)
  373. $(call print_available,MACOS)
  374. $(call print_available,WINDOWS)
  375. $(call print_available,HAIKU_OR_MACOS_OR_WINDOWS)
  376. $(call print_available,LINUX_OR_MACOS)
  377. $(call print_available,MACOS_OR_WINDOWS)
  378. $(call print_available,UNIX)
  379. @echo === Detected features
  380. $(call print_available,HAVE_ALSA)
  381. $(call print_available,HAVE_CAIRO)
  382. $(call print_available,HAVE_DGL)
  383. $(call print_available,HAVE_LIBLO)
  384. $(call print_available,HAVE_OPENGL)
  385. $(call print_available,HAVE_PULSEAUDIO)
  386. $(call print_available,HAVE_RTAUDIO)
  387. $(call print_available,HAVE_STUB)
  388. $(call print_available,HAVE_VULKAN)
  389. $(call print_available,HAVE_X11)
  390. $(call print_available,HAVE_XCURSOR)
  391. $(call print_available,HAVE_XEXT)
  392. $(call print_available,HAVE_XRANDR)
  393. # ---------------------------------------------------------------------------------------------------------------------