summaryrefslogtreecommitdiff
path: root/man/local.mk
blob: f4b213f7e825322c2a3105928a64b62a968d5434 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Make coreutils man pages.				-*-Makefile-*-
# This is included by the top-level Makefile.am.

# Copyright (C) 2002-2014 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

EXTRA_DIST += man/help2man man/dummy-man

## Graceful degradation for systems lacking perl.
if HAVE_PERL
run_help2man = $(PERL) -- $(srcdir)/man/help2man
else
run_help2man = $(SHELL) $(srcdir)/man/dummy-man
endif

man1_MANS = @man1_MANS@
EXTRA_DIST += $(man1_MANS:.1=.x)

EXTRA_MANS = @EXTRA_MANS@
EXTRA_DIST += $(EXTRA_MANS:.1=.x)

ALL_MANS = $(man1_MANS) $(EXTRA_MANS)

CLEANFILES += $(ALL_MANS)

# This is a kludge to remove generated 'man/*.1' from a non-srcdir build.
# Without this, "make distcheck" might fail.
distclean-local:
	test x$(srcdir) = x$(builddir) || rm -f $(ALL_MANS)

# Dependencies common to all man pages.  Updated below.
mandeps =

# Depend on this to get version number changes.
mandeps += .version

# This is required so that changes to e.g., emit_bug_reporting_address
# provoke regeneration of all the manpages.
mandeps += $(top_srcdir)/src/system.h

$(ALL_MANS): $(mandeps)

# Most prog.1 man pages depend on src/$prog, except when they are part of a
# single binary, in which case they depend on src/coreutils. The exceptions
# are handled by converting $name to $prog on the following code.
# $(ALL_MANS) includes the $(EXTRA_MANS) so even the programs that are not
# being installed will have the right dependency for the manpages.
DISTCLEANFILES += man/dynamic-deps.mk
man/dynamic-deps.mk: Makefile
	$(AM_V_GEN)rm -f $@ $@-t
	$(AM_V_at)for man in $(ALL_MANS); do				\
		name=`echo "$$man"|sed 's|.*/||; s|\.1$$||'` || exit 1;	\
		case $$name in						\
		     arch) prog='uname';;				\
		  install) prog='ginstall';;				\
		     test) prog='[';;					\
			*) prog=$$name;;				\
		esac;							\
		case " $(single_binary_progs) " in			\
			*" $$prog "*)					\
				echo $$man: src/coreutils$(EXEEXT);;	\
			*)						\
				echo $$man: src/$$prog$(EXEEXT);;	\
		esac							\
	done > $@-t							\
	&& mv $@-t $@

# Include the generated man dependencies.
@AMDEP_TRUE@@am__include@ man/dynamic-deps.mk

.x.1:
	$(AM_V_GEN)name=`echo $@ | sed 's|.*/||; s|\.1$$||'` || exit 1;	\
## Ensure that help2man runs the 'src/ginstall' binary as 'install' when
## creating 'install.1'.  Similarly, ensure that it uses the 'src/[' binary
## to create 'test.1'.
	case $$name in							\
	  install) prog='ginstall'; argv=$$name;;			\
	     test) prog='['; argv='[';;					\
		*) prog=$$name; argv=$$prog;;				\
	esac;								\
## Note the use of $$t/$*, rather than just '$*' as in other packages.
## That is necessary to avoid failures for programs that are also shell
## built-in functions like echo, false, printf, pwd.
	rm -f $@ $@-t							\
	  && t=$*.td							\
	  && rm -rf $$t							\
	  && $(MKDIR_P) $$t						\
	  && (cd $$t && $(LN_S) '$(abs_top_builddir)/src/'$$prog $$argv) \
	  && $(run_help2man)						\
		     --source='$(PACKAGE_STRING)'			\
		     --include=$(srcdir)/man/$$name.x			\
		     --output=$$t/$$name.1 $$t/$$argv			\
		     --info-page='coreutils \(aq'$$name' invocation\(aq' \
	  && sed \
	       -e 's|$*\.td/||g' \
	       -e '/For complete documentation/d' \
	       $$t/$$name.1 > $@-t			\
	  && rm -rf $$t							\
	  && chmod a-w $@-t						\
	  && mv $@-t $@