| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #!/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
- # Computing load values
- LOAD=$(nproc)
- JOBS=$((LOAD * 2))
- # 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 "${JOBS}" -l "${LOAD}"
- 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 "${JOBS}" -l "${LOAD}"
- make install DESTDIR=${ROOTFS}
- popd
- # Step 3: Build qemacs
- pushd qemacs
- touch config.mak
- make distclean
- chmod 755 configure
- # shellcheck disable=SC2097,SC2098
- 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
- # shellcheck disable=SC2097,SC2098
- CFLAGS="${CFLAGS} -I${ROOTFS}/usr/include -flto" \
- LDFLAGS="${LDFLAGS} -L${ROOTFS}/usr/lib -flto" \
- CC="${CC}" LD="${CC}" \
- make -j "${JOBS}" -l "${LOAD}"
- 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
- # shellcheck disable=SC2097,SC2098
- CFLAGS="${CFLAGS} -I${ROOTFS}/usr/include -flto" \
- LDFLAGS="${LDFLAGS} -L${ROOTFS}/usr/lib -flto" \
- CC="${CC}" LD="${CC}" \
- make -j "${JOBS}" -l "${LOAD}"
- make install
- 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" .
|