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.

629 lines
17KB

  1. #!/bin/bash
  2. # ---------------------------------------------------------------------------------------------------------------------
  3. function download() {
  4. local name="${1}"
  5. local version="${2}"
  6. local dlbaseurl="${3}"
  7. local dlext="${4}"
  8. local dlmethod="${5}"
  9. if [ -z "${dlext}" ]; then
  10. dlext="tar.gz"
  11. fi
  12. local dlfile="${PAWPAW_DOWNLOADDIR}/${name}-${version}.${dlext}"
  13. local dlfolder="${PAWPAW_BUILDDIR}/${name}-${version}"
  14. if [ ! -f "${dlfile}" ]; then
  15. if [ -n "${dlmethod}" ] && [ "${dlmethod}" = "git" ]; then
  16. local tmprepodir="${PAWPAW_TMPDIR}/${name}-${version}"
  17. rm -rf "${tmprepodir}"
  18. git clone --recursive "${dlbaseurl}" "${tmprepodir}"
  19. git -C "${tmprepodir}" checkout "${version}"
  20. git -C "${tmprepodir}" submodule update
  21. tar --exclude=".git" -czf "${dlfile}" -C "${PAWPAW_TMPDIR}" "${name}-${version}"
  22. rm -rf "${tmprepodir}"
  23. else
  24. local dlurl
  25. if echo ${dlbaseurl} | grep -q github.com; then
  26. if [ x"${dlmethod}" = x"nv" ]; then
  27. dlurl="${dlbaseurl}/${version}.${dlext}"
  28. else
  29. dlurl="${dlbaseurl}/v${version}.${dlext}"
  30. fi
  31. elif [ "${dlext}" = "orig.tar.gz" ]; then
  32. dlurl="${dlbaseurl}/${name}_${version}.${dlext}"
  33. else
  34. dlurl="${dlbaseurl}/${name}-${version}.${dlext}"
  35. fi
  36. curl -L "${dlurl}" -o "${dlfile}" --fail
  37. fi
  38. fi
  39. if [ ! -d "${dlfolder}" ]; then
  40. mkdir "${dlfolder}"
  41. tar -xf "${dlfile}" -C "${dlfolder}" --strip-components=1
  42. fi
  43. }
  44. function copy_download() {
  45. local name1="${1}"
  46. local name2="${2}"
  47. local version="${3}"
  48. local dlext="${4}"
  49. if [ -z "${dlext}" ]; then
  50. dlext="tar.gz"
  51. fi
  52. local dlfile1="${PAWPAW_DOWNLOADDIR}/${name1}-${version}.${dlext}"
  53. local dlfolder2="${PAWPAW_BUILDDIR}/${name2}-${version}"
  54. if [ ! -d "${dlfolder2}" ]; then
  55. mkdir "${dlfolder2}"
  56. tar -xf "${dlfile1}" -C "${dlfolder2}" --strip-components=1
  57. fi
  58. }
  59. # ---------------------------------------------------------------------------------------------------------------------
  60. function _prebuild() {
  61. local name="${1}"
  62. local pkgdir="${2}"
  63. export AR="${TARGET_AR}"
  64. export CC="${TARGET_CC}"
  65. export CXX="${TARGET_CXX}"
  66. export LD="${TARGET_LD}"
  67. export STRIP="${TARGET_STRIP}"
  68. export CFLAGS="${TARGET_CFLAGS} ${EXTRA_CFLAGS}"
  69. export CXXFLAGS="${TARGET_CXXFLAGS} ${EXTRA_CXXFLAGS}"
  70. export LDFLAGS="${TARGET_LDFLAGS} ${EXTRA_LDFLAGS}"
  71. export PKG_CONFIG_PATH="${TARGET_PKG_CONFIG_PATH}"
  72. unset CPPFLAGS
  73. export OLD_PATH="${PATH}"
  74. export PATH="${TARGET_PATH}"
  75. if [ -d "${PAWPAW_ROOT}/patches/${name}" ]; then
  76. for p in $(ls "${PAWPAW_ROOT}/patches/${name}/" | grep "\.patch" | sort); do
  77. if [ ! -f "${pkgdir}/.stamp_applied_${p}" ]; then
  78. patch -p1 -d "${pkgdir}" -i "${PAWPAW_ROOT}/patches/${name}/${p}"
  79. touch "${pkgdir}/.stamp_applied_${p}"
  80. fi
  81. done
  82. fi
  83. if [ -d "${PAWPAW_ROOT}/patches/${name}/${PAWPAW_TARGET}" ]; then
  84. for p in $(ls "${PAWPAW_ROOT}/patches/${name}/${PAWPAW_TARGET}/" | grep "\.patch" | sort); do
  85. if [ ! -f "${pkgdir}/.stamp_applied_${p}" ]; then
  86. patch -p1 -d "${pkgdir}" -i "${PAWPAW_ROOT}/patches/${name}/${PAWPAW_TARGET}/${p}"
  87. touch "${pkgdir}/.stamp_applied_${p}"
  88. fi
  89. done
  90. fi
  91. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  92. rm -f "${pkgdir}/.stamp_built"
  93. rm -f "${pkgdir}/.stamp_installed"
  94. rm -f "${pkgdir}/CMakeCache.txt"
  95. elif [ ! -f "${pkgdir}/.stamp_built" ]; then
  96. rm -f "${pkgdir}/.stamp_installed"
  97. fi
  98. }
  99. function _postbuild() {
  100. unset AR
  101. unset CC
  102. unset CXX
  103. unset LD
  104. unset STRIP
  105. unset CFLAGS
  106. unset CPPFLAGS
  107. unset CXXFLAGS
  108. unset LDFLAGS
  109. unset PKG_CONFIG_PATH
  110. unset EXTRA_CFLAGS
  111. unset EXTRA_CXXFLAGS
  112. unset EXTRA_LDFLAGS
  113. unset EXTRA_MAKE_ARGS
  114. export PATH="${OLD_PATH}"
  115. }
  116. # ---------------------------------------------------------------------------------------------------------------------
  117. function build_autoconf() {
  118. local name="${1}"
  119. local version="${2}"
  120. local extraconfrules="${3}"
  121. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  122. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  123. extraconfrules="--host=${TOOLCHAIN_PREFIX} ${extraconfrules}"
  124. fi
  125. _prebuild "${name}" "${pkgdir}"
  126. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  127. pushd "${pkgdir}"
  128. ./configure --enable-static --disable-shared --disable-debug --disable-doc --disable-docs --disable-maintainer-mode --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  129. touch .stamp_configured
  130. popd
  131. fi
  132. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  133. pushd "${pkgdir}"
  134. make ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}
  135. touch .stamp_built
  136. popd
  137. fi
  138. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  139. pushd "${pkgdir}"
  140. make ${MAKE_ARGS} install -j 1
  141. touch .stamp_installed
  142. popd
  143. fi
  144. _postbuild
  145. }
  146. function build_autoconfgen() {
  147. local name="${1}"
  148. local version="${2}"
  149. local extraconfrules="${3}"
  150. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  151. local EXTRA_CFLAGS2="${EXTRA_CFLAGS}"
  152. local EXTRA_CXXFLAGS2="${EXTRA_CXXFLAGS}"
  153. local EXTRA_LDFLAGS2="${EXTRA_LDFLAGS}"
  154. local EXTRA_MAKE_ARGS2="${EXTRA_MAKE_ARGS}"
  155. _prebuild "${name}" "${pkgdir}"
  156. if [ ! -f "${pkgdir}/.stamp_preconfigured" ]; then
  157. pushd "${pkgdir}"
  158. autoconf
  159. touch .stamp_preconfigured
  160. popd
  161. fi
  162. _postbuild
  163. export EXTRA_CFLAGS="${EXTRA_CFLAGS2}"
  164. export EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS2}"
  165. export EXTRA_LDFLAGS="${EXTRA_LDFLAGS2}"
  166. export EXTRA_MAKE_ARGS="${EXTRA_MAKE_ARGS2}"
  167. build_autoconf "${name}" "${version}" "${extraconfrules}"
  168. }
  169. function build_conf() {
  170. local name="${1}"
  171. local version="${2}"
  172. local extraconfrules="${3}"
  173. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  174. _prebuild "${name}" "${pkgdir}"
  175. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  176. pushd "${pkgdir}"
  177. ./configure ${extraconfrules}
  178. touch .stamp_configured
  179. popd
  180. fi
  181. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  182. pushd "${pkgdir}"
  183. make ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}
  184. touch .stamp_built
  185. popd
  186. fi
  187. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  188. pushd "${pkgdir}"
  189. make ${MAKE_ARGS} -j 1 install
  190. touch .stamp_installed
  191. popd
  192. fi
  193. _postbuild
  194. }
  195. function build_cmake() {
  196. local name="${1}"
  197. local version="${2}"
  198. local extraconfrules="${3}"
  199. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  200. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  201. extraconfrules+=" -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}"
  202. fi
  203. if [ "${MACOS}" -eq 1 ]; then
  204. if [ "${MACOS_OLD}" -eq 1 ]; then
  205. OSX_TARGET="10.5"
  206. elif [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  207. OSX_TARGET="10.12"
  208. else
  209. OSX_TARGET="10.8"
  210. fi
  211. extraconfrules+=" -DCMAKE_OSX_DEPLOYMENT_TARGET=${OSX_TARGET}"
  212. fi
  213. _prebuild "${name}" "${pkgdir}"
  214. mkdir -p "${pkgdir}/build"
  215. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  216. pushd "${pkgdir}/build"
  217. cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX="${PAWPAW_PREFIX}" ${extraconfrules} ..
  218. touch ../.stamp_configured
  219. popd
  220. fi
  221. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  222. pushd "${pkgdir}/build"
  223. make ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}
  224. touch ../.stamp_built
  225. popd
  226. fi
  227. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  228. pushd "${pkgdir}/build"
  229. make ${MAKE_ARGS} -j 1 install
  230. touch ../.stamp_installed
  231. popd
  232. fi
  233. _postbuild
  234. }
  235. function build_make() {
  236. local name="${1}"
  237. local version="${2}"
  238. local extraconfrules="${3}"
  239. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  240. _prebuild "${name}" "${pkgdir}"
  241. touch "${pkgdir}/.stamp_configured"
  242. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  243. pushd "${pkgdir}"
  244. make PREFIX="${PAWPAW_PREFIX}" PKG_CONFIG="${TARGET_PKG_CONFIG}" ${MAKE_ARGS} ${extraconfrules}
  245. touch .stamp_built
  246. popd
  247. fi
  248. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  249. pushd "${pkgdir}"
  250. make PREFIX="${PAWPAW_PREFIX}" PKG_CONFIG="${TARGET_PKG_CONFIG}" ${MAKE_ARGS} ${extraconfrules} -j 1 install
  251. touch .stamp_installed
  252. popd
  253. fi
  254. _postbuild
  255. }
  256. function build_meson() {
  257. local name="${1}"
  258. local version="${2}"
  259. local extraconfrules="${3}"
  260. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  261. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  262. extraconfrules="--cross-file "${PAWPAW_ROOT}/setup/meson/${PAWPAW_TARGET}.ini" ${extraconfrules}"
  263. fi
  264. _prebuild "${name}" "${pkgdir}"
  265. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  266. pushd "${pkgdir}"
  267. meson build --buildtype release --prefix "${PAWPAW_PREFIX}" ${extraconfrules}
  268. touch .stamp_configured
  269. popd
  270. fi
  271. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  272. pushd "${pkgdir}"
  273. ninja -v -C build
  274. touch .stamp_built
  275. popd
  276. fi
  277. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  278. pushd "${pkgdir}"
  279. ninja -C build install
  280. touch .stamp_installed
  281. popd
  282. fi
  283. _postbuild
  284. }
  285. function build_python() {
  286. local name="${1}"
  287. local version="${2}"
  288. local extraconfrules="${3}"
  289. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  290. local python=python3
  291. if [ ! -e "${PAWPAW_PREFIX}/bin/python3" ] && ! which python3 > /dev/null; then
  292. python=python
  293. fi
  294. _prebuild "${name}" "${pkgdir}"
  295. # fix build of python packages
  296. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fvisibility=hidden//')"
  297. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-ffast-math//')"
  298. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  299. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility=hidden//')"
  300. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-ffast-math//')"
  301. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility-inlines-hidden//')"
  302. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  303. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-dead_strip -Wl,-dead_strip_dylibs//')"
  304. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  305. touch "${pkgdir}/.stamp_configured"
  306. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  307. pushd "${pkgdir}"
  308. ${python} setup.py build ${extraconfrules}
  309. touch .stamp_built
  310. popd
  311. fi
  312. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  313. pushd "${pkgdir}"
  314. ${python} setup.py install --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  315. touch .stamp_installed
  316. popd
  317. fi
  318. _postbuild
  319. }
  320. function build_qmake() {
  321. local name="${1}"
  322. local version="${2}"
  323. local extraconfrules="${3}"
  324. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  325. _prebuild "${name}" "${pkgdir}"
  326. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  327. pushd "${pkgdir}"
  328. qmake ${extraconfrules}
  329. touch .stamp_configured
  330. popd
  331. fi
  332. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  333. pushd "${pkgdir}"
  334. make ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}
  335. touch .stamp_built
  336. popd
  337. fi
  338. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  339. pushd "${pkgdir}"
  340. make ${MAKE_ARGS} -j 1 install
  341. touch .stamp_installed
  342. popd
  343. fi
  344. _postbuild
  345. }
  346. function build_waf() {
  347. local name="${1}"
  348. local version="${2}"
  349. local extraconfrules="${3}"
  350. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  351. local python=python3
  352. if ! which python3 > /dev/null; then
  353. python=python
  354. fi
  355. _prebuild "${name}" "${pkgdir}"
  356. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  357. pushd "${pkgdir}"
  358. ${python} waf configure --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  359. touch .stamp_configured
  360. popd
  361. fi
  362. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  363. pushd "${pkgdir}"
  364. ${python} waf build ${WAF_ARGS}
  365. touch .stamp_built
  366. popd
  367. fi
  368. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  369. pushd "${pkgdir}"
  370. ${python} waf install ${WAF_ARGS} --prefix="${PAWPAW_PREFIX}" ${extraconfrules} -j 1
  371. rm -f ${PAWPAW_PREFIX}/lib/lv2/*/*.a
  372. touch .stamp_installed
  373. popd
  374. fi
  375. _postbuild
  376. }
  377. # ---------------------------------------------------------------------------------------------------------------------
  378. function build_host_autoconf() {
  379. local name="${1}"
  380. local version="${2}"
  381. local extraconfrules="${3}"
  382. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  383. unset AR
  384. unset CC
  385. unset CXX
  386. unset LD
  387. unset STRIP
  388. unset CFLAGS
  389. unset CPPFLAGS
  390. unset CXXFLAGS
  391. unset LDFLAGS
  392. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  393. pushd "${pkgdir}"
  394. ./configure --enable-static --disable-shared --disable-maintainer-mode --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  395. touch .stamp_configured
  396. popd
  397. fi
  398. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  399. pushd "${pkgdir}"
  400. make ${MAKE_ARGS}
  401. touch .stamp_built
  402. popd
  403. fi
  404. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  405. pushd "${pkgdir}"
  406. make ${MAKE_ARGS} install -j 1
  407. touch .stamp_installed
  408. popd
  409. fi
  410. }
  411. # ---------------------------------------------------------------------------------------------------------------------
  412. function patch_file() {
  413. local name="${1}"
  414. local version="${2}"
  415. local file="${3}"
  416. local rule="${4}"
  417. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  418. if [ -e "${pkgdir}/${file}" ]; then
  419. sed -i -e "${rule}" "${pkgdir}/${file}"
  420. fi
  421. }
  422. function copy_file() {
  423. local name="${1}"
  424. local version="${2}"
  425. local source="${3}"
  426. local target="${4}"
  427. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  428. if [ ! -e "${pkgdir}/${target}" ] || [ "${source}" -nt "${target}" ]; then
  429. pushd "${pkgdir}"
  430. cp -v "${source}" "${target}"
  431. popd
  432. fi
  433. }
  434. function install_file() {
  435. local name="${1}"
  436. local version="${2}"
  437. local source="${3}"
  438. local targetdir="${4}"
  439. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  440. if [ ! -e "${PAWPAW_PREFIX}/${targetdir}/$(basename ${source})" ]; then
  441. pushd "${pkgdir}"
  442. cp -v "${source}" "${PAWPAW_PREFIX}/${targetdir}/"
  443. popd
  444. fi
  445. }
  446. function link_file() {
  447. local name="${1}"
  448. local version="${2}"
  449. local source="${3}"
  450. local target="${4}"
  451. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  452. if [ ! -e "${pkgdir}/${target}" ]; then
  453. pushd "${pkgdir}"
  454. ln -sfv "${source}" "${target}"
  455. popd
  456. fi
  457. }
  458. function remove_file() {
  459. local name="${1}"
  460. local version="${2}"
  461. local file="${3}"
  462. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  463. if [ -e "${pkgdir}/${file}" ]; then
  464. rm -fv "${pkgdir}/${file}"
  465. fi
  466. }
  467. # ---------------------------------------------------------------------------------------------------------------------
  468. function patch_osx_binary_libs() {
  469. local file="${1}"
  470. if [ -L "${file}" ]; then
  471. return 0
  472. fi
  473. idname=$(otool -D "${file}")
  474. if otool -L "${file}" | grep -v ":" | grep -v "${idname}" | grep -q "${PAWPAW_PREFIX}"; then
  475. #install_name_tool -change "@rpath/QtCore.framework/Versions/5/QtCore" "@executable_path/QtCore" "${file}"
  476. #install_name_tool -change "@rpath/QtGui.framework/Versions/5/QtGui" "@executable_path/QtGui" "${file}"
  477. #install_name_tool -change "@rpath/QtWidgets.framework/Versions/5/QtWidgets" "@executable_path/QtWidgets" "${file}"
  478. #install_name_tool -change "@rpath/QtXml.framework/Versions/5/QtXml" "@executable_path/QtXml" "${file}"
  479. install_name_tool -change "@executable_path/../Frameworks/libjack.0.dylib" "/usr/local/lib/libjack.0.dylib" "${file}"
  480. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjack.0.dylib" "/usr/local/lib/libjack.0.dylib" "${file}"
  481. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjacknet.0.dylib" "/usr/local/lib/libjacknet.0.dylib" "${file}"
  482. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjackserver.0.dylib" "/usr/local/lib/libjackserver.0.dylib" "${file}"
  483. fi
  484. }
  485. function patch_osx_qtapp() {
  486. local name="${1}"
  487. local version="${2}"
  488. local appfile="${3}"
  489. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  490. _prebuild "${name}" "${pkgdir}"
  491. mkdir -p "${appfile}/Contents/PlugIns/platforms"
  492. mkdir -p "${appfile}/Contents/PlugIns/printsupport"
  493. cp -v "${PAWPAW_PREFIX}/lib/qt5/plugins/platforms/libqcocoa.dylib" "${appfile}/Contents/PlugIns/platforms/"
  494. cp -v "${PAWPAW_PREFIX}/lib/qt5/plugins/printsupport/libcocoaprintersupport.dylib" "${appfile}/Contents/PlugIns/printsupport/"
  495. macdeployqt "${appfile}"
  496. rm -f "${appfile}/Contents/Frameworks/libjack.0.dylib"
  497. _postbuild
  498. }
  499. # ---------------------------------------------------------------------------------------------------------------------