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.

246 lines
7.3KB

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