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.

290 lines
7.4KB

  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. ifneq ($(BSD),true)
  12. ifneq ($(HAIKU),true)
  13. ifneq ($(HURD),true)
  14. ifneq ($(LINUX),true)
  15. ifneq ($(MACOS),true)
  16. ifneq ($(WINDOWS),true)
  17. TARGET_MACHINE := $(shell $(CC) -dumpmachine)
  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. # Set PKG_CONFIG (can be overridden by environment variable)
  44. ifeq ($(WINDOWS),true)
  45. # Build statically on Windows by default
  46. PKG_CONFIG ?= pkg-config --static
  47. else
  48. PKG_CONFIG ?= pkg-config
  49. endif
  50. # ---------------------------------------------------------------------------------------------------------------------
  51. # Set LINUX_OR_MACOS
  52. ifeq ($(LINUX),true)
  53. LINUX_OR_MACOS=true
  54. endif
  55. ifeq ($(MACOS),true)
  56. LINUX_OR_MACOS=true
  57. endif
  58. # ---------------------------------------------------------------------------------------------------------------------
  59. # Set MACOS_OR_WINDOWS and HAIKU_OR_MACOS_OR_WINDOWS
  60. ifeq ($(HAIKU),true)
  61. HAIKU_OR_MACOS_OR_WINDOWS=true
  62. endif
  63. ifeq ($(MACOS),true)
  64. MACOS_OR_WINDOWS=true
  65. HAIKU_OR_MACOS_OR_WINDOWS=true
  66. endif
  67. ifeq ($(WINDOWS),true)
  68. MACOS_OR_WINDOWS=true
  69. HAIKU_OR_MACOS_OR_WINDOWS=true
  70. endif
  71. # ---------------------------------------------------------------------------------------------------------------------
  72. # Set UNIX
  73. ifeq ($(BSD),true)
  74. UNIX=true
  75. endif
  76. ifeq ($(HURD),true)
  77. UNIX=true
  78. endif
  79. ifeq ($(LINUX),true)
  80. UNIX=true
  81. endif
  82. ifeq ($(MACOS),true)
  83. UNIX=true
  84. endif
  85. # ---------------------------------------------------------------------------------------------------------------------
  86. # Set build and link flags
  87. BASE_FLAGS = -Wall -Wextra -pipe -MD -MP
  88. BASE_OPTS = -O3 -ffast-math -mtune=generic -msse -msse2 -fdata-sections -ffunction-sections
  89. ifeq ($(MACOS),true)
  90. # MacOS linker flags
  91. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,-dead_strip -Wl,-dead_strip_dylibs
  92. else
  93. # Common linker flags
  94. LINK_OPTS = -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-O1 -Wl,--as-needed
  95. ifneq ($(SKIP_STRIPPING),true)
  96. LINK_OPTS += -Wl,--strip-all
  97. endif
  98. endif
  99. ifeq ($(NOOPT),true)
  100. # No CPU-specific optimization flags
  101. BASE_OPTS = -O2 -ffast-math -fdata-sections -ffunction-sections
  102. endif
  103. ifeq ($(WINDOWS),true)
  104. # mingw has issues with this specific optimization
  105. # See https://github.com/falkTX/Carla/issues/696
  106. BASE_OPTS += -fno-rerun-cse-after-loop
  107. ifeq ($(BUILDING_FOR_WINDOWS),true)
  108. BASE_FLAGS += -DBUILDING_CARLA_FOR_WINDOWS
  109. endif
  110. else
  111. # Not needed for Windows
  112. BASE_FLAGS += -fPIC -DPIC
  113. endif
  114. ifeq ($(DEBUG),true)
  115. BASE_FLAGS += -DDEBUG -O0 -g
  116. LINK_OPTS =
  117. else
  118. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  119. CXXFLAGS += -fvisibility-inlines-hidden
  120. endif
  121. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  122. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
  123. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  124. ifneq ($(MACOS),true)
  125. # Not available on MacOS
  126. LINK_FLAGS += -Wl,--no-undefined
  127. endif
  128. ifeq ($(MACOS_OLD),true)
  129. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  130. endif
  131. ifeq ($(WINDOWS),true)
  132. # Always build statically on windows
  133. LINK_FLAGS += -static
  134. endif
  135. # ---------------------------------------------------------------------------------------------------------------------
  136. # Strict test build
  137. ifeq ($(TESTBUILD),true)
  138. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  139. BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5
  140. # BASE_FLAGS += -Wfloat-equal
  141. ifeq ($(CC),clang)
  142. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  143. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  144. else
  145. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  146. endif
  147. ifneq ($(MACOS),true)
  148. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  149. ifneq ($(CC),clang)
  150. BASE_FLAGS += -Wlogical-op
  151. endif
  152. endif
  153. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  154. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  155. endif
  156. # ---------------------------------------------------------------------------------------------------------------------
  157. # Check for required libraries
  158. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  159. ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  160. HAVE_OPENGL = true
  161. else
  162. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  163. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  164. endif
  165. # ---------------------------------------------------------------------------------------------------------------------
  166. # Check for optional libraries
  167. HAVE_JACK = $(shell $(PKG_CONFIG) --exists jack && echo true)
  168. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  169. # ---------------------------------------------------------------------------------------------------------------------
  170. # Set Generic DGL stuff
  171. ifeq ($(MACOS),true)
  172. DGL_SYSTEM_LIBS += -framework Cocoa
  173. endif
  174. ifeq ($(WINDOWS),true)
  175. DGL_SYSTEM_LIBS += -lgdi32
  176. endif
  177. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  178. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11)
  179. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  180. endif
  181. # ---------------------------------------------------------------------------------------------------------------------
  182. # Set Cairo specific stuff
  183. ifeq ($(HAVE_CAIRO),true)
  184. DGL_FLAGS += -DHAVE_CAIRO
  185. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  186. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  187. HAVE_CAIRO_OR_OPENGL = true
  188. endif
  189. # ---------------------------------------------------------------------------------------------------------------------
  190. # Set OpenGL specific stuff
  191. ifeq ($(HAVE_OPENGL),true)
  192. DGL_FLAGS += -DHAVE_OPENGL
  193. ifeq ($(MACOS),true)
  194. OPENGL_LIBS = -framework OpenGL
  195. endif
  196. ifeq ($(WINDOWS),true)
  197. OPENGL_LIBS = -lopengl32
  198. endif
  199. ifneq ($(MACOS_OR_WINDOWS),true)
  200. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  201. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  202. endif
  203. HAVE_CAIRO_OR_OPENGL = true
  204. endif
  205. # ---------------------------------------------------------------------------------------------------------------------
  206. # Set app extension
  207. ifeq ($(WINDOWS),true)
  208. APP_EXT = .exe
  209. endif
  210. # ---------------------------------------------------------------------------------------------------------------------
  211. # Set shared lib extension
  212. LIB_EXT = .so
  213. ifeq ($(MACOS),true)
  214. LIB_EXT = .dylib
  215. endif
  216. ifeq ($(WINDOWS),true)
  217. LIB_EXT = .dll
  218. endif
  219. # ---------------------------------------------------------------------------------------------------------------------
  220. # Set shared library CLI arg
  221. ifeq ($(MACOS),true)
  222. SHARED = -dynamiclib
  223. else
  224. SHARED = -shared
  225. endif
  226. # ---------------------------------------------------------------------------------------------------------------------