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.

334 lines
12KB

  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. # run bootstrap dependencies
  14. ./bootstrap-common.sh "${target}"
  15. # ---------------------------------------------------------------------------------------------------------------------
  16. # source setup code
  17. source setup/check_target.sh
  18. source setup/env.sh
  19. source setup/functions.sh
  20. source setup/versions.sh
  21. # ---------------------------------------------------------------------------------------------------------------------
  22. # check for depedencies
  23. if [ "${LINUX}" -eq 1 ] && ! command -v patchelf >/dev/null; then
  24. echo "missing 'patchelf' program, cannot continue!"
  25. exit 2
  26. fi
  27. # ---------------------------------------------------------------------------------------------------------------------
  28. # wine bootstrap for python (needed for cross-compilation)
  29. if [ "${WIN32}" -eq 1 ] && [ -n "${EXE_WRAPPER}" ] && [ ! -d "${WINEPREFIX}" ]; then
  30. wineboot -u
  31. fi
  32. # ---------------------------------------------------------------------------------------------------------------------
  33. # custom function for openssl
  34. function build_conf_openssl() {
  35. local name="${1}"
  36. local version="${2}"
  37. local extraconfrules="${3}"
  38. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  39. local extraflags=""
  40. if [ -n "${TOOLCHAIN_PREFIX}" ]; then
  41. if [ "${WIN64}" -eq 1 ]; then
  42. export MACHINE="x86_64"
  43. export SYSTEM="mingw64"
  44. extraflags="-Wa,-mbig-obj"
  45. elif [ "${WIN32}" -eq 1 ]; then
  46. export MACHINE="i686"
  47. export SYSTEM="mingw"
  48. elif [ -n "${LINUX_TARGET}" ]; then
  49. if [ "${LINUX_TARGET}" = "linux-armhf" ]; then
  50. export MACHINE="armv4"
  51. elif [ "${LINUX_TARGET}" = "linux-aarch64" ]; then
  52. export MACHINE="aarch64"
  53. elif [ "${LINUX_TARGET}" = "linux-i686" ]; then
  54. export MACHINE="i686"
  55. elif [ "${LINUX_TARGET}" = "linux-riscv64" ]; then
  56. export MACHINE="riscv64"
  57. elif [ "${LINUX_TARGET}" = "linux-x86_64" ]; then
  58. export MACHINE="x86_64"
  59. else
  60. export MACHINE="$(uname -m)"
  61. fi
  62. export SYSTEM="linux2"
  63. fi
  64. export RELEASE="whatever"
  65. export BUILD="unknown"
  66. elif [ "${MACOS_UNIVERSAL}" -eq 0 ] && [ "$(uname -m)" != "x86_64" ]; then
  67. export MACHINE="x86_64"
  68. fi
  69. _prebuild "${name}" "${pkgdir}"
  70. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  71. pushd "${pkgdir}"
  72. ./config --prefix="${PAWPAW_PREFIX}" ${extraconfrules} CFLAGS="${TARGET_CFLAGS} ${extraflags}"
  73. touch .stamp_configured
  74. popd
  75. fi
  76. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  77. pushd "${pkgdir}"
  78. make ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}
  79. touch .stamp_built
  80. popd
  81. fi
  82. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  83. pushd "${pkgdir}"
  84. make ${MAKE_ARGS} install_sw -j 1
  85. touch .stamp_installed
  86. popd
  87. fi
  88. if [ -n "${TOOLCHAIN_PREFIX}" ]; then
  89. unset MACHINE
  90. unset SYSTEM
  91. unset RELEASE
  92. unset BUILD
  93. fi
  94. _postbuild
  95. }
  96. # ---------------------------------------------------------------------------------------------------------------------
  97. # openssl
  98. if [ -z "${PAWPAW_SKIP_OPENSSL}" ]; then
  99. OPENSSL_URL="https://www.openssl.org/source"
  100. OPENSSL_VERSION="1.1.1w"
  101. OPENSSL_EXTRAFLAGS="no-capieng no-pinshared no-shared no-hw no-zlib threads"
  102. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  103. OPENSSL_EXTRAFLAGS+=" no-asm"
  104. fi
  105. download openssl "${OPENSSL_VERSION}" "${OPENSSL_URL}"
  106. build_conf_openssl openssl "${OPENSSL_VERSION}" "${OPENSSL_EXTRAFLAGS}"
  107. fi # PAWPAW_SKIP_OPENSSL
  108. # ---------------------------------------------------------------------------------------------------------------------
  109. # custom function for python
  110. function build_conf_python() {
  111. local name="${1}"
  112. local version="${2}"
  113. local extraconfrules="${3}"
  114. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  115. if [ -n "${TOOLCHAIN_PREFIX}" ]; then
  116. extraconfrules+=" --host=${TOOLCHAIN_PREFIX} --build=$(gcc -dumpmachine)"
  117. fi
  118. _prebuild "${name}" "${pkgdir}"
  119. # remove flags not compatible with python
  120. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fvisibility=hidden//')"
  121. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-ffast-math//')"
  122. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  123. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fno-strict-aliasing -flto//')"
  124. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-dead_strip,-dead_strip_dylibs,-x//')"
  125. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,--gc-sections,--no-undefined//')"
  126. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-O1//')"
  127. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,--as-needed,--strip-all//')"
  128. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  129. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fno-strict-aliasing -flto//')"
  130. # add host/native binaries to path
  131. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  132. export PATH="${PAWPAW_PREFIX}-host/bin:${PATH}"
  133. fi
  134. if [ "${WIN32}" -eq 1 ] && [ ! -f "${pkgdir}/.stamp_preconfigured" ]; then
  135. pushd "${pkgdir}"
  136. autoreconf -vfi
  137. touch .stamp_preconfigured
  138. popd
  139. fi
  140. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  141. pushd "${pkgdir}"
  142. ./configure ${extraconfrules}
  143. touch .stamp_configured
  144. popd
  145. fi
  146. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  147. pushd "${pkgdir}"
  148. # if [ "${WIN32}" -eq 1 ]; then
  149. # # inject exe-wrapper
  150. # if [ -n "${EXE_WRAPPER}" ]; then
  151. # sed -i -e "s|\t./Programs/_freeze_importlib|\t${EXE_WRAPPER} ./Programs/_freeze_importlib|" Makefile
  152. # fi
  153. # make regen-importlib
  154. # fi
  155. make ${MAKE_ARGS}
  156. touch .stamp_built
  157. popd
  158. fi
  159. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  160. pushd "${pkgdir}"
  161. make ${MAKE_ARGS} -j 1 install
  162. touch .stamp_installed
  163. popd
  164. fi
  165. _postbuild
  166. }
  167. # ---------------------------------------------------------------------------------------------------------------------
  168. # python
  169. # build for host first
  170. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  171. download host-Python "${PYTHON_VERSION}" "https://www.python.org/ftp/python/${PYTHON_VERSION}" "tgz" "" Python
  172. build_host_autoconf host-Python "${PYTHON_VERSION}" "--build=$(gcc -dumpmachine) --prefix=${PAWPAW_PREFIX}-host"
  173. # sed -i -e "s|${PAWPAW_PREFIX}-host|${PAWPAW_PREFIX}|" "${PAWPAW_PREFIX}-host/bin/python3.8-config"
  174. # # FIXME
  175. # mkdir -p "${PAWPAW_PREFIX}-host/lib/python3.8/config-3.8-x86_64-linux-gnu/Tools"
  176. # ln -sf "${PAWPAW_PREFIX}-host/bin" "${PAWPAW_PREFIX}-host/lib/python3.8/config-3.8-x86_64-linux-gnu/Tools/scripts"
  177. # # may be available in host, but not in build target
  178. # if [ "${WIN32}" -eq 1 ] && [ ! -e "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h-e" ]; then
  179. # sed -i -e '/HAVE_CRYPT_H/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  180. # sed -i -e '/HAVE_CRYPT_R/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  181. # sed -i -e '/HAVE_SYS_SELECT_H/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  182. # touch "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h-e"
  183. # fi
  184. fi
  185. PYTHON_EXTRAFLAGS=""
  186. if [ "${MACOS}" -eq 1 ]; then
  187. PYTHON_EXTRAFLAGS+=" --enable-optimizations"
  188. PYTHON_EXTRAFLAGS+=" ac_cv_lib_intl_textdomain=no"
  189. PYTHON_EXTRAFLAGS+=" ac_cv_header_libintl_h=no"
  190. PYTHON_EXTRAFLAGS+=" ac_cv_func_setlocale=no"
  191. PYTHON_EXTRAFLAGS+=" ac_cv_func_futimens=no"
  192. PYTHON_EXTRAFLAGS+=" ac_cv_func_preadv=no"
  193. PYTHON_EXTRAFLAGS+=" ac_cv_func_pwritev=no"
  194. PYTHON_EXTRAFLAGS+=" ac_cv_func_sendfile=no"
  195. PYTHON_EXTRAFLAGS+=" ac_cv_func_utimensat=no"
  196. elif [ "${WIN32}" -eq 1 ]; then
  197. export EXTRA_CFLAGS=" -fwrapv -D_WIN32_WINNT=0x0601"
  198. export EXTRA_CXXFLAGS=" -fwrapv -D_WIN32_WINNT=0x0601"
  199. PYTHON_EXTRAFLAGS+=" --with-nt-threads"
  200. PYTHON_EXTRAFLAGS+=" --without-ensurepip"
  201. PYTHON_EXTRAFLAGS+=" --without-c-locale-coercion"
  202. # Workaround for conftest error on 64-bit builds
  203. PYTHON_EXTRAFLAGS+=" ac_cv_working_tzset=no"
  204. # Workaround for when dlfcn exists on Windows, which causes
  205. # some conftests to succeed when they shouldn't (we don't use dlfcn).
  206. PYTHON_EXTRAFLAGS+=" ac_cv_header_dlfcn_h=no"
  207. PYTHON_EXTRAFLAGS+=" ac_cv_lib_dl_dlopen=no"
  208. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_GLOBAL=no"
  209. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_LAZY=no"
  210. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_LOCAL=no"
  211. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NOW=no"
  212. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_DEEPBIND=no"
  213. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_MEMBER=no"
  214. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NODELETE=no"
  215. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NOLOAD=no"
  216. elif [ "${CROSS_COMPILING}" -eq 1 ]; then
  217. PYTHON_EXTRAFLAGS+=" --disable-ipv6"
  218. PYTHON_EXTRAFLAGS+=" ac_cv_file__dev_ptc=no"
  219. PYTHON_EXTRAFLAGS+=" ac_cv_file__dev_ptmx=no"
  220. fi
  221. download Python "${PYTHON_VERSION}" "https://www.python.org/ftp/python/${PYTHON_VERSION}" "tgz"
  222. if [ "${PYTHON_VERSION}" = "3.7.4" ]; then
  223. patch_file Python "${PYTHON_VERSION}" "Modules/Setup.dist" 's/#zlib zlibmodule.c/zlib zlibmodule.c/'
  224. fi
  225. build_conf_python Python "${PYTHON_VERSION}" "--prefix=${PAWPAW_PREFIX} --enable-shared ${PYTHON_EXTRAFLAGS}"
  226. # ---------------------------------------------------------------------------------------------------------------------
  227. # cython (optional)
  228. if [ -n "${CYTHON_VERSION}" ]; then
  229. download Cython "${CYTHON_VERSION}" "https://files.pythonhosted.org/packages/6c/9f/f501ba9d178aeb1f5bf7da1ad5619b207c90ac235d9859961c11829d0160"
  230. build_python Cython "${CYTHON_VERSION}"
  231. fi
  232. # ---------------------------------------------------------------------------------------------------------------------
  233. # setuptools_scm (optional)
  234. if [ -n "${SETUPTOOLS_SCM_VERSION}" ]; then
  235. download setuptools_scm "${SETUPTOOLS_SCM_VERSION}" "https://files.pythonhosted.org/packages/ed/b6/979bfa7b81878b2b4475dde092aac517e7f25dd33661796ec35664907b31"
  236. build_python setuptools_scm "${SETUPTOOLS_SCM_VERSION}"
  237. fi
  238. # ---------------------------------------------------------------------------------------------------------------------
  239. # toml (optional)
  240. if [ -n "${TOML_VERSION}" ]; then
  241. download toml "${TOML_VERSION}" "https://files.pythonhosted.org/packages/be/ba/1f744cdc819428fc6b5084ec34d9b30660f6f9daaf70eead706e3203ec3c"
  242. build_python toml "${TOML_VERSION}"
  243. fi
  244. # ---------------------------------------------------------------------------------------------------------------------
  245. # zipp (optional)
  246. if [ -n "${ZIPP_VERSION}" ]; then
  247. download zipp "${ZIPP_VERSION}" "https://files.pythonhosted.org/packages/ce/b0/757db659e8b91cb3ea47d90350d7735817fe1df36086afc77c1c4610d559"
  248. build_python zipp "${ZIPP_VERSION}"
  249. fi
  250. # ---------------------------------------------------------------------------------------------------------------------
  251. # importlib_metadata (optional)
  252. if [ -n "${IMPORTLIB_METADATA_VERSION}" ]; then
  253. download importlib_metadata "${IMPORTLIB_METADATA_VERSION}" "https://files.pythonhosted.org/packages/f8/41/8ffb059708359ea14a3ec74a99a2bf0cd44a0c983a0c480d9eb7a69438bb"
  254. build_python importlib_metadata "${IMPORTLIB_METADATA_VERSION}"
  255. fi
  256. # ---------------------------------------------------------------------------------------------------------------------
  257. # cxfreeze
  258. git_clone cx_Freeze "${CXFREEZE_VERSION}" "https://github.com/anthony-tuininga/cx_Freeze.git"
  259. build_python cx_Freeze "${CXFREEZE_VERSION}"
  260. if [ "${WIN32}" -eq 1 ] && [ "${CROSS_COMPILING}" -eq 1 ]; then
  261. PYTHONPATH="${PAWPAW_PREFIX}/lib/python3.8/site-packages"
  262. if [ ! -e "${PYTHONPATH}/cx_Freeze" ]; then
  263. ln -sv "${PYTHONPATH}"/cx_Freeze-*.egg/cx_Freeze "${PYTHONPATH}/cx_Freeze"
  264. fi
  265. if [ ! -e "${PYTHONPATH}/cx_Freeze/util.pyd" ]; then
  266. ln -sv "$(realpath "${PYTHONPATH}/cx_Freeze"/util.*)" "${PYTHONPATH}/cx_Freeze/util.pyd"
  267. fi
  268. unset PYTHONPATH
  269. fi
  270. # ---------------------------------------------------------------------------------------------------------------------