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.

273 lines
7.9KB

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