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.

614 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 CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-fvisibility=hidden//')"
  289. export CXXFLAGS="$(echo ${CXXFLAGS} | sed -e 's/-ffast-math//')"
  290. touch "${pkgdir}/.stamp_configured"
  291. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  292. pushd "${pkgdir}"
  293. ${python} setup.py build ${extraconfrules}
  294. touch .stamp_built
  295. popd
  296. fi
  297. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  298. pushd "${pkgdir}"
  299. ${python} setup.py install --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  300. touch .stamp_installed
  301. popd
  302. fi
  303. _postbuild
  304. }
  305. function build_qmake() {
  306. local name="${1}"
  307. local version="${2}"
  308. local extraconfrules="${3}"
  309. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  310. _prebuild "${name}" "${pkgdir}"
  311. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  312. pushd "${pkgdir}"
  313. qmake ${extraconfrules}
  314. touch .stamp_configured
  315. popd
  316. fi
  317. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  318. pushd "${pkgdir}"
  319. make ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}
  320. touch .stamp_built
  321. popd
  322. fi
  323. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  324. pushd "${pkgdir}"
  325. make ${MAKE_ARGS} -j 1 install
  326. touch .stamp_installed
  327. popd
  328. fi
  329. _postbuild
  330. }
  331. function build_waf() {
  332. local name="${1}"
  333. local version="${2}"
  334. local extraconfrules="${3}"
  335. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  336. local python=python3
  337. if ! which python3 > /dev/null; then
  338. python=python
  339. fi
  340. _prebuild "${name}" "${pkgdir}"
  341. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  342. pushd "${pkgdir}"
  343. ${python} waf configure --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  344. touch .stamp_configured
  345. popd
  346. fi
  347. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  348. pushd "${pkgdir}"
  349. ${python} waf build ${WAF_ARGS}
  350. touch .stamp_built
  351. popd
  352. fi
  353. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  354. pushd "${pkgdir}"
  355. ${python} waf install ${WAF_ARGS} --prefix="${PAWPAW_PREFIX}" ${extraconfrules} -j 1
  356. rm -f ${PAWPAW_PREFIX}/lib/lv2/*/*.a
  357. touch .stamp_installed
  358. popd
  359. fi
  360. _postbuild
  361. }
  362. # ---------------------------------------------------------------------------------------------------------------------
  363. function build_host_autoconf() {
  364. local name="${1}"
  365. local version="${2}"
  366. local extraconfrules="${3}"
  367. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  368. unset AR
  369. unset CC
  370. unset CXX
  371. unset LD
  372. unset STRIP
  373. unset CFLAGS
  374. unset CPPFLAGS
  375. unset CXXFLAGS
  376. unset LDFLAGS
  377. if [ ! -f "${pkgdir}/.stamp_configured" ]; then
  378. pushd "${pkgdir}"
  379. ./configure --enable-static --disable-shared --disable-maintainer-mode --prefix="${PAWPAW_PREFIX}" ${extraconfrules}
  380. touch .stamp_configured
  381. popd
  382. fi
  383. if [ ! -f "${pkgdir}/.stamp_built" ]; then
  384. pushd "${pkgdir}"
  385. make ${MAKE_ARGS}
  386. touch .stamp_built
  387. popd
  388. fi
  389. if [ ! -f "${pkgdir}/.stamp_installed" ]; then
  390. pushd "${pkgdir}"
  391. make ${MAKE_ARGS} install -j 1
  392. touch .stamp_installed
  393. popd
  394. fi
  395. }
  396. # ---------------------------------------------------------------------------------------------------------------------
  397. function patch_file() {
  398. local name="${1}"
  399. local version="${2}"
  400. local file="${3}"
  401. local rule="${4}"
  402. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  403. if [ -e "${pkgdir}/${file}" ]; then
  404. sed -i -e "${rule}" "${pkgdir}/${file}"
  405. fi
  406. }
  407. function copy_file() {
  408. local name="${1}"
  409. local version="${2}"
  410. local source="${3}"
  411. local target="${4}"
  412. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  413. if [ ! -e "${pkgdir}/${target}" ]; then
  414. pushd "${pkgdir}"
  415. cp -v "${source}" "${target}"
  416. popd
  417. fi
  418. }
  419. function install_file() {
  420. local name="${1}"
  421. local version="${2}"
  422. local source="${3}"
  423. local targetdir="${4}"
  424. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  425. if [ ! -e "${PAWPAW_PREFIX}/${targetdir}/$(basename ${source})" ]; then
  426. pushd "${pkgdir}"
  427. cp -v "${source}" "${PAWPAW_PREFIX}/${targetdir}/"
  428. popd
  429. fi
  430. }
  431. function link_file() {
  432. local name="${1}"
  433. local version="${2}"
  434. local source="${3}"
  435. local target="${4}"
  436. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  437. if [ ! -e "${pkgdir}/${target}" ]; then
  438. pushd "${pkgdir}"
  439. ln -sfv "${source}" "${target}"
  440. popd
  441. fi
  442. }
  443. function remove_file() {
  444. local name="${1}"
  445. local version="${2}"
  446. local file="${3}"
  447. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  448. if [ -e "${pkgdir}/${file}" ]; then
  449. rm -fv "${pkgdir}/${file}"
  450. fi
  451. }
  452. # ---------------------------------------------------------------------------------------------------------------------
  453. function patch_osx_binary_libs() {
  454. local file="${1}"
  455. if [ -L "${file}" ]; then
  456. return 0
  457. fi
  458. idname=$(otool -D "${file}")
  459. if otool -L "${file}" | grep -v ":" | grep -v "${idname}" | grep -q "${PAWPAW_PREFIX}"; then
  460. #install_name_tool -change "@rpath/QtCore.framework/Versions/5/QtCore" "@executable_path/QtCore" "${file}"
  461. #install_name_tool -change "@rpath/QtGui.framework/Versions/5/QtGui" "@executable_path/QtGui" "${file}"
  462. #install_name_tool -change "@rpath/QtWidgets.framework/Versions/5/QtWidgets" "@executable_path/QtWidgets" "${file}"
  463. #install_name_tool -change "@rpath/QtXml.framework/Versions/5/QtXml" "@executable_path/QtXml" "${file}"
  464. install_name_tool -change "@executable_path/../Frameworks/libjack.0.dylib" "/usr/local/lib/libjack.0.dylib" "${file}"
  465. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjack.0.dylib" "/usr/local/lib/libjack.0.dylib" "${file}"
  466. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjacknet.0.dylib" "/usr/local/lib/libjacknet.0.dylib" "${file}"
  467. install_name_tool -change "${PAWPAW_PREFIX}/jack2/lib/libjackserver.0.dylib" "/usr/local/lib/libjackserver.0.dylib" "${file}"
  468. fi
  469. }
  470. function patch_osx_qtapp() {
  471. local name="${1}"
  472. local version="${2}"
  473. local appfile="${3}"
  474. local pkgdir="${PAWPAW_BUILDDIR}/${name}-${version}"
  475. _prebuild "${name}" "${pkgdir}"
  476. mkdir -p "${appfile}/Contents/PlugIns/platforms"
  477. mkdir -p "${appfile}/Contents/PlugIns/printsupport"
  478. cp -v "${PAWPAW_PREFIX}/lib/qt5/plugins/platforms/libqcocoa.dylib" "${appfile}/Contents/PlugIns/platforms/"
  479. cp -v "${PAWPAW_PREFIX}/lib/qt5/plugins/printsupport/libcocoaprintersupport.dylib" "${appfile}/Contents/PlugIns/printsupport/"
  480. macdeployqt "${appfile}"
  481. rm -f "${appfile}/Contents/Frameworks/libjack.0.dylib"
  482. _postbuild
  483. }
  484. # ---------------------------------------------------------------------------------------------------------------------