From 69c2296d510753e6df350c2860d3fd4ae0ef4bf1 Mon Sep 17 00:00:00 2001 From: Marcus Jaschen Date: Fri, 7 Apr 2017 15:41:36 +0200 Subject: [PATCH 1/2] Add some tweaks to the Makefile to make it behave more like a Makefile ;-) - use Make variables - remove empty target file in case of an error (the target file is created by the shell redirection before `mandoc` runs) --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 95fe60c..529abc0 100644 --- a/Makefile +++ b/Makefile @@ -2,5 +2,5 @@ src=hostmux.mandoc tgt=man/hostmux.1 $(tgt): $(src) - mkdir -p $(shell dirname $(tgt)) - mandoc -I os=sh -Tman $(src) > $(tgt) + mkdir -p $(shell dirname $@) + mandoc -I os=sh -Tman $< > $@ || { rm -f $@ ; exit 2 ; } From 44a1f657d2493a9625b6ed6865f8a3d906609dcb Mon Sep 17 00:00:00 2001 From: Marcus Jaschen Date: Fri, 7 Apr 2017 18:37:20 +0200 Subject: [PATCH 2/2] add some comments to the Makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `src` und `tgt` habe ich entfernt, da sie nicht notwendig sind -- make hat für die Stellen, an denen sie verwendet wurden eigene Variablen: - $@ - aktuelles Target - $< - erstes Prerequisite (hier: hostmux.mandoc) - das Starten einer Sub-Shell für `dirname` habe ich entfernt und mit der make-eigenen Funktion `dir` ersetzt (ist portabler) - die Notwendigkeit des Konstrukts zur Fehlerbehandlung während der `mandoc`-Ausführung habe ich im Makefile mit einem Comment erklärt --- Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 529abc0..713c8c4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ -src=hostmux.mandoc -tgt=man/hostmux.1 - -$(tgt): $(src) - mkdir -p $(shell dirname $@) +# This target creates the manpage from its source file +# +# (1) Create target's directory if it doesn't exist +# (2) create the target $@ from the first prerequisite $< +# The shell redirection creates the target file before `mandoc` is +# actually executed. To avoid working further with an empty target file +# it's removed in case of an error and make exits with an error code. +man/hostmux.1: hostmux.mandoc + mkdir -p $(dir $@) mandoc -I os=sh -Tman $< > $@ || { rm -f $@ ; exit 2 ; }