maint: move maintainer make rules in maint.mk
[platform/upstream/automake.git] / maint.mk
1 # Maintainer makefile rules for Automake.
2 #
3 # Copyright (C) 1995-2012 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 # --------------------------------------------------------- #
19 #  Automatic generation of the ChangeLog from git history.  #
20 # --------------------------------------------------------- #
21
22 gitlog_to_changelog_command = $(PERL) $(srcdir)/lib/gitlog-to-changelog
23 gitlog_to_changelog_fixes = $(srcdir)/.git-log-fix
24 gitlog_to_changelog_options = --amend=$(gitlog_to_changelog_fixes) \
25                               --since='2011-12-28 00:00:00' \
26                               --no-cluster --format '%s%n%n%b'
27
28 EXTRA_DIST += lib/gitlog-to-changelog
29 EXTRA_DIST += $(gitlog_to_changelog_fixes)
30
31 # When executed from a git checkout, generate the ChangeLog from the git
32 # history.  When executed from an extracted distribution tarball, just
33 # copy the distributed ChangeLog in the build directory (and if this
34 # fails, or if no distributed ChangeLog file is present, complain and
35 # give an error).
36 #
37 # We need the apparently useless dependency from another .PHONY target
38 # 'am--changelog-regen-hook' to work around a bug of Solaris make, which
39 # doesn't execute the recipe of a target named as an existing file, even
40 # if such target is declared '.PHONY' (yikes!)
41 #
42 # The ChangeLog should be regenerated unconditionally when working from
43 # checked-out sources; otherwise, if we're working from a distribution
44 # tarball, we expect the ChangeLog to be distributed, so check that it
45 # is indeed present in the source directory.
46 .PHONY: am--changelog-regen-hook
47 am--changelog-regen-hook:
48 ChangeLog: am--changelog-regen-hook
49         $(AM_V_GEN)set -e; set -u; \
50         if test -d $(srcdir)/.git; then \
51           rm -f $@-t \
52             && $(gitlog_to_changelog_command) \
53                $(gitlog_to_changelog_options) >$@-t \
54             && chmod a-w $@-t \
55             && mv -f $@-t $@ \
56             || exit 1; \
57         elif test ! -f $(srcdir)/$@; then \
58           echo "Source tree is not a git checkout, and no pre-existent" \
59                "$@ file has been found there" >&2; \
60           exit 1; \
61         fi
62
63
64 # --------------------------- #
65 #  Perl coverage statistics.  #
66 # --------------------------- #
67
68 PERL_COVERAGE_DB = $(abs_top_builddir)/cover_db
69 PERL_COVERAGE_FLAGS = -MDevel::Cover=-db,$(PERL_COVERAGE_DB),-silent,on,-summary,off
70 PERL_COVER = cover
71
72 check-coverage-run recheck-coverage-run: all
73         $(mkinstalldirs) $(PERL_COVERAGE_DB)
74         PERL5OPT="$$PERL5OPT $(PERL_COVERAGE_FLAGS)"; export PERL5OPT; \
75         WANT_NO_THREADS=yes; export WANT_NO_THREADS; unset AUTOMAKE_JOBS; \
76         $(MAKE) $(AM_MAKEFLAGS) `echo $@ | sed 's/-coverage-run//'`
77
78 check-coverage-report:
79         @if test ! -d "$(PERL_COVERAGE_DB)"; then \
80           echo "No coverage database found in '$(PERL_COVERAGE_DB)'." >&2; \
81           echo "Please run \"make check-coverage\" first" >&2; \
82           exit 1; \
83         fi
84         $(PERL_COVER) $(PERL_COVER_FLAGS) "$(PERL_COVERAGE_DB)"
85
86 # We don't use direct dependencies here because we'd like to be able
87 # to invoke the report even after interrupted check-coverage.
88 check-coverage: check-coverage-run
89         $(MAKE) $(AM_MAKEFLAGS) check-coverage-report
90
91 recheck-coverage: recheck-coverage-run
92         $(MAKE) $(AM_MAKEFLAGS) check-coverage-report
93
94 clean-coverage:
95         rm -rf "$(PERL_COVERAGE_DB)"
96 clean-local: clean-coverage
97
98 .PHONY: check-coverage recheck-coverage check-coverage-run \
99         recheck-coverage-run check-coverage-report clean-coverage
100
101
102 # ---------------------------------------------------- #
103 #  Tagging and/or uploading stable and beta releases.  #
104 # ---------------------------------------------------- #
105
106 GIT = git
107
108 EXTRA_DIST += lib/gnupload
109
110 base_version_rx = ^[1-9][0-9]*\.[0-9][0-9]*
111 stable_major_version_rx = $(base_version_rx)$$
112 stable_minor_version_rx = $(base_version_rx)\.[0-9][0-9]*$$
113 beta_version_rx = $(base_version_rx)(\.[0-9][0-9]*)?[bdfhjlnprtvxz]$$
114 match_version = echo "$(VERSION)" | $(EGREP) >/dev/null
115
116 # Check that we don't have uncommitted or unstaged changes.
117 # TODO: Maybe the git suite already offers a shortcut to verify if the
118 # TODO: working directory is "clean" or not?  If yes, use that instead
119 # TODO: of duplicating the logic here.
120 git_must_have_clean_workdir = \
121   $(GIT) rev-parse --verify HEAD >/dev/null \
122     && $(GIT) update-index -q --refresh \
123     && $(GIT) diff-files --quiet \
124     && $(GIT) diff-index --quiet --cached HEAD \
125     || fatal "you have uncommitted or unstaged changes"
126
127 determine_release_type = \
128   if $(match_version) '$(stable_major_version_rx)'; then \
129     release_type='Major release'; \
130     announcement_type='major release'; \
131     dest=ftp; \
132   elif $(match_version) '$(stable_minor_version_rx)'; then \
133     release_type='Minor release'; \
134     announcement_type='maintenance release'; \
135     dest=ftp; \
136   elif $(match_version) '$(beta_version_rx)'; then \
137     release_type='Beta release'; \
138     announcement_type='test release'; \
139     dest=alpha; \
140   else \
141     fatal "invalid version '$(VERSION)' for a release"; \
142   fi
143
144 # Help the debugging of $(determine_release_type) and related code.
145 print-release-type:
146         @set -e -u \
147           && fatal () { echo "$@: $$*"; exit 0; } \
148           && $(determine_release_type) \
149           && echo "$$release_type $(VERSION);" \
150                   "it will be announced as a $$announcement_type"
151
152 git-tag-release: maintainer-check
153         @set -e; set -u; \
154         fatal () { echo "$@: $$*; not tagging" >&2; exit 1; }; \
155         case '$(AM_TAG_DRYRUN)' in \
156           ""|[nN]|[nN]o|NO) run="";; \
157           *) run="echo Running:";; \
158         esac; \
159         $(determine_release_type); \
160         $(git_must_have_clean_workdir); \
161 ## If all was successful, tag the release in the local repository.
162         $$run $(GIT) tag -s "v$(VERSION)" -m "$$release_type $(VERSION)"
163
164 git-upload-release:
165         @set -e; set -u; \
166         fatal () { echo "$@: $$*; not releasing" >&2; exit 1; }; \
167         $(determine_release_type); \
168         dest=$$dest.gnu.org:automake; \
169         $(git_must_have_clean_workdir); \
170 ## Check that we are releasing from a valid tag.
171         tag=`$(GIT) describe` \
172           && case $$tag in "v$(VERSION)") true;; *) false;; esac \
173           || fatal "you can only create a release from a tagged version"; \
174 ## Build and upload the distribution tarball(s).
175         $(MAKE) $(AM_MAKEFLAGS) dist || exit 1; \
176         echo Will upload to $$dest: $(DIST_ARCHIVES); \
177         $(srcdir)/lib/gnupload $(GNUPLOADFLAGS) --to $$dest $(DIST_ARCHIVES)
178
179 .PHONY: print-release-type git-upload-release git-tag-release
180
181
182 # ------------------------------------------------------------------ #
183 #  Explore differences of autogenerated files in different commits.  #
184 # ------------------------------------------------------------------ #
185
186 # Visually comparing differences between the Makefile.in files in
187 # automake's own build system as generated in two different branches
188 # might help to catch bugs and blunders.  This has already happened a
189 # few times in the past, when we used to version-control Makefile.in.
190 autodiffs:
191         @set -u; \
192          NEW_COMMIT=$${NEW_COMMIT-"HEAD"}; \
193          OLD_COMMIT=$${OLD_COMMIT-"HEAD~1"}; \
194          am_gitdir='$(abs_top_srcdir)/.git'; \
195          get_autofiles_from_rev () \
196          { \
197              rev=$$1 dir=$$2 \
198                && echo "$@: will get files from revision $$rev" \
199                && $(GIT) clone -q --depth 1 "$$am_gitdir" tmp \
200                && $(am__cd) tmp \
201                && $(GIT) checkout -q "$$rev" \
202                && echo "$@: bootstrapping $$rev" \
203                && $(SHELL) ./bootstrap.sh \
204                && echo "$@: copying files from $$rev" \
205                && makefile_ins=`find . -name Makefile.in` \
206                && (tar cf - configure aclocal.m4 $$makefile_ins) | \
207                   (cd .. && $(am__cd) "$$dir" && tar xf -) \
208                && cd .. \
209                && rm -rf tmp; \
210          }; \
211          outdir=$@.dir \
212            && : Before proceeding, ensure the specified revisions truly exist. \
213            && $(GIT) --git-dir="$$am_gitdir" describe $$OLD_COMMIT >/dev/null \
214            && $(GIT) --git-dir="$$am_gitdir" describe $$NEW_COMMIT >/dev/null \
215            && rm -rf $$outdir \
216            && mkdir $$outdir \
217            && $(am__cd) $$outdir \
218            && mkdir new old \
219            && get_autofiles_from_rev $$OLD_COMMIT old \
220            && get_autofiles_from_rev $$NEW_COMMIT new \
221            && exit 0
222
223 # With lots of eye candy; we like our developers pampered and spoiled :-)
224 compare-autodiffs: autodiffs
225         @set -u; \
226         : $${COLORDIFF=colordiff} $${DIFF=diff}; \
227         dir=autodiffs.dir; \
228         if test ! -d "$$dir"; then \
229           echo "$@: $$dir: Not a directory" >&2; \
230           exit 1; \
231         fi; \
232         mydiff=false mypager=false; \
233         if test -t 1; then \
234           if ($$COLORDIFF -r . .) </dev/null >/dev/null 2>&1; then \
235             mydiff=$$COLORDIFF; \
236             mypager="less -R"; \
237           else \
238             mypager=less; \
239           fi; \
240         else \
241           mypager=cat; \
242         fi; \
243         if test "$$mydiff" = false; then \
244           if ($$DIFF -r -u . .); then \
245             mydiff=$$DIFF; \
246           else \
247             echo "$@: no good-enough diff program specified" >&2; \
248             exit 1; \
249           fi; \
250         fi; \
251         st=0; $$mydiff -r -u $$dir/old $$dir/new | $$mypager || st=$$?; \
252         rm -rf $$dir; \
253         exit $$st
254 .PHONY: autodiffs compare-autodiffs
255
256 # ---------------------------------------------- #
257 #  Help writing the announcement for a release.  #
258 # ---------------------------------------------- #
259
260 PACKAGE_MAILINGLIST = automake@gnu.org
261
262 announcement: NEWS
263         $(AM_V_GEN): \
264           && rm -f $@ $@-t \
265           && fatal () { echo "$@: $$*" >&2; exit 1; } \
266           && $(determine_release_type) \
267           && ftp_base="ftp://$$dest.gnu.org/gnu/$(PACKAGE)" \
268           && X () { printf '%s\n' "$$*" >> $@-t; } \
269           && X "We are pleased to announce the $(PACKAGE_NAME) $(VERSION)" \
270                "$$announcement_type." \
271           && X \
272           && X "**TODO** Brief description of the release here." \
273           && X \
274           && X "**TODO** This description can span multiple paragraphs." \
275           && X \
276           && X "See below for the detailed list of changes since the" \
277           && X "previous version, as summarized by the NEWS file." \
278           && X \
279           && X "Download here:" \
280           && X \
281           && X "  $$ftp_base/$(PACKAGE)-$(VERSION).tar.gz" \
282           && X "  $$ftp_base/$(PACKAGE)-$(VERSION).tar.xz" \
283           && X \
284           && X "Please report bugs and problems to" \
285                "<$(PACKAGE_BUGREPORT)>," \
286           && X "and send general comments and feedback to" \
287                "<$(PACKAGE_MAILINGLIST)>." \
288           && X \
289           && X "Thanks to everyone who has reported problems, contributed" \
290           && X "patches, and helped testing Automake!" \
291           && X \
292           && X "-*-*-*-" \
293           && X \
294           && sed -n -e '/^~~~/q' -e p $(srcdir)/NEWS >> $@-t \
295           && mv -f $@-t $@
296 .PHONY: announcement
297 CLEANFILES += announcement
298
299 # --------------------------------------------------------------------- #
300 #  Synchronize third-party files that are committed in our repository.  #
301 # --------------------------------------------------------------------- #
302
303 # Program to use to fetch files.
304 WGET = wget
305
306 # Some repositories we sync files from.
307 SV_CVS    = 'http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/'
308 SV_GIT_CF = 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;hb=HEAD;f='
309 SV_GIT_AC = 'http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob_plain;hb=HEAD;f='
310 SV_GIT_GL = 'http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;hb=HEAD;f='
311
312 # Files that we fetch and which we compare against.
313 # Note that the 'lib/COPYING' file must still be synced by hand.
314 FETCHFILES = \
315   $(SV_GIT_CF)config.guess \
316   $(SV_GIT_CF)config.sub \
317   $(SV_CVS)texinfo/texinfo/doc/texinfo.tex \
318   $(SV_CVS)texinfo/texinfo/util/gendocs.sh \
319   $(SV_CVS)texinfo/texinfo/util/gendocs_template \
320   $(SV_GIT_GL)build-aux/gitlog-to-changelog \
321   $(SV_GIT_GL)build-aux/gnupload \
322   $(SV_GIT_GL)build-aux/update-copyright \
323   $(SV_GIT_GL)doc/INSTALL
324
325 # Fetch the latest versions of few scripts and files we care about.
326 # A retrieval failure or a copying failure usually mean serious problems,
327 # so we'll just bail out if 'wget' or 'cp' fail.
328 fetch:
329         $(AM_V_at)rm -rf Fetchdir
330         $(AM_V_at)mkdir Fetchdir
331         $(AM_V_GEN)set -e; \
332         if $(AM_V_P); then wget_opts=; else wget_opts=-nv; fi; \
333         for url in $(FETCHFILES); do \
334            file=`printf '%s\n' "$$url" | sed 's|^.*/||; s|^.*=||'`; \
335            $(WGET) $$wget_opts "$$url" -O Fetchdir/$$file || exit 1; \
336            if cmp Fetchdir/$$file $(srcdir)/lib/$$file >/dev/null; then \
337              : Nothing to do; \
338            else \
339              echo "$@: updating file $$file"; \
340              cp Fetchdir/$$file $(srcdir)/lib/$$file || exit 1; \
341            fi; \
342         done
343         $(AM_V_at)rm -rf Fetchdir
344 .PHONY: fetch
345
346 # ---------------------------------------------------------------------- #
347 #  Generate and upload manuals in several formats, for the GNU website.  #
348 # ---------------------------------------------------------------------- #
349
350 web_manual_dir = doc/web-manual
351
352 RSYNC = rsync
353 CVS = cvs
354 CVSU = cvsu
355 CVS_USER = $${USER}
356 WEBCVS_ROOT = cvs.savannah.gnu.org:/web
357
358 .PHONY: web-manual web-manual-update
359 web-manual web-manual-update: t = $@.dir
360
361 # Build manual in several formats.  Note to the recipe:
362 # 1. The symlinking of automake.texi into the temporary directory is
363 #    required to pacify extra checks from gendocs.sh.
364 # 2. The redirection to /dev/null before the invocation of gendocs.sh
365 #    is done to better respect silent rules.
366 web-manual:
367         $(AM_V_at)rm -rf $(web_manual_dir) $t
368         $(AM_V_at)mkdir $t
369         $(AM_V_at)$(LN_S) '$(abs_srcdir)/doc/$(PACKAGE).texi' '$t/'
370         $(AM_V_GEN)$(am__cd) $t \
371           && GENDOCS_TEMPLATE_DIR='$(abs_srcdir)/lib' \
372           && export GENDOCS_TEMPLATE_DIR \
373           && if $(AM_V_P); then :; else exec >/dev/null 2>&1; fi \
374           && $(SHELL) '$(abs_srcdir)/lib/gendocs.sh' \
375              -I '$(abs_srcdir)/doc' --email $(PACKAGE_BUGREPORT) \
376              $(PACKAGE) '$(PACKAGE_NAME)'
377         $(AM_V_at)mkdir $(web_manual_dir)
378         $(AM_V_at)mv -f $t/manual/* $(web_manual_dir)
379         $(AM_V_at)rm -rf $t
380         @! $(AM_V_P) || ls -l $(web_manual_dir)
381
382 # Upload manual to www.gnu.org, using CVS (sigh!)
383 web-manual-update:
384         $(AM_V_at)fatal () { echo "$@: $$*" >&2; exit 1; }; \
385         $(determine_release_type); \
386         case $$release_type in \
387           [Mm]ajor\ release|[Mm]inor\ release);; \
388           *) echo "Cannot upload manuals from a \"$$release_type\"" >&2; \
389              exit 1;; \
390         esac
391         $(AM_V_at)test -f $(web_manual_dir)/$(PACKAGE).html || { \
392           echo 'You have to run "$(MAKE) web-manuals" before' \
393                'invoking "$(MAKE) $@"' >&2; \
394           exit 1; \
395         }
396         $(AM_V_at)rm -rf $t
397         $(AM_V_at)mkdir $t
398         $(AM_V_at)CVS_RSH=ssh && export CVS_RSH=ssh \
399           && $(am__cd) $t \
400           && $(CVS) -z3 -d :ext:$(CVS_USER)@$(WEBCVS_ROOT)/$(PACKAGE) \
401                     co $(PACKAGE)
402         @# According to the rsync manpage, "a trailing slash on the
403         @# source [...] avoids creating an additional directory
404         @# level at the destination".  So the trailing '/' after
405         @# '$(web_manual_dir)' below is intended.
406         $(AM_V_at)$(RSYNC) -avP $(web_manual_dir)/ $t/$(PACKAGE)/manual
407         $(AM_V_GEN)CVS_RSH=ssh && export CVS_RSH=ssh \
408           && cd $t/$(PACKAGE)/manual \
409           && new_files=`$(CVSU) --types='?'` \
410           && new_files=`echo "$$new_files" | sed s/^..//` \
411           && { test -z "$$new_files" || $(CVS) add -ko $$new_files; } \
412           && $(CVS) ci -m $(VERSION)
413         $(AM_V_at)rm -rf $t
414 .PHONY: web-manual-update
415
416 clean-web-manual:
417         $(AM_V_at)rm -rf $(web_manual_dir)
418 .PHONY: clean-web-manual
419 clean-local: clean-web-manual
420
421 EXTRA_DIST += lib/gendocs.sh lib/gendocs_template
422
423 # ------------------------------------------------ #
424 #  Update copyright years of all committed files.  #
425 # ------------------------------------------------ #
426
427 EXTRA_DIST += lib/update-copyright
428
429 update_copyright_env = \
430   UPDATE_COPYRIGHT_FORCE=1 \
431   UPDATE_COPYRIGHT_USE_INTERVALS=2
432
433 # In addition to the several README files, these as well are
434 # not expected to have a copyright notice.
435 files_without_copyright = \
436   .autom4te.cfg \
437   .git-log-fix \
438   .gitattributes \
439   .gitignore \
440   INSTALL \
441   COPYING \
442   AUTHORS \
443   THANKS \
444   lib/INSTALL \
445   lib/COPYING
446
447 # This script is in the public domain.
448 files_without_copyright += lib/mkinstalldirs
449
450 # This script has an MIT-style license
451 files_without_copyright += lib/install-sh
452
453 .PHONY: update-copyright
454 update-copyright:
455         $(AM_V_GEN)set -e; \
456         current_year=`date +%Y` && test -n "$$current_year" \
457           || { echo "$@: cannot get current year" >&2; exit 1; }; \
458         sed -i "/^RELEASE_YEAR=/s/=.*$$/=$$current_year/" \
459           bootstrap.sh configure.ac; \
460         excluded_re=`( \
461           for url in $(FETCHFILES); do echo "$$url"; done \
462             | sed -e 's!^.*/!!' -e 's!^.*=!!' -e 's!^!lib/!' \
463           && for f in $(files_without_copyright); do echo $$f; done \
464         ) | sed -e '$$!s,$$,|,' | tr -d '\012\015'`; \
465         $(GIT) ls-files \
466           | grep -Ev '(^|/)README$$' \
467           | grep -Ev "^($$excluded_re)$$" \
468           | $(update_copyright_env) xargs $(srcdir)/lib/$@