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.

293 lines
11KB

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