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.

410 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. endif
  37. endif
  38. endif
  39. endif
  40. endif
  41. endif
  42. # ---------------------------------------------------------------------------------------------------------------------
  43. # Auto-detect the processor
  44. TARGET_PROCESSOR := $(firstword $(subst -, ,$(TARGET_MACHINE)))
  45. ifneq (,$(filter i%86,$(TARGET_PROCESSOR)))
  46. CPU_I386=true
  47. CPU_I386_OR_X86_64=true
  48. endif
  49. ifneq (,$(filter x86_64,$(TARGET_PROCESSOR)))
  50. CPU_X86_64=true
  51. CPU_I386_OR_X86_64=true
  52. endif
  53. ifneq (,$(filter arm%,$(TARGET_PROCESSOR)))
  54. CPU_ARM=true
  55. CPU_ARM_OR_AARCH64=true
  56. endif
  57. ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR)))
  58. CPU_AARCH64=true
  59. CPU_ARM_OR_AARCH64=true
  60. endif
  61. # ---------------------------------------------------------------------------------------------------------------------
  62. # Set PKG_CONFIG (can be overridden by environment variable)
  63. ifeq ($(WINDOWS),true)
  64. # Build statically on Windows by default
  65. PKG_CONFIG ?= pkg-config --static
  66. else
  67. PKG_CONFIG ?= pkg-config
  68. endif
  69. # ---------------------------------------------------------------------------------------------------------------------
  70. # Set LINUX_OR_MACOS
  71. ifeq ($(LINUX),true)
  72. LINUX_OR_MACOS=true
  73. endif
  74. ifeq ($(MACOS),true)
  75. LINUX_OR_MACOS=true
  76. endif
  77. # ---------------------------------------------------------------------------------------------------------------------
  78. # Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS
  79. ifeq ($(HAIKU),true)
  80. HAIKU_OR_MACOS_OR_WINDOWS=true
  81. endif
  82. ifeq ($(MACOS),true)
  83. MACOS_OR_WINDOWS=true
  84. HAIKU_OR_MACOS_OR_WINDOWS=true
  85. endif
  86. ifeq ($(WINDOWS),true)
  87. MACOS_OR_WINDOWS=true
  88. HAIKU_OR_MACOS_OR_WINDOWS=true
  89. endif
  90. # ---------------------------------------------------------------------------------------------------------------------
  91. # Set UNIX
  92. ifeq ($(BSD),true)
  93. UNIX=true
  94. endif
  95. ifeq ($(HURD),true)
  96. UNIX=true
  97. endif
  98. ifeq ($(LINUX),true)
  99. UNIX=true
  100. endif
  101. ifeq ($(MACOS),true)
  102. UNIX=true
  103. endif
  104. # ---------------------------------------------------------------------------------------------------------------------
  105. # Set build and link flags
  106. BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
  107. BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
  108. ifeq ($(CPU_I386_OR_X86_64),true)
  109. BASE_OPTS += -mtune=generic -msse -msse2
  110. endif
  111. ifeq ($(CPU_ARM),true)
  112. BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard
  113. endif
  114. ifeq ($(MACOS),true)
  115. # MacOS linker flags
  116. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
  117. else
  118. # Common linker flags
  119. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
  120. ifneq ($(SKIP_STRIPPING),true)
  121. LINK_OPTS += -Wl,--strip-all
  122. endif
  123. endif
  124. ifeq ($(NOOPT),true)
  125. # Non-CPU-specific optimization flags
  126. BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections
  127. endif
  128. ifeq ($(WINDOWS),true)
  129. # mingw has issues with this specific optimization
  130. # See https://github.com/falkTX/Carla/issues/696
  131. BASE_OPTS += -fno-rerun-cse-after-loop
  132. # See https://github.com/falkTX/Carla/issues/855
  133. BASE_OPTS += -mstackrealign
  134. else
  135. # Not needed for Windows
  136. BASE_FLAGS += -fPIC -DPIC
  137. endif
  138. ifeq ($(DEBUG),true)
  139. BASE_FLAGS += -DDEBUG -O0 -g
  140. LINK_OPTS =
  141. else
  142. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  143. CXXFLAGS += -fvisibility-inlines-hidden
  144. endif
  145. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  146. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
  147. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  148. ifneq ($(MACOS),true)
  149. # Not available on MacOS
  150. LINK_FLAGS += -Wl,--no-undefined
  151. endif
  152. ifeq ($(MACOS_OLD),true)
  153. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  154. endif
  155. ifeq ($(WINDOWS),true)
  156. # Always build statically on windows
  157. LINK_FLAGS += -static
  158. endif
  159. # ---------------------------------------------------------------------------------------------------------------------
  160. # Strict test build
  161. ifeq ($(TESTBUILD),true)
  162. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  163. BASE_FLAGS += -Wpointer-arith -Wabi=98 -Winit-self -Wuninitialized -Wstrict-overflow=5
  164. # BASE_FLAGS += -Wfloat-equal
  165. ifeq ($(CC),clang)
  166. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  167. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  168. else
  169. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  170. endif
  171. ifneq ($(MACOS),true)
  172. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  173. ifneq ($(CC),clang)
  174. BASE_FLAGS += -Wlogical-op
  175. endif
  176. endif
  177. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  178. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  179. endif
  180. # ---------------------------------------------------------------------------------------------------------------------
  181. # Check for required libraries
  182. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  183. HAVE_VULKAN = $(shell $(PKG_CONFIG) --exists vulkan && echo true)
  184. ifeq ($(MACOS_OR_WINDOWS),true)
  185. HAVE_OPENGL = true
  186. else
  187. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  188. ifneq ($(HAIKU),true)
  189. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  190. HAVE_XCURSOR = $(shell $(PKG_CONFIG) --exists xcursor && echo true)
  191. HAVE_XEXT = $(shell $(PKG_CONFIG) --exists xext && echo true)
  192. HAVE_XRANDR = $(shell $(PKG_CONFIG) --exists xrandr && echo true)
  193. endif
  194. endif
  195. # ---------------------------------------------------------------------------------------------------------------------
  196. # Check for optional libraries
  197. HAVE_JACK = $(shell $(PKG_CONFIG) --exists jack && echo true)
  198. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  199. # ---------------------------------------------------------------------------------------------------------------------
  200. # Set Generic DGL stuff
  201. ifeq ($(HAIKU),true)
  202. DGL_SYSTEM_LIBS += -lbe
  203. endif
  204. ifeq ($(MACOS),true)
  205. DGL_SYSTEM_LIBS += -framework Cocoa
  206. endif
  207. ifeq ($(WINDOWS),true)
  208. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  209. endif
  210. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  211. ifeq ($(HAVE_X11),true)
  212. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11)
  213. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  214. ifeq ($(HAVE_XCURSOR),true)
  215. # TODO -DHAVE_XCURSOR
  216. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xcursor)
  217. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xcursor)
  218. endif
  219. ifeq ($(HAVE_XEXT),true)
  220. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xext) -DHAVE_XEXT -DHAVE_XSYNC
  221. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xext)
  222. endif
  223. ifeq ($(HAVE_XRANDR),true)
  224. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR
  225. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr)
  226. endif
  227. endif
  228. endif
  229. # ---------------------------------------------------------------------------------------------------------------------
  230. # Set Cairo specific stuff
  231. ifeq ($(HAVE_CAIRO),true)
  232. DGL_FLAGS += -DHAVE_CAIRO
  233. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  234. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  235. HAVE_CAIRO_OR_OPENGL = true
  236. endif
  237. # ---------------------------------------------------------------------------------------------------------------------
  238. # Set OpenGL specific stuff
  239. ifeq ($(HAVE_OPENGL),true)
  240. DGL_FLAGS += -DHAVE_OPENGL
  241. ifeq ($(HAIKU),true)
  242. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  243. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  244. endif
  245. ifeq ($(MACOS),true)
  246. OPENGL_LIBS = -framework OpenGL
  247. endif
  248. ifeq ($(WINDOWS),true)
  249. OPENGL_LIBS = -lopengl32
  250. endif
  251. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  252. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  253. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  254. endif
  255. HAVE_CAIRO_OR_OPENGL = true
  256. endif
  257. # ---------------------------------------------------------------------------------------------------------------------
  258. # Set Stub specific stuff
  259. ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  260. HAVE_STUB = true
  261. else
  262. HAVE_STUB = $(HAVE_X11)
  263. endif
  264. # ---------------------------------------------------------------------------------------------------------------------
  265. # Set Vulkan specific stuff
  266. ifeq ($(HAVE_VULKAN),true)
  267. DGL_FLAGS += -DHAVE_VULKAN
  268. VULKAN_FLAGS = $(shell $(PKG_CONFIG) --cflags vulkan)
  269. VULKAN_LIBS = $(shell $(PKG_CONFIG) --libs vulkan)
  270. ifneq ($(WINDOWS),true)
  271. VULKAN_LIBS += -ldl
  272. endif
  273. endif
  274. # ---------------------------------------------------------------------------------------------------------------------
  275. # Set optional libraries specific stuff
  276. ifeq ($(HAVE_JACK),true)
  277. JACK_FLAGS = $(shell $(PKG_CONFIG) --cflags jack)
  278. JACK_LIBS = $(shell $(PKG_CONFIG) --libs jack)
  279. endif
  280. ifeq ($(HAVE_LIBLO),true)
  281. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  282. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  283. endif
  284. # ---------------------------------------------------------------------------------------------------------------------
  285. # Backwards-compatible HAVE_DGL
  286. ifeq ($(MACOS_OR_WINDOWS),true)
  287. HAVE_DGL = true
  288. else ifeq ($(HAVE_OPENGL),true)
  289. ifeq ($(HAIKU),true)
  290. HAVE_DGL = true
  291. else
  292. HAVE_DGL = $(HAVE_X11)
  293. endif
  294. endif
  295. # ---------------------------------------------------------------------------------------------------------------------
  296. # Set app extension
  297. ifeq ($(WINDOWS),true)
  298. APP_EXT = .exe
  299. endif
  300. # ---------------------------------------------------------------------------------------------------------------------
  301. # Set shared lib extension
  302. LIB_EXT = .so
  303. ifeq ($(MACOS),true)
  304. LIB_EXT = .dylib
  305. endif
  306. ifeq ($(WINDOWS),true)
  307. LIB_EXT = .dll
  308. endif
  309. # ---------------------------------------------------------------------------------------------------------------------
  310. # Set shared library CLI arg
  311. ifeq ($(MACOS),true)
  312. SHARED = -dynamiclib
  313. else
  314. SHARED = -shared
  315. endif
  316. # ---------------------------------------------------------------------------------------------------------------------
  317. # Handle the verbosity switch
  318. ifeq ($(VERBOSE),true)
  319. SILENT =
  320. else
  321. SILENT = @
  322. endif
  323. # ---------------------------------------------------------------------------------------------------------------------