From f7154334ae14e0367ce7b3055844ac462360404f Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Sat, 4 Nov 2017 13:01:13 +0100 Subject: [PATCH] `man` (manpages) module added. --- Makefile | 30 ++++++++++++++++--- build.zsh.in | 1 + build/man.zsh | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 build/man.zsh diff --git a/Makefile b/Makefile index 77e0d79..e1c0f80 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ BINDIR := $(PREFIX)/bin LIBDIR := $(PREFIX)/lib SHAREDIR := $(PREFIX)/share INCLUDEDIR := $(PREFIX)/include +MANDIR := $(SHAREDIR)/man CC := cc AR := ar @@ -15,7 +16,7 @@ LDFLAGS := Q := @ -all: build.zsh build/binary.zsh build/crystal.zsh build/library.zsh build/moon.zsh build/ofile.zsh build/script.zsh build/sharedlib.zsh build/staticlib.zsh +all: build.zsh build/binary.zsh build/crystal.zsh build/library.zsh build/man.zsh build/moon.zsh build/ofile.zsh build/script.zsh build/sharedlib.zsh build/staticlib.zsh @: build.zsh: build.zsh.in @@ -76,6 +77,19 @@ build/library.zsh.uninstall: @echo ' RM > $(SHAREDIR)/build.zsh/library.zsh' $(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/library.zsh' +build/man.zsh: + +build/man.zsh.install: build/man.zsh + @echo ' IN > $(SHAREDIR)/build.zsh/man.zsh' + $(Q)mkdir -p '$(DESTDIR)$(SHAREDIR)/build.zsh' + $(Q)install -m0755 build/man.zsh $(DESTDIR)$(SHAREDIR)/build.zsh/man.zsh + +build/man.zsh.clean: + +build/man.zsh.uninstall: + @echo ' RM > $(SHAREDIR)/build.zsh/man.zsh' + $(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/man.zsh' + build/moon.zsh: build/moon.zsh.install: build/moon.zsh @@ -156,12 +170,15 @@ $(DESTDIR)$(SHAREDIR): $(DESTDIR)$(INCLUDEDIR): @echo ' DIR > $(INCLUDEDIR)' $(Q)mkdir -p $(DESTDIR)$(INCLUDEDIR) -install: subdirs.install build.zsh.install build/binary.zsh.install build/crystal.zsh.install build/library.zsh.install build/moon.zsh.install build/ofile.zsh.install build/script.zsh.install build/sharedlib.zsh.install build/staticlib.zsh.install +$(DESTDIR)$(MANDIR): + @echo ' DIR > $(MANDIR)' + $(Q)mkdir -p $(DESTDIR)$(MANDIR) +install: subdirs.install build.zsh.install build/binary.zsh.install build/crystal.zsh.install build/library.zsh.install build/man.zsh.install build/moon.zsh.install build/ofile.zsh.install build/script.zsh.install build/sharedlib.zsh.install build/staticlib.zsh.install @: subdirs.install: -uninstall: subdirs.uninstall build.zsh.uninstall build/binary.zsh.uninstall build/crystal.zsh.uninstall build/library.zsh.uninstall build/moon.zsh.uninstall build/ofile.zsh.uninstall build/script.zsh.uninstall build/sharedlib.zsh.uninstall build/staticlib.zsh.uninstall +uninstall: subdirs.uninstall build.zsh.uninstall build/binary.zsh.uninstall build/crystal.zsh.uninstall build/library.zsh.uninstall build/man.zsh.uninstall build/moon.zsh.uninstall build/ofile.zsh.uninstall build/script.zsh.uninstall build/sharedlib.zsh.uninstall build/staticlib.zsh.uninstall @: subdirs.uninstall: @@ -171,7 +188,7 @@ test: all subdirs subdirs.test subdirs.test: -clean: build.zsh.clean build/binary.zsh.clean build/crystal.zsh.clean build/library.zsh.clean build/moon.zsh.clean build/ofile.zsh.clean build/script.zsh.clean build/sharedlib.zsh.clean build/staticlib.zsh.clean +clean: build.zsh.clean build/binary.zsh.clean build/crystal.zsh.clean build/library.zsh.clean build/man.zsh.clean build/moon.zsh.clean build/ofile.zsh.clean build/script.zsh.clean build/sharedlib.zsh.clean build/staticlib.zsh.clean distclean: clean @@ -189,6 +206,7 @@ $(PACKAGE)-$(VERSION).tar.gz: distdir $(PACKAGE)-$(VERSION)/build/binary.zsh \ $(PACKAGE)-$(VERSION)/build/crystal.zsh \ $(PACKAGE)-$(VERSION)/build/library.zsh \ + $(PACKAGE)-$(VERSION)/build/man.zsh \ $(PACKAGE)-$(VERSION)/build/moon.zsh \ $(PACKAGE)-$(VERSION)/build/ofile.zsh \ $(PACKAGE)-$(VERSION)/build/script.zsh \ @@ -205,6 +223,7 @@ $(PACKAGE)-$(VERSION).tar.xz: distdir $(PACKAGE)-$(VERSION)/build/binary.zsh \ $(PACKAGE)-$(VERSION)/build/crystal.zsh \ $(PACKAGE)-$(VERSION)/build/library.zsh \ + $(PACKAGE)-$(VERSION)/build/man.zsh \ $(PACKAGE)-$(VERSION)/build/moon.zsh \ $(PACKAGE)-$(VERSION)/build/ofile.zsh \ $(PACKAGE)-$(VERSION)/build/script.zsh \ @@ -221,6 +240,7 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir $(PACKAGE)-$(VERSION)/build/binary.zsh \ $(PACKAGE)-$(VERSION)/build/crystal.zsh \ $(PACKAGE)-$(VERSION)/build/library.zsh \ + $(PACKAGE)-$(VERSION)/build/man.zsh \ $(PACKAGE)-$(VERSION)/build/moon.zsh \ $(PACKAGE)-$(VERSION)/build/ofile.zsh \ $(PACKAGE)-$(VERSION)/build/script.zsh \ @@ -251,12 +271,14 @@ help: @echo ' - LIBDIR ${LIBDIR}' @echo ' - SHAREDIR ${SHAREDIR}' @echo ' - INCLUDEDIR ${INCLUDEDIR}' + @echo ' - MANDIR ${MANDIR}' @echo '' @echo 'Project targets: ' @echo ' - build.zsh script' @echo ' - build/binary.zsh script' @echo ' - build/crystal.zsh script' @echo ' - build/library.zsh script' + @echo ' - build/man.zsh script' @echo ' - build/moon.zsh script' @echo ' - build/ofile.zsh script' @echo ' - build/script.zsh script' diff --git a/build.zsh.in b/build.zsh.in index 733cdc7..cb7e87c 100644 --- a/build.zsh.in +++ b/build.zsh.in @@ -194,6 +194,7 @@ function main { LIBDIR '$(PREFIX)/lib' SHAREDIR '$(PREFIX)/share' INCLUDEDIR '$(PREFIX)/include' + MANDIR '$(SHAREDIR)/man' ) if [[ -f project.zsh && -r project.zsh ]]; then diff --git a/build/man.zsh b/build/man.zsh new file mode 100644 index 0000000..91ee173 --- /dev/null +++ b/build/man.zsh @@ -0,0 +1,81 @@ + +function man.build { + typeset -l S + + if [[ -n "${sources[$target]}" ]]; then + S="${sources[$target]}" + elif [[ -e "${target}.md" ]]; then + S="${target}.md" + fi + + write -n "${target}:" + + if [[ -n "${S}" ]]; then + write " $S" + write "\t@echo '$(SED "${target}" | sed 's|SED|MAN|')'" + write "\t${Q}pandoc -s --from markdown --to man '$S' -o '${target}'" + fi + + write "\n" +} + +function man.install { + local basename="${filename[$target]}" + if [[ -z "$basename" ]]; then + basename="$(basename "${target}")" + fi + + local section="${basename%.md}" + section="${section##*.}" + local install="${install[$target]:-\$(MANDIR)/man${section}}" + + write "${target}.install: ${target}" + write "\t@echo '$(IN "${install}/${basename}")'" + write "\t${Q}mkdir -p '\$(DESTDIR)${install}'" + write "\t${Q}install -m0644 ${target} \$(DESTDIR)${install}/${basename}" + write +} + +function man.uninstall { + local basename="${filename[$target]}" + if [[ -z "$basename" ]]; then + basename="$(basename "${target}")" + fi + + local section="${basename%.md}" + section="${section##*.}" + local install="${install[$target]:-\$(MANDIR)/man${section}}" + + write "${target}.uninstall:" + write "\t@echo '$(RM ${install}/${basename})'" + write "\t${Q}rm -f '\$(DESTDIR)${install}/${basename}'" + write +} + +function man.clean { + typeset -l S + + if [[ -n "${sources[$target]}" ]]; then + S="${sources[$target]}" + else + S="${target}.md" + fi + + write "${target}.clean:" + + if [[ -e "${S%% *}" ]]; then + write "\t@echo '$(RM ${target})'" + write "\t${Q}rm -f ${target}" + fi + + write +} + +function man.distfiles { + if [[ -e "${target}.md" ]]; then + echo "${target}.md" + else + echo "${target}" + fi +} +