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.

619 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} ${extraconfrules}"
  202. fi
  203. _prebuild "${name}" "${pkgdir}"
  204. mkdir -p "${pkgdir}/build"
  205. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  206. pushd "${pkgdir}/build"
  207. cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX="${PAWPAW_PREFIX}" ${extraconfrules} ..
  208. touch ../.stamp_configured
  209. popd
  210. fi
  211. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  212. pushd "${pkgdir}/build"
  213. make ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}
  214. touch ../.stamp_built
  215. popd
  216. fi
  217. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  218. pushd "${pkgdir}/build"
  219. make ${MAKE_ARGS} -j 1 install
  220. touch ../.stamp_installed
  221. popd
  222. fi
  223. _postbuild
  224. }
  225. function build_make() {
  226. local name="${1}"
  227. local version="${2}"
  228. local extraconfrules="${3}"
  229. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  230. _prebuild "${name}" "${pkgdir}"
  231. touch "${pkgdir}/.stamp_configured"
  232. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  233. pushd "${pkgdir}"
  234. make PREFIX="${PAWPAW_PREFIX}" PKG_CONFIG="${TARGET_PKG_CONFIG}" ${MAKE_ARGS} ${extraconfrules}
  235. touch .stamp_built
  236. popd
  237. fi
  238. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  239. pushd "${pkgdir}"
  240. make PREFIX="${PAWPAW_PREFIX}" PKG_CONFIG="${TARGET_PKG_CONFIG}" ${MAKE_ARGS} ${extraconfrules} -j 1 install
  241. touch .stamp_installed
  242. popd
  243. fi
  244. _postbuild
  245. }
  246. function build_meson() {
  247. local name="${1}"
  248. local version="${2}"
  249. local extraconfrules="${3}"
  250. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  251. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  252. extraconfrules="--cross-file "${PAWPAW_ROOT}/setup/meson/${PAWPAW_TARGET}.ini" ${extraconfrules}"
  253. fi
  254. _prebuild "${name}" "${pkgdir}"
  255. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  256. pushd "${pkgdir}"
  257. meson build --buildtype release --prefix "${PAWPAW_PREFIX}" ${extraconfrules}
  258. touch .stamp_configured
  259. popd
  260. fi
  261. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  262. pushd "${pkgdir}"
  263. ninja -v -C build
  264. touch .stamp_built
  265. popd
  266. fi
  267. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  268. pushd "${pkgdir}"
  269. ninja -C build install
  270. touch .stamp_installed
  271. popd
  272. fi
  273. _postbuild
  274. }
  275. function build_python() {
  276. local name="${1}"
  277. local version="${2}"
  278. local extraconfrules="${3}"
  279. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  280. local python=python3
  281. if [ ! -e "${PAWPAW_PREFIX}/bin/python3" ] && ! which python3 > /dev/null; then
  282. python=python
  283. fi
  284. _prebuild "${name}" "${pkgdir}"
  285. # fix build of python packages
  286. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fvisibility=hidden//')"
  287. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-ffast-math//')"
  288. export CFLAGS="$(echo ${CFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  289. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility=hidden//')"
  290. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-ffast-math//')"
  291. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility-inlines-hidden//')"
  292. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  293. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-Wl,-dead_strip -Wl,-dead_strip_dylibs//')"
  294. export LDFLAGS="$(echo ${LDFLAGS} | sed -e 's/-fdata-sections -ffunction-sections//')"
  295. touch "${pkgdir}/.stamp_configured"
  296. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  297. pushd "${pkgdir}"
  298. ${python} setup.py build ${extraconfrules}
  299. touch .stamp_built
  300. popd
  301. fi
  302. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  303. pushd "${pkgdir}"
  304. ${python} setup.py install --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  305. touch .stamp_installed
  306. popd
  307. fi
  308. _postbuild
  309. }
  310. function build_qmake() {
  311. local name="${1}"
  312. local version="${2}"
  313. local extraconfrules="${3}"
  314. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  315. _prebuild "${name}" "${pkgdir}"
  316. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  317. pushd "${pkgdir}"
  318. qmake ${extraconfrules}
  319. touch .stamp_configured
  320. popd
  321. fi
  322. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  323. pushd "${pkgdir}"
  324. make ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}
  325. touch .stamp_built
  326. popd
  327. fi
  328. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  329. pushd "${pkgdir}"
  330. make ${MAKE_ARGS} -j 1 install
  331. touch .stamp_installed
  332. popd
  333. fi
  334. _postbuild
  335. }
  336. function build_waf() {
  337. local name="${1}"
  338. local version="${2}"
  339. local extraconfrules="${3}"
  340. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  341. local python=python3
  342. if ! which python3 > /dev/null; then
  343. python=python
  344. fi
  345. _prebuild "${name}" "${pkgdir}"
  346. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  347. pushd "${pkgdir}"
  348. ${python} waf configure --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  349. touch .stamp_configured
  350. popd
  351. fi
  352. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  353. pushd "${pkgdir}"
  354. ${python} waf build ${WAF_ARGS}
  355. touch .stamp_built
  356. popd
  357. fi
  358. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  359. pushd "${pkgdir}"
  360. ${python} waf install ${WAF_ARGS} --prefix="${PAWPAW_PREFIX}" ${extraconfrules} -j 1
  361. rm -f ${PAWPAW_PREFIX}/lib/lv2/*/*.a
  362. touch .stamp_installed
  363. popd
  364. fi
  365. _postbuild
  366. }
  367. # ---------------------------------------------------------------------------------------------------------------------
  368. function build_host_autoconf() {
  369. local name="${1}"
  370. local version="${2}"
  371. local extraconfrules="${3}"
  372. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  373. unset AR
  374. unset CC
  375. unset CXX
  376. unset LD
  377. unset STRIP
  378. unset CFLAGS
  379. unset CPPFLAGS
  380. unset CXXFLAGS
  381. unset LDFLAGS
  382. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  383. pushd "${pkgdir}"
  384. ./configure --enable-static --disable-shared --disable-maintainer-mode --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  385. touch .stamp_configured
  386. popd
  387. fi
  388. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  389. pushd "${pkgdir}"
  390. make ${MAKE_ARGS}
  391. touch .stamp_built
  392. popd
  393. fi
  394. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  395. pushd "${pkgdir}"
  396. make ${MAKE_ARGS} install -j 1
  397. touch .stamp_installed
  398. popd
  399. fi
  400. }
  401. # ---------------------------------------------------------------------------------------------------------------------
  402. function patch_file() {
  403. local name="${1}"
  404. local version="${2}"
  405. local file="${3}"
  406. local rule="${4}"
  407. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  408. if [ -e "${pkgdir}/${file}" ]; then
  409. sed -i -e "${rule}" "${pkgdir}/${file}"
  410. fi
  411. }
  412. function copy_file() {
  413. local name="${1}"
  414. local version="${2}"
  415. local source="${3}"
  416. local target="${4}"
  417. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  418. if [ ! -e "${pkgdir}/${target}" ]; then
  419. pushd "${pkgdir}"
  420. cp -v "${source}" "${target}"
  421. popd
  422. fi
  423. }
  424. function install_file() {
  425. local name="${1}"
  426. local version="${2}"
  427. local source="${3}"
  428. local targetdir="${4}"
  429. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  430. if [ ! -e "${PAWPAW_PREFIX}/${targetdir}/$(basename ${source})" ]; then
  431. pushd "${pkgdir}"
  432. cp -v "${source}" "${PAWPAW_PREFIX}/${targetdir}/"
  433. popd
  434. fi
  435. }
  436. function link_file() {
  437. local name="${1}"
  438. local version="${2}"
  439. local source="${3}"
  440. local target="${4}"
  441. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  442. if [ ! -e "${pkgdir}/${target}" ]; then
  443. pushd "${pkgdir}"
  444. ln -sfv "${source}" "${target}"
  445. popd
  446. fi
  447. }
  448. function remove_file() {
  449. local name="${1}"
  450. local version="${2}"
  451. local file="${3}"
  452. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  453. if [ -e "${pkgdir}/${file}" ]; then
  454. rm -fv "${pkgdir}/${file}"
  455. fi
  456. }
  457. # ---------------------------------------------------------------------------------------------------------------------
  458. function patch_osx_binary_libs() {
  459. local file="${1}"
  460. if [ -L "${file}" ]; then
  461. return 0
  462. fi
  463. idname=$(otool -D "${file}")
  464. if otool -L "${file}" | grep -v ":" | grep -v "${idname}" | grep -q "${PAWPAW_PREFIX}"; then
  465. #install_name_tool -change "@rpath/QtCore.framework/Versions/5/QtCore" "@executable_path/QtCore" "${file}"
  466. #install_name_tool -change "@rpath/QtGui.framework/Versions/5/QtGui" "@executable_path/QtGui" "${file}"
  467. #install_name_tool -change "@rpath/QtWidgets.framework/Versions/5/QtWidgets" "@executable_path/QtWidgets" "${file}"
  468. #install_name_tool -change "@rpath/QtXml.framework/Versions/5/QtXml" "@executable_path/QtXml" "${file}"
  469. install_name_tool -change "@executable_path/../Frameworks/libjack.0.dylib" "/usr/local/lib/libjack.0.dylib" "${file}"
  470. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjack.0.dylib" "/usr/local/lib/libjack.0.dylib" "${file}"
  471. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjacknet.0.dylib" "/usr/local/lib/libjacknet.0.dylib" "${file}"
  472. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjackserver.0.dylib" "/usr/local/lib/libjackserver.0.dylib" "${file}"
  473. fi
  474. }
  475. function patch_osx_qtapp() {
  476. local name="${1}"
  477. local version="${2}"
  478. local appfile="${3}"
  479. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  480. _prebuild "${name}" "${pkgdir}"
  481. mkdir -p "${appfile}/Contents/PlugIns/platforms"
  482. mkdir -p "${appfile}/Contents/PlugIns/printsupport"
  483. cp -v "${PAWPAW_PREFIX}/lib/qt5/plugins/platforms/libqcocoa.dylib" "${appfile}/Contents/PlugIns/platforms/"
  484. cp -v "${PAWPAW_PREFIX}/lib/qt5/plugins/printsupport/libcocoaprintersupport.dylib" "${appfile}/Contents/PlugIns/printsupport/"
  485. macdeployqt "${appfile}"
  486. rm -f "${appfile}/Contents/Frameworks/libjack.0.dylib"
  487. _postbuild
  488. }
  489. # ---------------------------------------------------------------------------------------------------------------------