blob: f7f2df9dc6c8ed4b785285427f03c26838693bb6 (
plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#!/bin/bash
set -e
set -x
BUILDDIR=/tmp/build
SRCDIR=$(dirname $(realpath "$0"))
SIZE_CFLAGS="-I/tmp/build/include -I/tmp/build/include/ncurses -Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables"
SIZE_LDFLAGS="-L/tmp/build/lib -Wl,--gc-sections -Wl,--strip-all"
NPROC=$(grep -sc processor /proc/cpuinfo || echo 4)
[ -d "$BUILDDIR" ] && exit 1
mkdir -p "$BUILDDIR"/rootfs/{dev,lib/terminfo/l,nethack,sbin}
pushd "$BUILDDIR"
# install build dependencies
grep -q ^deb-src /etc/apt/sources.list
su -c "export DEBIAN_FRONTEND=noninteractive;
apt-get update;
apt-get install --yes build-essential upx-ucl gawk lilo ca-certificates;
apt-get build-dep --yes musl nethack ncurses linux"
# download sources
pushd "$SRCDIR"
[ -f "ncurses-6.0.tar.gz" ] || wget "https://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz"
[ $(md5sum "ncurses-6.0.tar.gz" | cut -d ' ' -f 1) = "ee13d052e1ead260d7c28071f46eefb1" ] || exit 1
[ -f "nethack-360-src.tgz" ] || wget "http://prdownloads.sourceforge.net/nethack/nethack-360-src.tgz?download" -O "nethack-360-src.tgz"
[ $(md5sum "nethack-360-src.tgz" | cut -d ' ' -f 1) = "d42147b26e5fb4746fb72536ce145984" ] || exit 1
[ -f "linux-2.6.32.70.tar.xz" ] || wget "https://cdn.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.32/linux-2.6.32.70.tar.xz"
[ $(md5sum "linux-2.6.32.70.tar.xz" | cut -d ' ' -f 1) = "1a3ae82aab5acb3cb42e8514ee460a71" ] || exit 1
popd
# build musl
apt-get source musl
pushd musl-*/
patch -p1 < "$SRCDIR/musl.patch"
dpkg-buildpackage -us -uc -jauto
popd
su -c "dpkg -i musl_*.deb musl-dev_*.deb musl-tools_*.deb"
# build ncurses
tar zxf "$SRCDIR"/ncurses-*.tar.gz
pushd ncurses-*/
./configure --prefix="$BUILDDIR" --with-terminfo-dirs=/lib/terminfo --without-shared --without-gpm AWK="gawk" CC="musl-gcc" CFLAGS="$SIZE_CFLAGS" LDFLAGS="$SIZE_LDFLAGS"
make -j$NPROC
make install
install -m 644 "$BUILDDIR/share/terminfo/l/linux" "$BUILDDIR/rootfs/lib/terminfo/l/"
popd
# extract kernel for headers
tar Jxf "$SRCDIR"/linux-*.tar.xz
cp -a linux-*/include/linux "$BUILDDIR/include/"
# build nethack
tar zxf "$SRCDIR"/nethack-*-src.tgz
pushd nethack-*/
patch -p1 < "$SRCDIR/nethack.patch"
pushd sys/unix
./setup.sh
popd
make -j$NPROC nethack CC="musl-gcc" LINK="musl-gcc" CFLAGS="-I../include $SIZE_CFLAGS -flto" LFLAGS="$SIZE_LDFLAGS -flto -static"
make -C dat CFLAGS="-I../include"
make dlb CC="musl-gcc" LINK="musl-gcc" CFLAGS="-I../include $SIZE_CFLAGS -flto" LFLAGS="$SIZE_LDFLAGS -flto"
upx --ultra-brute --overlay=strip src/nethack
install -m 755 src/nethack "$BUILDDIR/rootfs/nethack"
install -m 644 dat/nhdat "$BUILDDIR/rootfs/nethack"
touch "$BUILDDIR/rootfs/nethack/perm"
popd
# build init
musl-gcc "$SRCDIR/init.c" -o "$BUILDDIR/rootfs/sbin/init" $SIZE_CFLAGS $SIZE_LDFLAGS -flto -static
# build kernel
echo "nod /dev/console 0600 0 0 c 5 1" > rootfs-files.txt
pushd linux-*/
patch -p1 < "$SRCDIR/kernel.patch"
cp "$SRCDIR/config-kernel" .config
make oldconfig
make -j$NPROC bzImage CC="gcc -std=gnu89"
popd
# create floppy
dd if=/dev/zero of=floppy.img bs=1024 count=1440
/sbin/mkfs.minix floppy.img
mkdir -p "$BUILDDIR/mnt"
su -c "
set -ex;
mount floppy.img \"$BUILDDIR/mnt\";
mkdir \"$BUILDDIR\"/mnt/{boot,dev};
mount /dev \"$BUILDDIR/mnt/dev\" -o bind;
cp \"$BUILDDIR\"/linux-*/arch/x86/boot/bzImage \"$SRCDIR/lilo.conf\" \"$BUILDDIR/mnt/\";
lilo -g -r \"$BUILDDIR/mnt\" -C /lilo.conf;
rm \"$BUILDDIR/mnt/lilo.conf\";
umount \"$BUILDDIR/mnt/dev\" \"$BUILDDIR/mnt\";
"
printf "\n\nFinished! Result is at $BUILDDIR/floppy.img\n\n"
|