summaryrefslogtreecommitdiff
path: root/Makefile.am
blob: 2cea9a61d27c3cce6e64b052f7327cd12ce2cbf4 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
## Process this file with Automake to produce Makefile.in

bin_SCRIPTS = bin/stow bin/chkstow
info_TEXINFOS = doc/stow.texi
dist_man_MANS = doc/stow.8
PDF = doc/manual.pdf
HTML = doc/manual-single.html
dist_doc_DATA = \
	README \
	$(PDF) $(HTML) doc/version.texi \
	ChangeLog doc/ChangeLog.OLD

pmdir = $(PMDIR)
pm_DATA = lib/Stow.pm
pmstowdir = $(pmdir)/Stow
dist_pmstow_DATA = lib/Stow/Util.pm

TEXINFO_TEX = doc/texinfo.tex
export TEXI2DVI_BUILD_MODE = clean
AM_MAKEINFOFLAGS = -I $(srcdir)

# We require this -I parameter to ensure that the include of the
# default ignore list in the manual works.  Unfortunately this is
# the only way to do it:
#
#   http://article.gmane.org/gmane.comp.sysutils.automake.bugs/4334/match=passing+parameters
#
# even though it annoyingly produces a warning with the -Wall option
# to AM_INIT_AUTOMAKE which has to be silenced via -Wno-override.
TEXI2DVI = texi2dvi $(AM_MAKEINFOFLAGS)

doc_deps = $(info_TEXINFOS) doc/version.texi

DEFAULT_IGNORE_LIST = $(srcdir)/default-ignore-list

TESTS_DIR = $(srcdir)/t
TESTS_OUT = tmp-testing-trees
TESTS_ENVIRONMENT = $(PERL) -Ibin -Ilib -I$(TESTS_DIR)

# This is a kind of hack; TESTS needs to be set to ensure that the
# `check-am' target makes check-TESTS, but we override check-TESTS
# so it doesn't really matter what it's set to, as long as it already
# exists (otherwise automake will try to build it).
TESTS = t

# GNU autotools standardised on the 'check' target, but CPAN (and the
# rest of the world) standardised on the 'test' target.
test: check

# required in vpath mode to ensure $build/t/ exists
check_DATA = $(TESTS_OUT)

# Test::Harness produces cleaner output than automake's default test
# harness, albeit without the pretty colours provided by the
# `color-tests' AM_INIT_AUTOMAKE option.  This also dodges having to
# set TESTS to the full list of tests, which is good because automake
# doesn't support wildcards, and so it would be too easy to forget to
# add a new one to the list.
#
# Note that automake's `check' rule cannot be overridden
# for some weird reason:
#
#   http://thread.gmane.org/gmane.comp.sysutils.automake.general/13040/focus=13041
#
# so we override check-TESTS instead which is where the real work is
# done anyway.  Unfortunately this produces a warning with the -Wall
# option to AM_INIT_AUTOMAKE which has to be silenced via
# -Wno-override.
check-TESTS:
	dir=$(TESTS_DIR); \
	$(TESTS_ENVIRONMENT) -MTest::Harness -e 'runtests(@ARGV)' "$${dir#./}"/*.t

$(TESTS_OUT):
	mkdir -p $@

CPAN_FILES = MANIFEST MANIFEST.SKIP Build.PL META.yml META.json
EXTRA_DIST = \
	bin/stow.in bin/chkstow.in lib/Stow.pm.in \
	doc/manual-split \
	$(TESTS) t/testutil.pm \
	$(TEXINFO_TEX) \
	$(DEFAULT_IGNORE_LIST) \
	$(CPAN_FILES)
CLEANFILES = $(bin_SCRIPTS) $(pm_DATA)
MAINTAINERCLEANFILES = $(dist_man_MANS) $(HTML) $(PDF) ChangeLog

# clean up auto-generated files
clean-local:
	-rm -rf $(TESTS_OUT)
maintainer-clean-local:
	-rm -rf doc/manual-split

# this is more explicit and reliable than the config file trick
edit = sed -e 's|[@]PERL[@]|$(PERL)|g'       \
	   -e 's|[@]VERSION[@]|$(VERSION)|g' \
	   -e "s|[@]USE_LIB_PMDIR[@]|$$use_lib_pmdir|g"

pmdir_in_INC = \
	PERL5LIB= $(PERL) -V | \
	    awk '/@INC/ {p=1; next} p==1 {print $$1}' | \
	    grep -q "$(pmdir)"

calc_use_lib_pmdir = \
	if $(pmdir_in_INC); then \
	    use_lib_pmdir=""; \
	else \
	    use_lib_pmdir="use lib \"$(pmdir)\";"; \
	fi

check_pmdir = \
	echo; \
	echo "\# Perl modules will be installed to $(pmdir)"; \
	echo "\# "; \
	if $(pmdir_in_INC); then \
	    echo "\# This is in $(PERL)'s built-in @INC, so everything"; \
	    echo "\# should work fine with no extra effort."; \
	else \
	    echo "\# This is not in $(PERL)'s built-in @INC, so the"; \
	    echo "\# front-end scripts will have an appropriate \"use lib\""; \
	    echo "\# line inserted to compensate."; \
	fi; \
	echo

bin/stow: bin/stow.in Makefile
	[ -d bin ] || mkdir bin # required in vpath mode
	@$(check_pmdir)
	@$(calc_use_lib_pmdir); \
	$(edit) < $< > $@
	@echo "Generated $@ from $<"
	chmod +x $@

bin/chkstow: bin/chkstow.in Makefile
	@[ -d bin ] || mkdir bin # required in vpath mode
	@$(edit) < $< > $@
	@echo "Generated $@ from $<"
	chmod +x $@

lib/Stow.pm: lib/Stow.pm.in $(DEFAULT_IGNORE_LIST) Makefile
	@[ -d lib ] || mkdir lib # required in vpath mode
	@( $(edit) < $<; cat $(DEFAULT_IGNORE_LIST) ) > $@
	@echo "Generated $@ from $< and $(DEFAULT_IGNORE_LIST)"

##############################################################################
# The below rules should only be needed by developers.
##############################################################################

doc/stow.8: bin/stow.in Makefile.am
	[ -d doc ] || mkdir doc # required in vpath mode
	$(edit) < $< | pod2man > $@

# We use automake's built-in rule to generate stow.info.  The built-in
# rules would also generate doc/stow.html and doc/stow.pdf, but after
# installation we want $(docdir) (typically /usr/share/doc/stow/) to
# contain manual-single.html, manual.pdf, and manual-split/*.html, to
# make it explicitly obvious that these files contain the user manual
# rather than some other Stow-related documentation.
#
# If it were not for a troublesome dependency on doc/$(am__dirstamp):
#
#   http://article.gmane.org/gmane.comp.sysutils.automake.general/13192
#
# we could have achieved this using the built-in rules combined with
# install-data-hook to rename from stow.pdf to manual.pdf etc. on
# install.  Instead, by overriding the built-in rules with modified
# versions, we can kill both birds with one stone.

$(HTML): $(doc_deps)
	[ -d doc ] || mkdir doc # required in vpath mode
	-rm -f $@
	texi2html --P=$(srcdir) --output=$@ -expandinfo -menu -monolithic -verbose $<

$(PDF): $(doc_deps)
	TEXINPUTS="$(am__TEXINFO_TEX_DIR)$(PATH_SEPARATOR)$$TEXINPUTS" \
	MAKEINFO='$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I doc -I $(srcdir)/doc' \
	$(TEXI2PDF) -o $@ `test -f 'doc/stow.texi' || echo '$(srcdir)/'`doc/stow.texi

doc/manual-split: $(doc_deps)
	rm -rf $@.new
	if $(MAKEINFOHTML) $(AM_MAKEINFOHTMLFLAGS) $(MAKEINFOFLAGS) -I doc -I $(srcdir)/doc \
	 -o $@.new `test -f 'doc/stow.texi' || echo '$(srcdir)/'`doc/stow.texi; \
	then \
	  rm -rf $@; \
	  mv $@.new $@; \
	else \
	  rm -Rf $@.new $@; \
	  exit 1; \
	fi

# The split version of the manual is copied to $(docdir)/manual-split
# by install-data-hook.  The whole subdirectory is included via
# EXTRA_DIST in order to avoid having to list each file explicitly in
# dist_doc_DATA, since automake doesn't support wildcards, and
# dist_doc_DATA cannot refer to directories while EXTRA_DIST can (go
# figure ...)

install-data-hook: doc/manual-split
	cp -r $(srcdir)/doc/manual-split $(DESTDIR)$(docdir)

uninstall-hook:
	chmod u+w -R $(DESTDIR)$(docdir)/manual-split
	rm -rf $(DESTDIR)$(docdir)/manual-split

# Using install-data-hook has the slightly annoying disadvantage that
# by default the split version of the manual isn't automatically
# rebuilt during development by a simple `make'.  A workaround hack
# for this is to piggy-back the dependency onto manual-single.html,
# which *is* automatically rebuilt by `make':
$(HTML): doc/manual-split

# With the above hack, this probably isn't necessary but is safer to
# keep in anyway:
dist-hook: doc/manual-split

dist-hook: $(dist_man_MANS)
## If we are creating a distribution from a git checkout, ensure
## the ChangeLog file is in sync the git repository.
	if test -d $(top_srcdir)/.git; then \
	  rm -f ChangeLog \
	    && $(MAKE) $(AM_MAKEFLAGS) ChangeLog \
	    && cp -f ChangeLog $(distdir)/ChangeLog; \
	fi

ChangeLog: doc/ChangeLog.OLD
	@if [ -d .git ]; then \
	    ( \
	        git log \
		    --format="format:%ad  %aN <%aE>%n%n    * %w(70,0,4)%s%+b%n" \
		    --name-status \
		    v2.0.2..HEAD \
                | sed 's/^\([A-Z]\)\t/      \1 /'; \
	        cat $< \
	    ) > $@; \
	    echo "Rebuilt $@ from git commit history."; \
	else \
	    echo "Not in a git repository; can't update ChangeLog."; \
	fi