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.

237 lines
5.8KB

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