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.

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