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.

350 lines
8.7KB

  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 arm64%,$(TARGET_PROCESSOR)))
  58. CPU_ARM64=true
  59. CPU_ARM_OR_AARCH64=true
  60. endif
  61. ifneq (,$(filter aarch64%,$(TARGET_PROCESSOR)))
  62. CPU_AARCH64=true
  63. CPU_ARM_OR_AARCH64=true
  64. endif
  65. # ---------------------------------------------------------------------------------------------------------------------
  66. # Set PKG_CONFIG (can be overridden by environment variable)
  67. ifeq ($(WINDOWS),true)
  68. # Build statically on Windows by default
  69. PKG_CONFIG ?= pkg-config --static
  70. else
  71. PKG_CONFIG ?= pkg-config
  72. endif
  73. # ---------------------------------------------------------------------------------------------------------------------
  74. # Set LINUX_OR_MACOS
  75. ifeq ($(LINUX),true)
  76. LINUX_OR_MACOS=true
  77. endif
  78. ifeq ($(MACOS),true)
  79. LINUX_OR_MACOS=true
  80. endif
  81. # ---------------------------------------------------------------------------------------------------------------------
  82. # Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS
  83. ifeq ($(HAIKU),true)
  84. HAIKU_OR_MACOS_OR_WINDOWS=true
  85. endif
  86. ifeq ($(MACOS),true)
  87. MACOS_OR_WINDOWS=true
  88. HAIKU_OR_MACOS_OR_WINDOWS=true
  89. endif
  90. ifeq ($(WINDOWS),true)
  91. MACOS_OR_WINDOWS=true
  92. HAIKU_OR_MACOS_OR_WINDOWS=true
  93. endif
  94. # ---------------------------------------------------------------------------------------------------------------------
  95. # Set UNIX
  96. ifeq ($(BSD),true)
  97. UNIX=true
  98. endif
  99. ifeq ($(HURD),true)
  100. UNIX=true
  101. endif
  102. ifeq ($(LINUX),true)
  103. UNIX=true
  104. endif
  105. ifeq ($(MACOS),true)
  106. UNIX=true
  107. endif
  108. # ---------------------------------------------------------------------------------------------------------------------
  109. # Set build and link flags
  110. BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
  111. BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
  112. ifeq ($(CPU_I386_OR_X86_64),true)
  113. BASE_OPTS += -mtune=generic -msse -msse2 -mfpmath=sse
  114. endif
  115. ifeq ($(CPU_ARM),true)
  116. ifneq ($(CPU_ARM64),true)
  117. BASE_OPTS += -mfpu=neon-vfpv4 -mfloat-abi=hard
  118. endif
  119. endif
  120. ifeq ($(MACOS),true)
  121. # MacOS linker flags
  122. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
  123. else
  124. # Common linker flags
  125. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
  126. ifneq ($(SKIP_STRIPPING),true)
  127. LINK_OPTS += -Wl,--strip-all
  128. endif
  129. endif
  130. ifeq ($(NOOPT),true)
  131. # No CPU-specific optimization flags
  132. BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections
  133. endif
  134. ifeq ($(WINDOWS),true)
  135. # mingw has issues with this specific optimization
  136. # See https://github.com/falkTX/Carla/issues/696
  137. BASE_OPTS += -fno-rerun-cse-after-loop
  138. # See https://github.com/falkTX/Carla/issues/855
  139. BASE_OPTS += -mstackrealign
  140. ifeq ($(BUILDING_FOR_WINDOWS),true)
  141. BASE_FLAGS += -DBUILDING_CARLA_FOR_WINDOWS
  142. endif
  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 -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. ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  193. HAVE_OPENGL = true
  194. else
  195. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  196. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  197. endif
  198. # ---------------------------------------------------------------------------------------------------------------------
  199. # Check for optional libraries
  200. HAVE_JACK = $(shell $(PKG_CONFIG) --exists jack && echo true)
  201. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  202. # ---------------------------------------------------------------------------------------------------------------------
  203. # Set Generic DGL stuff
  204. ifeq ($(HAIKU),true)
  205. DGL_SYSTEM_LIBS += -lbe
  206. endif
  207. ifeq ($(MACOS),true)
  208. DGL_SYSTEM_LIBS += -framework Cocoa
  209. endif
  210. ifeq ($(WINDOWS),true)
  211. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  212. endif
  213. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  214. ifeq ($(HAVE_X11),true)
  215. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11)
  216. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  217. endif
  218. endif
  219. # ---------------------------------------------------------------------------------------------------------------------
  220. # Set Cairo specific stuff
  221. ifeq ($(HAVE_CAIRO),true)
  222. DGL_FLAGS += -DHAVE_CAIRO
  223. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  224. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  225. HAVE_CAIRO_OR_OPENGL = true
  226. endif
  227. # ---------------------------------------------------------------------------------------------------------------------
  228. # Set OpenGL specific stuff
  229. ifeq ($(HAVE_OPENGL),true)
  230. DGL_FLAGS += -DHAVE_OPENGL
  231. ifeq ($(HAIKU),true)
  232. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  233. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  234. endif
  235. ifeq ($(MACOS),true)
  236. OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1
  237. OPENGL_LIBS = -framework OpenGL
  238. endif
  239. ifeq ($(WINDOWS),true)
  240. OPENGL_LIBS = -lopengl32
  241. endif
  242. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  243. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  244. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  245. endif
  246. HAVE_CAIRO_OR_OPENGL = true
  247. endif
  248. # ---------------------------------------------------------------------------------------------------------------------
  249. # Set app extension
  250. ifeq ($(WINDOWS),true)
  251. APP_EXT = .exe
  252. endif
  253. # ---------------------------------------------------------------------------------------------------------------------
  254. # Set shared lib extension
  255. LIB_EXT = .so
  256. ifeq ($(MACOS),true)
  257. LIB_EXT = .dylib
  258. endif
  259. ifeq ($(WINDOWS),true)
  260. LIB_EXT = .dll
  261. endif
  262. # ---------------------------------------------------------------------------------------------------------------------
  263. # Set shared library CLI arg
  264. ifeq ($(MACOS),true)
  265. SHARED = -dynamiclib
  266. else
  267. SHARED = -shared
  268. endif
  269. # ---------------------------------------------------------------------------------------------------------------------
  270. # Handle the verbosity switch
  271. ifeq ($(VERBOSE),true)
  272. SILENT =
  273. else
  274. SILENT = @
  275. endif
  276. # ---------------------------------------------------------------------------------------------------------------------