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.

333 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,-O1,--gc-sections,--no-undefined//')"
  126. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,--as-needed,--strip-all//')"
  127. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  128. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fno-strict-aliasing -flto//')"
  129. # add host/native binaries to path
  130. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  131. export PATH="${PAWPAW_PREFIX}-host/bin:${PATH}"
  132. fi
  133. if [ "${WIN32}" -eq 1 ] && [ ! -f "${pkgdir}/.stamp_preconfigured" ]; then
  134. pushd "${pkgdir}"
  135. autoreconf -vfi
  136. touch .stamp_preconfigured
  137. popd
  138. fi
  139. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  140. pushd "${pkgdir}"
  141. ./configure ${extraconfrules}
  142. touch .stamp_configured
  143. popd
  144. fi
  145. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  146. pushd "${pkgdir}"
  147. # if [ "${WIN32}" -eq 1 ]; then
  148. # # inject exe-wrapper
  149. # if [ -n "${EXE_WRAPPER}" ]; then
  150. # sed -i -e "s|\t./Programs/_freeze_importlib|\t${EXE_WRAPPER} ./Programs/_freeze_importlib|" Makefile
  151. # fi
  152. # make regen-importlib
  153. # fi
  154. make ${MAKE_ARGS}
  155. touch .stamp_built
  156. popd
  157. fi
  158. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  159. pushd "${pkgdir}"
  160. make ${MAKE_ARGS} -j 1 install
  161. touch .stamp_installed
  162. popd
  163. fi
  164. _postbuild
  165. }
  166. # ---------------------------------------------------------------------------------------------------------------------
  167. # python
  168. # build for host first
  169. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  170. download host-Python "${PYTHON_VERSION}" "https://www.python.org/ftp/python/${PYTHON_VERSION}" "tgz" "" Python
  171. build_host_autoconf host-Python "${PYTHON_VERSION}" "--build=$(gcc -dumpmachine) --prefix=${PAWPAW_PREFIX}-host"
  172. # sed -i -e "s|${PAWPAW_PREFIX}-host|${PAWPAW_PREFIX}|" "${PAWPAW_PREFIX}-host/bin/python3.8-config"
  173. # # FIXME
  174. # mkdir -p "${PAWPAW_PREFIX}-host/lib/python3.8/config-3.8-x86_64-linux-gnu/Tools"
  175. # ln -sf "${PAWPAW_PREFIX}-host/bin" "${PAWPAW_PREFIX}-host/lib/python3.8/config-3.8-x86_64-linux-gnu/Tools/scripts"
  176. # # may be available in host, but not in build target
  177. # if [ "${WIN32}" -eq 1 ] && [ ! -e "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h-e" ]; then
  178. # sed -i -e '/HAVE_CRYPT_H/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  179. # sed -i -e '/HAVE_CRYPT_R/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  180. # sed -i -e '/HAVE_SYS_SELECT_H/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  181. # touch "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h-e"
  182. # fi
  183. fi
  184. PYTHON_EXTRAFLAGS=""
  185. if [ "${MACOS}" -eq 1 ]; then
  186. PYTHON_EXTRAFLAGS+=" --enable-optimizations"
  187. PYTHON_EXTRAFLAGS+=" ac_cv_lib_intl_textdomain=no"
  188. PYTHON_EXTRAFLAGS+=" ac_cv_header_libintl_h=no"
  189. PYTHON_EXTRAFLAGS+=" ac_cv_func_setlocale=no"
  190. PYTHON_EXTRAFLAGS+=" ac_cv_func_futimens=no"
  191. PYTHON_EXTRAFLAGS+=" ac_cv_func_preadv=no"
  192. PYTHON_EXTRAFLAGS+=" ac_cv_func_pwritev=no"
  193. PYTHON_EXTRAFLAGS+=" ac_cv_func_sendfile=no"
  194. PYTHON_EXTRAFLAGS+=" ac_cv_func_utimensat=no"
  195. elif [ "${WIN32}" -eq 1 ]; then
  196. export EXTRA_CFLAGS=" -fwrapv -D_WIN32_WINNT=0x0601"
  197. export EXTRA_CXXFLAGS=" -fwrapv -D_WIN32_WINNT=0x0601"
  198. PYTHON_EXTRAFLAGS+=" --with-nt-threads"
  199. PYTHON_EXTRAFLAGS+=" --without-ensurepip"
  200. PYTHON_EXTRAFLAGS+=" --without-c-locale-coercion"
  201. # Workaround for conftest error on 64-bit builds
  202. PYTHON_EXTRAFLAGS+=" ac_cv_working_tzset=no"
  203. # Workaround for when dlfcn exists on Windows, which causes
  204. # some conftests to succeed when they shouldn't (we don't use dlfcn).
  205. PYTHON_EXTRAFLAGS+=" ac_cv_header_dlfcn_h=no"
  206. PYTHON_EXTRAFLAGS+=" ac_cv_lib_dl_dlopen=no"
  207. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_GLOBAL=no"
  208. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_LAZY=no"
  209. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_LOCAL=no"
  210. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NOW=no"
  211. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_DEEPBIND=no"
  212. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_MEMBER=no"
  213. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NODELETE=no"
  214. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NOLOAD=no"
  215. elif [ "${CROSS_COMPILING}" -eq 1 ]; then
  216. PYTHON_EXTRAFLAGS+=" --disable-ipv6"
  217. PYTHON_EXTRAFLAGS+=" ac_cv_file__dev_ptc=no"
  218. PYTHON_EXTRAFLAGS+=" ac_cv_file__dev_ptmx=no"
  219. fi
  220. download Python "${PYTHON_VERSION}" "https://www.python.org/ftp/python/${PYTHON_VERSION}" "tgz"
  221. if [ "${PYTHON_VERSION}" = "3.7.4" ]; then
  222. patch_file Python "${PYTHON_VERSION}" "Modules/Setup.dist" 's/#zlib zlibmodule.c/zlib zlibmodule.c/'
  223. fi
  224. build_conf_python Python "${PYTHON_VERSION}" "--prefix=${PAWPAW_PREFIX} --enable-shared ${PYTHON_EXTRAFLAGS}"
  225. # ---------------------------------------------------------------------------------------------------------------------
  226. # cython (optional)
  227. if [ -n "${CYTHON_VERSION}" ]; then
  228. download Cython "${CYTHON_VERSION}" "https://files.pythonhosted.org/packages/6c/9f/f501ba9d178aeb1f5bf7da1ad5619b207c90ac235d9859961c11829d0160"
  229. build_python Cython "${CYTHON_VERSION}"
  230. fi
  231. # ---------------------------------------------------------------------------------------------------------------------
  232. # setuptools_scm (optional)
  233. if [ -n "${SETUPTOOLS_SCM_VERSION}" ]; then
  234. download setuptools_scm "${SETUPTOOLS_SCM_VERSION}" "https://files.pythonhosted.org/packages/ed/b6/979bfa7b81878b2b4475dde092aac517e7f25dd33661796ec35664907b31"
  235. build_python setuptools_scm "${SETUPTOOLS_SCM_VERSION}"
  236. fi
  237. # ---------------------------------------------------------------------------------------------------------------------
  238. # toml (optional)
  239. if [ -n "${TOML_VERSION}" ]; then
  240. download toml "${TOML_VERSION}" "https://files.pythonhosted.org/packages/be/ba/1f744cdc819428fc6b5084ec34d9b30660f6f9daaf70eead706e3203ec3c"
  241. build_python toml "${TOML_VERSION}"
  242. fi
  243. # ---------------------------------------------------------------------------------------------------------------------
  244. # zipp (optional)
  245. if [ -n "${ZIPP_VERSION}" ]; then
  246. download zipp "${ZIPP_VERSION}" "https://files.pythonhosted.org/packages/ce/b0/757db659e8b91cb3ea47d90350d7735817fe1df36086afc77c1c4610d559"
  247. build_python zipp "${ZIPP_VERSION}"
  248. fi
  249. # ---------------------------------------------------------------------------------------------------------------------
  250. # importlib_metadata (optional)
  251. if [ -n "${IMPORTLIB_METADATA_VERSION}" ]; then
  252. download importlib_metadata "${IMPORTLIB_METADATA_VERSION}" "https://files.pythonhosted.org/packages/f8/41/8ffb059708359ea14a3ec74a99a2bf0cd44a0c983a0c480d9eb7a69438bb"
  253. build_python importlib_metadata "${IMPORTLIB_METADATA_VERSION}"
  254. fi
  255. # ---------------------------------------------------------------------------------------------------------------------
  256. # cxfreeze
  257. git_clone cx_Freeze "${CXFREEZE_VERSION}" "https://github.com/anthony-tuininga/cx_Freeze.git"
  258. build_python cx_Freeze "${CXFREEZE_VERSION}"
  259. if [ "${WIN32}" -eq 1 ] && [ "${CROSS_COMPILING}" -eq 1 ]; then
  260. PYTHONPATH="${PAWPAW_PREFIX}/lib/python3.8/site-packages"
  261. if [ ! -e "${PYTHONPATH}/cx_Freeze" ]; then
  262. ln -sv "${PYTHONPATH}"/cx_Freeze-*.egg/cx_Freeze "${PYTHONPATH}/cx_Freeze"
  263. fi
  264. if [ ! -e "${PYTHONPATH}/cx_Freeze/util.pyd" ]; then
  265. ln -sv "$(realpath "${PYTHONPATH}/cx_Freeze"/util.*)" "${PYTHONPATH}/cx_Freeze/util.pyd"
  266. fi
  267. unset PYTHONPATH
  268. fi
  269. # ---------------------------------------------------------------------------------------------------------------------