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.

280 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 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}/x11.pc" ]; then
  79. cp $(pkg-config --variable=pcfiledir x11)/x11.pc ${TARGET_PKG_CONFIG_PATH}/
  80. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/x11.pc
  81. fi
  82. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xcb.pc" ]; then
  83. cp $(pkg-config --variable=pcfiledir xcb)/{xau,xcb,xdmcp}.pc ${TARGET_PKG_CONFIG_PATH}/
  84. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/{xau,xcb,xdmcp}.pc
  85. fi
  86. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xcursor.pc" ]; then
  87. cp $(pkg-config --variable=pcfiledir xcursor)/xcursor.pc ${TARGET_PKG_CONFIG_PATH}/
  88. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xcursor.pc
  89. fi
  90. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xext.pc" ]; then
  91. cp $(pkg-config --variable=pcfiledir xext)/xext.pc ${TARGET_PKG_CONFIG_PATH}/
  92. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xext.pc
  93. fi
  94. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xfixes.pc" ]; then
  95. cp $(pkg-config --variable=pcfiledir xfixes)/xfixes.pc ${TARGET_PKG_CONFIG_PATH}/
  96. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xfixes.pc
  97. fi
  98. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xproto.pc" ]; then
  99. cp $(pkg-config --variable=pcfiledir xproto)/{fixesproto,kbproto,randrproto,renderproto,xextproto,xproto}.pc ${TARGET_PKG_CONFIG_PATH}/
  100. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/{fixesproto,kbproto,randrproto,renderproto,xextproto,xproto}.pc
  101. fi
  102. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xrandr.pc" ]; then
  103. cp $(pkg-config --variable=pcfiledir xrandr)/xrandr.pc ${TARGET_PKG_CONFIG_PATH}/
  104. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xrandr.pc
  105. fi
  106. if [ ! -e "${TARGET_PKG_CONFIG_PATH}/xrender.pc" ]; then
  107. cp $(pkg-config --variable=pcfiledir xrender)/xrender.pc ${TARGET_PKG_CONFIG_PATH}/
  108. sed -i '/Libs.private/d' ${TARGET_PKG_CONFIG_PATH}/xrender.pc
  109. fi
  110. fi
  111. # ---------------------------------------------------------------------------------------------------------------------
  112. # pkgconfig
  113. download pkg-config "${PKG_CONFIG_VERSION}" "${PKG_CONFIG_URL}"
  114. build_host_autoconf pkg-config "${PKG_CONFIG_VERSION}" "--enable-indirect-deps --with-internal-glib --with-pc-path=${TARGET_PKG_CONFIG_PATH}"
  115. if [ "${CROSS_COMPILING}" -eq 1 ] && [ ! -e "${PAWPAW_PREFIX}/bin/${TOOLCHAIN_PREFIX_}pkg-config" ]; then
  116. ln -s pkg-config "${PAWPAW_PREFIX}/bin/${TOOLCHAIN_PREFIX_}pkg-config"
  117. fi
  118. # ---------------------------------------------------------------------------------------------------------------------
  119. # libogg
  120. download libogg "${LIBOGG_VERSION}" "${LIBOGG_URL}"
  121. build_autoconf libogg "${LIBOGG_VERSION}"
  122. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  123. run_make libogg "${LIBOGG_VERSION}" "check -j 1"
  124. fi
  125. # ---------------------------------------------------------------------------------------------------------------------
  126. # libvorbis
  127. LIBVORBIS_EXTRAFLAGS="--disable-examples"
  128. download libvorbis "${LIBVORBIS_VERSION}" "${LIBVORBIS_URL}"
  129. build_autoconf libvorbis "${LIBVORBIS_VERSION}" "${LIBVORBIS_EXTRAFLAGS}"
  130. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  131. run_make libvorbis "${LIBVORBIS_VERSION}" "check -j 1"
  132. fi
  133. # ---------------------------------------------------------------------------------------------------------------------
  134. # flac
  135. FLAC_EXTRAFLAGS="--disable-doxygen-docs --disable-examples --disable-thorough-tests --disable-xmms-plugin"
  136. if [ -n "${PAWPAW_SKIP_FORTIFY}" ] && [ "${PAWPAW_SKIP_FORTIFY}" -eq 1 ]; then
  137. FLAC_EXTRAFLAGS+=" --disable-stack-smash-protection"
  138. fi
  139. # force intrinsic optimizations on macos-universal target
  140. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  141. FLAC_EXTRAFLAGS+=" ac_cv_header_x86intrin_h=yes asm_opt=yes"
  142. fi
  143. download flac "${FLAC_VERSION}" "${FLAC_URL}" "tar.xz"
  144. # fixup for intrinsic optimizations on macos-universal target
  145. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  146. patch_file flac "${FLAC_VERSION}" "configure" 's/amd64|x86_64/amd64|arm|x86_64/'
  147. fi
  148. build_autoconf flac "${FLAC_VERSION}" "${FLAC_EXTRAFLAGS}"
  149. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  150. run_make flac "${FLAC_VERSION}" check
  151. fi
  152. # ---------------------------------------------------------------------------------------------------------------------
  153. # opus
  154. OPUS_EXTRAFLAGS="--enable-custom-modes --enable-float-approx"
  155. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  156. OPUS_EXTRAFLAGS+=" --disable-extra-programs"
  157. fi
  158. # FIXME macos-universal proper optimizations
  159. # https://github.com/DISTRHO/PawPaw/issues/4
  160. if [ "${MACOS_UNIVERSAL}" -eq 1 ] || [ "${WASM}" -eq 1 ]; then
  161. OPUS_EXTRAFLAGS+=" --disable-intrinsics"
  162. fi
  163. if [ -n "${PAWPAW_SKIP_FORTIFY}" ] && [ "${PAWPAW_SKIP_FORTIFY}" -eq 1 ]; then
  164. OPUS_EXTRAFLAGS+=" --disable-stack-protector"
  165. fi
  166. download opus "${OPUS_VERSION}" "${OPUS_URL}"
  167. build_autoconf opus "${OPUS_VERSION}" "${OPUS_EXTRAFLAGS}"
  168. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  169. run_make opus "${OPUS_VERSION}" check
  170. fi
  171. # ---------------------------------------------------------------------------------------------------------------------
  172. # libsndfile
  173. LIBSNDFILE_EXTRAFLAGS="--disable-alsa --disable-full-suite --disable-sqlite"
  174. # force disable mp3 support for now, until we handle those libs
  175. LIBSNDFILE_EXTRAFLAGS+=" --disable-mpeg"
  176. # force intrinsic optimizations on macos-universal target
  177. if [ "${MACOS_UNIVERSAL}" -eq 1 ] || [ "${WASM}" -eq 1 ]; then
  178. LIBSNDFILE_EXTRAFLAGS+=" ac_cv_header_immintrin_h=yes"
  179. fi
  180. # fix build, regex matching fails
  181. if [ "${WASM}" -eq 1 ]; then
  182. LIBSNDFILE_EXTRAFLAGS+=" ax_cv_c_compiler_version=15.0.0"
  183. LIBSNDFILE_EXTRAFLAGS+=" ax_cv_cxx_compiler_version=15.0.0"
  184. fi
  185. # otherwise tests fail
  186. export EXTRA_CFLAGS="-fno-associative-math -frounding-math"
  187. if [ "${CLANG}" -eq 1 ]; then
  188. export EXTRA_CFLAGS+=" -fno-reciprocal-math"
  189. else
  190. export EXTRA_CFLAGS+=" -fsignaling-nans"
  191. fi
  192. download libsndfile "${LIBSNDFILE_VERSION}" "${LIBSNDFILE_URL}" "tar.xz"
  193. build_autoconf libsndfile "${LIBSNDFILE_VERSION}" "${LIBSNDFILE_EXTRAFLAGS}"
  194. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  195. run_make libsndfile "${LIBSNDFILE_VERSION}" check
  196. fi
  197. # ---------------------------------------------------------------------------------------------------------------------
  198. # libsamplerate
  199. if [ -z "${PAWPAW_SKIP_SAMPLERATE}" ]; then
  200. LIBSAMPLERATE_EXTRAFLAGS="--disable-fftw"
  201. # NOTE: sndfile tests use Carbon, which is not always available on macOS
  202. if [ "${CROSS_COMPILING}" -eq 1 ] || [ "${MACOS}" -eq 1 ]; then
  203. LIBSAMPLERATE_EXTRAFLAGS+=" --disable-sndfile"
  204. fi
  205. download libsamplerate "${LIBSAMPLERATE_VERSION}" "${LIBSAMPLERATE_URL}"
  206. build_autoconf libsamplerate "${LIBSAMPLERATE_VERSION}" "${LIBSAMPLERATE_EXTRAFLAGS}"
  207. if [ "${CROSS_COMPILING}" -eq 0 ] && [ "${MACOS}" -eq 0 ]; then
  208. run_make libsamplerate "${LIBSAMPLERATE_VERSION}" check
  209. fi
  210. fi # PAWPAW_SKIP_SAMPLERATE
  211. # ---------------------------------------------------------------------------------------------------------------------
  212. # zlib (skipped on macOS)
  213. if [ "${MACOS}" -eq 0 ]; then
  214. git_clone zlib "${ZLIB_VERSION}" "${ZLIB_URL}"
  215. build_conf zlib "${ZLIB_VERSION}" "--static --prefix=${PAWPAW_PREFIX}"
  216. if [ "${CROSS_COMPILING}" -eq 0 ]; then
  217. run_make zlib "${ZLIB_VERSION}" check
  218. fi
  219. fi
  220. # ---------------------------------------------------------------------------------------------------------------------