From 2e96fc06f325110af8c7177c0c60694eed5fd245 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 2 Jan 2024 17:28:59 -0300 Subject: 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%. --- tools/manpages.sh | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 tools/manpages.sh (limited to 'tools/manpages.sh') diff --git a/tools/manpages.sh b/tools/manpages.sh new file mode 100755 index 00000000..755ff777 --- /dev/null +++ b/tools/manpages.sh @@ -0,0 +1,126 @@ +#!/bin/sh +set -eu + +. tools/lib.sh + + +usage() { + cat <<-'EOF' + Usage: + sh doc/manpages.sh -i|-u -p MANDIR FILE... + sh doc/manpages.sh -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -i set ACTION=install + -u set ACTION=uninstall + -p MANDIR use $MANDIR as the prefix directory + -h, --help show this message + + + Installs/uninstalls manpage files into MANDIR using the original + filename as a hint towards which subdirectory to pick: the + `prog.ru.1` file is installed under the `man1/` directory + hierarchy under the `ru/` language folder. When then language + is `en`, a the toplevel `man1/` gets a symlink to the `en/` + language folder: + + man/ + en/ + man1/ + prog.1 + ru/ + man1/ + prog.1 + man1/ + prog.1 -> ../en/man1/prog.1 + + + Examples: + + Install prog.en.1 under `/usr/man`: + + $ sh doc/manpages.sh -ip/usr/man prog.en.1 + + + Uninstall all files listed under doc/ from `$PREFIX`: + + sh doc/manpages.sh -up "$PREFIX" doc/*.[0-9] + EOF +} + + +for flag in "$@"; do + case "$flag" in + (--) + break + ;; + (--help) + usage + help + exit + ;; + (*) + ;; + esac +done + +while getopts 'iup:h' flag; do + case "$flag" in + (i) + ACTION=install + ;; + (u) + ACTION=uninstall + ;; + (p) + MANDIR="$OPTARG" + ;; + (h) + usage + help + exit + ;; + (*) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +eval "$(assert_arg "${ACTION:-}" '-[iu] for choosing action')" +eval "$(assert_arg "${MANDIR:-}" '-p MANDIR')" +eval "$(assert_arg "${1:-}" 'FILE...')" + + +for f in "$@"; do + l="$(echo "$f" | awk -F. '{print $(NF-1)}')" + n="$(echo "$f" | awk -F. '{print $NF}')" + case "$ACTION" in + (install) + to_name="$(basename "${f%."$l"."$n"}.$n")" + mkdir -p "$MANDIR/$l/man$n" "$MANDIR/man$n" + cp "$f" "$MANDIR/$l/man$n/$to_name" + if [ "$l" = 'en' ]; then + ln -fs "../en/man$n/$to_name" \ + "$MANDIR/man$n/$to_name" + fi + ;; + (uninstall) + to_name="$(basename "${f%."$l"."$n"}.$n")" + rm -f \ + "$MANDIR/$l/man$n/$to_name" \ + "$MANDIR/man$n/$to_name" + ;; + (*) + echo "Bad ACTION: $ACTION" + exit 1 + ;; + esac +done -- cgit v1.2.3