]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
Makefile: Use standard features (IMPORTANT: default prefix changed)
authorAlejandro Colomar <alx.manpages@gmail.com>
Sun, 9 May 2021 21:39:27 +0000 (23:39 +0200)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Mon, 10 May 2021 01:05:36 +0000 (13:05 +1200)
IMPORTANT for distributions:
This changes prefix to be '/usr/local' as is expected by default,
instead of the old '/usr' value.

- Use standard variables:
    - prefix should be '/usr/local'
    - mandir (instead of MANDIR)
    - htmldir (instead of HTDIR)
    - ...
    see <https://www.gnu.org/software/make/manual/html_node/Directory-Variables.html>

- Use standard targets:
    - html (build html files; don't install them)
    - install-html (instead of html)
    - installdirs (instead of 'mkdir -p'/'install -d' inside other targets)
    - ...
    see <https://www.gnu.org/software/make/manual/html_node/Standard-Targets.html#Standard-Targets>

- Use .PHONY

- ?= is not needed.  User input overrides any assignment.  Use =

- Use standard command variables, instead of directly calling commands.
    - $(INSTALL_DATA) (instead of install -m 644)
    - $(INSTALL_DIR) (instead of install -d -m 755 or mkdir -p)
    see <https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables>

- Specify SHELL = /bin/bash

- Specify shebang

- Allow variable html extension (or no extension at all)

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Makefile

index 607b8c98b3ca0a00e1ae825102f1520a99b72f3a..430090801c77ecb17b280ba8602011c5ed4b739a 100644 (file)
--- a/Makefile
+++ b/Makefile
-DESTDIR=
-prefix?=/usr
-MANDIR=$(prefix)/share/man
-HTDIR?=.html
+#!/usr/bin/make -f
 
-all: remove install
+# Do not print "Entering directory ..."
+MAKEFLAGS += --no-print-directory
 
-uninstall remove:
-       for i in man?/*; do \
-               rm -f $(MANDIR)/"$$i" $(MANDIR)/"$$i".*; \
-       done
+htmlbuilddir = $(CURDIR)/.html
+HTOPTS =
+
+DESTDIR =
+prefix = /usr/local
+datarootdir = $(prefix)/share
+docdir = $(datarootdir)/doc
+mandir = $(datarootdir)/man
+htmldir = $(docdir)
+htmldir_ = $(htmldir)/man
+htmlext = .html
+
+INSTALL = install
+INSTALL_DATA = $(INSTALL) -m 644
+INSTALL_DIR = $(INSTALL) -m 755 -d
+
+.PHONY: all
+all: remove install
 
 # Use with
-#  make HTDIR=/some/dir HTOPTS=whatever html
+#  make HTOPTS=whatever html
 # The sed removes the lines "Content-type: text/html\n\n"
-html:
-       for i in man?; do \
-               mkdir -p $(HTDIR)/"$$i"; \
-               find "$$i/" -type f | while read f; do \
-                       man2html $(HTOPTS) $$f | \
-                       sed -e '1,2d' > $(HTDIR)/"$$i"/`basename $$f`.html; \
-               done; \
-       done
-
-install:
-       for i in man?; do \
-               install -d -m 755 $(DESTDIR)$(MANDIR)/"$$i" || exit $$?; \
-               install -m 644 "$$i"/* $(DESTDIR)$(MANDIR)/"$$i" || exit $$?; \
-       done
+.PHONY: html
+html: | builddirs-html
+       find man?/ -type f \
+       |while read f; do \
+               man2html $(HTOPTS) "$$f" \
+               |sed -e '1,2d' \
+               >"$(htmlbuilddir)/$${f}$(htmlext)" \
+                       || exit $$?; \
+       done;
+
+.PHONY: builddirs-html
+builddirs-html:
+       find man?/ -type d \
+       |while read d; do \
+               $(INSTALL_DIR) "$(htmlbuilddir)/$$d" || exit $$?; \
+       done;
+
+.PHONY: install-html
+install-html: | installdirs-html
+       cd $(htmlbuilddir) && \
+       find man?/ -type f \
+       |while read f; do \
+               $(INSTALL_DATA) -T "$$f" "$(DESTDIR)$(htmldir_)/$$f" || exit $$?; \
+       done;
+
+.PHONY: installdirs-html
+installdirs-html:
+       find man?/ -type d \
+       |while read d; do \
+               $(INSTALL_DIR) "$(DESTDIR)$(htmldir_)/$$d" || exit $$?; \
+       done;
+
+.PHONY: install
+install: | installdirs
+       find man?/ -type f \
+       |while read f; do \
+               $(INSTALL_DATA) -T "$$f" "$(DESTDIR)$(mandir)/$$f" || exit $$?; \
+       done;
+
+.PHONY: installdirs
+installdirs:
+       find man?/ -type d \
+       |while read d; do \
+               $(INSTALL_DIR) "$(DESTDIR)$(mandir)/$$d" || exit $$?; \
+       done;
+
+.PHONY: uninstall remove
+uninstall remove:
+       find man?/ -type f \
+       |while read f; do \
+               rm -f "$(DESTDIR)$(mandir)/$$f" || exit $$?; \
+               rm -f "$(DESTDIR)$(mandir)/$$f".* || exit $$?; \
+       done;
+
+.PHONY: uninstall-html
+uninstall-html:
+       find man?/ -type f \
+       |while read f; do \
+               rm -f "$(DESTDIR)$(htmldir_)/$$f".* || exit $$?; \
+       done;
+
+.PHONY: clean
+clean:
+       find man?/ -type f \
+       |while read f; do \
+               rm -f "$(htmlbuilddir)/$$f".* || exit $$?; \
+       done;
 
 # Check if groff reports warnings (may be words of sentences not displayed)
 # from https://lintian.debian.org/tags/groff-message.html
+.PHONY: check-groff-warnings
 check-groff-warnings:
        GROFF_LOG="$$(mktemp --tmpdir manpages-checksXXXX)" || exit $$?; \
        for i in man?/*.[1-9]; \