diff options
author | Andreas Grapentin <andreas@grapentin.org> | 2018-03-01 10:33:51 +0100 |
---|---|---|
committer | Andreas Grapentin <andreas@grapentin.org> | 2018-03-01 10:33:51 +0100 |
commit | f65dc07b1bc6e22c31a871bc31e274b5bc92c5b8 (patch) | |
tree | 39b98aae7cb9801b288273c54689bf67e93affa4 /src/stage3/stage3.sh | |
parent | b2217b6adc3ee98c2acfedf12a78eaab03609afa (diff) |
building native stage3 packages
Diffstat (limited to 'src/stage3/stage3.sh')
-rwxr-xr-x | src/stage3/stage3.sh | 134 |
1 files changed, 130 insertions, 4 deletions
diff --git a/src/stage3/stage3.sh b/src/stage3/stage3.sh index 6b51e60..bd8457a 100755 --- a/src/stage3/stage3.sh +++ b/src/stage3/stage3.sh @@ -25,16 +25,142 @@ msg "Entering Stage 3" # set a bunch of convenience variables _builddir="$topbuilddir"/stage3 _srcdir="$topsrcdir"/stage3 -_chrootdir="$_builddir"/$CARCH-root +_makepkgdir="$_builddir"/$CARCH-makepkg _deptree="$_builddir"/DEPTREE _groups="base-devel" -_pkgdest="$_builddir"/packages +_pkgdest="$_builddir"/packages/$CARCH _logdest="$_builddir"/makepkglogs +export PKGDEST="$_pkgdest" +export LOGDEST="$_logdest" + check_exe librechroot -check_exe librelib check_exe libremakepkg +check_exe makepkg # prepare for the build -. "$_srcdir"/prepare_libretools.sh +. "$_srcdir"/prepare_chroot.sh +. "$_srcdir"/prepare_deptree.sh +. "$_srcdir"/prepare_decross.sh + +msg "starting $CARCH native build" + +# keep building packages until the deptree is empty +while [ -s "$_deptree" ]; do + # grab one without unfulfilled dependencies + _pkgname=$(grep '\[ *\]' "$_deptree" | head -n1 | awk '{print $1}') || true + [ -n "$_pkgname" ] || die "could not resolve dependencies. exiting." + + _pkgarch=$(pacman -Si $_pkgname | grep '^Architecture' | awk '{print $3}') + + # set arch to $CARCH, unless it is any + [ "x$_pkgarch" == "xany" ] || _pkgarch=$CARCH + + msg "makepkg: $_pkgname" + msg " remaining packages: $(cat "$_deptree" | wc -l)" + + echo -n "checking for built $_pkgname package ... " + _pkgfile=$(find $_pkgdest -regex "^.*/$_pkgname-[^-]*-[^-]*-[^-]*\.pkg\.tar\.xz\$") + [ -n "$_pkgfile" ] && _have_pkg=yes || _have_pkg=no + echo $_have_pkg + + if [ "x$_have_pkg" == "xno" ]; then + # prepare directories + _pkgdir="$_makepkgdir"/$_pkgname/pkg/$_pkgname + rm -rf "$_makepkgdir"/$_pkgname + mkdir -pv "$_makepkgdir"/$_pkgname + pushd "$_makepkgdir"/$_pkgname >/dev/null + + if [ "x$_pkgarch" == "xany" ]; then + # repackage arch=(any) packages + _pkgver=$(pacman -Si $_pkgname | grep '^Version' | awk '{print $3}') + pacman -Sw --noconfirm --cachedir "$_pkgdest" $_pkgname + ln -s "$_pkgdest"/$_pkgname-$_pkgver-any.pkg.tar.xz \ + "$_makepkgdir"/$_pkgname/$_pkgname-$_pkgver-any.pkg.tar.xz + elif [ "x$_pkgname" == "xca-certificates-mozilla" ]; then + # repackage ca-certificates-mozilla to avoid building nss + _pkgver=$(pacman -Si $_pkgname | grep '^Version' | awk '{print $3}') + pacman -Sw --noconfirm --cachedir . $_pkgname + mkdir tmp && bsdtar -C tmp -xf $_pkgname-$_pkgver-*.pkg.tar.xz + mkdir -p "$_pkgdir"/usr/share/ + cp -rv tmp/usr/share/ca-certificates/ "$_pkgdir"/usr/share/ + cat > "$_pkgdir"/.PKGINFO << EOF +pkgname = $_pkgname +pkgver = $_pkgver +pkgdesc = Mozilla's set of trusted CA certificates +url = https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS +builddate = $(date '+%s') +size = 0 +arch = $_pkgarch +EOF + cd "$_pkgdir" + env LANG=C bsdtar -czf .MTREE \ + --format=mtree \ + --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \ + .PKGINFO * + env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > \ + "$_pkgdest"/$_pkgname-$_pkgver-$_pkgarch.pkg.tar.xz + ln -s "$_pkgdest"/$_pkgname-$_pkgver-$_pkgarch.pkg.tar.xz \ + "$_makepkgdir"/$_pkgname/$_pkgname-$_pkgver-$_pkgarch.pkg.tar.xz + else + # acquire the pkgbuild and auxiliary files + _libre=https://www.parabola.nu/packages/libre/x86_64/$_pkgname/ + _core=https://www.archlinux.org/packages/core/x86_64/$_pkgname/ + _extra=https://www.archlinux.org/packages/extra/x86_64/$_pkgname/ + _community=https://www.archlinux.org/packages/community/x86_64/$_pkgname/ + for url in $_libre $_core $_extra $_community; do + if ! curl -s $url | grep -iq 'not found'; then + src=$(curl -s $url | grep -i 'source files' | cut -d'"' -f2 | sed 's#/tree/#/plain/#') + for link in $(curl -sL $src | grep '^ <li><a href' | cut -d"'" -f2 \ + | sed "s#^#$(echo $src | awk -F/ '{print $3}')#"); do + wget -q $link -O $(basename ${link%\?*}); + done + break + fi + done + + # patch for cross-compiling + if [ -f "$_srcdir"/patches/$_pkgname.patch ]; then + cp PKGBUILD{,.old} + patch -Np1 -i "$_srcdir"/patches/$_pkgname.patch + fi + + # substitute common variables + _config="https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain" + _config_sub="$_config;f=config.sub;hb=HEAD" + _config_guess="$_config;f=config.guess;hb=HEAD" + sed -i "s#@CONFIG_SUB@#curl \"$_config_sub\"#g; \ + s#@CONFIG_GUESS@#curl \"$_config_guess\"#g;" \ + PKGBUILD + + # enable the target CARCH in arch array + sed -i "s/arch=([^)]*/& $CARCH/" PKGBUILD + + # build the package + chown -R $SUDO_USER "$_makepkgdir"/$_pkgname + libremakepkg -n $CHOST-stage3 || die "error building $_pkgname" + fi + + popd >/dev/null + + # update pacman cache + rm -rf /var/cache/pacman/pkg-$CARCH/* + rm -rf "$_pkgdest"/native.{db,files}* + repo-add -q -R "$_pkgdest"/{native.db.tar.gz,*.pkg.tar.xz} + fi + + # install in chroot + _pkgfile=$(find $_pkgdest -regex "^.*/$_pkgname-[^-]*-[^-]*-[^-]*\.pkg\.tar\.xz\$" | head -n1) + set +o pipefail + yes | librechroot \ + -n "$CHOST-stage3" \ + -C "$_builddir"/config/pacman.conf \ + -M "$_builddir"/config/makepkg.conf \ + install-file "$_pkgfile" + set -o pipefail + + # remove pkg from deptree + sed -i "/^$_pkgname :/d; s/ $_pkgname\b//g" "$_deptree" +done +echo "all packages built." |