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.

340 lines
8.5KB

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