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.

325 lines
9.8KB

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