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.

379 lines
15KB

  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. ./bootstrap-qt.sh "${target}"
  17. # ---------------------------------------------------------------------------------------------------------------------
  18. # source setup code
  19. source setup/check_target.sh
  20. source setup/env.sh
  21. source setup/functions.sh
  22. source setup/versions.sh
  23. # ---------------------------------------------------------------------------------------------------------------------
  24. # custom function as needed for pyqt packages
  25. function build_conf_python() {
  26. local name="${1}"
  27. local version="${2}"
  28. local extraconfrules="${3}"
  29. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  30. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  31. extraconfrules+=" --host=${TOOLCHAIN_PREFIX} --build=x86_64-linux-gnu"
  32. fi
  33. _prebuild "${name}" "${pkgdir}"
  34. # remove flags not compatible with python
  35. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fvisibility=hidden//')"
  36. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-ffast-math//')"
  37. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  38. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-dead_strip -Wl,-dead_strip_dylibs//')"
  39. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,--strip-all//')"
  40. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  41. if [ ! -f "${pkgdir}/.stamp_preconfigured" ] && [ "${WIN32}" -eq 1 ]; then
  42. pushd "${pkgdir}"
  43. autoreconf -vfi
  44. touch .stamp_preconfigured
  45. popd
  46. fi
  47. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  48. pushd "${pkgdir}"
  49. ./configure ${extraconfrules}
  50. touch .stamp_configured
  51. popd
  52. fi
  53. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  54. pushd "${pkgdir}"
  55. if [ "${WIN32}" -eq 1 ]; then
  56. # adds -Wl,-Bdynamic so we link to shared python lib
  57. sed -i -e 's|BLDLIBRARY= -L.|BLDLIBRARY= -Wl,-Bdynamic -L.|' Makefile
  58. # EXE suffix missing
  59. sed -i -e 's|./Programs/_freeze_importlib zipimport|./Programs/_freeze_importlib$(EXE) zipimport|' Makefile
  60. # inject exe-wrapper
  61. if [ -n "${EXE_WRAPPER}" ]; then
  62. sed -i -e "s|\t./Programs/_freeze_importlib|\t${EXE_WRAPPER} ./Programs/_freeze_importlib|" Makefile
  63. fi
  64. # use toolchain prefix on windres tool if cross-compiling
  65. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  66. sed -i -e "s|\twindres|\t${TOOLCHAIN_PREFIX_}windres|" Makefile
  67. fi
  68. make regen-importlib
  69. fi
  70. make ${MAKE_ARGS}
  71. touch .stamp_built
  72. popd
  73. fi
  74. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  75. pushd "${pkgdir}"
  76. make ${MAKE_ARGS} -j 1 install
  77. touch .stamp_installed
  78. popd
  79. fi
  80. _postbuild
  81. }
  82. function build_pyqt() {
  83. local name="${1}"
  84. local version="${2}"
  85. local extraconfrules="${3}"
  86. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  87. _prebuild "${name}" "${pkgdir}"
  88. # remove flags not compatible with python
  89. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fvisibility=hidden//')"
  90. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-ffast-math//')"
  91. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  92. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility=hidden//')"
  93. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-ffast-math//')"
  94. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility-inlines-hidden//')"
  95. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  96. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-dead_strip -Wl,-dead_strip_dylibs//')"
  97. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,--strip-all//')"
  98. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  99. if [ "${WIN32}" -eq 1 ]; then
  100. export CXXFLAGS+=" -Wno-deprecated-copy"
  101. fi
  102. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  103. pushd "${pkgdir}"
  104. # Place link to Qt DLLs for PyQt tests
  105. if [ "${WIN32}" -eq 1 ] && [ "${name}" = "PyQt5_gpl" ]; then
  106. mkdir -p release
  107. ln -sf "${PAWPAW_PREFIX}/bin"/Qt* release/
  108. fi
  109. local python3=python3
  110. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  111. python3=python3.8
  112. fi
  113. ${python3} configure.py ${extraconfrules}
  114. # build sip as host tool first
  115. if [ "${CROSS_COMPILING}" -eq 1 ] && [ "${name}" = "sip" ]; then
  116. pushd "sipgen"
  117. PATH="${OLD_PATH}" make sip LFLAGS="-Wl,-s" ${MAKE_ARGS}
  118. popd
  119. if [ "${WIN32}" -eq 1 ]; then
  120. sed -i -e "s/sip.so/sip.pyd/" installed.txt
  121. fi
  122. fi
  123. # use env vars
  124. sed -i -e 's/CC = gcc/CC ?= gcc/' */Makefile
  125. sed -i -e 's/CXX = g++/CXX ?= g++/' */Makefile
  126. sed -i -e 's/LINK = g++/LINK = $(CXX)/' */Makefile
  127. sed -i -e 's/CFLAGS *=/CFLAGS +=/' */Makefile
  128. sed -i -e 's/CXXFLAGS *=/CXXFLAGS +=/' */Makefile
  129. sed -i -e 's/LIBS *=/LIBS += $(LDFLAGS)/' */Makefile
  130. if [ -f "QtCore/Makefile.Release" ]; then
  131. sed -i -e 's/CFLAGS *=/CFLAGS +=/' */Makefile.Release
  132. sed -i -e 's/CXXFLAGS *=/CXXFLAGS +=/' */Makefile.Release
  133. sed -i -e 's/LIBS *=/LIBS += $(LDFLAGS)/' */Makefile.Release
  134. fi
  135. # use abstract python3 path
  136. sed -i -e 's|/usr/bin/python3|python3|g' Makefile
  137. # use PREFIX var
  138. sed -i -e "s|/usr|${PAWPAW_PREFIX}|g" installed.txt Makefile */Makefile
  139. if [ -f "QtCore/Makefile.Release" ]; then
  140. sed -i -e "s|/usr|${PAWPAW_PREFIX}|g" */Makefile.Release
  141. fi
  142. # fix win32 linkage
  143. if [ "${WIN32}" -eq 1 ]; then
  144. sed -i -e 's|config -lpython3.8|config-3.8 -Wl,-Bdynamic -lpython3.8 -Wl,-Bstatic|' */Makefile
  145. if [ -f "QtCore/Makefile.Release" ]; then
  146. for mak in $(find -maxdepth 2 -type f -name Makefile.Release); do
  147. echo "LIBS += -L${PAWPAW_PREFIX}/lib/python3.8/config-3.8 -Wl,-Bdynamic -lpython3.8 -Wl,-Bstatic" >> ${mak}
  148. done
  149. fi
  150. fi
  151. touch .stamp_configured
  152. popd
  153. fi
  154. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  155. pushd "${pkgdir}"
  156. make PREFIX="${PAWPAW_PREFIX}" PKG_CONFIG="${TARGET_PKG_CONFIG}" ${MAKE_ARGS}
  157. touch .stamp_built
  158. popd
  159. fi
  160. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  161. pushd "${pkgdir}"
  162. make PREFIX="${PAWPAW_PREFIX}" PKG_CONFIG="${TARGET_PKG_CONFIG}" ${MAKE_ARGS} -j 1 install
  163. if [ "${name}" = "PyQt5_gpl" ]; then
  164. sed -i -e "s|/usr|${PAWPAW_PREFIX}|g" ${PAWPAW_PREFIX}/bin/py*5
  165. if [ -n "${APP_EXT}" ]; then
  166. sed -i -e "s|3.8 -m|3.8${APP_EXT} -m|" ${PAWPAW_PREFIX}/bin/py*5
  167. fi
  168. if [ -n "${EXE_WRAPPER}" ]; then
  169. sed -i -e "s|exec /|exec ${EXE_WRAPPER} /|" ${PAWPAW_PREFIX}/bin/py*5
  170. fi
  171. if [ "${WIN32}" -eq 1 ]; then
  172. sed -i -e "s|d ||" ${PAWPAW_PREFIX}/lib/pkgconfig/Qt5*.pc
  173. fi
  174. fi
  175. touch .stamp_installed
  176. popd
  177. fi
  178. }
  179. # ---------------------------------------------------------------------------------------------------------------------
  180. # file/magic (posix only)
  181. if [ "${WIN32}" -eq 0 ]; then
  182. download file "${FILE_VERSION}" "ftp://ftp.astron.com/pub/file"
  183. build_autoconf file "${FILE_VERSION}"
  184. fi
  185. # ---------------------------------------------------------------------------------------------------------------------
  186. # libffi (for python, not needed in macOS)
  187. if [ "${MACOS}" -eq 0 ]; then
  188. download libffi "${LIBFFI_VERSION}" "https://sourceware.org/pub/libffi"
  189. build_autoconf libffi "${LIBFFI_VERSION}"
  190. fi
  191. # ---------------------------------------------------------------------------------------------------------------------
  192. # python
  193. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  194. PYTHON_EXTRAFLAGS="--enable-optimizations"
  195. elif [ "${WIN32}" -eq 1 ]; then
  196. export EXTRA_CFLAGS=" -fwrapv -D__USE_MINGW_ANSI_STDIO=1 -D_WIN32_WINNT=0x0601"
  197. export EXTRA_CXXFLAGS=" -fwrapv -D__USE_MINGW_ANSI_STDIO=1 -D_WIN32_WINNT=0x0601"
  198. PYTHON_EXTRAFLAGS="--with-nt-threads"
  199. PYTHON_EXTRAFLAGS+=" --without-ensurepip"
  200. PYTHON_EXTRAFLAGS+=" --without-c-locale-coercion"
  201. # PYTHON_EXTRAFLAGS+=" --enable-optimizations"
  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. PYTHON_EXTRAFLAGS+=" OPT="
  217. fi
  218. download Python "${PYTHON_VERSION}" "https://www.python.org/ftp/python/${PYTHON_VERSION}" "tgz"
  219. if [ "${PYTHON_VERSION}" = "3.7.4" ]; then
  220. patch_file Python "${PYTHON_VERSION}" "Modules/Setup.dist" 's/#zlib zlibmodule.c/zlib zlibmodule.c/'
  221. fi
  222. build_conf_python Python "${PYTHON_VERSION}" "--prefix=${PAWPAW_PREFIX} --enable-shared ${PYTHON_EXTRAFLAGS}"
  223. # ---------------------------------------------------------------------------------------------------------------------
  224. # sip
  225. if [ "${SIP_VERSION}" = "4.19.19" ]; then
  226. SIP_DOWNLOAD_URL="https://files.kde.org/krita/build/dependencies"
  227. SIP_EXTRAFLAGS="--sip-module PyQt5.sip"
  228. else
  229. SIP_DOWNLOAD_URL="http://sourceforge.net/projects/pyqt/files/sip/sip-${SIP_VERSION}"
  230. fi
  231. if [ "${WIN32}" -eq 1 ]; then
  232. SIP_EXTRAFLAGS+=" --platform win32-g++ EXTENSION_PLUGIN=pyd"
  233. fi
  234. download sip "${SIP_VERSION}" "${SIP_DOWNLOAD_URL}"
  235. build_pyqt sip "${SIP_VERSION}" "${SIP_EXTRAFLAGS}"
  236. # ---------------------------------------------------------------------------------------------------------------------
  237. # pyqt5
  238. if [ "${PYQT5_VERSION}" = "5.13.1" ]; then
  239. PYQT5_DOWNLOAD_URL="https://files.kde.org/krita/build/dependencies"
  240. PYQT5_SUFFIX="_gpl"
  241. else
  242. PYQT5_DOWNLOAD_URL="http://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-${PYQT5_VERSION}"
  243. PYQT5_SUFFIX="_gpl"
  244. fi
  245. PYQT5_EXTRAFLAGS="--qmake ${PAWPAW_PREFIX}/bin/qmake --sip ${PAWPAW_PREFIX}/bin/sip"
  246. download PyQt5${PYQT5_SUFFIX} "${PYQT5_VERSION}" "${PYQT5_DOWNLOAD_URL}"
  247. build_pyqt PyQt5${PYQT5_SUFFIX} "${PYQT5_VERSION}" "${PYQT5_EXTRAFLAGS} --concatenate --confirm-license -c"
  248. # ---------------------------------------------------------------------------------------------------------------------
  249. # cython (optional)
  250. if [ -n "${CYTHON_VERSION}" ]; then
  251. download Cython "${CYTHON_VERSION}" "https://files.pythonhosted.org/packages/6c/9f/f501ba9d178aeb1f5bf7da1ad5619b207c90ac235d9859961c11829d0160"
  252. build_python Cython "${CYTHON_VERSION}"
  253. fi
  254. # ---------------------------------------------------------------------------------------------------------------------
  255. # pyliblo
  256. export EXTRA_CFLAGS="$(${PAWPAW_PREFIX}/bin/python3-config --cflags | awk 'sub("-ne","")')"
  257. export EXTRA_CFLAGS+=" $(pkg-config --cflags liblo)"
  258. export EXTRA_LDFLAGS="-shared -L/home/falktx/PawPawBuilds/targets/win64/bin $(${PAWPAW_PREFIX}/bin/python3-config --ldflags | awk 'sub("-ne","")' | awk 'sub("/lib -lpython3.8","/lib -Wl,-Bdynamic -lpython3.8")')"
  259. export EXTRA_LDFLAGS+=" -Wl,-Bstatic $(pkg-config --libs liblo)"
  260. # export LINK="${TARGET_CXX}"
  261. # export LINKER="${TARGET_CXX}"
  262. export LDSHARED="${TARGET_CXX}"
  263. # export PYTHONPATH="/home/falktx/PawPawBuilds/targets/win64/lib/python3.8"
  264. download pyliblo "${PYLIBLO_VERSION}" "http://das.nasophon.de/download"
  265. build_python pyliblo "${PYLIBLO_VERSION}"
  266. # TODO: finish this
  267. if [ "${WIN32}" -eq 1 ]; then
  268. exit 0
  269. fi
  270. # ---------------------------------------------------------------------------------------------------------------------
  271. # setuptools_scm (optional)
  272. if [ -n "${SETUPTOOLS_SCM_VERSION}" ]; then
  273. download setuptools_scm "${SETUPTOOLS_SCM_VERSION}" "https://files.pythonhosted.org/packages/ed/b6/979bfa7b81878b2b4475dde092aac517e7f25dd33661796ec35664907b31"
  274. build_python setuptools_scm "${SETUPTOOLS_SCM_VERSION}"
  275. fi
  276. # ---------------------------------------------------------------------------------------------------------------------
  277. # toml (optional)
  278. if [ -n "${TOML_VERSION}" ]; then
  279. download toml "${TOML_VERSION}" "https://files.pythonhosted.org/packages/be/ba/1f744cdc819428fc6b5084ec34d9b30660f6f9daaf70eead706e3203ec3c"
  280. build_python toml "${TOML_VERSION}"
  281. fi
  282. # ---------------------------------------------------------------------------------------------------------------------
  283. # zipp (optional)
  284. if [ -n "${ZIPP_VERSION}" ]; then
  285. download zipp "${ZIPP_VERSION}" "https://files.pythonhosted.org/packages/ce/b0/757db659e8b91cb3ea47d90350d7735817fe1df36086afc77c1c4610d559"
  286. build_python zipp "${ZIPP_VERSION}"
  287. fi
  288. # ---------------------------------------------------------------------------------------------------------------------
  289. # importlib_metadata (optional)
  290. if [ -n "${IMPORTLIB_METADATA_VERSION}" ]; then
  291. download importlib_metadata "${IMPORTLIB_METADATA_VERSION}" "https://files.pythonhosted.org/packages/3f/a8/16dc098b0addd1c20719c18a86e985be851b3ec1e103e703297169bb22cc"
  292. build_python importlib_metadata "${IMPORTLIB_METADATA_VERSION}"
  293. fi
  294. # ---------------------------------------------------------------------------------------------------------------------
  295. # cxfreeze
  296. download cx_Freeze "${CXFREEZE_VERSION}" "https://github.com/anthony-tuininga/cx_Freeze/archive" "" "nv"
  297. if [ "${CXFREEZE_VERSION}" = "6.4.2" ]; then
  298. patch_file cx_Freeze "${CXFREEZE_VERSION}" "setup.py" 's/extra_postargs=extraArgs,/extra_postargs=extraArgs+os.getenv("LDFLAGS").split(),/'
  299. patch_file cx_Freeze "${CXFREEZE_VERSION}" "cx_Freeze/macdist.py" 's/, use_builtin_types=False//'
  300. fi
  301. build_python cx_Freeze "${CXFREEZE_VERSION}"
  302. # ---------------------------------------------------------------------------------------------------------------------