RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / ports / dash / build.sh
1726 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
# Build dash (the Debian Almquist shell, a small POSIX sh) for Foundry OS:
# unpack the cached tarball, apply patches/*.patch in order, then the
# ordinary autoconf steps with our compiler:
#   CC=toolchain/foundry-cc ./configure --host=x86_64-linux-musl && make
# foundry-cc makes a static-PIE against our musl, which Rustbelt runs as is.
# The result is installed as /bin/dash. It is NOT /bin/sh yet: the kernel
# starts /bin/sh as its shell, and that stays rbsh until kernel request K5.
#
# Usage: ports/dash/build.sh CACHE_DIR BUILD_DIR OUT_FILE
set -euo pipefail
HERE=$(cd "$(dirname "$0")" && pwd)
ROOT=$(cd "$HERE/../.." && pwd)
CACHE=$(realpath "$1") BUILD=$(realpath -m "$2") OUTFILE=$(realpath -m "$3")
read -r _ file < "$HERE/dash.sha256"
rm -rf "$BUILD" && mkdir -p "$BUILD"
tar -xzf "$CACHE/$file" -C "$BUILD"
src=$BUILD/${file%.tar.gz}
for p in "$HERE"/patches/*.patch; do
    [ -e "$p" ] || continue
    echo "[dash] applying $(basename "$p")"; patch -d "$src" -p1 < "$p"
done
cd "$src"
# --host makes configure name the target (we are cross-building for
# Rustbelt), but our binaries also run on the build machine, so configure's
# test programs still work.
CC=$ROOT/toolchain/foundry-cc CFLAGS="-O2" \
    ./configure --host=x86_64-linux-musl > "$BUILD/configure.log"
make -j"$(nproc)" > "$BUILD/make.log" 2>&1 || { tail -30 "$BUILD/make.log"; exit 1; }
mkdir -p "$(dirname "$OUTFILE")"
cp src/dash "$OUTFILE"
strip --strip-debug "$OUTFILE"
if readelf -l "$OUTFILE" | grep -q INTERP; then
    echo "[dash] $OUTFILE has a PT_INTERP: not a static-PIE"; exit 1
fi
echo "[dash] built $OUTFILE ($(stat -c %s "$OUTFILE") bytes, $(readelf -h "$OUTFILE" | awk '/Type:/{print $2}'), no PT_INTERP)"