aboutsummaryrefslogtreecommitdiff
path: root/tools/makehelp.sh
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-01-02 17:28:59 -0300
committerEuAndreh <eu@euandre.org>2024-01-05 05:43:22 -0300
commit2e96fc06f325110af8c7177c0c60694eed5fd245 (patch)
treeba4e2ae8c50136cbf2f00a0edc8f31c90901bb64 /tools/makehelp.sh
parentsrc/internal/version.h: Check-in file with fixed value for compilation (diff)
downloadgrovel-2e96fc06f325110af8c7177c0c60694eed5fd245.tar.gz
grovel-2e96fc06f325110af8c7177c0c60694eed5fd245.tar.xz
Fix the build system.
The improvements are: - use most of the default "Makefile" for standard packaging; - also use the default ".gitignore" with for the derived assets; - don't impose so many $CFLAGS on the user. GCC still needs to be given the `-ffreestanding` flag explicitly for us to get a good binary; - stop using ad-hoc tools/* scripts, and avoid the code-generation anti-pattern overall on the build. Some of the generated files were checked-in, and some were removed; - remove empty files; - use POSIX make(1) over gmake; - add fuzz targets; - partial "install" and "uninstall" targets; - complete "clean" target. The shortcomings are: - only working on x86_64. More platforms coming soon; - code is still messy: way too many warnings, GNU/BSD specific extensions, inline assembly, and all kinds of unportable code; - still only works with GCC and GCC-like compilers, and completly fails with tcc(1) and cproc(1); - the `deps.mk` file is being maintained manually. As I work on the source files I'll finish automating its generation with `mkdeps.sh`; - still seems to be coupled with Linux; - still is missing tests setup; - still uses `#include <$NAME.h>` instead of the correct `#include "$NAME.h"` form. The generated libgrovel.a did match the previous lib/libc.a 100%.
Diffstat (limited to 'tools/makehelp.sh')
-rwxr-xr-xtools/makehelp.sh149
1 files changed, 149 insertions, 0 deletions
diff --git a/tools/makehelp.sh b/tools/makehelp.sh
new file mode 100755
index 00000000..e6118de7
--- /dev/null
+++ b/tools/makehelp.sh
@@ -0,0 +1,149 @@
+#!/bin/sh
+set -eu
+
+. tools/lib.sh
+
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ makehelp.sh < MAKEFILE
+ makehelp.sh -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+
+ Options:
+ -h, --help show this message
+
+
+ Generate a help message from the given Makefile.
+
+ Any target or variable commented with two "#" characters gets
+ picked up. Multi-line comments are supported:
+
+ VAR1 = 1
+ # a comment
+ VAR2 = 2
+ ## another comment -> this one is included in the docs
+ VAR3 = 3
+
+ ## with a big
+ ## comment, which is also included
+ a-target:
+
+
+ Examples:
+
+ Generate help messages from "Makefile":
+
+ $ aux/makehelp.sh < Makefile
+
+
+ Generate help messages for all targets:
+
+ $ cat Makefile dev.mk | aux/makehelp.sh
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ (--)
+ break
+ ;;
+ (--help)
+ usage
+ help
+ exit
+ ;;
+ (*)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ (h)
+ usage
+ help
+ exit
+ ;;
+ (*)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+TARGETS="$(mkstemp)"
+VARIABLES="$(mkstemp)"
+trap 'rm -f "$TARGETS" "$VARIABLES"' EXIT
+
+awk -vCOLUMN=15 -vTARGETS="$TARGETS" -vVARIABLES="$VARIABLES" '
+function indent(n, where) {
+ for (INDENT = 0; INDENT < n; INDENT++) {
+ printf " " > where
+ }
+}
+
+/^## / { doc[len++] = substr($0, 4) }
+
+/^[-_a-zA-Z]+:/ && len {
+ printf "\033[36m%s\033[0m", substr($1, 1, length($1) - 1) > TARGETS
+ for (i = 0; i < len; i++) {
+ n = COLUMN - (i == 0 ? length($1) - 1 : 0)
+ indent(n, TARGETS)
+ printf "%s\n", doc[i] > TARGETS
+ }
+ len = 0
+}
+
+/^.++=/ && len {
+ printf "\033[36m%s\033[0m", $1 > VARIABLES
+ for (i = 0; i < len; i++) {
+ n = COLUMN - (i == 0 ? length($1) : 0)
+ indent(n, VARIABLES)
+ printf "%s\n", doc[i] > VARIABLES
+ }
+ len = 0
+}'
+
+
+
+indent() {
+ sed 's|^| |'
+}
+
+cat <<-EOF
+ Usage:
+
+ make [VARIABLE=value...] [target...]
+
+
+ Targets:
+
+ $(indent < "$TARGETS")
+
+
+ Variables:
+
+ $(indent < "$VARIABLES")
+
+
+ Examples:
+
+ Build "all", the default target:
+
+ $ make
+
+
+ Test and install, with \$(DESTDIR) set to "tmp/":
+
+ $ make DESTDIR=tmp check install
+EOF