Path and compile musl libc into kernel

This commit is contained in:
2022-01-09 22:51:55 +01:00
parent c95f256e1b
commit 8d53f5468e
8 changed files with 158 additions and 7 deletions

26
toolchain/build-musl.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/sh -e
target=x86_64-elf
SYSROOT=/opt/sysroot
# Pull or update musl libc
mkdir -p /opt/external && cd /opt/external
[ -d musl ] || git clone --depth=1 git://git.musl-libc.org/musl
cd musl
git reset --hard
git pull
[ -d /opt/src/patch-musl ] && rsync -a /opt/src/patch-musl/ /opt/external/musl/
mkdir -p /opt/external/build-musl && cd /opt/external/build-musl
rm -r *
../musl/configure \
--target=${target} \
--prefix=${SYSROOT}/usr \
--disable-shared \
--enable-debug \
CFLAGS="-O0 -mcmodel=large"
make
make install-headers
make install

View File

@@ -5,14 +5,31 @@ apk add gmp-dev mpfr-dev mpc1-dev
apk add make
apk add grub-bios xorriso
apk add python3
apk add python3 git rsync
rm -rf /var/cache/apk/*
target=x86_64-elf
SYSROOT=/opt/sysroot
binutils=binutils-2.37
gcc=gcc-11.2.0
mkdir -p /opt/external
cd /opt/external
[ -d musl ] || git clone --depth=1 git://git.musl-libc.org/musl
cd musl
git reset --hard
git pull
cat > config.mak << EOF
ARCH=x86_64
prefix=${SYSROOT}/usr
includedir=\$(prefix)/include
EOF
make install-headers
# Build binutils
cd /opt
wget http://ftp.gnu.org/gnu/binutils/${binutils}.tar.gz
tar -xf ${binutils}.tar.gz
@@ -21,11 +38,12 @@ mkdir binutils-build && cd binutils-build
--target=${target} \
--disable-nls \
--disable-werror \
--with-sysroot \
--with-sysroot=${SYSROOT}
make -j 4
make install
# Build gcc and libgcc
cd /opt
wget http://ftp.gnu.org/gnu/gcc/${gcc}/${gcc}.tar.gz
tar -xf ${gcc}.tar.gz
@@ -34,7 +52,7 @@ mkdir gcc-build && cd gcc-build
--target=${target} \
--disable-nls \
--enable-languages=c \
--without-headers \
--with-sysroot=${SYSROOT}
make all-gcc all-target-libgcc -j 4
make install-gcc install-target-libgcc