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.

289 lines
8.7KB

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