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.

571 lines
15KB

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