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.

362 lines
9.1KB

  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. # Non-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. else
  141. # Not needed for Windows
  142. BASE_FLAGS += -fPIC -DPIC
  143. endif
  144. ifeq ($(DEBUG),true)
  145. BASE_FLAGS += -DDEBUG -O0 -g
  146. LINK_OPTS =
  147. else
  148. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  149. CXXFLAGS += -fvisibility-inlines-hidden
  150. endif
  151. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  152. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
  153. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  154. ifneq ($(MACOS),true)
  155. # Not available on MacOS
  156. LINK_FLAGS += -Wl,--no-undefined
  157. endif
  158. ifeq ($(MACOS_OLD),true)
  159. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  160. endif
  161. ifeq ($(WINDOWS),true)
  162. # Always build statically on windows
  163. LINK_FLAGS += -static
  164. endif
  165. # ---------------------------------------------------------------------------------------------------------------------
  166. # Strict test build
  167. ifeq ($(TESTBUILD),true)
  168. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  169. BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5
  170. # BASE_FLAGS += -Wfloat-equal
  171. ifeq ($(CC),clang)
  172. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  173. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  174. else
  175. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  176. endif
  177. ifneq ($(MACOS),true)
  178. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  179. ifneq ($(CC),clang)
  180. BASE_FLAGS += -Wlogical-op
  181. endif
  182. endif
  183. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  184. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  185. endif
  186. # ---------------------------------------------------------------------------------------------------------------------
  187. # Check for required libraries
  188. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  189. ifeq ($(MACOS_OR_WINDOWS),true)
  190. HAVE_OPENGL = true
  191. else
  192. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  193. ifneq ($(HAIKU),true)
  194. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  195. endif
  196. endif
  197. # ---------------------------------------------------------------------------------------------------------------------
  198. # Check for optional libraries
  199. HAVE_JACK = $(shell $(PKG_CONFIG) --exists jack && echo true)
  200. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  201. # ---------------------------------------------------------------------------------------------------------------------
  202. # Set Generic DGL stuff
  203. ifeq ($(HAIKU),true)
  204. DGL_SYSTEM_LIBS += -lbe
  205. endif
  206. ifeq ($(MACOS),true)
  207. DGL_SYSTEM_LIBS += -framework Cocoa
  208. endif
  209. ifeq ($(WINDOWS),true)
  210. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  211. endif
  212. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  213. ifeq ($(HAVE_X11),true)
  214. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11)
  215. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  216. endif
  217. endif
  218. # ---------------------------------------------------------------------------------------------------------------------
  219. # Set Cairo specific stuff
  220. ifeq ($(HAVE_CAIRO),true)
  221. DGL_FLAGS += -DHAVE_CAIRO
  222. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  223. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  224. HAVE_CAIRO_OR_OPENGL = true
  225. endif
  226. # ---------------------------------------------------------------------------------------------------------------------
  227. # Set OpenGL specific stuff
  228. ifeq ($(HAVE_OPENGL),true)
  229. DGL_FLAGS += -DHAVE_OPENGL
  230. ifeq ($(HAIKU),true)
  231. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  232. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  233. endif
  234. ifeq ($(MACOS),true)
  235. OPENGL_FLAGS = -DGL_SILENCE_DEPRECATION=1
  236. OPENGL_LIBS = -framework OpenGL
  237. endif
  238. ifeq ($(WINDOWS),true)
  239. OPENGL_LIBS = -lopengl32
  240. endif
  241. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  242. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  243. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  244. endif
  245. HAVE_CAIRO_OR_OPENGL = true
  246. endif
  247. # ---------------------------------------------------------------------------------------------------------------------
  248. # Set optional libraries specific stuff
  249. ifeq ($(HAVE_JACK),true)
  250. JACK_FLAGS = $(shell $(PKG_CONFIG) --cflags jack)
  251. JACK_LIBS = $(shell $(PKG_CONFIG) --libs jack)
  252. endif
  253. ifeq ($(HAVE_LIBLO),true)
  254. LIBLO_FLAGS = $(shell $(PKG_CONFIG) --cflags liblo)
  255. LIBLO_LIBS = $(shell $(PKG_CONFIG) --libs liblo)
  256. endif
  257. # ---------------------------------------------------------------------------------------------------------------------
  258. # Set app extension
  259. ifeq ($(WINDOWS),true)
  260. APP_EXT = .exe
  261. endif
  262. # ---------------------------------------------------------------------------------------------------------------------
  263. # Set shared lib extension
  264. LIB_EXT = .so
  265. ifeq ($(MACOS),true)
  266. LIB_EXT = .dylib
  267. endif
  268. ifeq ($(WINDOWS),true)
  269. LIB_EXT = .dll
  270. endif
  271. # ---------------------------------------------------------------------------------------------------------------------
  272. # Set shared library CLI arg
  273. ifeq ($(MACOS),true)
  274. SHARED = -dynamiclib
  275. else
  276. SHARED = -shared
  277. endif
  278. # ---------------------------------------------------------------------------------------------------------------------
  279. # Handle the verbosity switch
  280. ifeq ($(VERBOSE),true)
  281. SILENT =
  282. else
  283. SILENT = @
  284. endif
  285. # ---------------------------------------------------------------------------------------------------------------------