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.

413 lines
16KB

  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. ./bootstrap-plugins.sh "${target}"
  16. if [ -z "${PAWPAW_SKIP_QT}" ]; then
  17. ./bootstrap-qt.sh "${target}"
  18. fi
  19. # ---------------------------------------------------------------------------------------------------------------------
  20. # source setup code
  21. source setup/check_target.sh
  22. source setup/env.sh
  23. source setup/functions.sh
  24. source setup/versions.sh
  25. # ---------------------------------------------------------------------------------------------------------------------
  26. # file/magic (posix only)
  27. if [ "${WASM}" -eq 0 ] && [ "${WIN32}" -eq 0 ]; then
  28. download file "${FILE_VERSION}" "${FILE_URL}"
  29. build_autoconf file "${FILE_VERSION}"
  30. fi
  31. # ---------------------------------------------------------------------------------------------------------------------
  32. # everything after this point requires Qt or PyQt
  33. if [ -n "${PAWPAW_SKIP_QT}" ]; then
  34. exit 0
  35. fi
  36. # ---------------------------------------------------------------------------------------------------------------------
  37. # custom function for python
  38. function build_conf_python() {
  39. local name="${1}"
  40. local version="${2}"
  41. local extraconfrules="${3}"
  42. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  43. if [ -n "${TOOLCHAIN_PREFIX}" ]; then
  44. extraconfrules+=" --host=${TOOLCHAIN_PREFIX} --build=$(gcc -dumpmachine)"
  45. fi
  46. _prebuild "${name}" "${pkgdir}"
  47. # remove flags not compatible with python
  48. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fvisibility=hidden//')"
  49. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-ffast-math//')"
  50. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  51. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fno-strict-aliasing -flto//')"
  52. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-dead_strip,-dead_strip_dylibs,-x//')"
  53. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-O1,--as-needed,--gc-sections,--no-undefined,--strip-all//')"
  54. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  55. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fno-strict-aliasing -flto//')"
  56. # add host/native binaries to path
  57. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  58. export PATH="${PAWPAW_PREFIX}-host/bin:${PATH}"
  59. fi
  60. if [ "${WIN32}" -eq 1 ] && [ ! -f "${pkgdir}/.stamp_preconfigured" ]; then
  61. pushd "${pkgdir}"
  62. autoreconf -vfi
  63. touch .stamp_preconfigured
  64. popd
  65. fi
  66. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  67. pushd "${pkgdir}"
  68. ./configure ${extraconfrules}
  69. touch .stamp_configured
  70. popd
  71. fi
  72. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  73. pushd "${pkgdir}"
  74. # if [ "${WIN32}" -eq 1 ]; then
  75. # # inject exe-wrapper
  76. # if [ -n "${EXE_WRAPPER}" ]; then
  77. # sed -i -e "s|\t./Programs/_freeze_importlib|\t${EXE_WRAPPER} ./Programs/_freeze_importlib|" Makefile
  78. # fi
  79. # make regen-importlib
  80. # fi
  81. make ${MAKE_ARGS}
  82. touch .stamp_built
  83. popd
  84. fi
  85. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  86. pushd "${pkgdir}"
  87. make ${MAKE_ARGS} -j 1 install
  88. touch .stamp_installed
  89. popd
  90. fi
  91. _postbuild
  92. }
  93. # ---------------------------------------------------------------------------------------------------------------------
  94. # custom function for sip and pyqt packages
  95. function build_pyqt() {
  96. local name="${1}"
  97. local version="${2}"
  98. local extraconfrules="${3}"
  99. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  100. local python="python$(echo ${PYTHON_VERSION} | cut -b 1,2,3)"
  101. _prebuild "${name}" "${pkgdir}"
  102. # remove flags not compatible with python
  103. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fvisibility=hidden//')"
  104. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-ffast-math//')"
  105. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  106. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fno-strict-aliasing -flto//')"
  107. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility=hidden//')"
  108. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility-inlines-hidden//')"
  109. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-ffast-math//')"
  110. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  111. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fno-strict-aliasing -flto//')"
  112. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-dead_strip,-dead_strip_dylibs,-x//')"
  113. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-O1,--as-needed,--gc-sections,--no-undefined,--strip-all//')"
  114. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  115. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fno-strict-aliasing -flto//')"
  116. # non-standard vars used by sip/pyqt
  117. export LFLAGS="${LDFLAGS}"
  118. export LINK="${CXX}"
  119. # add host/native binaries to path
  120. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  121. export PATH="${PAWPAW_PREFIX}-host/bin:${PATH}"
  122. fi
  123. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  124. pushd "${pkgdir}"
  125. # Place link to Qt DLLs for PyQt tests
  126. if [ "${WIN32}" -eq 1 ] && [ -d "pyuic" ] && [ ! -d "release" ]; then
  127. mkdir release
  128. ln -sf "${PAWPAW_PREFIX}/bin"/Qt* release/
  129. fi
  130. ${python} configure.py ${extraconfrules}
  131. if [ -f "QtCore/Makefile.Release" ]; then
  132. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  133. sed -i -e "s|${PAWPAW_PREFIX}-host|${PAWPAW_PREFIX}|" pylupdate5 pyrcc5 pyuic5
  134. fi
  135. if [ -n "${EXE_WRAPPER}" ]; then
  136. sed -i -e "s|exec /|exec ${EXE_WRAPPER} /|" pylupdate5 pyrcc5 pyuic5
  137. fi
  138. fi
  139. touch .stamp_configured
  140. popd
  141. fi
  142. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  143. pushd "${pkgdir}"
  144. # build sip as host tool first
  145. if [ "${CROSS_COMPILING}" -eq 1 ] && [ -d "sipgen" ] && [ ! -f "sipgen/sip" ]; then
  146. pushd "sipgen"
  147. PATH="${OLD_PATH}" make sip CC="gcc" CFLAGS= LINK="gcc" LFLAGS="-Wl,-s" ${MAKE_ARGS}
  148. popd
  149. fi
  150. # CC="${TARGET_CC}" CXX="${TARGET_CXX}" LFLAGS="${LDFLAGS}" LINK="${TARGET_CXX}" PREFIX="${PAWPAW_PREFIX}" PKG_CONFIG="${TARGET_PKG_CONFIG}"
  151. make ${MAKE_ARGS}
  152. touch .stamp_built
  153. popd
  154. fi
  155. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  156. pushd "${pkgdir}"
  157. # PREFIX="${PAWPAW_PREFIX}" PKG_CONFIG="${TARGET_PKG_CONFIG}"
  158. make ${MAKE_ARGS} -j 1 install
  159. touch .stamp_installed
  160. popd
  161. fi
  162. unset LFLAGS
  163. unset LINK
  164. }
  165. # ---------------------------------------------------------------------------------------------------------------------
  166. # wine bootstrap for python (needed for cross-compilation)
  167. if [ "${WIN32}" -eq 1 ] && [ -n "${EXE_WRAPPER}" ] && [ ! -d "${WINEPREFIX}" ]; then
  168. wineboot -u
  169. fi
  170. # ---------------------------------------------------------------------------------------------------------------------
  171. # python
  172. # build for host first
  173. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  174. download host-Python "${PYTHON_VERSION}" "https://www.python.org/ftp/python/${PYTHON_VERSION}" "tgz" "" Python
  175. build_host_autoconf host-Python "${PYTHON_VERSION}" "--build=$(gcc -dumpmachine) --prefix=${PAWPAW_PREFIX}-host"
  176. # sed -i -e "s|${PAWPAW_PREFIX}-host|${PAWPAW_PREFIX}|" "${PAWPAW_PREFIX}-host/bin/python3.8-config"
  177. # # FIXME
  178. # mkdir -p "${PAWPAW_PREFIX}-host/lib/python3.8/config-3.8-x86_64-linux-gnu/Tools"
  179. # ln -sf "${PAWPAW_PREFIX}-host/bin" "${PAWPAW_PREFIX}-host/lib/python3.8/config-3.8-x86_64-linux-gnu/Tools/scripts"
  180. # # may be available in host, but not in build target
  181. # if [ "${WIN32}" -eq 1 ] && [ ! -e "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h-e" ]; then
  182. # sed -i -e '/HAVE_CRYPT_H/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  183. # sed -i -e '/HAVE_CRYPT_R/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  184. # sed -i -e '/HAVE_SYS_SELECT_H/d' "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h"
  185. # touch "${PAWPAW_PREFIX}-host/include/python3.8/pyconfig.h-e"
  186. # fi
  187. fi
  188. PYTHON_EXTRAFLAGS=""
  189. if [ "${MACOS}" -eq 1 ]; then
  190. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  191. PYTHON_EXTRAFLAGS+=" --enable-optimizations"
  192. PYTHON_EXTRAFLAGS+=" ac_cv_lib_intl_textdomain=no"
  193. PYTHON_EXTRAFLAGS+=" ac_cv_header_libintl_h=no"
  194. PYTHON_EXTRAFLAGS+=" ac_cv_func_setlocale=no"
  195. fi
  196. PYTHON_EXTRAFLAGS+=" ac_cv_func_futimens=no"
  197. PYTHON_EXTRAFLAGS+=" ac_cv_func_preadv=no"
  198. PYTHON_EXTRAFLAGS+=" ac_cv_func_pwritev=no"
  199. PYTHON_EXTRAFLAGS+=" ac_cv_func_sendfile=no"
  200. PYTHON_EXTRAFLAGS+=" ac_cv_func_utimensat=no"
  201. elif [ "${WIN32}" -eq 1 ]; then
  202. export EXTRA_CFLAGS=" -fwrapv -D_WIN32_WINNT=0x0601"
  203. export EXTRA_CXXFLAGS=" -fwrapv -D_WIN32_WINNT=0x0601"
  204. PYTHON_EXTRAFLAGS="--with-nt-threads"
  205. PYTHON_EXTRAFLAGS+=" --without-ensurepip"
  206. PYTHON_EXTRAFLAGS+=" --without-c-locale-coercion"
  207. # Workaround for conftest error on 64-bit builds
  208. PYTHON_EXTRAFLAGS+=" ac_cv_working_tzset=no"
  209. # Workaround for when dlfcn exists on Windows, which causes
  210. # some conftests to succeed when they shouldn't (we don't use dlfcn).
  211. PYTHON_EXTRAFLAGS+=" ac_cv_header_dlfcn_h=no"
  212. PYTHON_EXTRAFLAGS+=" ac_cv_lib_dl_dlopen=no"
  213. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_GLOBAL=no"
  214. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_LAZY=no"
  215. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_LOCAL=no"
  216. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NOW=no"
  217. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_DEEPBIND=no"
  218. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_MEMBER=no"
  219. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NODELETE=no"
  220. PYTHON_EXTRAFLAGS+=" ac_cv_have_decl_RTLD_NOLOAD=no"
  221. fi
  222. download Python "${PYTHON_VERSION}" "https://www.python.org/ftp/python/${PYTHON_VERSION}" "tgz"
  223. if [ "${PYTHON_VERSION}" = "3.7.4" ]; then
  224. patch_file Python "${PYTHON_VERSION}" "Modules/Setup.dist" 's/#zlib zlibmodule.c/zlib zlibmodule.c/'
  225. fi
  226. build_conf_python Python "${PYTHON_VERSION}" "--prefix=${PAWPAW_PREFIX} --enable-shared ${PYTHON_EXTRAFLAGS}"
  227. # ---------------------------------------------------------------------------------------------------------------------
  228. # sip
  229. if [ "${SIP_VERSION}" = "4.19.19" ]; then
  230. SIP_DOWNLOAD_URL="https://files.kde.org/krita/build/dependencies"
  231. SIP_EXTRAFLAGS="--sip-module PyQt5.sip"
  232. else
  233. SIP_DOWNLOAD_URL="http://sourceforge.net/projects/pyqt/files/sip/sip-${SIP_VERSION}"
  234. fi
  235. if [ "${WIN32}" -eq 1 ]; then
  236. SIP_EXTRAFLAGS+=" --platform win32-g++"
  237. SIP_EXTRAFLAGS+=" EXTENSION_PLUGIN=pyd"
  238. fi
  239. SIP_EXTRAFLAGS+=" --sysroot=${PAWPAW_PREFIX}"
  240. SIP_EXTRAFLAGS+=" INCDIR=${PAWPAW_PREFIX}/include/python3.8"
  241. SIP_EXTRAFLAGS+=" LIBDIR=${PAWPAW_PREFIX}/lib/python3.8/config-3.8"
  242. download sip "${SIP_VERSION}" "${SIP_DOWNLOAD_URL}"
  243. build_pyqt sip "${SIP_VERSION}" "${SIP_EXTRAFLAGS}"
  244. # ---------------------------------------------------------------------------------------------------------------------
  245. # pyqt5
  246. if [ "${PYQT5_VERSION}" = "5.13.1" ]; then
  247. PYQT5_DOWNLOAD_URL="https://files.kde.org/krita/build/dependencies"
  248. PYQT5_SUFFIX="_gpl"
  249. else
  250. PYQT5_DOWNLOAD_URL="http://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-${PYQT5_VERSION}"
  251. PYQT5_SUFFIX="_gpl"
  252. fi
  253. # qmake needs this
  254. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  255. export PKG_CONFIG_LIBDIR="${TARGET_PKG_CONFIG_PATH}"
  256. export PKG_CONFIG_SYSROOT_DIR="/"
  257. fi
  258. PYQT5_EXTRAFLAGS="--qmake ${PAWPAW_PREFIX}/bin/qmake --sip ${PAWPAW_PREFIX}/bin/sip --sysroot ${PAWPAW_PREFIX}"
  259. download PyQt5${PYQT5_SUFFIX} "${PYQT5_VERSION}" "${PYQT5_DOWNLOAD_URL}"
  260. build_pyqt PyQt5${PYQT5_SUFFIX} "${PYQT5_VERSION}" "${PYQT5_EXTRAFLAGS} --concatenate --confirm-license"
  261. # --verbose
  262. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  263. unset PKG_CONFIG_LIBDIR
  264. unset PKG_CONFIG_SYSROOT_DIR
  265. fi
  266. # ---------------------------------------------------------------------------------------------------------------------
  267. # cython (optional)
  268. if [ -n "${CYTHON_VERSION}" ]; then
  269. download Cython "${CYTHON_VERSION}" "https://files.pythonhosted.org/packages/6c/9f/f501ba9d178aeb1f5bf7da1ad5619b207c90ac235d9859961c11829d0160"
  270. build_python Cython "${CYTHON_VERSION}"
  271. fi
  272. # ---------------------------------------------------------------------------------------------------------------------
  273. # pyliblo
  274. if [ "${WIN32}" -eq 1 ]; then
  275. export EXTRA_CFLAGS="$(${PAWPAW_PREFIX}/bin/pkg-config --cflags python3 liblo)"
  276. export EXTRA_LDFLAGS="-shared $(${PAWPAW_PREFIX}/bin/pkg-config --libs python3 liblo)"
  277. export LDSHARED="${TARGET_CXX}"
  278. fi
  279. download pyliblo "${PYLIBLO_VERSION}" "http://das.nasophon.de/download"
  280. build_python pyliblo "${PYLIBLO_VERSION}"
  281. if [ "${WIN32}" -eq 1 ]; then
  282. unset LDSHARED
  283. fi
  284. if [ "${WIN32}" -eq 1 ] && [ "${CROSS_COMPILING}" -eq 1 ]; then
  285. PYTHONPATH="${PAWPAW_PREFIX}/lib/python3.8/site-packages"
  286. if [ "${CROSS_COMPILING}" -eq 1 ] && [ ! -e "${PYTHONPATH}/liblo.pyd" ]; then
  287. ln -sv "${PYTHONPATH}"/pyliblo-*.egg/*.so "${PYTHONPATH}/liblo.pyd"
  288. fi
  289. unset PYTHONPATH
  290. fi
  291. # ---------------------------------------------------------------------------------------------------------------------
  292. # setuptools_scm (optional)
  293. if [ -n "${SETUPTOOLS_SCM_VERSION}" ]; then
  294. download setuptools_scm "${SETUPTOOLS_SCM_VERSION}" "https://files.pythonhosted.org/packages/ed/b6/979bfa7b81878b2b4475dde092aac517e7f25dd33661796ec35664907b31"
  295. build_python setuptools_scm "${SETUPTOOLS_SCM_VERSION}"
  296. fi
  297. # ---------------------------------------------------------------------------------------------------------------------
  298. # toml (optional)
  299. if [ -n "${TOML_VERSION}" ]; then
  300. download toml "${TOML_VERSION}" "https://files.pythonhosted.org/packages/be/ba/1f744cdc819428fc6b5084ec34d9b30660f6f9daaf70eead706e3203ec3c"
  301. build_python toml "${TOML_VERSION}"
  302. fi
  303. # ---------------------------------------------------------------------------------------------------------------------
  304. # zipp (optional)
  305. if [ -n "${ZIPP_VERSION}" ]; then
  306. download zipp "${ZIPP_VERSION}" "https://files.pythonhosted.org/packages/ce/b0/757db659e8b91cb3ea47d90350d7735817fe1df36086afc77c1c4610d559"
  307. build_python zipp "${ZIPP_VERSION}"
  308. fi
  309. # ---------------------------------------------------------------------------------------------------------------------
  310. # importlib_metadata (optional)
  311. if [ -n "${IMPORTLIB_METADATA_VERSION}" ]; then
  312. download importlib_metadata "${IMPORTLIB_METADATA_VERSION}" "https://files.pythonhosted.org/packages/f8/41/8ffb059708359ea14a3ec74a99a2bf0cd44a0c983a0c480d9eb7a69438bb"
  313. build_python importlib_metadata "${IMPORTLIB_METADATA_VERSION}"
  314. fi
  315. # ---------------------------------------------------------------------------------------------------------------------
  316. # cxfreeze
  317. git_clone cx_Freeze "${CXFREEZE_VERSION}" "https://github.com/anthony-tuininga/cx_Freeze.git"
  318. build_python cx_Freeze "${CXFREEZE_VERSION}"
  319. if [ "${WIN32}" -eq 1 ] && [ "${CROSS_COMPILING}" -eq 1 ]; then
  320. PYTHONPATH="${PAWPAW_PREFIX}/lib/python3.8/site-packages"
  321. if [ ! -e "${PYTHONPATH}/cx_Freeze" ]; then
  322. ln -sv "${PYTHONPATH}"/cx_Freeze-*.egg/cx_Freeze "${PYTHONPATH}/cx_Freeze"
  323. fi
  324. if [ ! -e "${PYTHONPATH}/cx_Freeze/util.pyd" ]; then
  325. ln -sv "$(realpath "${PYTHONPATH}/cx_Freeze"/util.*)" "${PYTHONPATH}/cx_Freeze/util.pyd"
  326. fi
  327. unset PYTHONPATH
  328. fi
  329. # ---------------------------------------------------------------------------------------------------------------------