Cross-Platform build scripts for audio plugins
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.

330 lines
13KB

  1. #!/bin/bash
  2. set -e
  3. cd $(dirname ${0})
  4. PAWPAW_ROOT="${PWD}"
  5. # ---------------------------------------------------------------------------------------------------------------------
  6. # check target
  7. target="${1}"
  8. if [ -z "${target}" ]; then
  9. echo "usage: ${0} <target>"
  10. exit 1
  11. fi
  12. # ---------------------------------------------------------------------------------------------------------------------
  13. # source setup code
  14. source setup/check_target.sh
  15. source setup/env.sh
  16. source setup/functions.sh
  17. source setup/versions.sh
  18. # ---------------------------------------------------------------------------------------------------------------------
  19. # check for depedencies
  20. if ! command -v curl >/dev/null; then
  21. echo "missing 'curl' program, cannot continue!"
  22. exit 2
  23. fi
  24. if ! command -v make >/dev/null; then
  25. echo "missing 'make' program, cannot continue!"
  26. exit 2
  27. fi
  28. if ! command -v patch >/dev/null; then
  29. echo "missing 'patch' program, cannot continue!"
  30. exit 2
  31. fi
  32. if ! command -v python3 >/dev/null; then
  33. echo "missing 'python3' program, cannot continue!"
  34. exit 2
  35. fi
  36. if ! command -v sed >/dev/null; then
  37. echo "missing 'sed' program, cannot continue!"
  38. exit 2
  39. fi
  40. if ! command -v tar >/dev/null; then
  41. echo "missing 'tar' program, cannot continue!"
  42. exit 2
  43. fi
  44. if [ "${LINUX}" -eq 1 ] && ! command -v pkg-config >/dev/null; then
  45. echo "missing 'pkg-config' program, cannot continue!"
  46. exit 2
  47. fi
  48. if [ -z "${cmake}" ]; then
  49. echo "missing 'cmake' program, cannot continue!"
  50. exit 2
  51. fi
  52. # ---------------------------------------------------------------------------------------------------------------------
  53. # create common directories
  54. mkdir -p "${PAWPAW_BUILDDIR}"
  55. mkdir -p "${PAWPAW_DOWNLOADDIR}"
  56. mkdir -p "${PAWPAW_PREFIX}"
  57. mkdir -p "${PAWPAW_TMPDIR}"
  58. # ---------------------------------------------------------------------------------------------------------------------
  59. # let's use some native libs for linux builds
  60. if [ "${LINUX}" -eq 1 ]; then
  61. mkdir -p ${TARGET_PKG_CONFIG_PATH}
  62. if [ "${LINUX_TARGET}" = "linux-aarch64" ]; then
  63. export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig
  64. elif [ "${LINUX_TARGET}" = "linux-armhf" ]; then
  65. export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig
  66. elif [ "${LINUX_TARGET}" = "linux-i686" ]; then
  67. export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig
  68. elif [ "${LINUX_TARGET}" = "linux-riscv64" ]; then
  69. export PKG_CONFIG_PATH=/usr/lib/riscv64-linux-gnu/pkgconfig
  70. elif [ "${LINUX_TARGET}" = "linux-x86_64" ]; then
  71. export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
  72. fi
  73. if ! pkg-config --exists alsa dbus-1 gl glib-2.0 libpcre pthread-stubs uuid x11 xcb xcursor xext xfixes xproto xrandr xrender; then
  74. echo "some system libs are not available, cannot continue"
  75. exit 2
  76. fi
  77. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/alsa.pc" ]; then
  78. cp $(pkg-config --variable=pcfiledir alsa)/alsa.pc ${TARGET_PKG_CONFIG_PATH}/
  79. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/alsa.pc
  80. fi
  81. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/dbus-1.pc" ]; then
  82. cp $(pkg-config --variable=pcfiledir dbus-1)/dbus-1.pc ${TARGET_PKG_CONFIG_PATH}/
  83. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/dbus-1.pc
  84. fi
  85. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/gl.pc" ]; then
  86. cp $(pkg-config --variable=pcfiledir gl)/gl.pc ${TARGET_PKG_CONFIG_PATH}/
  87. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/gl.pc
  88. fi
  89. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/glib-2.0.pc" ]; then
  90. cp $(pkg-config --variable=pcfiledir glib-2.0)/g{io,lib,module,object,thread}-2.0.pc ${TARGET_PKG_CONFIG_PATH}/
  91. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/g{io,lib,module,object,thread}-2.0.pc
  92. fi
  93. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/libpcre.pc" ]; then
  94. cp $(pkg-config --variable=pcfiledir libpcre)/libpcre.pc ${TARGET_PKG_CONFIG_PATH}/
  95. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/libpcre.pc
  96. fi
  97. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/pthread-stubs.pc" ]; then
  98. cp $(pkg-config --variable=pcfiledir pthread-stubs)/pthread-stubs.pc ${TARGET_PKG_CONFIG_PATH}/
  99. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/pthread-stubs.pc
  100. fi
  101. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/uuid.pc" ]; then
  102. cp $(pkg-config --variable=pcfiledir uuid)/uuid.pc ${TARGET_PKG_CONFIG_PATH}/
  103. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/uuid.pc
  104. fi
  105. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/x11.pc" ]; then
  106. cp $(pkg-config --variable=pcfiledir x11)/x11.pc ${TARGET_PKG_CONFIG_PATH}/
  107. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/x11.pc
  108. fi
  109. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xcb.pc" ]; then
  110. cp $(pkg-config --variable=pcfiledir xcb)/{xau,xcb,xdmcp}.pc ${TARGET_PKG_CONFIG_PATH}/
  111. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/{xau,xcb,xdmcp}.pc
  112. fi
  113. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xcursor.pc" ]; then
  114. cp $(pkg-config --variable=pcfiledir xcursor)/xcursor.pc ${TARGET_PKG_CONFIG_PATH}/
  115. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xcursor.pc
  116. fi
  117. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xext.pc" ]; then
  118. cp $(pkg-config --variable=pcfiledir xext)/xext.pc ${TARGET_PKG_CONFIG_PATH}/
  119. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xext.pc
  120. fi
  121. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xfixes.pc" ]; then
  122. cp $(pkg-config --variable=pcfiledir xfixes)/xfixes.pc ${TARGET_PKG_CONFIG_PATH}/
  123. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xfixes.pc
  124. fi
  125. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xproto.pc" ]; then
  126. cp $(pkg-config --variable=pcfiledir xproto)/{fixesproto,kbproto,randrproto,renderproto,xextproto,xproto}.pc ${TARGET_PKG_CONFIG_PATH}/
  127. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/{fixesproto,kbproto,randrproto,renderproto,xextproto,xproto}.pc
  128. fi
  129. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xrandr.pc" ]; then
  130. cp $(pkg-config --variable=pcfiledir xrandr)/xrandr.pc ${TARGET_PKG_CONFIG_PATH}/
  131. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xrandr.pc
  132. fi
  133. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xrender.pc" ]; then
  134. cp $(pkg-config --variable=pcfiledir xrender)/xrender.pc ${TARGET_PKG_CONFIG_PATH}/
  135. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xrender.pc
  136. fi
  137. fi
  138. # ---------------------------------------------------------------------------------------------------------------------
  139. # pkgconfig
  140. download pkg-config "${PKG_CONFIG_VERSION}" "${PKG_CONFIG_URL}"
  141. build_host_autoconf pkg-config "${PKG_CONFIG_VERSION}" "--enable-indirect-deps --with-internal-glib --with-pc-path=${TARGET_PKG_CONFIG_PATH}"
  142. if [ -n "${TOOLCHAIN_PREFIX_}" ] && [ ! -e "${PAWPAW_PREFIX}/bin/${TOOLCHAIN_PREFIX_}pkg-config" ]; then
  143. ln -s pkg-config "${PAWPAW_PREFIX}/bin/${TOOLCHAIN_PREFIX_}pkg-config"
  144. fi
  145. # ---------------------------------------------------------------------------------------------------------------------
  146. # libogg
  147. download libogg "${LIBOGG_VERSION}" "${LIBOGG_URL}"
  148. build_autoconf libogg "${LIBOGG_VERSION}"
  149. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  150. run_make libogg "${LIBOGG_VERSION}" "check -j 1"
  151. fi
  152. # ---------------------------------------------------------------------------------------------------------------------
  153. # libvorbis
  154. LIBVORBIS_EXTRAFLAGS="--disable-examples"
  155. download libvorbis "${LIBVORBIS_VERSION}" "${LIBVORBIS_URL}"
  156. build_autoconf libvorbis "${LIBVORBIS_VERSION}" "${LIBVORBIS_EXTRAFLAGS}"
  157. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  158. run_make libvorbis "${LIBVORBIS_VERSION}" "check -j 1"
  159. fi
  160. # ---------------------------------------------------------------------------------------------------------------------
  161. # flac
  162. FLAC_EXTRAFLAGS=""
  163. FLAC_EXTRAFLAGS+=" --disable-doxygen-docs"
  164. FLAC_EXTRAFLAGS+=" --disable-examples"
  165. FLAC_EXTRAFLAGS+=" --disable-stack-smash-protection"
  166. FLAC_EXTRAFLAGS+=" --disable-thorough-tests"
  167. FLAC_EXTRAFLAGS+=" --disable-xmms-plugin"
  168. if [ -n "${PAWPAW_NOSIMD}" ] && [ "${PAWPAW_NOSIMD}" -ne 0 ]; then
  169. FLAC_EXTRAFLAGS+=" ac_cv_header_x86intrin_h=no ac_cv_header_arm_neon_h=no asm_opt=no"
  170. elif [ "${MACOS_UNIVERSAL}" -eq 1 ] || [ "${WASM}" -eq 1 ]; then
  171. # FIXME
  172. FLAC_EXTRAFLAGS+=" ac_cv_header_x86intrin_h=no ac_cv_header_arm_neon_h=no asm_opt=no"
  173. else
  174. # force intrinsic optimizations on targets where auto-detection fails
  175. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  176. FLAC_EXTRAFLAGS+=" ac_cv_header_x86intrin_h=yes ac_cv_header_arm_neon_h=yes asm_opt=yes"
  177. elif [ "${WASM}" -eq 1 ]; then
  178. FLAC_EXTRAFLAGS+=" ac_cv_header_x86intrin_h=yes asm_opt=yes"
  179. fi
  180. fi
  181. download flac "${FLAC_VERSION}" "${FLAC_URL}" "tar.xz"
  182. build_autoconf flac "${FLAC_VERSION}" "${FLAC_EXTRAFLAGS}"
  183. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  184. run_make flac "${FLAC_VERSION}" "check -j 1"
  185. fi
  186. # ---------------------------------------------------------------------------------------------------------------------
  187. # opus
  188. OPUS_EXTRAFLAGS="--enable-custom-modes --enable-float-approx"
  189. OPUS_EXTRAFLAGS+=" --disable-stack-protector"
  190. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  191. OPUS_EXTRAFLAGS+=" --disable-extra-programs"
  192. fi
  193. if [ -n "${PAWPAW_NOSIMD}" ] && [ "${PAWPAW_NOSIMD}" -ne 0 ]; then
  194. OPUS_EXTRAFLAGS+=" --disable-intrinsics"
  195. # FIXME macos-universal proper optimizations https://github.com/DISTRHO/PawPaw/issues/4
  196. elif [ "${MACOS_UNIVERSAL}" -eq 1 ] || [ "${WASM}" -eq 1 ]; then
  197. OPUS_EXTRAFLAGS+=" --disable-intrinsics"
  198. fi
  199. download opus "${OPUS_VERSION}" "${OPUS_URL}"
  200. build_autoconf opus "${OPUS_VERSION}" "${OPUS_EXTRAFLAGS}"
  201. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  202. run_make opus "${OPUS_VERSION}" check
  203. fi
  204. # ---------------------------------------------------------------------------------------------------------------------
  205. # libsndfile
  206. LIBSNDFILE_EXTRAFLAGS="--disable-alsa --disable-full-suite --disable-sqlite"
  207. # force disable mp3 support for now, until we handle those libs
  208. LIBSNDFILE_EXTRAFLAGS+=" --disable-mpeg"
  209. # force intrinsic optimizations on some targets
  210. if [ -z "${PAWPAW_NOSIMD}" ] || [ "${PAWPAW_NOSIMD}" -eq 0 ]; then
  211. if [ "${MACOS_UNIVERSAL}" -eq 1 ] || [ "${WASM}" -eq 1 ]; then
  212. LIBSNDFILE_EXTRAFLAGS+=" ac_cv_header_immintrin_h=yes"
  213. fi
  214. fi
  215. # fix build, regex matching fails
  216. if [ "${WASM}" -eq 1 ]; then
  217. LIBSNDFILE_EXTRAFLAGS+=" ax_cv_c_compiler_version=15.0.0"
  218. LIBSNDFILE_EXTRAFLAGS+=" ax_cv_cxx_compiler_version=15.0.0"
  219. fi
  220. # otherwise tests fail
  221. export EXTRA_CFLAGS="-fno-associative-math -frounding-math"
  222. if [ "${CLANG}" -eq 1 ]; then
  223. export EXTRA_CFLAGS+=" -fno-reciprocal-math"
  224. else
  225. export EXTRA_CFLAGS+=" -fsignaling-nans"
  226. fi
  227. download libsndfile "${LIBSNDFILE_VERSION}" "${LIBSNDFILE_URL}" "tar.xz"
  228. build_autoconf libsndfile "${LIBSNDFILE_VERSION}" "${LIBSNDFILE_EXTRAFLAGS}"
  229. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  230. run_make libsndfile "${LIBSNDFILE_VERSION}" check
  231. fi
  232. # ---------------------------------------------------------------------------------------------------------------------
  233. # libsamplerate
  234. if [ -z "${PAWPAW_SKIP_SAMPLERATE}" ]; then
  235. LIBSAMPLERATE_EXTRAFLAGS="--disable-fftw"
  236. # NOTE: sndfile tests use Carbon, which is not always available on macOS
  237. if [ "${CROSS_COMPILING}" -eq 1 ] || [ "${MACOS}" -eq 1 ]; then
  238. LIBSAMPLERATE_EXTRAFLAGS+=" --disable-sndfile"
  239. fi
  240. download libsamplerate "${LIBSAMPLERATE_VERSION}" "${LIBSAMPLERATE_URL}"
  241. build_autoconf libsamplerate "${LIBSAMPLERATE_VERSION}" "${LIBSAMPLERATE_EXTRAFLAGS}"
  242. if [ "${CROSS_COMPILING}" -eq 0 ] && [ "${MACOS}" -eq 0 ]; then
  243. run_make libsamplerate "${LIBSAMPLERATE_VERSION}" check
  244. fi
  245. fi # PAWPAW_SKIP_SAMPLERATE
  246. # ---------------------------------------------------------------------------------------------------------------------
  247. # zlib (skipped on macOS)
  248. if [ "${MACOS}" -eq 0 ]; then
  249. git_clone zlib "${ZLIB_VERSION}" "${ZLIB_URL}"
  250. build_conf zlib "${ZLIB_VERSION}" "--static --prefix=${PAWPAW_PREFIX} --zprefix"
  251. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  252. run_make zlib "${ZLIB_VERSION}" check
  253. fi
  254. fi
  255. # ---------------------------------------------------------------------------------------------------------------------
  256. # mingw-std-threads (download, win32 only)
  257. if [ "${WIN32}" -eq 1 ]; then
  258. git_clone mingw-std-threads "${MINGW_STD_THREADS_VERSION}" "${MINGW_STD_THREADS_URL}"
  259. if [ ! -e "${PAWPAW_BUILDDIR}/mingw-std-threads-${MINGW_STD_THREADS_VERSION}/.stamp-installed" ]; then
  260. install -m 644 "${PAWPAW_BUILDDIR}/mingw-std-threads-${MINGW_STD_THREADS_VERSION}"/mingw.*.h "${PAWPAW_PREFIX}/include/"
  261. install -m 644 "${PAWPAW_ROOT}/mingw-compat"/* "${PAWPAW_PREFIX}/include/"
  262. touch "${PAWPAW_BUILDDIR}/mingw-std-threads-${MINGW_STD_THREADS_VERSION}/.stamp-installed"
  263. fi
  264. fi
  265. # ---------------------------------------------------------------------------------------------------------------------