limine/bootstrap

123 lines
4.0 KiB
Bash
Executable File

#! /bin/sh
set -ex
LC_ALL=C
export LC_ALL
srcdir="$(dirname "$0")"
test -z "$srcdir" && srcdir=.
: "${AUTORECONF:=autoreconf}"
: "${AUTOMAKE:=automake}"
cd "$srcdir"
FREESTANDING_TOOLCHAIN_COMMIT_HASH=18a5e52483344e117d45738c9afb2b34792cbced
FREESTANDING_HEADERS_COMMIT_HASH=dd3abd2d7147efc4170dff478d3b7730bed14147
CC_RUNTIME_COMMIT_HASH=38942e9a0d11af77c5d9fb45794850f7a1565d2b
LIMINE_EFI_COMMIT_HASH=f49bfc29a344f1bd57a6a99d8c71fcc133cd72c7
TINF_COMMIT_HASH=57ffa1f1d5e3dde19011b2127bd26d01689b694b
FLANTERM_COMMIT_HASH=347d9cf1e3fced64aa20ab278e2fdcc834086035
STB_COMMIT_HASH=f4a71b13373436a2866c5d68f8f80ac6f0bc1ffe
AUXFILES="config.guess config.sub install-sh"
clone_repo_commit() {
if [ -d $2/.git ]; then
git -C $2 reset --hard
git -C $2 clean -fd
if ! git -C $2 checkout $3; then
rm -rf $2
fi
else
if [ -d $2 ]; then
echo "error: '$2' is not a Git repository"
exit 1
fi
fi
if ! [ -d $2 ]; then
git clone $1 $2
git -C $2 checkout $3
fi
}
if ! [ -f version ]; then
clone_repo_commit https://github.com/mintsuki/freestanding-toolchain.git build-aux/freestanding-toolchain $FREESTANDING_TOOLCHAIN_COMMIT_HASH
clone_repo_commit https://github.com/mintsuki/freestanding-headers.git freestanding-headers $FREESTANDING_HEADERS_COMMIT_HASH
clone_repo_commit https://github.com/mintsuki/cc-runtime.git decompressor/cc-runtime $CC_RUNTIME_COMMIT_HASH
rm -rf common/cc-runtime
cp -rp decompressor/cc-runtime common/
for f in common/cc-runtime/*.c; do
mv "$f" "$(echo "$f" | sed 's/\.c/.s2.c/g')"
done
clone_repo_commit https://github.com/limine-bootloader/limine-efi.git limine-efi $LIMINE_EFI_COMMIT_HASH
clone_repo_commit https://github.com/jibsen/tinf.git tinf $TINF_COMMIT_HASH
mkdir -p decompressor/tinf
cp tinf/src/tinf.h tinf/src/tinflate.c tinf/src/tinfgzip.c decompressor/tinf/
patch -p0 < decompressor/tinf.patch
rm -f tinf/src/tinf.h.orig tinf/src/tinflate.c.orig tinf/src/tinfgzip.c.orig
clone_repo_commit https://github.com/mintsuki/flanterm.git common/flanterm $FLANTERM_COMMIT_HASH
clone_repo_commit https://github.com/nothings/stb.git stb $STB_COMMIT_HASH
cp stb/stb_image.h common/lib/
patch -p0 < common/stb_image.patch
rm -f common/lib/stb_image.h.orig
fi
# Create timestamps and version file
if git log -1 >/dev/null 2>&1; then
cat >timestamps <<EOF
REGEN_DATE="$(git log -1 --pretty=%cd --date='format:%B %Y')"
SOURCE_DATE_EPOCH="$(git log -1 --pretty=%ct)"
SOURCE_DATE_EPOCH_TOUCH="$(git log -1 --pretty=%cI | sed 's/-//g;s/T//g;s/://g;s/[0-9][0-9]+.*//g')"
EOF
fi
if ! test -f timestamps; then
echo "error: Not a Git repository and 'timestamps' file missing."
exit 1
fi
if git describe --exact-match --tags $(git log -n1 --pretty='%h') >/dev/null 2>&1; then
git describe --exact-match --tags $(git log -n1 --pretty='%h') | sed 's/^v//g' >version
elif git log -n1 --pretty='%h' >/dev/null 2>&1; then
echo g$(git log -n1 --pretty='%h') >version
fi
if ! test -f version; then
echo "error: Not a Git repository and 'version' file missing."
exit 1
fi
for auxfile in $AUXFILES; do
rm -f build-aux/$auxfile
done
$AUTORECONF -fvi -Wall
# Older versions of autoreconf have a bug where they do not
# install auxiliary files, sometimes... Check if that is the
# case and work around...
for auxfile in $AUXFILES; do
if ! [ -f build-aux/$auxfile ]; then
if ! $AUTOMAKE --print-libdir >/dev/null 2>&1; then
echo "error: Broken autoreconf detected, but missing or broken automake."
echo " Please make sure automake is installed and working."
exit 1
fi
AUTOMAKE_LIBDIR="$($AUTOMAKE --print-libdir)"
if [ -z "$AUTOMAKE_LIBDIR" ]; then
# Assume `true` was passed as $AUTOMAKE
continue
fi
mkdir -p build-aux
cp -v "$AUTOMAKE_LIBDIR/$auxfile" build-aux/
chmod +x build-aux/$auxfile
fi
done