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.

420 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_JACK = $(shell $(PKG_CONFIG) --exists jack && echo true)
  207. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  208. # ---------------------------------------------------------------------------------------------------------------------
  209. # Set Generic DGL stuff
  210. ifeq ($(HAIKU),true)
  211. DGL_SYSTEM_LIBS += -lbe
  212. endif
  213. ifeq ($(MACOS),true)
  214. DGL_SYSTEM_LIBS += -framework Cocoa -framework CoreVideo
  215. endif
  216. ifeq ($(WINDOWS),true)
  217. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  218. endif
  219. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  220. ifeq ($(HAVE_X11),true)
  221. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11) -DHAVE_X11
  222. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  223. ifeq ($(HAVE_XCURSOR),true)
  224. # TODO -DHAVE_XCURSOR
  225. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor)
  226. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor)
  227. endif
  228. ifeq ($(HAVE_XEXT),true)
  229. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xext) -DHAVE_XEXT -DHAVE_XSYNC
  230. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xext)
  231. endif
  232. ifeq ($(HAVE_XRANDR),true)
  233. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR
  234. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr)
  235. endif
  236. endif
  237. endif
  238. # ---------------------------------------------------------------------------------------------------------------------
  239. # Set Cairo specific stuff
  240. ifeq ($(HAVE_CAIRO),true)
  241. DGL_FLAGS += -DHAVE_CAIRO
  242. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  243. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  244. HAVE_CAIRO_OR_OPENGL = true
  245. endif
  246. # ---------------------------------------------------------------------------------------------------------------------
  247. # Set OpenGL specific stuff
  248. ifeq ($(HAVE_OPENGL),true)
  249. DGL_FLAGS += -DHAVE_OPENGL
  250. ifeq ($(HAIKU),true)
  251. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  252. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  253. endif
  254. ifeq ($(MACOS),true)
  255. OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1 -Wno-deprecated-declarations
  256. OPENGL_LIBS = -framework OpenGL
  257. endif
  258. ifeq ($(WINDOWS),true)
  259. OPENGL_LIBS = -lopengl32
  260. endif
  261. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  262. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  263. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  264. endif
  265. HAVE_CAIRO_OR_OPENGL = true
  266. endif
  267. # ---------------------------------------------------------------------------------------------------------------------
  268. # Set Stub specific stuff
  269. ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  270. HAVE_STUB = true
  271. else
  272. HAVE_STUB = $(HAVE_X11)
  273. endif
  274. # ---------------------------------------------------------------------------------------------------------------------
  275. # Set Vulkan specific stuff
  276. ifeq ($(HAVE_VULKAN),true)
  277. DGL_FLAGS += -DHAVE_VULKAN
  278. VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan)
  279. VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan)
  280. ifneq ($(WINDOWS),true)
  281. VULKAN_LIBS += -ldl
  282. endif
  283. endif
  284. # ---------------------------------------------------------------------------------------------------------------------
  285. # Set optional libraries specific stuff
  286. ifeq ($(HAVE_JACK),true)
  287. JACK_FLAGS = $(shell $(PKG_CONFIG) --cflags jack)
  288. JACK_LIBS = $(shell $(PKG_CONFIG) --libs jack)
  289. endif
  290. ifeq ($(HAVE_LIBLO),true)
  291. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  292. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  293. endif
  294. # ---------------------------------------------------------------------------------------------------------------------
  295. # Backwards-compatible HAVE_DGL
  296. ifeq ($(MACOS_OR_WINDOWS),true)
  297. HAVE_DGL = true
  298. else ifeq ($(HAVE_OPENGL),true)
  299. ifeq ($(HAIKU),true)
  300. HAVE_DGL = true
  301. else
  302. HAVE_DGL = $(HAVE_X11)
  303. endif
  304. endif
  305. # ---------------------------------------------------------------------------------------------------------------------
  306. # Set app extension
  307. ifeq ($(WINDOWS),true)
  308. APP_EXT = .exe
  309. endif
  310. # ---------------------------------------------------------------------------------------------------------------------
  311. # Set shared lib extension
  312. LIB_EXT = .so
  313. ifeq ($(MACOS),true)
  314. LIB_EXT = .dylib
  315. endif
  316. ifeq ($(WINDOWS),true)
  317. LIB_EXT = .dll
  318. endif
  319. # ---------------------------------------------------------------------------------------------------------------------
  320. # Set shared library CLI arg
  321. ifeq ($(MACOS),true)
  322. SHARED = -dynamiclib
  323. else
  324. SHARED = -shared
  325. endif
  326. # ---------------------------------------------------------------------------------------------------------------------
  327. # Handle the verbosity switch
  328. ifeq ($(VERBOSE),true)
  329. SILENT =
  330. else
  331. SILENT = @
  332. endif
  333. # ---------------------------------------------------------------------------------------------------------------------