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.

303 lines
7.6KB

  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. # See https://github.com/falkTX/Carla/issues/855
  108. BASE_OPTS += -mstackrealign
  109. ifeq ($(BUILDING_FOR_WINDOWS),true)
  110. BASE_FLAGS += -DBUILDING_CARLA_FOR_WINDOWS
  111. endif
  112. else
  113. # Not needed for Windows
  114. BASE_FLAGS += -fPIC -DPIC
  115. endif
  116. ifeq ($(DEBUG),true)
  117. BASE_FLAGS += -DDEBUG -O0 -g
  118. LINK_OPTS =
  119. else
  120. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  121. CXXFLAGS += -fvisibility-inlines-hidden
  122. endif
  123. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  124. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
  125. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  126. ifneq ($(MACOS),true)
  127. # Not available on MacOS
  128. LINK_FLAGS += -Wl,--no-undefined
  129. endif
  130. ifeq ($(MACOS_OLD),true)
  131. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  132. endif
  133. ifeq ($(WINDOWS),true)
  134. # Always build statically on windows
  135. LINK_FLAGS += -static
  136. endif
  137. # ---------------------------------------------------------------------------------------------------------------------
  138. # Strict test build
  139. ifeq ($(TESTBUILD),true)
  140. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  141. BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5
  142. # BASE_FLAGS += -Wfloat-equal
  143. ifeq ($(CC),clang)
  144. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  145. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  146. else
  147. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  148. endif
  149. ifneq ($(MACOS),true)
  150. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  151. ifneq ($(CC),clang)
  152. BASE_FLAGS += -Wlogical-op
  153. endif
  154. endif
  155. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  156. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  157. endif
  158. # ---------------------------------------------------------------------------------------------------------------------
  159. # Check for required libraries
  160. HAVE_CAIRO = $(shell $(PKG_CONFIG) --exists cairo && echo true)
  161. ifeq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  162. HAVE_OPENGL = true
  163. else
  164. HAVE_OPENGL = $(shell $(PKG_CONFIG) --exists gl && echo true)
  165. HAVE_X11 = $(shell $(PKG_CONFIG) --exists x11 && echo true)
  166. endif
  167. # ---------------------------------------------------------------------------------------------------------------------
  168. # Check for optional libraries
  169. HAVE_JACK = $(shell $(PKG_CONFIG) --exists jack && echo true)
  170. HAVE_LIBLO = $(shell $(PKG_CONFIG) --exists liblo && echo true)
  171. # ---------------------------------------------------------------------------------------------------------------------
  172. # Set Generic DGL stuff
  173. ifeq ($(HAIKU),true)
  174. DGL_SYSTEM_LIBS += -lbe
  175. endif
  176. ifeq ($(MACOS),true)
  177. DGL_SYSTEM_LIBS += -framework Cocoa
  178. endif
  179. ifeq ($(WINDOWS),true)
  180. DGL_SYSTEM_LIBS += -lgdi32 -lcomdlg32
  181. endif
  182. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  183. ifeq ($(HAVE_X11),true)
  184. DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags x11)
  185. DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs x11)
  186. endif
  187. endif
  188. # ---------------------------------------------------------------------------------------------------------------------
  189. # Set Cairo specific stuff
  190. ifeq ($(HAVE_CAIRO),true)
  191. DGL_FLAGS += -DHAVE_CAIRO
  192. CAIRO_FLAGS = $(shell $(PKG_CONFIG) --cflags cairo)
  193. CAIRO_LIBS = $(shell $(PKG_CONFIG) --libs cairo)
  194. HAVE_CAIRO_OR_OPENGL = true
  195. endif
  196. # ---------------------------------------------------------------------------------------------------------------------
  197. # Set OpenGL specific stuff
  198. ifeq ($(HAVE_OPENGL),true)
  199. DGL_FLAGS += -DHAVE_OPENGL
  200. ifeq ($(HAIKU),true)
  201. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl)
  202. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl)
  203. endif
  204. ifeq ($(MACOS),true)
  205. OPENGL_LIBS = -framework OpenGL
  206. endif
  207. ifeq ($(WINDOWS),true)
  208. OPENGL_LIBS = -lopengl32
  209. endif
  210. ifneq ($(HAIKU_OR_MACOS_OR_WINDOWS),true)
  211. OPENGL_FLAGS = $(shell $(PKG_CONFIG) --cflags gl x11)
  212. OPENGL_LIBS = $(shell $(PKG_CONFIG) --libs gl x11)
  213. endif
  214. HAVE_CAIRO_OR_OPENGL = true
  215. endif
  216. # ---------------------------------------------------------------------------------------------------------------------
  217. # Set app extension
  218. ifeq ($(WINDOWS),true)
  219. APP_EXT = .exe
  220. endif
  221. # ---------------------------------------------------------------------------------------------------------------------
  222. # Set shared lib extension
  223. LIB_EXT = .so
  224. ifeq ($(MACOS),true)
  225. LIB_EXT = .dylib
  226. endif
  227. ifeq ($(WINDOWS),true)
  228. LIB_EXT = .dll
  229. endif
  230. # ---------------------------------------------------------------------------------------------------------------------
  231. # Set shared library CLI arg
  232. ifeq ($(MACOS),true)
  233. SHARED = -dynamiclib
  234. else
  235. SHARED = -shared
  236. endif
  237. # ---------------------------------------------------------------------------------------------------------------------