From 809d6629c97bd9c4bdf6c799e74a261bb510b1fd Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 27 Jan 2021 22:35:39 -0500 Subject: Completely rewrite how manuals are fetched and installed Also add section 6 manuals from NetBSD and OpenBSD! --- .gitignore | 9 ++---- FreeBSD/Makefile | 8 ++++++ Linux/Makefile | 8 ++++++ Makefile | 84 +++++++++++++++++++++----------------------------------- NetBSD/Makefile | 8 ++++++ OpenBSD/Makefile | 9 ++++++ POSIX/Makefile | 8 ++++++ README.7 | 45 +++++++++++++++--------------- exman.1 | 28 +++++++++---------- exman.in | 52 +++++++++++++++++++++++++++++++++++ exman.sh | 58 -------------------------------------- freebsd.url | 1 - linux.url | 1 - netbsd-comp.url | 1 - netbsd-man.url | 1 - openbsd-comp.url | 1 - openbsd-man.url | 1 - posix.url | 1 - system.mk | 27 ++++++++++++++++++ 19 files changed, 190 insertions(+), 161 deletions(-) create mode 100644 FreeBSD/Makefile create mode 100644 Linux/Makefile create mode 100644 NetBSD/Makefile create mode 100644 OpenBSD/Makefile create mode 100644 POSIX/Makefile create mode 100644 exman.in delete mode 100644 exman.sh delete mode 100644 freebsd.url delete mode 100644 linux.url delete mode 100644 netbsd-comp.url delete mode 100644 netbsd-man.url delete mode 100644 openbsd-comp.url delete mode 100644 openbsd-man.url delete mode 100644 posix.url create mode 100644 system.mk diff --git a/.gitignore b/.gitignore index 8f9e5a6..d5017e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ -*.tar +*.tar.xz +*.tgz +*.txz exman -freebsd/ -linux/ -netbsd/ -openbsd/ -posix/ diff --git a/FreeBSD/Makefile b/FreeBSD/Makefile new file mode 100644 index 0000000..57e6e7b --- /dev/null +++ b/FreeBSD/Makefile @@ -0,0 +1,8 @@ +SYSTEM = FreeBSD +VERSION = 12.2-RELEASE +MIRROR = https://download.FreeBSD.org/ftp/releases/amd64/${VERSION} +DISTFILES = base.txz +FILES = ./usr/share/man/man[1-9]/ +STRIP = 4 + +.include "../system.mk" diff --git a/Linux/Makefile b/Linux/Makefile new file mode 100644 index 0000000..c81394d --- /dev/null +++ b/Linux/Makefile @@ -0,0 +1,8 @@ +SYSTEM = Linux +VERSION = 5.09 +MIRROR = https://mirrors.edge.kernel.org/pub/linux/docs/man-pages +DISTFILES = man-pages-${VERSION}.tar.xz +FILES = man-pages-${VERSION}/man[1-9]/ +STRIP = 1 + +.include "../system.mk" diff --git a/Makefile b/Makefile index 80c41b6..275d6ac 100644 --- a/Makefile +++ b/Makefile @@ -1,63 +1,41 @@ -PREFIX = /usr/local -SHAREDIR = ${PREFIX}/share -MANDIR = ${SHAREDIR}/man +PREFIX ?= /usr/local +SHAREDIR ?= ${PREFIX}/share +MANDIR ?= ${SHAREDIR}/man +EXMANDIR ?= ${SHAREDIR}/exman -CURL ?= curl -TAR ?= tar +SYSTEMS += FreeBSD +SYSTEMS += Linux +SYSTEMS += NetBSD +SYSTEMS += OpenBSD +SYSTEMS += POSIX -SYSTEMS += freebsd -SYSTEMS += linux -SYSTEMS += netbsd -SYSTEMS += openbsd -SYSTEMS += posix +all: exman +.for system in ${SYSTEMS} + ${MAKE} -C ${system} ${.TARGET} +.endfor -all: exman ${SYSTEMS} +.SUFFIXES: .in -.SUFFIXES: .tar .url - -.PRECIOUS: ${SYSTEMS:=.tar} - -.url.tar: - ${CURL} -f -o $@ "$$(cat $<)" - -.tar: - mkdir -p $@ - ${TAR} -x -f $< -C $@ --strip-components ${STRIP.$@} ${FILES.$@} - -netbsd: netbsd-man.tar netbsd-comp.tar - mkdir -p $@ - ${TAR} -x -f netbsd-man.tar -C $@ --strip-components ${STRIP.$@} ${FILES.$@} - ${TAR} -x -f netbsd-comp.tar -C $@ --strip-components ${STRIP.$@} ${FILES.$@} - -.PRECIOUS: netbsd-man.tar netbsd-comp.tar - -openbsd: openbsd-man.tar openbsd-comp.tar - mkdir -p $@ - ${TAR} -x -f openbsd-man.tar -C $@ --strip-components ${STRIP.$@} ${FILES.$@} - ${TAR} -x -f openbsd-comp.tar -C $@ --strip-components ${STRIP.$@} ${FILES.$@} - -.PRECIOUS: openbsd-man.tar openbsd-comp.tar - -FILES.freebsd = './usr/share/man/man[1-9]/' -FILES.netbsd = './usr/share/man/man[1-9]*/' -FILES.openbsd = './usr/share/man/man[1-9]*/' -FILES.linux = '*/man[1-9]/' -FILES.posix = '*/man[0-3]p/' - -STRIP.freebsd = 4 -STRIP.netbsd = 4 -STRIP.openbsd = 4 -STRIP.linux = 1 -STRIP.posix = 1 +.in: + sed 's|%%EXMANDIR%%|${EXMANDIR}|g' ${.IMPSRC} > ${.TARGET} + chmod a+x ${.TARGET} clean: - rm -fr ${SYSTEMS} *.tar + rm -f exman +.for system in ${SYSTEMS} + ${MAKE} -C ${system} ${.TARGET} +.endfor -install: exman exman.1 ${SYSTEMS} - install -d ${PREFIX}/bin ${MANDIR}/man1 ${SHAREDIR}/exman +install: exman exman.1 + install -d ${PREFIX}/bin ${MANDIR}/man1 install exman ${PREFIX}/bin - gzip -c exman.1 > ${MANDIR}/man1/exman.1.gz - ${TAR} -c -f - ${SYSTEMS} | ${TAR} -xo -f - -C ${SHAREDIR}/exman + install -m 644 exman.1 ${MANDIR}/man1 +.for system in ${SYSTEMS} + ${MAKE} -C ${system} ${.TARGET} +.endfor uninstall: - rm -fr ${PREFIX}/bin/exman ${MANDIR}/man1/exman.1.gz ${SHAREDIR}/exman + rm -f ${PREFIX}/bin/exman ${MANDIR}/man1/exman.1 +.for system in ${SYSTEMS} + ${MAKE} -C ${system} ${.TARGET} +.endfor diff --git a/NetBSD/Makefile b/NetBSD/Makefile new file mode 100644 index 0000000..d39769f --- /dev/null +++ b/NetBSD/Makefile @@ -0,0 +1,8 @@ +SYSTEM = NetBSD +VERSION = 9.1 +MIRROR = https://cdn.netbsd.org/pub/NetBSD/NetBSD-${VERSION}/amd64/binary/sets +DISTFILES = comp.tar.xz games.tar.xz man.tar.xz +FILES = ./usr/share/man/man[1-9]*/ +STRIP = 4 + +.include "../system.mk" diff --git a/OpenBSD/Makefile b/OpenBSD/Makefile new file mode 100644 index 0000000..0fd4e2e --- /dev/null +++ b/OpenBSD/Makefile @@ -0,0 +1,9 @@ +SYSTEM = OpenBSD +VERSION = 6.8 +MIRROR = https://cdn.openbsd.org/pub/OpenBSD/${VERSION}/amd64 +V = ${VERSION:S/.//} +DISTFILES = comp${V}.tgz game${V}.tgz man${V}.tgz +FILES = ./usr/share/man/man[1-9]*/ +STRIP = 4 + +.include "../system.mk" diff --git a/POSIX/Makefile b/POSIX/Makefile new file mode 100644 index 0000000..6a36ca4 --- /dev/null +++ b/POSIX/Makefile @@ -0,0 +1,8 @@ +SYSTEM = POSIX +VERSION = 2017 +MIRROR = https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/man-pages-posix +DISTFILES = man-pages-posix-${VERSION}-a.tar.xz +FILES = man-pages-posix-${VERSION}/man[0-3]p/ +STRIP = 1 + +.include "../system.mk" diff --git a/README.7 b/README.7 index 0548095..23b5d67 100644 --- a/README.7 +++ b/README.7 @@ -1,4 +1,4 @@ -.Dd May 3, 2020 +.Dd January 27, 2021 .Dt README 7 .Os "Causal Agency" . @@ -7,31 +7,30 @@ .Nd manuals for other systems . .Sh INSTALLING -Use +.Nm +requires BSD .Xr make 1 -to download and extract -manuals for various systems: -.Bd -literal -offset indent -make -.Ed -. -.Pp -If +and +.Xr tar 1 , +sometimes called +.Xr bmake 1 +and +.Xr bsdtar 1 , +respectively, +as well as +.Xr curl 1 . +The paths of .Xr tar 1 -is GNU, -it requires the -.Fl Fl wildcards -option: -.Bd -literal -offset indent -TAR='tar --wildcards' make -.Ed -. -.Pp -Install manuals and the -.Xr exman 1 -utility: +and +.Xr curl 1 +can be set by the environment variables +.Ev TAR +and +.Ev CURL , +respectively. .Bd -literal -offset indent -sudo make install PREFIX=/usr/local +make all +sudo make install .Ed . .Sh CONTRIBUTING diff --git a/exman.1 b/exman.1 index b2cc204..af0f349 100644 --- a/exman.1 +++ b/exman.1 @@ -1,4 +1,4 @@ -.Dd December 14, 2020 +.Dd January 27, 2021 .Dt EXMAN 1 .Os . @@ -25,23 +25,23 @@ are passed to . .Pp The available systems are as follows: -.Bl -tag -width "freebsd" -.It Sy freebsd -.Fx 12.2-RELEASE -.It Sy linux -The Linux man-pages project 5.09 -.It Sy netbsd -.Nx 9.1 -.It Sy openbsd -.Ox 6.8 -.It Sy posix -The Linux man-pages-posix project 2017-a +.Bl -tag -width "FreeBSD" +.It Fx +12.2-RELEASE +.It Linux +man-pages 5.09 +.It Nx +9.1 +.It Ox +6.8 +.It POSIX +man-pages-posix 2017 .El . .Sh EXAMPLES .Bd -literal -exman freebsd 4 unix -exman linux 7 unix +exman FreeBSD 4 unix +exman Linux 7 unix .Ed . .Sh SEE ALSO diff --git a/exman.in b/exman.in new file mode 100644 index 0000000..7d4a9c8 --- /dev/null +++ b/exman.in @@ -0,0 +1,52 @@ +#!/bin/sh +set -eu + +die() { + echo "$@" >&2 + exit 1 +} + +system=${1:-} +[ -n "${system}" ] || die 'What system do you want?' +shift + +export MANPATH="%%EXMANDIR%%/${system}" +[ -d "${MANPATH}" ] || die "No manuals for ${system}" + +export MANSECT +for sect in "${MANPATH}"/man*/; do + sect=${sect%/} + sect=${sect##*/man} + MANSECT="${MANSECT:-}${MANSECT:+:}${sect}" +done + +# macOS man(1) refuses to search in directories such as "man3p", so do it +# manually here unless there are other flags passed. +hack() { + case "${1:-}" in + (-*) exec man "$@";; + ([0-9]*) MANSECT=$1; shift;; + esac + [ $# -gt 0 ] || die 'What manual page do you want?' + for page in "$@"; do + found=0 + IFS=: + for sect in $MANSECT; do + path="${MANPATH}/man${sect}/${page}" + for ext in ".${sect}" ".${sect}.gz"; do + [ -f "${path}${ext}" ] || continue + man "${path}${ext}" + found=1 + break + done + [ $found -eq 0 ] || break + done + [ $found -ne 0 ] || die "No manual entry for ${page}" + done +} + +if [ "$(uname)" = 'Darwin' ]; then + hack "$@" +else + exec man "$@" +fi diff --git a/exman.sh b/exman.sh deleted file mode 100644 index 9b6777d..0000000 --- a/exman.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh -set -eu - -die() { - echo "$@" >&2 - exit 1 -} - -script=$0 -path=${script%/*} -prefix=${path%/bin} -exman="${prefix}/share/exman" -[ -d "${exman}" ] || exman=$prefix - -system=${1:-} -[ -n "${system}" ] || die 'What system do you want?' -shift - -export MANPATH="${exman}/${system}" -[ -d "${MANPATH}" ] || die "No manuals for ${system}" - -export MANSECT -for sect in "${MANPATH}"/man*/; do - sect=${sect%/} - sect=${sect##*/man} - MANSECT="${MANSECT:-}${MANSECT:+:}${sect}" -done - -# macOS man(1) refuses to search in directories such as "man3p", so do it -# manually here unless there are other flags passed. -hack() { - case "${1:-}" in - (-*) exec man "$@";; - ([0-9]*) MANSECT=$1; shift;; - esac - [ $# -gt 0 ] || die 'What manual page do you want?' - for page in "$@"; do - found=0 - IFS=: - for sect in $MANSECT; do - path="${MANPATH}/man${sect}/${page}" - for ext in ".${sect}" ".${sect}.gz"; do - [ -f "${path}${ext}" ] || continue - man "${path}${ext}" - found=1 - break - done - [ $found -eq 0 ] || break - done - [ $found -ne 0 ] || die "No manual entry for ${page}" - done -} - -if [ "$(uname)" = 'Darwin' ]; then - hack "$@" -else - exec man "$@" -fi diff --git a/freebsd.url b/freebsd.url deleted file mode 100644 index 269af5e..0000000 --- a/freebsd.url +++ /dev/null @@ -1 +0,0 @@ -https://download.FreeBSD.org/ftp/releases/amd64/12.2-RELEASE/base.txz diff --git a/linux.url b/linux.url deleted file mode 100644 index f0584b8..0000000 --- a/linux.url +++ /dev/null @@ -1 +0,0 @@ -https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/man-pages-5.09.tar.xz diff --git a/netbsd-comp.url b/netbsd-comp.url deleted file mode 100644 index c4704a5..0000000 --- a/netbsd-comp.url +++ /dev/null @@ -1 +0,0 @@ -https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.1/amd64/binary/sets/comp.tar.xz diff --git a/netbsd-man.url b/netbsd-man.url deleted file mode 100644 index bf0d532..0000000 --- a/netbsd-man.url +++ /dev/null @@ -1 +0,0 @@ -https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.1/amd64/binary/sets/man.tar.xz diff --git a/openbsd-comp.url b/openbsd-comp.url deleted file mode 100644 index fce012f..0000000 --- a/openbsd-comp.url +++ /dev/null @@ -1 +0,0 @@ -https://cdn.openbsd.org/pub/OpenBSD/6.8/amd64/comp68.tgz diff --git a/openbsd-man.url b/openbsd-man.url deleted file mode 100644 index f21fa7c..0000000 --- a/openbsd-man.url +++ /dev/null @@ -1 +0,0 @@ -https://cdn.openbsd.org/pub/OpenBSD/6.8/amd64/man68.tgz diff --git a/posix.url b/posix.url deleted file mode 100644 index 6dc7ad7..0000000 --- a/posix.url +++ /dev/null @@ -1 +0,0 @@ -https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/man-pages-posix/man-pages-posix-2017-a.tar.xz diff --git a/system.mk b/system.mk new file mode 100644 index 0000000..7ab5aba --- /dev/null +++ b/system.mk @@ -0,0 +1,27 @@ +PREFIX ?= /usr/local +SHAREDIR ?= ${PREFIX}/share +EXMANDIR ?= ${SHAREDIR}/exman + +CURL ?= curl +TAR ?= tar +ALLOW_FAILURE ?= false + +all: ${DISTFILES} + +.PRECIOUS: ${DISTFILES} + +${DISTFILES}: + ${CURL} -O ${MIRROR}/${.TARGET} + +clean: + rm -f ${DISTFILES} + +install: ${DISTFILES} + install -d ${EXMANDIR}/${SYSTEM} +.for distfile in ${DISTFILES} + ${TAR} -x -f ${distfile} -C ${EXMANDIR}/${SYSTEM} \ + --strip-components=${STRIP} '${FILES}' || ${ALLOW_FAILURE} +.endfor + +uninstall: + rm -fr ${EXMANDIR}/${SYSTEM} -- cgit 1.4.1