Skip to content

Instantly share code, notes, and snippets.

@bensallen
Last active November 25, 2021 03:50
Show Gist options
  • Save bensallen/764b94ad702bc144ca04d861f50cbeef to your computer and use it in GitHub Desktop.
Save bensallen/764b94ad702bc144ca04d861f50cbeef to your computer and use it in GitHub Desktop.
MUSL libc - busybox
#!/bin/sh -e
MUSL_VERS=1.1.14
BUSYBOX_VERS=1.24.2
BASE=$PWD
mkdir -p $BASE/warewulf4/initramfs
mkdir -p $BASE/warewulf4/initramfs/3rd_party/MIT
mkdir -p $BASE/warewulf4/initramfs/3rd_party/GPL
INSTALLROOT=$BASE/warewulf4/initramfs/_install
mkdir -p $INSTALLROOT
BUILDROOT=$BASE/warewulf4/initramfs/BUILD
mkdir -p $BUILDROOT
KHDR_BASE=/usr
# MUSL-C
cd $BASE/warewulf4/initramfs/3rd_party/MIT
curl -O https://www.musl-libc.org/releases/musl-$MUSL_VERS.tar.gz
tar -C $BUILDROOT -xf musl-$MUSL_VERS.tar.gz
cd $BUILDROOT/musl-$MUSL_VERS
./configure --prefix=$BUILDROOT/_work/musl-$MUSL_VERS --disable-shared
make -j2 && make install
PATH=$BUILDROOT/_work/musl-$MUSL_VERS/bin:$PATH
# Ugh hacks, use binutils and linux-headers from the buildhost
mkdir -p $BUILDROOT/_work/musl-$MUSL_VERS/bin
cd $BUILDROOT/_work/musl-$MUSL_VERS/bin
ln -s `which ar` musl-ar
ln -s `which strip` musl-strip
cd $BUILDROOT/_work/musl-$MUSL_VERS/include
ln -s $KHDR_BASE/include/linux linux
ln -s $KHDR_BASE/include/mtd mtd
if [ -d $KHDR_BASE/include/asm ]
then
ln -s $KHDR_BASE/include/asm asm
else
ln -s $KHDR_BASE/include/asm-generic asm
fi
ln -s $KHDR_BASE/include/asm-generic asm-generic
# Busybox (static)
cd $BASE/warewulf4/initramfs/3rd_party/GPL
curl -O https://www.busybox.net/downloads/busybox-$BUSYBOX_VERS.tar.bz2
tar -C $BUILDROOT -xf busybox-$BUSYBOX_VERS.tar.bz2
cd $BUILDROOT/busybox-$BUSYBOX_VERS
curl https://raw.githubusercontent.com/alpinelinux/aports/master/main/busybox/busyboxconfig > .config
sed -i -e "s/CONFIG_EXTRA_COMPAT=y/CONFIG_EXTRA_COMPAT=n/" \
-e "s/.*CONFIG_CROSS_COMPILER_PREFIX.*/CONFIG_CROSS_COMPILER_PREFIX=\"musl-\"/" \
-e "s|.*CONFIG_PREFIX.*|CONFIG_PREFIX=\"$INSTALLROOT\"|" \
-e "s/.*CONFIG_PIE.*/\# CONFIG_PIE is not set/" \
-e "s/.*CONFIG_INSTALL_APPLET_DONT.*/\# CONFIG_INSTALL_APPLET_DONT is not set/" \
-e "s/.*CONFIG_STATIC.*/CONFIG_STATIC=y/" \
-e "s/.*CONFIG_INSTALL_APPLET_SYMLINKS.*/CONFIG_INSTALL_APPLET_SYMLINKS=y/" \
.config
make V=1 -j2
make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment