#!/bin/bash set -e pipefail CC=gcc LD=gcc CFLAGS="-static -Oz -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fno-merge-all-constants" LDFLAGS="-static -Oz -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -Wl,--gc-sections -Wl,-O2 -Wl,-s" ROOTFS=/tmp/initramfs # Step 0: Cleanup rm -rf ${ROOTFS}/* # Step 1: Build musl pushd musl make distclean CC=${CC} LD=${LD} CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \ ./configure --enable-static --disable-shared --prefix=/usr CC=${CC} LD=${LD} CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \ make -j 24 VERBOSE=1 make install DESTDIR=${ROOTFS} popd # Step 2: Build tcc pushd tcc make distclean ./configure --enable-static --disable-shared --prefix=/usr \ --config-musl \ --extra-cflags="${CFLAGS} -I${ROOTFS}/usr/include" \ --extra-ldflags="${LDFLAGS} -L${ROOTFS}/usr/include" \ --includedir="/usr/include" \ --libpaths="/usr/lib" \ --tccdir="/usr/lib" \ --cc="${CC}" echo '#define CONFIG_TCC_CRTPREFIX "/usr/lib"' >> config.h CC="${CC}" \ C_INCLUDE_PATH="${ROOTFS}/usr/include" \ LIBRARY_PATH="${ROOTFS}/usr/lib" \ CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \ make -j 24 VERBOSE=1 make install DESTDIR=${ROOTFS} popd # Step 3: Build qemacs pushd qemacs make distclean chmod 755 configure CFLAGS="${CFLAGS} -I${ROOTFS}/usr/include -flto" \ LDFLAGS="${LDFLAGS} -L${ROOTFS}/usr/lib -flto" \ CC="${CC}" LD="${CC}" \ ./configure --prefix=/usr/ --disable-x11 --disable-xv \ --disable-xrender --disable-html --disable-png CFLAGS="${CFLAGS} -I${ROOTFS}/usr/include -flto" \ LDFLAGS="${LDFLAGS} -L${ROOTFS}/usr/lib -flto" \ CC="${CC}" LD="${CC}" \ make -j 24 VERBOSE=1 make install DESTDIR=${ROOTFS} popd # Step 4: Build busybox pushd busybox make distclean cp ../bbconfig .config sed -e "/CONFIG_PREFIX/s|=.*$|=\"${ROOTFS}\"|" -i .config sed -e "/CONFIG_EXTRA_CFLAGS/s|=.*$|=\"${CFLAGS}\"|" -i .config sed -e "/CONFIG_EXTRA_LDFLAGS/s|=.*$|=\"${LDFLAGS}\"|" -i .config CFLAGS="${CFLAGS} -I${ROOTFS}/usr/include -flto" \ LDFLAGS="${LDFLAGS} -L${ROOTFS}/usr/lib -flto" \ CC="${CC}" LD="${CC}" \ make -j 24 VERBOSE=1 make -j 24 install VERBOSE=1 popd # Step 5: Cleanup the resulting env rm -rf ${ROOTFS}/usr/share/{info,doc,man} ${ROOTFS}/usr/man # Step 6: Prepare the cpio fakeroot sh -c " cd ${ROOTFS} && find . -print0 | cpio --null -ov --format=newc > ../base.cpio " mv "${ROOTFS}/../base.cpio" .