GNUmakefile: cfg.mk definitions override default autoreconf-rerun policy
[gnulib.git] / top / GNUmakefile
1 # Having a separate GNUmakefile lets me `include' the dynamically
2 # generated rules created via cfg.mk (package-local configuration)
3 # as well as maint.mk (generic maintainer rules).
4 # This makefile is used only if you run GNU Make.
5 # It is necessary if you want to build targets usually of interest
6 # only to the maintainer.
7
8 # Copyright (C) 2001, 2003, 2006-2008 Free Software Foundation, Inc.
9
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 # Systems where /bin/sh is not the default shell need this.  The $(shell)
24 # command below won't work with e.g. stock DOS/Windows shells.
25 ifeq ($(wildcard /bin/s[h]),/bin/sh)
26 SHELL = /bin/sh
27 else
28 # will be used only with the next shell-test line, then overwritten
29 # by a configured-in value
30 SHELL = sh
31 endif
32
33 # If the user runs GNU make but has not yet run ./configure,
34 # give them a diagnostic.
35 _have-Makefile := $(shell test -f Makefile && echo yes)
36 ifeq ($(_have-Makefile),yes)
37
38 # Make tar archive easier to reproduce.
39 export TAR_OPTIONS = --owner=0 --group=0 --numeric-owner
40
41 include Makefile
42
43 # Some projects override e.g., _autoreconf here.
44 -include $(srcdir)/cfg.mk
45 include $(srcdir)/maint.mk
46
47 # Allow cfg.mk to override these.
48 _build-aux ?= build-aux
49 _autoreconf ?= autoreconf
50
51 # Ensure that $(VERSION) is up to date for dist-related targets, but not
52 # for others: rerunning autoreconf and recompiling everything isn't cheap.
53 _have-git-version-gen := \
54   $(shell test -f $(srcdir)/$(_build-aux)/git-version-gen && echo yes)
55 ifeq ($(_have-git-version-gen)0,yes$(MAKELEVEL))
56   _is-dist-target ?= $(filter-out %clean, \
57     $(filter maintainer-% dist% alpha beta major,$(MAKECMDGOALS)))
58   _is-install-target ?= $(filter-out %check, $(filter install%,$(MAKECMDGOALS)))
59   ifneq (,$(_is-dist-target)$(_is-install-target))
60     _curr-ver := $(shell cd $(srcdir) \
61                    && $(_build-aux)/git-version-gen .tarball-version)
62     ifneq ($(_curr-ver),$(VERSION))
63       ifeq ($(_curr-ver),UNKNOWN)
64         $(info WARNING: unable to verify if $(VERSION) is correct version)
65       else
66         ifneq (,$(_is-install-target))
67           # GNU Coding Standards state that 'make install' should not cause
68           # recompilation after 'make all'.  But as long as changing the version
69           # string alters config.h, the cost of having 'make all' always have an
70           # up-to-date version is prohibitive.  So, as a compromise, we merely
71           # warn when installing a version string that is out of date; the user
72           # should run 'autoreconf' (or something like 'make distcheck') to
73           # fix the version, 'make all' to propagate it, then 'make install'.
74           $(info WARNING: version string $(VERSION) is out of date; run autoreconf -f to fix it)
75         else
76           $(info INFO: running autoreconf for new version string: $(_curr-ver))
77           _dummy := $(shell cd $(srcdir) && rm -rf autom4te.cache .version \
78             && $(_autoreconf))
79         endif
80       endif
81     endif
82   endif
83 endif
84
85 else
86
87 .DEFAULT_GOAL := abort-due-to-no-makefile
88 srcdir = .
89
90 # The package can override .DEFAULT_GOAL to run actions like autoreconf.
91 -include ./cfg.mk
92 include ./maint.mk
93
94 ifeq ($(.DEFAULT_GOAL),abort-due-to-no-makefile)
95 $(MAKECMDGOALS): abort-due-to-no-makefile
96 endif
97
98 abort-due-to-no-makefile:
99         @echo There seems to be no Makefile in this directory.   1>&2
100         @echo "You must run ./configure before running \`make'." 1>&2
101         @exit 1
102
103 endif
104
105 # Tell version 3.79 and up of GNU make to not build goals in this
106 # directory in parallel.  This is necessary in case someone tries to
107 # build multiple targets on one command line.
108 .NOTPARALLEL: