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.

280 lines
7.0KB

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