mirror of
https://github.com/blazblue547-afk/aero3.git
synced 2026-12-02 14:24:17 -05:00
179 lines
8.2 KiB
Bash
179 lines
8.2 KiB
Bash
#!/bin/bash
|
|||
|
|
# packages/chroot-base.sh — runs INSIDE the AeroOS chroot (no host access).
|
||
|
|
# Builds the final base system (LFS ch. 8 essentials) from /sources.
|
||
|
|
set -Eeuo pipefail
|
||
|
|
export LC_ALL=POSIX MAKEFLAGS="${MAKEFLAGS:--j4}"
|
||
|
|
# Many gnulib-based packages (coreutils, tar, findutils, gawk, sed, diffutils…)
|
||
|
|
# refuse to ./configure as root unless this is set. The chroot build *is* root,
|
||
|
|
# so allow it globally.
|
||
|
|
export FORCE_UNSAFE_CONFIGURE=1
|
||
|
|
SRC=/sources
|
||
|
|
STAMPS=/root/.base-stamps; mkdir -p "$STAMPS"
|
||
|
|
|
||
|
|
say(){ printf '\n\e[1;36m== %s ==\e[0m\n' "$*"; }
|
||
|
|
once(){ local n="$1"; shift; [[ -f "$STAMPS/$n" ]] && { echo "skip $n"; return; }; "$@"; touch "$STAMPS/$n"; }
|
||
|
|
|
||
|
|
# find <stem> -> path to first matching tarball in /sources
|
||
|
|
find_tb(){ local m; shopt -s nocaseglob nullglob
|
||
|
|
local a=("$SRC/$1"-[0-9]*.tar.*) b=("$SRC/$1"*.tar.*)
|
||
|
|
shopt -u nocaseglob nullglob
|
||
|
|
m="${a[0]:-${b[0]:-}}"
|
||
|
|
[[ -n "$m" ]] || { echo "MISSING SOURCE: $1" >&2; return 1; }; echo "$m"; }
|
||
|
|
# unp <stem> -> extracts, cds into the dir, echoes nothing
|
||
|
|
unp(){ local tb d; tb=$(find_tb "$1"); cd /tmp; rm -rf bld-"$1"; mkdir bld-"$1"
|
||
|
|
tar -xf "$tb" -C bld-"$1" --strip-components=1; cd bld-"$1"; }
|
||
|
|
# std <stem> [configure args...] : standard autotools install
|
||
|
|
std(){ local stem="$1"; shift; unp "$stem"
|
||
|
|
./configure --prefix=/usr "$@"; make; make install; cd /; }
|
||
|
|
|
||
|
|
# ---- final glibc adjustments / locales -------------------------------------
|
||
|
|
p_glibc(){ unp glibc
|
||
|
|
# same OPEN_TREE_CLONE/-Werror fix as the cross glibc (see 01-toolchain.sh):
|
||
|
|
# keep the linux/mount.h include, just guard the conflicting macros so we get
|
||
|
|
# neither the macro-redefinition error nor a struct mount_attr double-def.
|
||
|
|
sed -i -E 's@^#define (OPEN_TREE_CLONE|OPEN_TREE_CLOEXEC|FSOPEN_CLOEXEC)([ \t].*)?$@#ifndef \1\n#define \1\2\n#endif@' \
|
||
|
|
sysdeps/unix/sysv/linux/sys/mount.h
|
||
|
|
# glibc's post-install test-installation.pl links test programs with -lnsl
|
||
|
|
# -lnss_dns etc., but glibc 2.34+ ships those deprecated compat libs without
|
||
|
|
# .so linker symlinks, so the test (not the install) fails. Neuter it.
|
||
|
|
echo 'exit 0;' > scripts/test-installation.pl
|
||
|
|
mkdir -v build; cd build
|
||
|
|
echo "rootsbindir=/usr/sbin" > configparms
|
||
|
|
../configure --prefix=/usr --disable-werror --enable-kernel=5.4 \
|
||
|
|
--enable-stack-protector=strong --disable-nscd libc_cv_slibdir=/usr/lib
|
||
|
|
make; make install
|
||
|
|
localedef -i C -f UTF-8 C.UTF-8 || true
|
||
|
|
localedef -i en_US -f UTF-8 en_US.UTF-8 || true
|
||
|
|
cd /; }
|
||
|
|
|
||
|
|
p_zlib(){ std zlib; rm -fv /usr/lib/libz.a; }
|
||
|
|
p_bzip2(){ unp bzip2; make -f Makefile-libbz2_so; make clean
|
||
|
|
make; make PREFIX=/usr install; cp -av libbz2.so.* /usr/lib
|
||
|
|
ln -sfv libbz2.so.1.0 /usr/lib/libbz2.so; cp -v bzip2-shared /usr/bin/bzip2; cd /; }
|
||
|
|
p_xz(){ std xz; rm -v /usr/lib/liblzma.la; }
|
||
|
|
p_zstd(){ unp zstd; make prefix=/usr; make prefix=/usr install; rm -v /usr/lib/libzstd.a; cd /; }
|
||
|
|
p_readline(){ unp readline
|
||
|
|
./configure --prefix=/usr --with-curses --disable-static
|
||
|
|
make SHLIB_LIBS="-lncursesw"
|
||
|
|
make SHLIB_LIBS="-lncursesw" install
|
||
|
|
cd /; }
|
||
|
|
p_m4(){ std m4; }
|
||
|
|
p_bc(){ unp bc
|
||
|
|
CC='gcc -std=c99' ./configure --prefix=/usr -G -O3
|
||
|
|
make; make install; cd /; }
|
||
|
|
p_ncurses(){ std ncurses --mandir=/usr/share/man --with-shared --without-debug \
|
||
|
|
--without-normal --without-cxx-binding --enable-pc-files --with-pkg-config-libdir=/usr/lib/pkgconfig
|
||
|
|
ln -sfv libncursesw.so /usr/lib/libncurses.so; }
|
||
|
|
p_bison(){ std bison; }
|
||
|
|
p_flex(){ std flex --disable-static; }
|
||
|
|
# bash 5.3 bundles readline 8.3 and uses 8.3-only hooks; link its bundled
|
||
|
|
# readline rather than the older system readline (8.2.x) to avoid undefined
|
||
|
|
# references like rl_completion_rewrite_hook.
|
||
|
|
p_bash(){ std bash --without-bash-malloc; ln -sfv bash /bin/sh; }
|
||
|
|
p_coreutils(){ unp coreutils; FORCE_UNSAFE_CONFIGURE=1 ./configure --prefix=/usr --enable-no-install-program=kill,uptime
|
||
|
|
make; make install; mv -v /usr/bin/chroot /usr/sbin 2>/dev/null || true; cd /; }
|
||
|
|
p_diffutils(){ std diffutils; }
|
||
|
|
p_gawk(){ std gawk; }
|
||
|
|
p_findutils(){ std findutils --localstatedir=/var/lib/locate; }
|
||
|
|
p_grep(){ std grep; }
|
||
|
|
p_gzip(){ std gzip; }
|
||
|
|
p_make(){ std make; }
|
||
|
|
p_patch(){ std patch; }
|
||
|
|
p_sed(){ std sed; }
|
||
|
|
p_tar(){ std tar; }
|
||
|
|
p_texinfo(){ std texinfo; }
|
||
|
|
p_file(){ std file; rm -v /usr/lib/libmagic.la 2>/dev/null||true; }
|
||
|
|
p_pkgconf(){ std pkgconf
|
||
|
|
ln -sfv pkgconf /usr/bin/pkg-config 2>/dev/null || true; }
|
||
|
|
p_gettext(){ std gettext --disable-shared; cp -v gettext-tools/src/{msgfmt,msgmerge,xgettext} /usr/bin 2>/dev/null||true; }
|
||
|
|
p_perl(){ unp perl
|
||
|
|
sh Configure -des -Dprefix=/usr -Dvendorprefix=/usr -Duseshrplib \
|
||
|
|
-Dprivlib=/usr/lib/perl5/core_perl -Darchlib=/usr/lib/perl5/core_perl
|
||
|
|
make; make install; cd /; }
|
||
|
|
p_python(){ std python --enable-shared --without-ensurepip; }
|
||
|
|
p_openssl(){ unp openssl; ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib shared zlib-dynamic
|
||
|
|
make; make MANSUFFIX=ssl install; cd /; }
|
||
|
|
p_kmod(){ std kmod --with-xz --with-zstd --with-openssl --disable-manpages
|
||
|
|
for t in depmod insmod modinfo modprobe rmmod; do ln -sfv kmod /usr/bin/$t; done; }
|
||
|
|
p_libcap(){ unp libcap; make prefix=/usr lib=lib; make prefix=/usr lib=lib install; cd /; }
|
||
|
|
p_libxcrypt(){ std libxcrypt --enable-hashes=strong,glibc \
|
||
|
|
--enable-obsolete-api=no --disable-static --disable-failure-tokens; }
|
||
|
|
p_util_linux(){ unp util-linux
|
||
|
|
./configure --libdir=/usr/lib --runstatedir=/run --disable-chfn-chsh \
|
||
|
|
--disable-login --disable-nologin --disable-su --disable-setpriv \
|
||
|
|
--disable-runuser --disable-pylibmount --disable-static \
|
||
|
|
--disable-liblastlog2 \
|
||
|
|
--without-python ADJTIME_PATH=/var/lib/hwclock/adjtime --docdir=/usr/share/doc/util-linux
|
||
|
|
make; make install; cd /; }
|
||
|
|
p_elfutils(){ std elfutils --disable-debuginfod --enable-libdebuginfod=dummy; }
|
||
|
|
p_rsync(){ unp rsync
|
||
|
|
./configure --prefix=/usr --with-included-popt --disable-md2man \
|
||
|
|
--disable-roll-simd \
|
||
|
|
--disable-openssl --disable-xxhash --disable-zstd --disable-lz4 \
|
||
|
|
--disable-acl-support --disable-xattr-support --disable-iconv
|
||
|
|
make; make install; cd /; }
|
||
|
|
p_expat(){ std expat --without-docbook; }
|
||
|
|
p_libffi(){ std libffi --disable-static --with-gcc-arch=native; }
|
||
|
|
|
||
|
|
# ---- final GCC (the system compiler) ---------------------------------------
|
||
|
|
p_gcc(){ unp gcc
|
||
|
|
tar -xf "$(find_tb mpfr)"; mv "$(ls -d mpfr-*)" mpfr
|
||
|
|
tar -xf "$(find_tb gmp)"; mv "$(ls -d gmp-*)" gmp
|
||
|
|
tar -xf "$(find_tb mpc)"; mv "$(ls -d mpc-*)" mpc
|
||
|
|
case "$(uname -m)" in x86_64) sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64;; esac
|
||
|
|
mkdir -v build; cd build
|
||
|
|
../configure --prefix=/usr LD=ld --enable-languages=c,c++ \
|
||
|
|
--enable-default-pie --enable-default-ssp --enable-host-pie \
|
||
|
|
--disable-multilib --disable-bootstrap --disable-fixincludes \
|
||
|
|
--disable-libsanitizer --with-system-zlib
|
||
|
|
make; make install
|
||
|
|
ln -sfv ../usr/bin/cpp /usr/lib 2>/dev/null || true
|
||
|
|
ln -sfv gcc /usr/bin/cc
|
||
|
|
cd /; }
|
||
|
|
|
||
|
|
say "AeroOS final base system"
|
||
|
|
# ---- bootstrap tools glibc (and others) need at build time --------------
|
||
|
|
# glibc's configure requires bison + python; python wants zlib/bzip2/xz/
|
||
|
|
# openssl/libffi modules, and openssl's Configure needs perl. Build these
|
||
|
|
# against the existing (stage-01) glibc before rebuilding the final glibc.
|
||
|
|
once b-m4 p_m4
|
||
|
|
once b-zlib p_zlib
|
||
|
|
once b-bzip2 p_bzip2
|
||
|
|
once b-xz p_xz
|
||
|
|
once b-bison p_bison
|
||
|
|
once b-perl p_perl
|
||
|
|
once b-openssl p_openssl
|
||
|
|
once b-libffi p_libffi
|
||
|
|
once b-python p_python
|
||
|
|
once b-texinfo p_texinfo
|
||
|
|
# ---- final glibc --------------------------------------------------------
|
||
|
|
once b-glibc p_glibc
|
||
|
|
# ---- remaining base system ----------------------------------------------
|
||
|
|
once b-zstd p_zstd
|
||
|
|
once b-readline-ncurses p_readline
|
||
|
|
once b-bc p_bc
|
||
|
|
once b-ncurses p_ncurses
|
||
|
|
once b-bash p_bash
|
||
|
|
once b-coreutils p_coreutils
|
||
|
|
once b-diffutils p_diffutils
|
||
|
|
once b-file p_file
|
||
|
|
once b-findutils p_findutils
|
||
|
|
once b-gawk p_gawk
|
||
|
|
once b-grep p_grep
|
||
|
|
once b-gzip p_gzip
|
||
|
|
once b-make p_make
|
||
|
|
once b-patch p_patch
|
||
|
|
once b-sed p_sed
|
||
|
|
once b-tar p_tar
|
||
|
|
once b-flex p_flex
|
||
|
|
once b-pkgconf p_pkgconf
|
||
|
|
once b-gettext p_gettext
|
||
|
|
once b-expat p_expat
|
||
|
|
once b-libcap p_libcap
|
||
|
|
once b-libxcrypt p_libxcrypt
|
||
|
|
once b-util-linux p_util_linux
|
||
|
|
once b-gcc p_gcc
|
||
|
|
once b-kmod p_kmod
|
||
|
|
once b-elfutils p_elfutils
|
||
|
|
once b-rsync p_rsync
|
||
|
|
echo "AeroOS base system build complete."
|