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.

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