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.

235 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. # See https://github.com/falkTX/Carla/issues/855
  95. BASE_OPTS += -mstackrealign
  96. ifeq ($(BUILDING_FOR_WINDOWS),true)
  97. BASE_FLAGS += -DBUILDING_CARLA_FOR_WINDOWS
  98. endif
  99. else
  100. # Not needed for Windows
  101. BASE_FLAGS += -fPIC -DPIC
  102. endif
  103. ifeq ($(DEBUG),true)
  104. BASE_FLAGS += -DDEBUG -O0 -g
  105. LINK_OPTS =
  106. else
  107. BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden
  108. CXXFLAGS += -fvisibility-inlines-hidden
  109. endif
  110. BUILD_C_FLAGS = $(BASE_FLAGS) -std=gnu99 $(CFLAGS)
  111. BUILD_CXX_FLAGS = $(BASE_FLAGS) -std=gnu++0x $(CXXFLAGS)
  112. LINK_FLAGS = $(LINK_OPTS) $(LDFLAGS)
  113. ifneq ($(MACOS),true)
  114. # Not available on MacOS
  115. LINK_FLAGS += -Wl,--no-undefined
  116. endif
  117. ifeq ($(MACOS_OLD),true)
  118. BUILD_CXX_FLAGS = $(BASE_FLAGS) $(CXXFLAGS) -DHAVE_CPP11_SUPPORT=0
  119. endif
  120. ifeq ($(WIN32),true)
  121. # Always build statically on windows
  122. LINK_FLAGS += -static
  123. endif
  124. # ---------------------------------------------------------------------------------------------------------------------
  125. # Strict test build
  126. ifeq ($(TESTBUILD),true)
  127. BASE_FLAGS += -Werror -Wcast-qual -Wconversion -Wformat -Wformat-security -Wredundant-decls -Wshadow -Wstrict-overflow -fstrict-overflow -Wundef -Wwrite-strings
  128. BASE_FLAGS += -Wpointer-arith -Wabi -Winit-self -Wuninitialized -Wstrict-overflow=5
  129. # BASE_FLAGS += -Wfloat-equal
  130. ifeq ($(CC),clang)
  131. BASE_FLAGS += -Wdocumentation -Wdocumentation-unknown-command
  132. BASE_FLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-exit-time-destructors -Wno-float-equal
  133. else
  134. BASE_FLAGS += -Wcast-align -Wunsafe-loop-optimizations
  135. endif
  136. ifneq ($(MACOS),true)
  137. BASE_FLAGS += -Wmissing-declarations -Wsign-conversion
  138. ifneq ($(CC),clang)
  139. BASE_FLAGS += -Wlogical-op
  140. endif
  141. endif
  142. CFLAGS += -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes
  143. CXXFLAGS += -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual
  144. endif
  145. # ---------------------------------------------------------------------------------------------------------------------
  146. # Check for optional libs
  147. ifeq ($(MACOS_OR_WIN32),true)
  148. HAVE_DGL = true
  149. else
  150. HAVE_DGL = $(shell pkg-config --exists gl x11 && echo true)
  151. HAVE_JACK = $(shell pkg-config --exists jack && echo true)
  152. HAVE_LIBLO = $(shell pkg-config --exists liblo && echo true)
  153. endif
  154. # ---------------------------------------------------------------------------------------------------------------------
  155. # Set libs stuff
  156. ifeq ($(HAVE_DGL),true)
  157. ifeq ($(MACOS),true)
  158. DGL_LIBS = -framework OpenGL -framework Cocoa
  159. endif
  160. ifeq ($(WIN32),true)
  161. DGL_LIBS = -lopengl32 -lgdi32
  162. endif
  163. ifneq ($(MACOS_OR_WIN32),true)
  164. DGL_FLAGS = $(shell pkg-config --cflags gl x11)
  165. DGL_LIBS = $(shell pkg-config --libs gl x11)
  166. endif
  167. endif # HAVE_DGL
  168. # ---------------------------------------------------------------------------------------------------------------------
  169. # Set app extension
  170. ifeq ($(WIN32),true)
  171. APP_EXT = .exe
  172. endif
  173. # ---------------------------------------------------------------------------------------------------------------------
  174. # Set shared lib extension
  175. LIB_EXT = .so
  176. ifeq ($(MACOS),true)
  177. LIB_EXT = .dylib
  178. endif
  179. ifeq ($(WIN32),true)
  180. LIB_EXT = .dll
  181. endif
  182. # ---------------------------------------------------------------------------------------------------------------------
  183. # Set shared library CLI arg
  184. SHARED = -shared
  185. ifeq ($(MACOS),true)
  186. SHARED = -dynamiclib
  187. endif
  188. # ---------------------------------------------------------------------------------------------------------------------