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.

355 lines
8.9KB

  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 -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. ifeq ($(MACOS_OR_WINDOWS),true)
  184. HAVE_OPENGL = true
  185. else
  186. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  187. ifneq ($(HAIKU),true)
  188. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  189. endif
  190. endif
  191. # ---------------------------------------------------------------------------------------------------------------------
  192. # Check for optional libraries
  193. HAVE_JACK = $(shell $(PKG_CONFIG) --exists jack && echo true)
  194. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  195. # ---------------------------------------------------------------------------------------------------------------------
  196. # Set Generic DGL stuff
  197. ifeq ($(HAIKU),true)
  198. DGL_SYSTEM_LIBS += -lbe
  199. endif
  200. ifeq ($(MACOS),true)
  201. DGL_SYSTEM_LIBS += -framework Cocoa
  202. endif
  203. ifeq ($(WINDOWS),true)
  204. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  205. endif
  206. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  207. ifeq ($(HAVE_X11),true)
  208. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11)
  209. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  210. endif
  211. endif
  212. # ---------------------------------------------------------------------------------------------------------------------
  213. # Set Cairo specific stuff
  214. ifeq ($(HAVE_CAIRO),true)
  215. DGL_FLAGS += -DHAVE_CAIRO
  216. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  217. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  218. HAVE_CAIRO_OR_OPENGL = true
  219. endif
  220. # ---------------------------------------------------------------------------------------------------------------------
  221. # Set OpenGL specific stuff
  222. ifeq ($(HAVE_OPENGL),true)
  223. DGL_FLAGS += -DHAVE_OPENGL
  224. ifeq ($(HAIKU),true)
  225. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  226. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  227. endif
  228. ifeq ($(MACOS),true)
  229. OPENGL_LIBS = -framework OpenGL
  230. endif
  231. ifeq ($(WINDOWS),true)
  232. OPENGL_LIBS = -lopengl32
  233. endif
  234. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  235. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  236. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  237. endif
  238. HAVE_CAIRO_OR_OPENGL = true
  239. endif
  240. # ---------------------------------------------------------------------------------------------------------------------
  241. # Set optional libraries specific stuff
  242. ifeq ($(HAVE_JACK),true)
  243. JACK_FLAGS = $(shell $(PKG_CONFIG) --cflags jack)
  244. JACK_LIBS = $(shell $(PKG_CONFIG) --libs jack)
  245. endif
  246. ifeq ($(HAVE_LIBLO),true)
  247. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  248. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  249. endif
  250. # ---------------------------------------------------------------------------------------------------------------------
  251. # Set app extension
  252. ifeq ($(WINDOWS),true)
  253. APP_EXT = .exe
  254. endif
  255. # ---------------------------------------------------------------------------------------------------------------------
  256. # Set shared lib extension
  257. LIB_EXT = .so
  258. ifeq ($(MACOS),true)
  259. LIB_EXT = .dylib
  260. endif
  261. ifeq ($(WINDOWS),true)
  262. LIB_EXT = .dll
  263. endif
  264. # ---------------------------------------------------------------------------------------------------------------------
  265. # Set shared library CLI arg
  266. ifeq ($(MACOS),true)
  267. SHARED = -dynamiclib
  268. else
  269. SHARED = -shared
  270. endif
  271. # ---------------------------------------------------------------------------------------------------------------------
  272. # Handle the verbosity switch
  273. ifeq ($(VERBOSE),true)
  274. SILENT =
  275. else
  276. SILENT = @
  277. endif
  278. # ---------------------------------------------------------------------------------------------------------------------