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.

312 lines
9.4KB

  1. #!/usr/bin/make -f
  2. # Makefile for Cardinal #
  3. # --------------------- #
  4. # Created by falkTX
  5. #
  6. # --------------------------------------------------------------
  7. # Import base definitions
  8. DISTRHO_NAMESPACE = CardinalDISTRHO
  9. DGL_NAMESPACE = CardinalDGL
  10. USE_NANOVG_FBO = true
  11. WASM_EXCEPTIONS = true
  12. include ../dpf/Makefile.base.mk
  13. # --------------------------------------------------------------
  14. # Build config
  15. ifeq ($(BSD),true)
  16. SYSDEPS ?= true
  17. else
  18. SYSDEPS ?= false
  19. endif
  20. ifeq ($(SYSDEPS),true)
  21. DEP_PATH = $(abspath sysroot)
  22. else
  23. DEP_PATH = $(abspath ../src/Rack/dep)
  24. endif
  25. # --------------------------------------------------------------
  26. # custom build flags
  27. BASE_FLAGS += -I../include
  28. BASE_FLAGS += -I../include/simd-compat
  29. ifeq ($(HEADLESS),true)
  30. ifeq ($(WITH_LTO),true)
  31. BASE_FLAGS += -ffat-lto-objects
  32. endif
  33. endif
  34. ifneq ($(SYSDEPS),true)
  35. BASE_FLAGS += -DZSTDLIB_VISIBILITY=
  36. endif
  37. ifneq ($(HAIKU),true)
  38. ifneq ($(WASM),true)
  39. BASE_FLAGS += -pthread
  40. endif
  41. endif
  42. ifeq ($(WINDOWS),true)
  43. BASE_FLAGS += -D_USE_MATH_DEFINES
  44. BASE_FLAGS += -DWIN32_LEAN_AND_MEAN
  45. BASE_FLAGS += -I../include/mingw-compat
  46. BASE_FLAGS += -I../include/mingw-std-threads
  47. endif
  48. BUILD_C_FLAGS += -fno-finite-math-only -fno-strict-aliasing
  49. BUILD_CXX_FLAGS += -fno-finite-math-only -fno-strict-aliasing
  50. # Rack code is not tested for this flag, unset it
  51. BUILD_CXX_FLAGS += -U_GLIBCXX_ASSERTIONS -Wp,-U_GLIBCXX_ASSERTIONS
  52. # --------------------------------------------------------------
  53. # override VCV arch.mk stuff so we can build more architectures
  54. ifeq ($(CPU_AARCH64),true)
  55. ARCH_NAME = aarch64
  56. MACHINE = x86_64-the-rack
  57. else ifeq ($(CPU_ARM64),true)
  58. ARCH_NAME = arm64
  59. MACHINE = x86_64-the-rack
  60. else ifeq ($(CPU_ARM),true)
  61. ARCH_NAME = arm
  62. MACHINE = i686-the-rack
  63. else ifeq ($(WASM),true)
  64. MACHINE = i686-wasm
  65. else
  66. MACHINE = $(TARGET_MACHINE)
  67. endif
  68. ifeq ($(MACOS),true)
  69. MACHINE_SUFFIX = -darwin
  70. else ifeq ($(WINDOWS),true)
  71. MACHINE_SUFFIX = -mingw32
  72. else
  73. MACHINE_SUFFIX = -linux
  74. endif
  75. # --------------------------------------------------------------
  76. # Set up env to pass to cmake and configure
  77. ENV = env
  78. ENV += AR=$(AR)
  79. ENV += CC=$(CC)
  80. ENV += CXX=$(CXX)
  81. ENV += CFLAGS='$(BUILD_C_FLAGS)'
  82. ENV += CXXFLAGS='$(BUILD_CXX_FLAGS)'
  83. ENV += LDFLAGS='$(LINK_FLAGS)'
  84. # --------------------------------------------------------------
  85. # Fix up cmake
  86. SPACE =
  87. SPACE +=
  88. CMAKE = cmake
  89. CMAKE += -DCMAKE_INSTALL_LIBDIR=lib
  90. CMAKE += -DCMAKE_INSTALL_PREFIX='$(DEP_PATH)'
  91. CMAKE += -DBUILD_SHARED_LIBS=OFF
  92. # make sure debug/release matches
  93. ifeq ($(DEBUG),true)
  94. CMAKE += -DCMAKE_BUILD_TYPE=Debug
  95. else
  96. CMAKE += -DCMAKE_BUILD_TYPE=Release
  97. endif
  98. # make sure macOS target matches ours
  99. ifeq ($(MACOS),true)
  100. ifneq (,$(findstring -arch$(SPACE),$(CXXFLAGS)))
  101. CMAKE += -DCMAKE_OSX_ARCHITECTURES='$(subst $(SPACE),;,$(subst -arch=,,$(filter -arch=%,$(subst -arch$(SPACE),-arch=,$(CXXFLAGS)))))'
  102. else ifeq ($(CIBUILD),true)
  103. $(error CI build requires -march flag on macOS)
  104. endif
  105. ifneq (,$(findstring -mmacosx-version-min=,$(CXXFLAGS)))
  106. export MACOSX_DEPLOYMENT_TARGET = $(subst -mmacosx-version-min=,,$(filter -mmacosx-version-min=%,$(CXXFLAGS)))
  107. CMAKE += -DCMAKE_OSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET)
  108. else ifeq ($(CIBUILD),true)
  109. $(error CI build requires -mmacosx-version-min flag on macOS)
  110. endif
  111. CMAKE += -DCMAKE_OSX_SYSROOT=$(shell xcrun --sdk macosx --show-sdk-path)
  112. endif
  113. # fix cross-compilation for windows
  114. ifeq ($(WINDOWS),true)
  115. CMAKE += -G 'Unix Makefiles'
  116. CMAKE += -DCMAKE_RC_COMPILER=$(subst gcc,windres,$(CC))
  117. CMAKE += -DCMAKE_SYSTEM_NAME=Windows
  118. endif
  119. # --------------------------------------------------------------
  120. # Fix up configure
  121. CONFIGURE = ./configure
  122. CONFIGURE += --prefix="$(DEP_PATH)"
  123. CONFIGURE += --host=$(TARGET_MACHINE)
  124. CONFIGURE += --enable-static
  125. CONFIGURE += --disable-shared
  126. # NOTE libsamplerate wants to link against alsa, so we disable that
  127. CONFIGURE += --disable-alsa
  128. # NOTE speex fails to build when neon is enabled, so we disable that
  129. CONFIGURE += --disable-neon
  130. # NOTE libsamplerate fails with invalid host, so we force ac_cv_host
  131. CONFIGURE += ac_cv_host=$(TARGET_MACHINE)
  132. # --------------------------------------------------------------
  133. # Fix up make
  134. DEP_MAKE = $(MAKE)
  135. DEP_MAKE += ARCH_NAME=$(ARCH_NAME)
  136. DEP_MAKE += AR=$(AR)
  137. DEP_MAKE += CC=$(CC)
  138. DEP_MAKE += CXX=$(CXX)
  139. DEP_MAKE += CFLAGS="$(BUILD_C_FLAGS)"
  140. DEP_MAKE += CXXFLAGS="$(BUILD_CXX_FLAGS)"
  141. DEP_MAKE += LDFLAGS="$(LINK_FLAGS)"
  142. DEP_MAKE += DEP_FLAGS="$(BASE_FLAGS)"
  143. DEP_MAKE += DEP_MAC_SDK_FLAGS=
  144. DEP_MAKE += MACHINE=$(MACHINE)$(MACHINE_SUFFIX)
  145. DEP_MAKE += VERBOSE=1
  146. ifeq ($(shell uname -s),Darwin)
  147. ifeq ($(CIBUILD),true)
  148. DEP_MAKE += SHA256SUM="shasum5.28 -a 256"
  149. else
  150. DEP_MAKE += SHA256SUM="shasum5.30 -a 256"
  151. endif
  152. endif
  153. DEP_MAKE2 = $(DEP_MAKE)
  154. DEP_MAKE2 += CMAKE="$(ENV) $(CMAKE)"
  155. DEP_MAKE2 += CONFIGURE="$(ENV) $(CONFIGURE)"
  156. # --------------------------------------------------------------
  157. # Rack internal dependencies target
  158. $(DEP_PATH)/lib/%.a:
  159. $(DEP_MAKE2) -C $(DEP_PATH) lib/$*.a
  160. $(DEP_PATH)/jansson-2.12:
  161. $(DEP_MAKE2) -C $(DEP_PATH) jansson-2.12
  162. # libarchive: skip shared lib and ensure libzstd is enabled
  163. $(DEP_PATH)/lib/libarchive.a: $(DEP_PATH)/lib/libzstd.a $(DEP_PATH)/libarchive-3.4.3/.stamp-patched
  164. $(DEP_PATH)/lib/libarchive_static.a: $(DEP_PATH)/lib/libzstd.a $(DEP_PATH)/libarchive-3.4.3/.stamp-patched
  165. $(DEP_PATH)/libarchive-3.4.3/.stamp-patched:
  166. $(DEP_MAKE2) -C $(DEP_PATH) libarchive-3.4.3
  167. sed -i -e "618,625d" $(DEP_PATH)/libarchive-3.4.3/CMakeLists.txt
  168. awk 'NR==616{print " SET(HAVE_LIBZSTD 1)"}1' $(DEP_PATH)/libarchive-3.4.3/CMakeLists.txt > $(DEP_PATH)/libarchive-3.4.3/CMakeLists.txt2
  169. mv $(DEP_PATH)/libarchive-3.4.3/CMakeLists.txt2 $(DEP_PATH)/libarchive-3.4.3/CMakeLists.txt
  170. sed -i -e "238,243d" $(DEP_PATH)/libarchive-3.4.3/libarchive/CMakeLists.txt
  171. sed -i -e "s/TARGETS archive archive_static/TARGETS archive_static/" $(DEP_PATH)/libarchive-3.4.3/libarchive/CMakeLists.txt
  172. touch $@
  173. # libsamplerate: skip tests, fails to build in some systems and are not needed or wanted anyway
  174. $(DEP_PATH)/lib/libsamplerate.a: $(DEP_PATH)/libsamplerate-0.1.9/.stamp-patched
  175. $(DEP_PATH)/libsamplerate-0.1.9/.stamp-patched:
  176. $(DEP_MAKE2) -C $(DEP_PATH) libsamplerate-0.1.9
  177. sed -i -e "s/src doc examples tests/src/" $(DEP_PATH)/libsamplerate-0.1.9/Makefile.in
  178. touch $@
  179. # libspeexdsp: hide symbols
  180. $(DEP_PATH)/lib/libspeexdsp.a: $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3/.stamp-patched
  181. $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3/.stamp-patched:
  182. $(DEP_MAKE2) -C $(DEP_PATH) speexdsp-SpeexDSP-1.2rc3 \
  183. WGET="wget -c http://downloads.xiph.org/releases/speex/speexdsp-1.2rc3.tar.gz && mv speexdsp-1.2rc3.tar.gz speexdsp-SpeexDSP-1.2rc3.tgz #" \
  184. SHA256SUM="true" \
  185. UNTAR="mkdir -p speexdsp-SpeexDSP-1.2rc3 && tar -x --strip-components=1 --directory=$(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3 -f"
  186. sed -i -e "s/#pragma GCC visibility push/#error we dont want this/" $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3/configure
  187. touch $@
  188. # custom zstd build for only building static libs
  189. $(DEP_PATH)/lib/libzstd.a: $(DEP_PATH)/zstd-1.4.5/.stamp-patched
  190. cd $(DEP_PATH)/zstd-1.4.5/build/cmake && $(CMAKE) -DZSTD_BUILD_STATIC=ON -DZSTD_BUILD_PROGRAMS=OFF -DZSTD_BUILD_SHARED=OFF -DZSTD_MULTITHREAD_SUPPORT=OFF .
  191. $(DEP_MAKE2) -C $(DEP_PATH)/zstd-1.4.5/build/cmake
  192. $(DEP_MAKE2) -C $(DEP_PATH)/zstd-1.4.5/build/cmake install
  193. # zstd cmake is borked, see https://github.com/facebook/zstd/issues/1401
  194. # zstd also fails to build on old systems, patch that too
  195. $(DEP_PATH)/zstd-1.4.5/.stamp-patched:
  196. $(DEP_MAKE2) -C $(DEP_PATH) zstd-1.4.5
  197. sed -i -e "56,66d" $(DEP_PATH)/zstd-1.4.5/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
  198. sed -i -e "146,175d" $(DEP_PATH)/zstd-1.4.5/programs/util.c
  199. sed -i -e "142,144d" $(DEP_PATH)/zstd-1.4.5/programs/util.c
  200. touch $@
  201. # --------------------------------------------------------------
  202. # QuickJS target, needed for AriaModules
  203. QUICKJS_MAKE_FLAGS = CFLAGS="$(BUILD_C_FLAGS) -D_GNU_SOURCE -DCONFIG_VERSION='\"Cardinal\"' -w"
  204. QUICKJS_MAKE_FLAGS += PROGS=libquickjs.a
  205. ifeq ($(WITH_LTO),true)
  206. QUICKJS_MAKE_FLAGS += CONFIG_LTO=y
  207. else
  208. QUICKJS_MAKE_FLAGS += CONFIG_LTO=
  209. endif
  210. ifeq ($(WINDOWS),true)
  211. QUICKJS_MAKE_FLAGS += CONFIG_WIN32=y
  212. else ifeq ($(MACOS),true)
  213. QUICKJS_MAKE_FLAGS += CONFIG_DARWIN=y
  214. endif
  215. $(DEP_PATH)/lib/libquickjs.a:
  216. $(DEP_MAKE) $(QUICKJS_MAKE_FLAGS) -C $(CURDIR)/QuickJS
  217. install -d $(DEP_PATH)/include
  218. install -d $(DEP_PATH)/lib
  219. install -m644 $(CURDIR)/QuickJS/libquickjs.a $@
  220. install -m644 $(CURDIR)/QuickJS/quickjs.h $(DEP_PATH)/include/quickjs.h
  221. # --------------------------------------------------------------
  222. # Build targets
  223. TARGETS += $(DEP_PATH)/lib/libjansson.a
  224. TARGETS += $(DEP_PATH)/lib/libquickjs.a
  225. TARGETS += $(DEP_PATH)/lib/libsamplerate.a
  226. TARGETS += $(DEP_PATH)/lib/libspeexdsp.a
  227. ifeq ($(WINDOWS),true)
  228. TARGETS += $(DEP_PATH)/lib/libarchive_static.a
  229. else
  230. TARGETS += $(DEP_PATH)/lib/libarchive.a
  231. endif
  232. TARGETS += $(DEP_PATH)/lib/libzstd.a
  233. all: $(TARGETS)
  234. clean:
  235. $(DEP_MAKE) $(QUICKJS_MAKE_FLAGS) -C $(CURDIR)/QuickJS clean
  236. rm -f $(TARGETS)
  237. rm -f $(DEP_PATH)/*.tgz
  238. rm -f $(DEP_PATH)/*.tar.gz
  239. rm -rf $(DEP_PATH)/bin
  240. rm -rf $(DEP_PATH)/include
  241. rm -rf $(DEP_PATH)/lib
  242. rm -rf $(DEP_PATH)/share
  243. rm -rf $(DEP_PATH)/jansson-2.12
  244. rm -rf $(DEP_PATH)/libarchive-3.4.3
  245. rm -rf $(DEP_PATH)/libsamplerate-0.1.9
  246. rm -rf $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3
  247. rm -rf $(DEP_PATH)/zstd-1.4.5
  248. download: \
  249. $(DEP_PATH)/jansson-2.12 \
  250. $(DEP_PATH)/libarchive-3.4.3/.stamp-patched \
  251. $(DEP_PATH)/libsamplerate-0.1.9/.stamp-patched \
  252. $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3/.stamp-patched \
  253. $(DEP_PATH)/zstd-1.4.5/.stamp-patched
  254. quickjs: $(DEP_PATH)/lib/libquickjs.a
  255. # --------------------------------------------------------------