Bläddra i källkod

doc: Add README

Slava Barinov 3 månader sedan
förälder
incheckning
e63f577fa4
2 ändrade filer med 52 tillägg och 7 borttagningar
  1. 36 0
      README.md
  2. 16 7
      build.sh

+ 36 - 0
README.md

@@ -0,0 +1,36 @@
+# Minimal C Development Environment
+
+## Why?
+
+I don't have any particular reason not to have a working C compiler everywhere
+you go.
+
+## Components
+
+- [busybox](busybox.net)
+- [musl](musl.libc.org) (static build)
+- [tcc](https://bellard.org/tcc/)
+- [qemacs](https://github.com/qemacs/qemacs)
+
+The resulting directory is ~8.5 MiB.
+
+## Usage
+
+Can be used in limited environments when you need some quick and dirty in-place
+development. I keep it inside my initramfs just in case.
+
+### TCC usage in the environment
+
+The script only builds static version of `musl` so the only working binaries
+will be static unless you provide your own Libc.
+
+### Adding as initramfs
+
+My `/usr/src/linux/.config` file contains the line
+```
+CONFIG_INITRAMFS_SOURCE="/usr/src/initramfs/base /usr/src/initramfs/list"
+```
+
+In this case the `base` is the resulting directory of the build, and the `list`
+file contains some additional tools from my host system I need inside initramfs
+(like `lvm`).

+ 16 - 7
build.sh

@@ -8,8 +8,13 @@ CFLAGS="-static -Oz -ffunction-sections -fdata-sections -fvisibility=hidden -fom
 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}/*
+rm -rf ${ROOTFS:?}/*
 
 # Step 1: Build musl
 pushd musl
@@ -17,7 +22,7 @@ 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 -j "${JOBS}" -l "${LOAD}"
 
 make install DESTDIR=${ROOTFS}
 popd
@@ -38,24 +43,27 @@ CC="${CC}" \
   C_INCLUDE_PATH="${ROOTFS}/usr/include" \
   LIBRARY_PATH="${ROOTFS}/usr/lib" \
   CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
-  make -j 24 VERBOSE=1
+  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
+		  --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 24 VERBOSE=1
+      make -j "${JOBS}" -l "${LOAD}"
 make install DESTDIR=${ROOTFS}
 popd
 
@@ -66,11 +74,12 @@ 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 24 VERBOSE=1
-make -j 24 install VERBOSE=1
+      make -j "${JOBS}" -l "${LOAD}"
+make install
 popd
 
 # Step 5: Cleanup the resulting env