This commit is contained in:
Ella Stanforth 2022-02-13 08:56:12 +00:00
parent b723a08fb7
commit 3c57204221

View file

@ -1,26 +1,29 @@
#!/bin/sh #!/bin/sh
# set -e
# TODO:
#
# - `iglupkg p` just packages
# - `iglupkg b` just builds
# - `iglupkg f` just fetches
# - `iglupkg bp` clean builds then packages
# - `iglupkg bp --dirty` builds then packages
# Each will always clean
# except build will allow dirty build steps
CWD="$(pwd)"
export HOST_ARCH=$(uname -m)
export HOST_TRIPLE="$HOST_ARCH-unknown-linux-musl"
cross=
if [ -z "$ARCH" ]; then
export ARCH=$HOST_ARCH
else
cross=-$ARCH
fi
export TRIPLE="$ARCH-unknown-linux-musl"
export CC=cc export CC=cc
export CXX=c++ export CXX=c++
export ARCH="$(uname -m)" export AR=ar
export TRIPLE="$ARCH-unknown-linux-musl" export RANLIB=ranlib
export CFLAGS="-flto -O3"
export CXXFLAGS=$CFLAGS
export JOBS=$(nproc) export JOBS=$(nproc)
usage() {
echo "usage: $(basename $0) [fbp]"
exit 1
}
fatal() { fatal() {
echo "ERROR: $@" echo "ERROR: $@"
exit 1 exit 1
@ -30,81 +33,17 @@ warn() {
echo "WARNING: $@" echo "WARNING: $@"
} }
assert_file() { [ -f build.sh ] || fatal 'build.sh not found'
stat "$1" \
> /dev/null \
2> /dev/null \
|| fatal "$1 does not exist!"
}
assert_func() {
command -V "$1" \
> /dev/null \
2> /dev/null \
|| fatal "build.sh not sane: $1 not defined!"
}
make_dir() {
stat "$1" \
> /dev/null \
2> /dev/null \
|| mkdir -p "$1"
}
# fetch file, checks the md5sum and only curls if needed
fetch_file() {
F_NAME=$1
MD5_SUM=$2
URL=$3
stat "$F_NAME" \
> /dev/null \
2> /dev/null \
|| curl -L "$URL" -o "$F_NAME"
echo "$MD5_SUM $F_NAME" | md5sum -c || (
rm "$F_NAME"
fetch_file $1 $2 $3
)
}
fetch_tar() {
F_NAME=$1
MD5_SUM=$2
URL=$3
stat "$F_NAME" \
> /dev/null \
2> /dev/null \
|| (
curl -L "$URL" -o "$F_NAME"
tar -xf "$F_NAME"
)
echo "$MD5_SUM $F_NAME" | md5sum -c || (
rm "$F_NAME"
fetch_tar $1 $2 $3
)
}
assert_file build.sh
. ./build.sh . ./build.sh
[ -n "$pkgname" ] || fatal "build.sh not sane: pkgname not defined" srcdir="$(pwd)/src"
[ -n "$pkgver" ] || fatal "build.sh not sane: pkgver not defined" outdir="$(pwd)/out"
assert_func fetch pkgdir="$(pwd)/out/$pkgname.$pkgver"
assert_func build
assert_func package
assert_func backup
assert_func license
srcdir="$CWD/src" rm -rf "$outdir"
outdir="$CWD/out"
pkgdir="$outdir/$pkgname.$pkgver"
pkgfile="$outdir/$pkgname.$pkgver.tar.zst"
genmeta() { _genmeta() {
echo "[pkg]" echo "[pkg]"
echo "pkgname=$pkgname" echo "pkgname=$pkgname"
echo "pkgver=$pkgver" echo "pkgver=$pkgver"
@ -123,63 +62,42 @@ genmeta() {
cd "$srcdir" cd "$srcdir"
} }
if [ ! -n "$FAKEROOTKEY" ]; then _f() {
if stat $pkgfile \ rm -rf "$srcdir"
> /dev/null \ mkdir -p "$srcdir"
2> /dev/null; then
warn 'Package already built'
elif stat $srcdir \
> /dev/null \
2> /dev/null; then
warn 'Package partially built'
fi
make_dir "$srcdir"
cd "$srcdir" cd "$srcdir"
echo "=========="
echo " Fetching "
echo "=========="
fetch fetch
cd "$srcdir" cd "$srcdir"
:> .fetched
}
echo "==========" _b() {
echo " Building "
echo "=========="
MAKEFLAGS="-j$JOBS" build
cd "$CWD"
fakeroot "$0"
else
echo "=========="
echo " Bundling "
echo "=========="
stat "$outdir" \
> /dev/null \
2> /dev/null && rm -rf "$outdir"
make_dir "$outdir"
make_dir "$pkgdir"
cd "$srcdir" cd "$srcdir"
[ -f .fetched ] || fatal 'must fetch before building'
pkgdir="$pkgdir" package build
cd "$srcdir" cd "$srcdir"
:> .built
}
install -d "$pkgdir/usr/share/iglupkg" _p() {
cd "$srcdir"
pkgmetafile="$pkgdir/usr/share/iglupkg/$pkgname" [ -f .built ] || fatal 'must build before packaging'
mkdir -p "$pkgdir"
genmeta > "$pkgmetafile" package
install -d "$pkgdir/usr/share/iglupkg/"
cd "$srcdir"
_genmeta > "$pkgdir/usr/share/iglupkg/$pkgname$cross"
cd "$pkgdir" cd "$pkgdir"
tar --owner=0 --group=0 -cf ../$pkgname$cross.$pkgver.tar.zstd * -I zstd
}
tar -I zstd -cf "$pkgfile" * if [ -z "$@" ]; then
[ -f "$srcdir/.fetched" ] || _f
[ -f "$srcdir/.built" ] || _b
_p
else
while [ ! -z "$1" ]; do
_"$1"
shift
done
fi fi