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.

211 lines
6.4KB

  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. ifeq ($(WITH_LTO),true)
  28. BASE_FLAGS += -fno-strict-aliasing -flto -ffat-lto-objects
  29. LINK_FLAGS += -fno-strict-aliasing -flto -ffat-lto-objects -Werror=odr -Werror=lto-type-mismatch
  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 += CFLAGS="$(BUILD_C_FLAGS)"
  101. DEP_MAKE += CXXFLAGS="$(BUILD_CXX_FLAGS)"
  102. DEP_MAKE += LDFLAGS="$(LINK_FLAGS)"
  103. DEP_MAKE += CMAKE="$(CMAKE)"
  104. DEP_MAKE += CONFIGURE="$(CONFIGURE)"
  105. DEP_MAKE += DEP_FLAGS="$(BASE_FLAGS)"
  106. DEP_MAKE += DEP_MAC_SDK_FLAGS=
  107. DEP_MAKE += MACHINE=$(MACHINE)$(MACHINE_SUFFIX)
  108. # --------------------------------------------------------------
  109. # VCV internal dependencies target
  110. $(DEP_PATH)/lib/%.a:
  111. $(DEP_MAKE) -C $(DEP_PATH) lib/$*.a
  112. # libarchive: skip shared lib and ensure libzstd is enabled
  113. $(DEP_PATH)/lib/libarchive.a: $(DEP_PATH)/lib/libzstd.a $(DEP_PATH)/libarchive-3.4.3/.stamp-patched
  114. $(DEP_PATH)/lib/libarchive_static.a: $(DEP_PATH)/lib/libzstd.a $(DEP_PATH)/libarchive-3.4.3/.stamp-patched
  115. $(DEP_PATH)/libarchive-3.4.3/.stamp-patched:
  116. $(DEP_MAKE) -C $(DEP_PATH) libarchive-3.4.3
  117. sed -i -e "618,625d" $(DEP_PATH)/libarchive-3.4.3/CMakeLists.txt
  118. 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
  119. mv $(DEP_PATH)/libarchive-3.4.3/CMakeLists.txt2 $(DEP_PATH)/libarchive-3.4.3/CMakeLists.txt
  120. sed -i -e "238,243d" $(DEP_PATH)/libarchive-3.4.3/libarchive/CMakeLists.txt
  121. sed -i -e "s/TARGETS archive archive_static/TARGETS archive_static/" $(DEP_PATH)/libarchive-3.4.3/libarchive/CMakeLists.txt
  122. touch $@
  123. # libsamplerate: skip tests, fails to build in some systems and are not needed or wanted anyway
  124. $(DEP_PATH)/lib/libsamplerate.a: $(DEP_PATH)/libsamplerate-0.1.9/.stamp-patched
  125. $(DEP_PATH)/libsamplerate-0.1.9/.stamp-patched:
  126. $(DEP_MAKE) -C $(DEP_PATH) libsamplerate-0.1.9
  127. sed -i -e "s/src doc examples tests/src/" $(DEP_PATH)/libsamplerate-0.1.9/Makefile.in
  128. touch $@
  129. # libspeexdsp: hide symbols
  130. $(DEP_PATH)/lib/libspeexdsp.a: $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3/.stamp-patched
  131. $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3/.stamp-patched:
  132. $(DEP_MAKE) -C $(DEP_PATH) speexdsp-SpeexDSP-1.2rc3
  133. sed -i -e "s/#pragma GCC visibility push/#error we dont want this/" $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3/configure
  134. touch $@
  135. # zstd cmake is borked, see https://github.com/facebook/zstd/issues/1401
  136. # zstd also fails to build on old systems, patch that too
  137. $(DEP_PATH)/lib/libzstd.a: $(DEP_PATH)/zstd-1.4.5/.stamp-patched
  138. $(DEP_PATH)/zstd-1.4.5/.stamp-patched:
  139. $(DEP_MAKE) -C $(DEP_PATH) zstd-1.4.5
  140. sed -i -e "56,66d" $(DEP_PATH)/zstd-1.4.5/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
  141. sed -i -e "146,175d" $(DEP_PATH)/zstd-1.4.5/programs/util.c
  142. sed -i -e "142,144d" $(DEP_PATH)/zstd-1.4.5/programs/util.c
  143. touch $@
  144. # --------------------------------------------------------------
  145. # Build targets
  146. TARGETS += $(DEP_PATH)/lib/libjansson.a
  147. TARGETS += $(DEP_PATH)/lib/libsamplerate.a
  148. TARGETS += $(DEP_PATH)/lib/libspeexdsp.a
  149. ifeq ($(WINDOWS),true)
  150. TARGETS += $(DEP_PATH)/lib/libarchive_static.a
  151. else
  152. TARGETS += $(DEP_PATH)/lib/libarchive.a
  153. endif
  154. TARGETS += $(DEP_PATH)/lib/libzstd.a
  155. all: $(TARGETS)
  156. clean:
  157. rm -f $(TARGETS)
  158. rm -f $(DEP_PATH)/*.tgz
  159. rm -f $(DEP_PATH)/*.tar.gz
  160. rm -rf $(DEP_PATH)/bin
  161. rm -rf $(DEP_PATH)/include
  162. rm -rf $(DEP_PATH)/lib
  163. rm -rf $(DEP_PATH)/share
  164. rm -rf $(DEP_PATH)/jansson-2.12
  165. rm -rf $(DEP_PATH)/libarchive-3.4.3
  166. rm -rf $(DEP_PATH)/libsamplerate-0.1.9
  167. rm -rf $(DEP_PATH)/speexdsp-SpeexDSP-1.2rc3
  168. rm -rf $(DEP_PATH)/zstd-1.4.5
  169. # --------------------------------------------------------------