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.

284 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. if [ -n "${PAWPAW_SKIP_FORTIFY}" ] && [ "${PAWPAW_SKIP_FORTIFY}" -eq 1 ]; then
  141. FLAC_EXTRAFLAGS+=" --disable-stack-smash-protection"
  142. fi
  143. # force intrinsic optimizations on macos-universal target
  144. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  145. FLAC_EXTRAFLAGS+=" ac_cv_header_x86intrin_h=yes asm_opt=yes"
  146. fi
  147. download flac "${FLAC_VERSION}" "${FLAC_URL}" "tar.xz"
  148. # fixup for intrinsic optimizations on macos-universal target
  149. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  150. patch_file flac "${FLAC_VERSION}" "configure" 's/amd64|x86_64/amd64|arm|x86_64/'
  151. fi
  152. build_autoconf flac "${FLAC_VERSION}" "${FLAC_EXTRAFLAGS}"
  153. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  154. run_make flac "${FLAC_VERSION}" check
  155. fi
  156. # ---------------------------------------------------------------------------------------------------------------------
  157. # opus
  158. OPUS_EXTRAFLAGS="--enable-custom-modes --enable-float-approx"
  159. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  160. OPUS_EXTRAFLAGS+=" --disable-extra-programs"
  161. fi
  162. # FIXME macos-universal proper optimizations
  163. # https://github.com/DISTRHO/PawPaw/issues/4
  164. if [ "${MACOS_UNIVERSAL}" -eq 1 ] || [ "${WASM}" -eq 1 ]; then
  165. OPUS_EXTRAFLAGS+=" --disable-intrinsics"
  166. fi
  167. if [ -n "${PAWPAW_SKIP_FORTIFY}" ] && [ "${PAWPAW_SKIP_FORTIFY}" -eq 1 ]; then
  168. OPUS_EXTRAFLAGS+=" --disable-stack-protector"
  169. fi
  170. download opus "${OPUS_VERSION}" "${OPUS_URL}"
  171. build_autoconf opus "${OPUS_VERSION}" "${OPUS_EXTRAFLAGS}"
  172. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  173. run_make opus "${OPUS_VERSION}" check
  174. fi
  175. # ---------------------------------------------------------------------------------------------------------------------
  176. # libsndfile
  177. LIBSNDFILE_EXTRAFLAGS="--disable-alsa --disable-full-suite --disable-sqlite"
  178. # force disable mp3 support for now, until we handle those libs
  179. LIBSNDFILE_EXTRAFLAGS+=" --disable-mpeg"
  180. # force intrinsic optimizations on macos-universal target
  181. if [ "${MACOS_UNIVERSAL}" -eq 1 ] || [ "${WASM}" -eq 1 ]; then
  182. LIBSNDFILE_EXTRAFLAGS+=" ac_cv_header_immintrin_h=yes"
  183. fi
  184. # fix build, regex matching fails
  185. if [ "${WASM}" -eq 1 ]; then
  186. LIBSNDFILE_EXTRAFLAGS+=" ax_cv_c_compiler_version=15.0.0"
  187. LIBSNDFILE_EXTRAFLAGS+=" ax_cv_cxx_compiler_version=15.0.0"
  188. fi
  189. # otherwise tests fail
  190. export EXTRA_CFLAGS="-fno-associative-math -frounding-math"
  191. if [ "${CLANG}" -eq 1 ]; then
  192. export EXTRA_CFLAGS+=" -fno-reciprocal-math"
  193. else
  194. export EXTRA_CFLAGS+=" -fsignaling-nans"
  195. fi
  196. download libsndfile "${LIBSNDFILE_VERSION}" "${LIBSNDFILE_URL}" "tar.xz"
  197. build_autoconf libsndfile "${LIBSNDFILE_VERSION}" "${LIBSNDFILE_EXTRAFLAGS}"
  198. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  199. run_make libsndfile "${LIBSNDFILE_VERSION}" check
  200. fi
  201. # ---------------------------------------------------------------------------------------------------------------------
  202. # libsamplerate
  203. if [ -z "${PAWPAW_SKIP_SAMPLERATE}" ]; then
  204. LIBSAMPLERATE_EXTRAFLAGS="--disable-fftw"
  205. # NOTE: sndfile tests use Carbon, which is not always available on macOS
  206. if [ "${CROSS_COMPILING}" -eq 1 ] || [ "${MACOS}" -eq 1 ]; then
  207. LIBSAMPLERATE_EXTRAFLAGS+=" --disable-sndfile"
  208. fi
  209. download libsamplerate "${LIBSAMPLERATE_VERSION}" "${LIBSAMPLERATE_URL}"
  210. build_autoconf libsamplerate "${LIBSAMPLERATE_VERSION}" "${LIBSAMPLERATE_EXTRAFLAGS}"
  211. if [ "${CROSS_COMPILING}" -eq 0 ] && [ "${MACOS}" -eq 0 ]; then
  212. run_make libsamplerate "${LIBSAMPLERATE_VERSION}" check
  213. fi
  214. fi # PAWPAW_SKIP_SAMPLERATE
  215. # ---------------------------------------------------------------------------------------------------------------------
  216. # zlib (skipped on macOS)
  217. if [ "${MACOS}" -eq 0 ]; then
  218. git_clone zlib "${ZLIB_VERSION}" "${ZLIB_URL}"
  219. build_conf zlib "${ZLIB_VERSION}" "--static --prefix=${PAWPAW_PREFIX} --zprefix"
  220. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  221. run_make zlib "${ZLIB_VERSION}" check
  222. fi
  223. fi
  224. # ---------------------------------------------------------------------------------------------------------------------