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.

441 lines
11KB

  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 gnu,$(TARGET_MACHINE)))
  25. HURD=true
  26. endif
  27. ifneq (,$(findstring linux,$(TARGET_MACHINE)))
  28. LINUX=true
  29. endif
  30. ifneq (,$(findstring apple,$(TARGET_MACHINE)))
  31. MACOS=true
  32. endif
  33. ifneq (,$(findstring mingw,$(TARGET_MACHINE)))
  34. WINDOWS=true
  35. endif
  36. ifneq (,$(findstring windows,$(TARGET_MACHINE)))
  37. WINDOWS=true
  38. endif
  39. endif
  40. endif
  41. endif
  42. endif
  43. endif
  44. endif
  45. # ---------------------------------------------------------------------------------------------------------------------
  46. # Auto-detect the processor
  47. TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE)))
  48. ifneq (,$(filter i%86,$(TARGET_PROCESSOR)))
  49. CPU_I386=true
  50. CPU_I386_OR_X86_64=true
  51. endif
  52. ifneq (,$(filter x86_64,$(TARGET_PROCESSOR)))
  53. CPU_X86_64=true
  54. CPU_I386_OR_X86_64=true
  55. endif
  56. ifneq (,$(filter arm%,$(TARGET_PROCESSOR)))
  57. CPU_ARM=true
  58. CPU_ARM_OR_AARCH64=true
  59. endif
  60. ifneq (,$(filter arm64%,$(TARGET_PROCESSOR)))
  61. CPU_ARM64=true
  62. CPU_ARM_OR_AARCH64=true
  63. endif
  64. ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR)))
  65. CPU_AARCH64=true
  66. CPU_ARM_OR_AARCH64=true
  67. endif
  68. # ---------------------------------------------------------------------------------------------------------------------
  69. # Set PKG_CONFIG (can be overridden by environment variable)
  70. ifeq ($(WINDOWS),true)
  71. # Build statically on Windows by default
  72. PKG_CONFIG ?= pkg-config --static
  73. else
  74. PKG_CONFIG ?= pkg-config
  75. endif
  76. # ---------------------------------------------------------------------------------------------------------------------
  77. # Set LINUX_OR_MACOS
  78. ifeq ($(LINUX),true)
  79. LINUX_OR_MACOS=true
  80. endif
  81. ifeq ($(MACOS),true)
  82. LINUX_OR_MACOS=true
  83. endif
  84. # ---------------------------------------------------------------------------------------------------------------------
  85. # Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS
  86. ifeq ($(HAIKU),true)
  87. HAIKU_OR_MACOS_OR_WINDOWS=true
  88. endif
  89. ifeq ($(MACOS),true)
  90. MACOS_OR_WINDOWS=true
  91. HAIKU_OR_MACOS_OR_WINDOWS=true
  92. endif
  93. ifeq ($(WINDOWS),true)
  94. MACOS_OR_WINDOWS=true
  95. HAIKU_OR_MACOS_OR_WINDOWS=true
  96. endif
  97. # ---------------------------------------------------------------------------------------------------------------------
  98. # Set UNIX
  99. ifeq ($(BSD),true)
  100. UNIX=true
  101. endif
  102. ifeq ($(HURD),true)
  103. UNIX=true
  104. endif
  105. ifeq ($(LINUX),true)
  106. UNIX=true
  107. endif
  108. ifeq ($(MACOS),true)
  109. UNIX=true
  110. endif
  111. # ---------------------------------------------------------------------------------------------------------------------
  112. # Set build and link flags
  113. BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
  114. BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
  115. ifeq ($(CPU_I386_OR_X86_64),true)
  116. BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse
  117. endif
  118. ifeq ($(CPU_ARM),true)
  119. ifneq ($(CPU_ARM64),true)
  120. BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard
  121. endif
  122. endif
  123. ifeq ($(MACOS),true)
  124. # MacOS linker flags
  125. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
  126. ifneq ($(SKIP_STRIPPING),true)
  127. LINK_OPTS += -Wl,-x
  128. endif
  129. else
  130. # Common linker flags
  131. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
  132. ifneq ($(SKIP_STRIPPING),true)
  133. LINK_OPTS += -Wl,--strip-all
  134. endif
  135. endif
  136. ifeq ($(NOOPT),true)
  137. # Non-CPU-specific optimization flags
  138. BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections
  139. endif
  140. ifeq ($(WINDOWS),true)
  141. # Needed for windows, see https://github.com/falkTX/Carla/issues/855
  142. BASE_OPTS += -mstackrealign
  143. else
  144. # Not needed for Windows
  145. BASE_FLAGS += -fPIC -DPIC
  146. endif
  147. ifeq ($(DEBUG),true)
  148. BASE_FLAGS += -DDEBUG -O0 -g
  149. LINK_OPTS =
  150. else
  151. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  152. CXXFLAGS += -fvisibility-inlines-hidden
  153. endif
  154. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  155. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
  156. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  157. ifneq ($(MACOS),true)
  158. # Not available on MacOS
  159. LINK_FLAGS += -Wl,--no-undefined
  160. endif
  161. ifeq ($(MACOS_OLD),true)
  162. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  163. endif
  164. ifeq ($(WINDOWS),true)
  165. # Always build statically on windows
  166. LINK_FLAGS += -static
  167. endif
  168. # ---------------------------------------------------------------------------------------------------------------------
  169. # Strict test build
  170. ifeq ($(TESTBUILD),true)
  171. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  172. BASE_FLAGS += -Wpointer-arith -Wabi=98 -Winit-self -Wuninitialized -Wstrict-overflow=5
  173. # BASE_FLAGS += -Wfloat-equal
  174. ifeq ($(CC),clang)
  175. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  176. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  177. else
  178. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  179. endif
  180. ifneq ($(MACOS),true)
  181. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  182. ifneq ($(CC),clang)
  183. BASE_FLAGS += -Wlogical-op
  184. endif
  185. endif
  186. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  187. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  188. endif
  189. # ---------------------------------------------------------------------------------------------------------------------
  190. # Check for required libraries
  191. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  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. # ---------------------------------------------------------------------------------------------------------------------
  313. # Backwards-compatible HAVE_DGL
  314. ifeq ($(MACOS_OR_WINDOWS),true)
  315. HAVE_DGL = true
  316. else ifeq ($(HAVE_OPENGL),true)
  317. ifeq ($(HAIKU),true)
  318. HAVE_DGL = true
  319. else
  320. HAVE_DGL = $(HAVE_X11)
  321. endif
  322. endif
  323. # ---------------------------------------------------------------------------------------------------------------------
  324. # Set app extension
  325. ifeq ($(WINDOWS),true)
  326. APP_EXT = .exe
  327. endif
  328. # ---------------------------------------------------------------------------------------------------------------------
  329. # Set shared lib extension
  330. LIB_EXT = .so
  331. ifeq ($(MACOS),true)
  332. LIB_EXT = .dylib
  333. endif
  334. ifeq ($(WINDOWS),true)
  335. LIB_EXT = .dll
  336. endif
  337. # ---------------------------------------------------------------------------------------------------------------------
  338. # Set shared library CLI arg
  339. ifeq ($(MACOS),true)
  340. SHARED = -dynamiclib
  341. else
  342. SHARED = -shared
  343. endif
  344. # ---------------------------------------------------------------------------------------------------------------------
  345. # Handle the verbosity switch
  346. ifeq ($(VERBOSE),true)
  347. SILENT =
  348. else
  349. SILENT = @
  350. endif
  351. # ---------------------------------------------------------------------------------------------------------------------