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.

298 lines
9.0KB

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