resetting manifest requested domain to floor
[platform/upstream/m4.git] / bootstrap
1 #! /bin/sh
2
3 # bootstrap (GNU M4) version 2010-03-02
4 # Written by Gary V. Vaughan  <gary@gnu.org>
5
6 # Copyright (C) 2004-2011 Free Software Foundation, Inc.
7
8 # This file is part of GNU M4.
9 #
10 # GNU M4 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 # GNU M4 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 # Usage: $progname [options]
24
25 # -f      --force            bootstrap even when sources are not from git
26 #         --gnulib-srcdir=DIRNAME
27 #                            Specify the local directory where gnulib
28 #                            sources reside.  Use this if you already
29 #                            have gnulib sources on your machine, and
30 #                            do not want to waste your bandwidth downloading
31 #                            them again.  Defaults to $GNULIB_SRCDIR.
32 # -v      --version          print version information
33 # -h,-?   --help             print short or long help message
34
35 # You can also set the following variables to help $progname
36 # locate the right tools:
37 #   AUTORECONF, CONFIG_SHELL, GNULIB_SRCDIR, M4, RM, SED
38
39 # This script bootstraps a git checkout of GNU M4 by correctly calling
40 # out to parts of the GNU Build Platform.  See HACKING for a list of
41 # prerequisite tools and versions required.  If you are re-running
42 # bootstrap on a release tarball rather than using a git checkout,
43 # then see the release announcement for the prerequisite tools used.
44
45 # Report bugs to <bug-m4@gnu.org>
46
47 : ${AUTORECONF=autoreconf}
48 : ${CONFIG_SHELL=/bin/sh}
49 : ${RM='rm -f'}
50 : ${SED=sed}
51
52 # Ensure file names are sorted consistently across platforms.
53 LC_ALL=C
54 export LC_ALL
55
56 config_macro_dir=m4
57
58 dirname="s,/[^/]*$,,"
59 basename="s,^.*/,,g"
60
61 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
62 # is ksh but when the shell is invoked as "sh" and the current value of
63 # the _XPG environment variable is not equal to 1 (one), the special
64 # positional parameter $0, within a function call, is the name of the
65 # function.
66 progpath="$0"
67
68 # The name of this program:
69 progname=`echo "$progpath" | $SED "$basename"`
70 PROGRAM=bootstrap
71
72 # Detect whether this is a version control system checkout or a tarball
73 vcs_only_file=HACKING
74
75 # func_echo arg...
76 # Echo program name prefixed message.
77 func_echo ()
78 {
79     echo $progname: ${1+"$@"}
80 }
81
82
83 # func_error arg...
84 # Echo program name prefixed message to standard error.
85 func_error ()
86 {
87     echo $progname: ${1+"$@"} >&2
88 }
89
90 # func_fatal_error arg...
91 # Echo program name prefixed message to standard error, and exit.
92 func_fatal_error ()
93 {
94     func_error ${1+"$@"}
95     exit $EXIT_FAILURE
96 }
97
98 # func_verbose arg...
99 # Echo program name prefixed message in verbose mode only.
100 func_verbose ()
101 {
102     $opt_verbose && func_error ${1+"$@"}
103 }
104
105 # func_missing_arg argname
106 # Echo program name prefixed message to standard error and set global
107 # exit_cmd.
108 func_missing_arg ()
109 {
110    func_error "missing argument for $1"
111    exit_cmd=exit
112 }
113
114 # func_fatal_help arg...
115 # Echo program name prefixed message to standard error, followed by
116 # a help hint, and exit.
117 func_fatal_help ()
118 {
119     func_error ${1+"$@"}
120     func_fatal_error "Try \`$progname --help' for more information."
121 }
122
123 # func_missing_arg argname
124 # Echo program name prefixed message to standard error and set global
125 # exit_cmd.
126 func_missing_arg ()
127 {
128    func_error "missing argument for $1"
129    exit_cmd=exit
130 }
131
132 # func_usage
133 # Echo short help message to standard output and exit.
134 func_usage ()
135 {
136     $SED '/^# Usage:/,/# -h/ {
137         s/^# //; s/^# *$//;
138         s/\$progname/'$progname'/;
139         p;
140     }; d' < "$progpath"
141     echo
142     echo "run \`$progname --help | more' for full usage"
143     exit $EXIT_SUCCESS
144 }
145
146 # func_help
147 # Echo long help message to standard output and exit.
148 func_help ()
149 {
150     $SED '/^# Usage:/,/# Report bugs to/ {
151         s/^# //; s/^# *$//;
152         s/\$progname/'$progname'/;
153         p;
154      }; d' < "$progpath"
155     exit $EXIT_SUCCESS
156 }
157
158 # func_version
159 # Echo version message to standard output and exit.
160 func_version ()
161 {
162     $SED '/^# '$PROGRAM' (GNU /,/# warranty; / {
163         s/^# //; s/^# *$//;
164         s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
165         p;
166      }; d' < "$progpath"
167      exit $EXIT_SUCCESS
168 }
169
170 # func_update
171 # Copy $1 to $2 if it is newer.
172 func_update ()
173 {
174   if test -f "$2" && cmp -s "$1" "$2" ; then
175     func_verbose "$2 is up-to-date"
176   else
177     func_echo "copying $1 -> $2"
178     cp "$1" "$2"
179   fi
180 }
181
182 # Parse options once, thoroughly.  This comes as soon as possible in
183 # the script to make things like `bootstrap --version' happen quickly.
184 {
185   # sed scripts:
186   my_sed_single_opt='1s/^\(..\).*$/\1/;q'
187   my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
188   my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
189   my_sed_long_arg='1s/^--[^=]*=//'
190
191   # this just eases exit handling
192   while test $# -gt 0; do
193     opt="$1"
194     shift
195     case $opt in
196       # Separate optargs to short options:
197       -f|--force)       vcs_only_file=                                  ;;
198       --gnulib-srcdir=*)
199         GNULIB_SRCDIR=`expr "X$opt" : 'X--gnulib-srcdir=\(.*\)'`        ;;
200       -\?|-h)           func_usage                                      ;;
201       --help)           func_help                                       ;;
202       --version)        func_version                                    ;;
203       --)               break                                           ;;
204       -*)               func_fatal_help "unrecognized option \`$opt'"   ;;
205       *)                set -- "$opt" ${1+"$@"};        break           ;;
206     esac
207   done
208
209   # Bail if the options were screwed
210   $exit_cmd $EXIT_FAILURE
211
212   if test -n "$vcs_only_file" && test ! -r "$vcs_only_file"; then
213     func_fatal_error \
214       "Bootstrapping from a non-version-control distribution is risky."
215   fi
216 }
217
218 ## ---------------- ##
219 ## Version control. ##
220 ## ---------------- ##
221
222 # gnulib-tool updates m4/.{git,cvs}ignore and lib/.{git,cvs}ignore, and
223 # keeping generated files under version control does not make sense.
224 # Since lib is entirely ignored, we only need to prepopulate the m4 ignore
225 # files with generated files not tracked by gnulib-tool.
226 if test -f $config_macro_dir/.gitignore ; then
227   :
228 else
229   func_echo "creating initial $config_macro_dir/.cvsignore"
230   cat > $config_macro_dir/.cvsignore <<\EOF
231 # files created by gnulib, but that gnulib doesn't track
232 *~
233 .cvsignore
234 .gitignore
235 gnulib-comp.m4
236 # gnulib-tool edits below here
237 EOF
238   func_echo "creating initial $config_macro_dir/.gitignore"
239   cp $config_macro_dir/.cvsignore $config_macro_dir/.gitignore
240 fi
241
242 # See if we can use gnulib's git-merge-changelog merge driver.
243 if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
244   if git config merge.merge-changelog.driver >/dev/null ; then
245     :
246   elif (git-merge-changelog --version) >/dev/null 2>/dev/null ; then
247     func_echo "initializing git-merge-changelog driver"
248     git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
249     git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
250   else
251     func_echo "consider installing git-merge-changelog from gnulib"
252   fi
253   if git config diff.texinfo.funcname >/dev/null ; then
254     :
255   else
256     func_echo "initializing git texinfo diff driver"
257     git config diff.texinfo.funcname '^@node[ \t][ \t]*\\([^,][^,]*\\)'
258   fi
259 fi
260
261 ## ------------------------------ ##
262 ## Update the gnulib module tree. ##
263 ## ------------------------------ ##
264
265 if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
266   if test -f gnulib/gnulib-tool ; then
267     func_echo "updating gnulib submodule"
268     git submodule update \
269       || func_fatal_error "Unable to update gnulib"
270   else
271     # A fresh checkout creates an empty subdirectory gnulib.  However,
272     # older git didn't know how to clone into an empty subdir.  If the
273     # user provided GNULIB_SRCDIR, then make the initial clone refer
274     # to the existing checkout, to save network traffic.
275     func_echo "importing gnulib submodule"
276     if test -d "$GNULIB_SRCDIR" ; then
277       rmdir gnulib 2>/dev/null
278       git clone --reference "$GNULIB_SRCDIR" git://git.sv.gnu.org/gnulib.git \
279         && git submodule init && git submodule update \
280         || func_fatal_error "Unable to update gnulib"
281     else
282       git submodule update --init \
283         || func_fatal_error "Unable to update gnulib"
284     fi
285   fi
286 else
287   func_echo "git not detected.  If needed, update gnulib subdirectory manually"
288 fi
289
290 ## ---------------------- ##
291 ## Import Gnulib modules. ##
292 ## ---------------------- ##
293
294 func_echo "running: $CONFIG_SHELL gnulib/gnulib-tool --update"
295 $CONFIG_SHELL gnulib/gnulib-tool --update \
296   || func_fatal_error "gnulib-tool failed"
297
298 ## ----------- ##
299 ## Autoreconf. ##
300 ## ----------- ##
301
302 func_echo "running: $AUTORECONF --verbose --install"
303 $AUTORECONF --verbose --install || func_fatal_error "autoreconf failed"
304
305 exit 0
306
307 # Local variables:
308 # eval: (add-hook 'write-file-hooks 'time-stamp)
309 # time-stamp-start: "# bootstrap (GNU M4) version "
310 # time-stamp-format: "%:y-%02m-%02d"
311 # time-stamp-end: "$"
312 # End: