2022-07-23 00:19:12 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2022-07-23 17:44:55 +00:00
|
|
|
#
|
|
|
|
# Set variables
|
|
|
|
#
|
|
|
|
# This syntax may look odd, but as far as I can tell, it is POSIX,
|
|
|
|
# and it allows the values to be overridden by the environment,
|
|
|
|
# such that these serve more as sane defaults than hard requirements.
|
|
|
|
#
|
2022-07-23 00:19:12 +00:00
|
|
|
|
2022-07-23 17:44:55 +00:00
|
|
|
: "${TELODENDRIA_VERSION:=0.0.0}"
|
|
|
|
: "${CVS_TAG:=Telodendria-$(echo $TELODENDRIA_VERSION | sed 's/\./_/g')}"
|
2022-07-23 00:19:12 +00:00
|
|
|
|
2022-07-23 17:44:55 +00:00
|
|
|
: "${HEADERS:=-D_POSIX_C_SOURCE=199506L -DTELODENDRIA_VERSION=\"$TELODENDRIA_VERSION\"}"
|
|
|
|
: "${INCLUDES:=-Isrc/include}"
|
|
|
|
|
|
|
|
: "${CC:=cc}"
|
2022-07-27 17:45:19 +00:00
|
|
|
: "${CFLAGS:=-Wall -Wextra -pedantic -ansi -std=c89 -O3 $HEADERS $INCLUDES}"
|
2022-07-23 17:44:55 +00:00
|
|
|
: "${LDFLAGS:=-static -flto -fdata-sections -ffunction-sections -s -Wl,-static -Wl,-gc-sections}"
|
|
|
|
: "${PROG:=telodendria}"
|
|
|
|
|
|
|
|
if [ -f "$(pwd)/.env" ]; then
|
|
|
|
. "$(pwd)/.env"
|
|
|
|
fi
|
2022-07-23 00:19:12 +00:00
|
|
|
|
|
|
|
mod_time() {
|
|
|
|
if [ -n "$1" ] && [ -f "$1" ]; then
|
|
|
|
case "$(uname)" in
|
|
|
|
Linux)
|
|
|
|
stat -c %Y "$1"
|
|
|
|
;;
|
|
|
|
*BSD)
|
|
|
|
stat -f %m "$1"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "0"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
echo "0"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-07-23 05:05:55 +00:00
|
|
|
recipe_build() {
|
|
|
|
mkdir -p build
|
2022-07-23 00:19:12 +00:00
|
|
|
|
2022-07-23 05:05:55 +00:00
|
|
|
do_rebuild=0
|
|
|
|
objs=""
|
|
|
|
for src in $(find src -name '*.c'); do
|
|
|
|
obj=$(echo "$src" | sed -e 's/^src/build/' -e 's/\.c$/\.o/')
|
|
|
|
objs="$objs $obj"
|
2022-07-23 00:19:12 +00:00
|
|
|
|
2022-07-23 05:05:55 +00:00
|
|
|
if [ $(mod_time "$src") -gt $(mod_time "$obj") ]; then
|
|
|
|
echo "CC $obj"
|
|
|
|
obj_dir=$(dirname "$obj")
|
|
|
|
mkdir -p "$obj_dir"
|
|
|
|
if ! $CC $CFLAGS -c -o "$obj" "$src"; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
do_rebuild=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $do_rebuild -eq 1 ] || [ ! -f "build/$PROG" ]; then
|
|
|
|
echo "LD build/$PROG"
|
|
|
|
$CC $LDFLAGS -o "build/$PROG" $objs
|
|
|
|
else
|
|
|
|
echo "Up to date."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
recipe_clean() {
|
|
|
|
rm -rv build
|
|
|
|
}
|
|
|
|
|
2022-07-25 19:18:25 +00:00
|
|
|
recipe_format() {
|
2022-07-25 19:25:06 +00:00
|
|
|
find src -name '*.c' -or -name '*.h' | while IFS= read -r src; do
|
2022-07-28 15:46:57 +00:00
|
|
|
# Update the headers
|
|
|
|
srcHeader=$(grep -n -m 1 '^ \*/' "$src" | cut -d ':' -f 1)
|
|
|
|
head "-n$srcHeader" "$src" |
|
|
|
|
diff -u -p - src/header.txt |
|
|
|
|
patch "$src"
|
|
|
|
|
|
|
|
# Format the source code
|
2022-07-26 02:54:56 +00:00
|
|
|
if indent "$src"; then
|
|
|
|
rm $(basename "$src").BAK
|
|
|
|
fi
|
2022-07-25 19:18:25 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-07-23 05:05:55 +00:00
|
|
|
recipe_test() {
|
|
|
|
echo "Unit tests are not implemented yet."
|
|
|
|
}
|
|
|
|
|
2022-07-23 17:44:55 +00:00
|
|
|
recipe_site() {
|
|
|
|
if [ -z "$TELODENDRIA_PUB" ]; then
|
|
|
|
echo "No public root directory specified."
|
|
|
|
echo "Set TELODENDRIA_PUB."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-07-23 21:29:54 +00:00
|
|
|
# In the future, this might do more.
|
2022-07-23 21:35:12 +00:00
|
|
|
cp -v site/* "$TELODENDRIA_PUB/"
|
2022-07-23 17:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
recipe_release() {
|
|
|
|
if [ -z "$TELODENDRIA_PUB" ]; then
|
|
|
|
echo "No public root directory specified."
|
|
|
|
echo "Set TELODENDRIA_PUB."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION"
|
|
|
|
cd "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION"
|
|
|
|
|
|
|
|
cvs export "-r$CVS_TAG" "Telodendria"
|
|
|
|
mv "Telodendria" "Telodendria-v$TELODENDRIA_VERSION"
|
|
|
|
tar -czf "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
|
|
|
|
"Telodendria-v$TELODENDRIA_VERSION"
|
|
|
|
rm -r "Telodendria-v$TELODENDRIA_VERSION"
|
|
|
|
sha256 "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
|
|
|
|
> "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sha256"
|
2022-07-29 00:50:09 +00:00
|
|
|
|
|
|
|
if [ ! -z "$TELODENDRIA_SIGNIFY_SECRET" ]; then
|
|
|
|
signify -S -s "$TELODENDRIA_SIGNIFY_SECRET" \
|
|
|
|
-m "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
|
|
|
|
-x "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sig"
|
|
|
|
else
|
|
|
|
echo "Warning: TELODENDRIA_SIGNIFY_SECRET not net."
|
|
|
|
echo "The built tarball will not be signed."
|
|
|
|
fi
|
2022-07-23 17:44:55 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 18:42:23 +00:00
|
|
|
recipe_patch() {
|
|
|
|
if [ -z "$MXID" ]; then
|
|
|
|
MXID="@${USER}:$(hostname)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$DISPLAY_NAME" ]; then
|
|
|
|
DISPLAY_NAME=$(getent passwd "$USER" | cut -d ':' -f 5 | cut -d ',' -f 1)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$EDITOR" ]; then
|
|
|
|
EDITOR=vi
|
|
|
|
fi
|
|
|
|
|
2022-07-29 19:17:55 +00:00
|
|
|
PATCH_FILE="${MXID}_$(date +%s).patch"
|
|
|
|
|
2022-07-29 18:42:23 +00:00
|
|
|
(
|
|
|
|
printf 'From: "%s" <%s>\n' "$DISPLAY_NAME" "$MXID"
|
2022-07-29 19:17:55 +00:00
|
|
|
echo "Date: $(date)"
|
2022-07-29 18:42:23 +00:00
|
|
|
echo "Subject: "
|
|
|
|
echo
|
|
|
|
cvs diff -uNp $PATCH | grep -v '^\? '
|
2022-07-29 19:17:55 +00:00
|
|
|
) > "$PATCH_FILE"
|
2022-07-29 18:42:23 +00:00
|
|
|
|
2022-07-29 19:17:55 +00:00
|
|
|
"$EDITOR" "$PATCH_FILE"
|
|
|
|
echo "$PATCH_FILE"
|
2022-07-29 18:42:23 +00:00
|
|
|
}
|
|
|
|
|
2022-07-23 05:05:55 +00:00
|
|
|
for recipe in $@; do
|
|
|
|
recipe_$recipe
|
2022-07-23 00:19:12 +00:00
|
|
|
done
|
|
|
|
|
2022-07-23 05:05:55 +00:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
recipe_build
|
2022-07-23 00:19:12 +00:00
|
|
|
fi
|
2022-07-23 17:44:55 +00:00
|
|
|
|