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.

279 lines
8.3KB

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