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.

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