Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile installs an empty manpage if help2man isn't present #40

Open
tomparkin opened this issue Apr 29, 2020 · 0 comments
Open

Makefile installs an empty manpage if help2man isn't present #40

tomparkin opened this issue Apr 29, 2020 · 0 comments

Comments

@tomparkin
Copy link

The makefile autogenerates the manpage to install using the help2man command:

$(MANPAGE):
	help2man -N -n "$(PKGDESC)" -h -h -v -v ./$(SCRIPT) | gzip - > $@

If help2man isn't installed an empty manpage is generated, without make being aware of an error:

[tom@jackdaw mons]$ which help2man
help2man not found
[tom@jackdaw mons]$ help2man -N -n "POSIX Shell script to quickly manage 2-monitors display." -h -h -v -v ./mons.sh | gzip - > mons.1.gz
zsh: command not found: help2man
[tom@jackdaw mons]$ echo $?
0
[tom@jackdaw mons]$ ls -l mons.1.gz 
-rw-r--r-- 1 tom tom 20 Apr 29 10:51 mons.1.gz
[tom@jackdaw mons]$ 

This is because (quoting from the Bash manpage, although I believe the behaviour is POSIX) "The exit status of a pipeline is the exit status of the last command in the pipeline". So because gzip is successful, the pipeline as a whole is seen to have succeeded, and make happily installs the empty manpage.

There are of course various workarounds. One option is set -o pipefail although that's not POSIX, and in particular doesn't work on dash so far as I'm aware.

This patch worked for me to cause the makefile to fail rather than silently install a broken manpage:

diff --git a/Makefile b/Makefile
index b04ba89..69ad61f 100644
--- a/Makefile
+++ b/Makefile
@@ -27,11 +27,14 @@ install: $(LIB) $(MANPAGE)
        cp $(SCRIPT) $(BINDIR)/$(PKGNAME)
        sed -i -e "s#%LIBDIR%#$(LIBDIR)#" $(BINDIR)/$(PKGNAME)
 
-$(MANPAGE):
+check_help2man:
+       which help2man
+
+$(MANPAGE): check_help2man
        help2man -N -n "$(PKGDESC)" -h -h -v -v ./$(SCRIPT) | gzip - > $@
 
 uninstall:
        $(RM) -r $(LICENSEDIR) $(LIBDIR)
        $(RM) $(MANDIR)/$(MANPAGE) $(BINDIR)/$(PKGNAME)
 
-.PHONY: install uninstall
+.PHONY: install uninstall check_help2man
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant