Instead of having a monolithic 'make install', break it into multiple targets such as 'make install-man3'. This simplifies packaging, for example in Debian, where they break this project into several packages: 'manpages' and 'manpages-dev', each containinng different mandirs. The above allows for multithread installation: 'make -j8' Also, don't overwrite files that don't need to be overwritten, by having a target for files, which makes use of make's timestamp comparison. This allows much faster installation times (although, it's a bit slower to do a full clean install). Now that the installation overwrites target files when needed, 'make [all]' is aliased to 'make install', as an uninstall is almost never needed (unless you specifically want to test a clean install, in which case you can run 'make uninstall; make install'). Also, I replaced = by ?=, because eventhough user input overrides any of those, I don't trust make to not start a subshell for every submake, in the cases where I invoke a shell. I want the shell to be invoked only in the main make process in variable assignments. Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx> --- Makefile | 217 +++++++++++++++++++++++++++++++++++++++++++------------ README | 8 +- 2 files changed, 176 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index 78d953f3c..159b2fe78 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,178 @@ SHELL = /bin/bash -Eeuo pipefail -# Do not print "Entering directory ..." MAKEFLAGS += --no-print-directory +MAKEFLAGS += --silent + +htmlbuilddir ?= $(CURDIR)/.html +HTOPTS ?= + +DESTDIR ?= +prefix ?= /usr/local +datarootdir ?= $(prefix)/share +docdir ?= $(datarootdir)/doc +MANDIR ?= $(CURDIR) +mandir ?= $(datarootdir)/man +MAN1DIR ?= $(CURDIR)/man1 +MAN2DIR ?= $(CURDIR)/man2 +MAN3DIR ?= $(CURDIR)/man3 +MAN4DIR ?= $(CURDIR)/man4 +MAN5DIR ?= $(CURDIR)/man5 +MAN6DIR ?= $(CURDIR)/man6 +MAN7DIR ?= $(CURDIR)/man7 +MAN8DIR ?= $(CURDIR)/man8 +man1dir ?= $(mandir)/man1 +man2dir ?= $(mandir)/man2 +man3dir ?= $(mandir)/man3 +man4dir ?= $(mandir)/man4 +man5dir ?= $(mandir)/man5 +man6dir ?= $(mandir)/man6 +man7dir ?= $(mandir)/man7 +man8dir ?= $(mandir)/man8 +htmldir ?= $(docdir) +htmldir_ ?= $(htmldir)/man +htmlext ?= .html + +INSTALL ?= install +INSTALL_DATA ?= $(INSTALL) -m 644 +INSTALL_DIR ?= $(INSTALL) -m 755 -d +RMDIR ?= rmdir --ignore-fail-on-non-empty -htmlbuilddir = $(CURDIR)/.html -HTOPTS = -DESTDIR = -prefix = /usr/local -datarootdir = $(prefix)/share -docdir = $(datarootdir)/doc -mandir = $(datarootdir)/man -htmldir = $(docdir) -htmldir_ = $(htmldir)/man -htmlext = .html +.PHONY: all +all: install -INSTALL = install -INSTALL_DATA = $(INSTALL) -m 644 -INSTALL_DIR = $(INSTALL) -m 755 -d -.PHONY: all -all: - $(MAKE) uninstall; - $(MAKE) install; +%/: + @echo ' INSTALL $@'; + $(INSTALL_DIR) $@; + + +.PHONY: install +install: install-man + +.PHONY: uninstall remove +uninstall remove: uninstall-man + +.PHONY: installdirs +installdirs: installdirs-man +installdirs: installdirs-man1 +installdirs: installdirs-man2 +installdirs: installdirs-man3 +installdirs: installdirs-man4 +installdirs: installdirs-man5 +installdirs: installdirs-man6 +installdirs: installdirs-man7 +installdirs: installdirs-man8 + +.PHONY: clean +clean: + find man?/ -type f \ + |while read f; do \ + rm -f "$(htmlbuilddir)/$$f".*; \ + done; + +################################################################################ +# man + +MAN1PAGES ?= $(shell find $(MAN1DIR) -type f | grep '$(man1ext)$$') +MAN2PAGES ?= $(shell find $(MAN2DIR) -type f | grep '$(man2ext)$$') +MAN3PAGES ?= $(shell find $(MAN3DIR) -type f | grep '$(man3ext)$$') +MAN4PAGES ?= $(shell find $(MAN4DIR) -type f | grep '$(man4ext)$$') +MAN5PAGES ?= $(shell find $(MAN5DIR) -type f | grep '$(man5ext)$$') +MAN6PAGES ?= $(shell find $(MAN6DIR) -type f | grep '$(man6ext)$$') +MAN7PAGES ?= $(shell find $(MAN7DIR) -type f | grep '$(man7ext)$$') +MAN8PAGES ?= $(shell find $(MAN8DIR) -type f | grep '$(man8ext)$$') +MANPAGES ?= $(MAN1PAGES) \ + $(MAN2PAGES) \ + $(MAN3PAGES) \ + $(MAN4PAGES) \ + $(MAN5PAGES) \ + $(MAN6PAGES) \ + $(MAN7PAGES) \ + $(MAN8PAGES) +man1pages ?= $(addprefix $(DESTDIR)$(man1dir)/,$(notdir $(MAN1PAGES))) +man2pages ?= $(addprefix $(DESTDIR)$(man2dir)/,$(notdir $(MAN2PAGES))) +man3pages ?= $(addprefix $(DESTDIR)$(man3dir)/,$(notdir $(MAN3PAGES))) +man4pages ?= $(addprefix $(DESTDIR)$(man4dir)/,$(notdir $(MAN4PAGES))) +man5pages ?= $(addprefix $(DESTDIR)$(man5dir)/,$(notdir $(MAN5PAGES))) +man6pages ?= $(addprefix $(DESTDIR)$(man6dir)/,$(notdir $(MAN6PAGES))) +man7pages ?= $(addprefix $(DESTDIR)$(man7dir)/,$(notdir $(MAN7PAGES))) +man8pages ?= $(addprefix $(DESTDIR)$(man8dir)/,$(notdir $(MAN8PAGES))) +manpages ?= $(man1pages) \ + $(man2pages) \ + $(man3pages) \ + $(man4pages) \ + $(man5pages) \ + $(man6pages) \ + $(man7pages) \ + $(man8pages) + + +$(manpages): $(DESTDIR)$(mandir)/%: $(MANDIR)/% + @echo ' INSTALL $@'; + $(INSTALL_DATA) -T "$(MANDIR)/$*" $@; + + +INSTALLDIRS_MANN ?= installdirs-man1 \ + installdirs-man2 \ + installdirs-man3 \ + installdirs-man4 \ + installdirs-man5 \ + installdirs-man6 \ + installdirs-man7 \ + installdirs-man8 +.PHONY: $(INSTALLDIRS_MANN) +$(INSTALLDIRS_MANN): installdirs-%: $(DESTDIR)$(mandir)/%/ | installdirs-man + @:; +.PHONY: installdirs-man +installdirs-man: $(DESTDIR)$(mandir)/ + @:; + +INSTALL_MANN ?= install-man1 \ + install-man2 \ + install-man3 \ + install-man4 \ + install-man5 \ + install-man6 \ + install-man7 \ + install-man8 +.PHONY: install-man +install-man: $(INSTALL_MANN) | $(INSTALLDIRS_MANN) + @:; + +.PHONY: $(INSTALL_MANN) +$(INSTALL_MANN): install-%: | installdirs-% + @echo ' INSTALL $(DESTDIR)$(mandir)/$*/'; + find $(MANDIR)/$*/ -type f \ + | grep '.[0-9]$$' \ + | sed 's,$(MANDIR)/$*/,$(DESTDIR)$(mandir)/$*/,' \ + | xargs $(MAKE); + +UNINSTALL_MANN ?= uninstall-man1 \ + uninstall-man2 \ + uninstall-man3 \ + uninstall-man4 \ + uninstall-man5 \ + uninstall-man6 \ + uninstall-man7 \ + uninstall-man8 + +.PHONY: $(UNINSTALL_MANN) +$(UNINSTALL_MANN): uninstall-%: + @echo ' UNINSTALL $(DESTDIR)$(mandir)/$*/'; + find $(MANDIR)/$*/ -type f \ + | grep '.[0-9]$$' \ + | sed 's,$(MANDIR)/$*/,$(DESTDIR)$(mandir)/$*/,' \ + | xargs rm -f; + $(RMDIR) $(DESTDIR)$(mandir)/$*/ 2>/dev/null ||:; +.PHONY: uninstall-man +uninstall-man: $(UNINSTALL_MANN) + @echo ' UNINSTALL $(DESTDIR)$(mandir)/'; + $(RMDIR) $(DESTDIR)$(mandir)/ ||:; + + +################################################################################ +# html # Use with # make HTOPTS=whatever html @@ -58,28 +208,6 @@ installdirs-html: $(INSTALL_DIR) "$(DESTDIR)$(htmldir_)/$$d"; \ done; -.PHONY: install -install: | installdirs - find man?/ -type f \ - |while read f; do \ - $(INSTALL_DATA) -T "$$f" "$(DESTDIR)$(mandir)/$$f"; \ - done; - -.PHONY: installdirs -installdirs: - find man?/ -type d \ - |while read d; do \ - $(INSTALL_DIR) "$(DESTDIR)$(mandir)/$$d"; \ - done; - -.PHONY: uninstall remove -uninstall remove: - find man?/ -type f \ - |while read f; do \ - rm -f "$(DESTDIR)$(mandir)/$$f"; \ - rm -f "$(DESTDIR)$(mandir)/$$f".*; \ - done; - .PHONY: uninstall-html uninstall-html: find man?/ -type f \ @@ -87,12 +215,9 @@ uninstall-html: rm -f "$(DESTDIR)$(htmldir_)/$$f".*; \ done; -.PHONY: clean -clean: - find man?/ -type f \ - |while read f; do \ - rm -f "$(htmlbuilddir)/$$f".*; \ - done; + +################################################################################ +# tests # Check if groff reports warnings (may be words of sentences not displayed) # from https://lintian.debian.org/tags/groff-message.html diff --git a/README b/README index 6598170c0..b8c7d6edc 100644 --- a/README +++ b/README @@ -17,7 +17,8 @@ For further information on contributing, see the CONTRIBUTING file. Installing and uninstalling =========================== -"make install" will copy these man pages to /usr/local/share/man/man[1-8]. +"make", "make all", or "make install" will copy these man pages to +/usr/local/share/man/man[1-8]. To install to a path different from /usr/local, use "make install prefix=/install/path". @@ -26,8 +27,9 @@ To install to a path different from /usr/local, use distribution from its destination. Use with caution, and remember to use "prefix" if desired, as with the "install" target. -"make" or "make all" will perform "make uninstall" followed by "make -install". +To install only a specific man section (mandir) such as man3, use +"make install-man3". Similar syntax can be used to uninstall a +specific man section, such as man7: "make uninstall-man7". Copyrights ========== -- 2.31.1