build.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. set -e pipefail
  3. CC=gcc
  4. LD=gcc
  5. CFLAGS="-static -Oz -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fno-merge-all-constants"
  6. LDFLAGS="-static -Oz -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -Wl,--gc-sections -Wl,-O2 -Wl,-s"
  7. ROOTFS=/tmp/initramfs
  8. # Computing load values
  9. LOAD=$(nproc)
  10. JOBS=$((LOAD * 2))
  11. # Step 0: Cleanup
  12. rm -rf ${ROOTFS:?}/*
  13. # Step 1: Build musl
  14. pushd musl
  15. make distclean
  16. CC=${CC} LD=${LD} CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
  17. ./configure --enable-static --disable-shared --prefix=/usr
  18. CC=${CC} LD=${LD} CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
  19. make -j "${JOBS}" -l "${LOAD}"
  20. make install DESTDIR=${ROOTFS}
  21. popd
  22. # Step 2: Build tcc
  23. pushd tcc
  24. make distclean
  25. ./configure --enable-static --disable-shared --prefix=/usr \
  26. --config-musl \
  27. --extra-cflags="${CFLAGS} -I${ROOTFS}/usr/include" \
  28. --extra-ldflags="${LDFLAGS} -L${ROOTFS}/usr/include" \
  29. --includedir="/usr/include" \
  30. --libpaths="/usr/lib" \
  31. --tccdir="/usr/lib" \
  32. --cc="${CC}"
  33. echo '#define CONFIG_TCC_CRTPREFIX "/usr/lib"' >> config.h
  34. CC="${CC}" \
  35. C_INCLUDE_PATH="${ROOTFS}/usr/include" \
  36. LIBRARY_PATH="${ROOTFS}/usr/lib" \
  37. CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
  38. make -j "${JOBS}" -l "${LOAD}"
  39. make install DESTDIR=${ROOTFS}
  40. popd
  41. # Step 3: Build qemacs
  42. pushd qemacs
  43. touch config.mak
  44. make distclean
  45. chmod 755 configure
  46. # shellcheck disable=SC2097,SC2098
  47. CFLAGS="${CFLAGS} -I${ROOTFS}/usr/include -flto" \
  48. LDFLAGS="${LDFLAGS} -L${ROOTFS}/usr/lib -flto" \
  49. CC="${CC}" LD="${CC}" \
  50. ./configure --prefix=/usr/ --disable-x11 --disable-xv \
  51. --disable-xrender --disable-html --disable-png
  52. # shellcheck disable=SC2097,SC2098
  53. CFLAGS="${CFLAGS} -I${ROOTFS}/usr/include -flto" \
  54. LDFLAGS="${LDFLAGS} -L${ROOTFS}/usr/lib -flto" \
  55. CC="${CC}" LD="${CC}" \
  56. make -j "${JOBS}" -l "${LOAD}"
  57. make install DESTDIR=${ROOTFS}
  58. popd
  59. # Step 4: Build busybox
  60. pushd busybox
  61. make distclean
  62. cp ../bbconfig .config
  63. sed -e "/CONFIG_PREFIX/s|=.*$|=\"${ROOTFS}\"|" -i .config
  64. sed -e "/CONFIG_EXTRA_CFLAGS/s|=.*$|=\"${CFLAGS}\"|" -i .config
  65. sed -e "/CONFIG_EXTRA_LDFLAGS/s|=.*$|=\"${LDFLAGS}\"|" -i .config
  66. # shellcheck disable=SC2097,SC2098
  67. CFLAGS="${CFLAGS} -I${ROOTFS}/usr/include -flto" \
  68. LDFLAGS="${LDFLAGS} -L${ROOTFS}/usr/lib -flto" \
  69. CC="${CC}" LD="${CC}" \
  70. make -j "${JOBS}" -l "${LOAD}"
  71. make install
  72. popd
  73. # Step 5: Cleanup the resulting env
  74. rm -rf ${ROOTFS}/usr/share/{info,doc,man} ${ROOTFS}/usr/man
  75. # Step 6: Prepare the cpio
  76. fakeroot sh -c "
  77. cd ${ROOTFS} &&
  78. find . -print0 | cpio --null -ov --format=newc > ../base.cpio
  79. "
  80. mv "${ROOTFS}/../base.cpio" .