2 # Convenience script for regenerating all autogeneratable files that are
3 # omitted from the version control repository. In particular, this script
4 # also regenerates all aclocal.m4, config.h.in, Makefile.in, configure files
5 # with new versions of autoconf or automake.
7 # Copyright (C) 2003-2022 Free Software Foundation, Inc.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
22 # Originally written by Paul Eggert. The canonical version of this
23 # script is maintained as top/autogen.sh in gnulib. However, to be
24 # useful to your package, you should place a copy of it under version
25 # control in the top-level directory of your package. The intent is
26 # that all customization can be done with a bootstrap.conf file also
27 # maintained in your version control; gnulib comes with a template
28 # build-aux/bootstrap.conf to get you started.
30 # Alternatively, you can use an autogen.sh script that is specific
33 scriptversion
=2022-07-24.15
; # UTC
38 # Read the function library and the configuration.
39 .
"$medir"/bootstrap-funclib.sh
41 # Ensure that CDPATH is not set. Otherwise, the output from cd
42 # would cause trouble in at least one use below.
43 (unset CDPATH
) >/dev
/null
2>&1 && unset CDPATH
45 # Environment variables that may be set by the user.
46 : "${AUTOPOINT=autopoint}"
47 : "${AUTORECONF=autoreconf}"
49 if test "$vc_ignore" = auto
; then
51 test -d .git
&& vc_ignore
=.gitignore
52 test -d CVS
&& vc_ignore
="$vc_ignore .cvsignore"
57 Usage: $me [OPTION]...
58 Bootstrap this package from the checked-out sources.
60 Optional environment variables:
61 GNULIB_SRCDIR Specifies the local directory where gnulib
62 sources reside. Use this if you already
63 have gnulib sources on your machine, and
64 you want to use these sources.
67 --copy copy files instead of creating symbolic links
68 --force attempt to bootstrap even if the sources seem
69 not to have been checked out
71 bootstrap_print_option_usage_hook
73 If the file bootstrap.conf exists in the same directory as this script, its
74 contents are read as shell variables to configure the bootstrap.
76 For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
79 Gnulib sources are assumed to be present:
80 * in \$GNULIB_SRCDIR, if that environment variable is set,
81 * otherwise, in the 'gnulib' submodule, if such a submodule is configured,
82 * otherwise, in the 'gnulib' subdirectory.
84 Running without arguments will suffice in most cases.
90 # Whether to use copies instead of symlinks.
101 echo "autogen.sh $scriptversion"
106 checkout_only_file
=;;
110 bootstrap_option_hook
$option || die
"$option: unknown option";;
114 test -z "$GNULIB_SRCDIR" ||
test -d "$GNULIB_SRCDIR" \
115 || die
"Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory"
117 if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
118 die
"Running this script from a non-checked-out distribution is risky."
122 if test -z "$GNULIB_SRCDIR"; then
123 gnulib_path
=$
(test -f .gitmodules
&& git config
--file .gitmodules submodule.gnulib.path
)
124 test -z "$gnulib_path" && gnulib_path
=gnulib
125 GNULIB_SRCDIR
=$gnulib_path
129 version_controlled_file
() {
132 if test -d .git
; then
133 git
rm -n "$file" > /dev
/null
2>&1
134 elif test -d .svn
; then
135 svn log
-r HEAD
"$file" > /dev
/null
2>&1
136 elif test -d CVS
; then
137 grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev
/null |
138 grep '^/[^/]*/[0-9]' > /dev
/null
140 warn_
"no version control for $file?"
145 # Strip blank and comment lines to leave significant entries.
146 gitignore_entries
() {
147 sed '/^#/d; /^$/d' "$@"
150 # If $STR is not already on a line by itself in $FILE, insert it at the start.
151 # Entries are inserted at the start of the ignore list to ensure existing
152 # entries starting with ! are not overridden. Such entries support
153 # whitelisting exceptions after a more generic blacklist pattern.
157 test -f $file ||
touch $file
158 test -r $file || die
"Error: failed to read ignore file: $file"
159 duplicate_entries
=$
(gitignore_entries
$file |
sort |
uniq -d)
160 if [ "$duplicate_entries" ] ; then
161 die
"Error: Duplicate entries in $file: " $duplicate_entries
163 linesold
=$
(gitignore_entries
$file |
wc -l)
164 linesnew
=$
( { echo "$str"; cat $file; } | gitignore_entries |
sort -u |
wc -l)
165 if [ $linesold != $linesnew ] ; then
166 { echo "$str" |
cat - $file > $file.bak
&& mv $file.bak
$file; } \
167 || die
"insert_if_absent $file $str: failed"
171 # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
176 case $vc_ignore_file in
178 # A .gitignore entry that does not start with '/' applies
179 # recursively to subdirectories, so prepend '/' to every
181 pattern
=$
(echo "$pattern" |
sed s
,^
,/,);;
183 insert_if_absent
"$vc_ignore_file" "$pattern"
193 # If the destination directory doesn't exist, create it.
194 # This is required at least for "lib/uniwidth/cjk.h".
195 dst_dir
=$
(dirname "$dst")
196 if ! test -d "$dst_dir"; then
199 # If we've just created a directory like lib/uniwidth,
200 # tell version control system(s) it's ignorable.
201 # FIXME: for now, this does only one level
202 parent
=$
(dirname "$dst_dir")
203 for dot_ig
in x
$vc_ignore; do
204 test $dot_ig = x
&& continue
206 insert_vc_ignore
$ig "${dst_dir##*/}"
212 test ! -h "$dst" ||
{
213 echo "$me: rm -f $dst" &&
218 cmp -s "$src" "$dst" ||
{
219 echo "$me: cp -fp $src $dst" &&
223 # Leave any existing symlink alone, if it already points to the source,
224 # so that broken build tools that care about symlink times
225 # aren't confused into doing unnecessary builds. Conversely, if the
226 # existing symlink's timestamp is older than the source, make it afresh,
227 # so that broken tools aren't confused into skipping needed builds. See
228 # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
230 src_ls
=$
(ls -diL "$src" 2>/dev
/null
) && set $src_ls && src_i
=$1 &&
231 dst_ls
=$
(ls -diL "$dst" 2>/dev
/null
) && set $dst_ls && dst_i
=$1 &&
232 test "$src_i" = "$dst_i" &&
233 both_ls
=$
(ls -dt "$src" "$dst") &&
234 test "X$both_ls" = "X$dst$nl$src" ||
{
240 *//* |
*/..
/* |
*/.
/* |
/*/*/*/*/*/)
241 die
"invalid symlink calculation: $src -> $dst";;
242 /*/*/*/*/) dot_dots
=..
/..
/..
/;;
243 /*/*/*/) dot_dots
=..
/..
/;;
244 /*/*/) dot_dots
=..
/;;
248 echo "$me: ln -fs $dot_dots$src $dst" &&
249 ln -fs "$dot_dots$src" "$dst"
255 # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
257 grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'])' configure.ac \
258 >/dev
/null
&& found_aux_dir
=yes
259 grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
260 >/dev
/null
&& found_aux_dir
=yes
261 test $found_aux_dir = yes \
262 || die
"configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
264 # If $build_aux doesn't exist, create it now, otherwise some bits
265 # below will malfunction. If creating it, also mark it as ignored.
266 if test ! -d $build_aux; then
268 for dot_ig
in x
$vc_ignore; do
269 test $dot_ig = x
&& continue
270 insert_vc_ignore
$dot_ig $build_aux
274 check_build_prerequisites false
277 # We'd like to use grep -E, to see if any of LT_INIT,
278 # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
279 # but that's not portable enough (e.g., for Solaris).
280 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac
>/dev
/null \
282 grep '^[ ]*LT_INIT' configure.ac
>/dev
/null \
284 if test $use_libtool = 1; then
285 find_tool LIBTOOLIZE glibtoolize libtoolize
289 gnulib_tool
=$GNULIB_SRCDIR/gnulib-tool
290 <$gnulib_tool ||
exit $?
293 # NOTE: we have to be careful to run both autopoint and libtoolize
294 # before gnulib-tool, since gnulib-tool is likely to provide newer
295 # versions of files "installed" by these two programs.
296 # Then, *after* gnulib-tool (see below), we have to be careful to
297 # run autoreconf in such a way that it does not run either of these
298 # two just-pre-run programs.
300 # Import from gettext.
302 grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac
>/dev
/null || \
305 if test $with_gettext = yes ||
test $use_libtool = 1; then
307 tempbase
=.bootstrap$$
308 trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
310 > $tempbase.0 > $tempbase.1 &&
311 find .
! -type d
-print |
sort > $tempbase.0 ||
exit
313 if test $with_gettext = yes; then
314 # Released autopoint has the tendency to install macros that have been
315 # obsoleted in current gnulib, so run this before gnulib-tool.
316 echo "$0: $AUTOPOINT --force"
317 $AUTOPOINT --force ||
exit
320 # Autoreconf runs aclocal before libtoolize, which causes spurious
321 # warnings if the initial aclocal is confused by the libtoolized
322 # (or worse out-of-date) macro directory.
323 # libtoolize 1.9b added the --install option; but we support back
324 # to libtoolize 1.5.22, where the install action was default.
325 if test $use_libtool = 1; then
327 case $
($LIBTOOLIZE --help) in
328 *--install*) install=--install ;;
330 echo "running: $LIBTOOLIZE $install --copy"
331 $LIBTOOLIZE $install --copy
334 find .
! -type d
-print |
sort >$tempbase.1
337 for file in $
(comm -13 $tempbase.0 $tempbase.1); do
340 version_controlled_file
"$parent" "$file" ||
{
341 for dot_ig
in x
$vc_ignore; do
342 test $dot_ig = x
&& continue
344 insert_vc_ignore
"$ig" "${file##*/}"
350 rm -f $tempbase.0 $tempbase.1
354 # Import from gnulib.
357 gnulib_tool_options
="\
359 --aux-dir=$build_aux\
360 --doc-base=$doc_base\
363 --source-base=$source_base/\
364 --tests-base=$tests_base\
365 --local-dir=$local_gl_dir\
366 $gnulib_tool_option_extras\
368 if test $use_libtool = 1; then
369 case "$gnulib_tool_options " in
371 *) gnulib_tool_options
="$gnulib_tool_options --libtool" ;;
374 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
375 $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
376 || die
"gnulib-tool failed"
378 for file in $gnulib_files; do
379 symlink_to_dir
"$GNULIB_SRCDIR" $file \
380 || die
"failed to symlink $file"
384 bootstrap_post_import_hook \
385 || die
"bootstrap_post_import_hook failed"
387 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
388 # gnulib-populated directories. Such .m4 files would cause aclocal to fail.
389 # The following requires GNU find 4.2.3 or newer. Considering the usual
390 # portability constraints of this script, that may seem a very demanding
391 # requirement, but it should be ok. Ignore any failure, which is fine,
392 # since this is only a convenience to help developers avoid the relatively
393 # unusual case in which a symlinked-to .m4 file is git-removed from gnulib
394 # between successive runs of this script.
395 find "$m4_base" "$source_base" \
396 -depth \
( -name '*.m4' -o -name '*.[ch]' \
) \
397 -type l
-xtype l
-delete > /dev
/null
2>&1
399 # Invoke autoreconf with --force --install to ensure upgrades of tools
401 AUTORECONFFLAGS
="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
403 # Some systems (RHEL 5) are using ancient autotools, for which the
404 # --no-recursive option had not been invented. Detect that lack and
405 # omit the option when it's not supported. FIXME in 2017: remove this
406 # hack when RHEL 5 autotools are updated, or when they become irrelevant.
407 case $
($AUTORECONF --help) in
408 *--no-recursive*) AUTORECONFFLAGS
="$AUTORECONFFLAGS --no-recursive";;
411 # Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
412 echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
413 AUTOPOINT
=true LIBTOOLIZE
=true
$AUTORECONF $AUTORECONFFLAGS \
414 || die
"autoreconf failed"
416 # Get some extra files from gnulib, overriding existing files.
417 for file in $gnulib_extra_files; do
419 */INSTALL
) dst
=INSTALL
;;
420 build-aux
/*) dst
=$build_aux/${file#build-aux/};;
423 symlink_to_dir
"$GNULIB_SRCDIR" $file $dst \
424 || die
"failed to symlink $file"
427 if test $with_gettext = yes; then
428 # Create gettext configuration.
429 echo "$0: Creating po/Makevars from po/Makevars.template ..."
432 /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
433 /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
434 /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
435 /^XGETTEXT_OPTIONS *=/{
438 '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
440 ' po
/Makevars.template
>po
/Makevars \
441 || die
'cannot generate po/Makevars'
443 # If the 'gettext' module is in use, grab the latest Makefile.in.in.
444 # If only the 'gettext-h' module is in use, assume autopoint already
445 # put the correct version of this file into place.
446 case $gnulib_modules in
449 cp $GNULIB_SRCDIR/build-aux
/po
/Makefile.
in.
in po
/Makefile.
in.
in \
450 || die
"cannot create po/Makefile.in.in"
454 if test -d runtime-po
; then
455 # Similarly for runtime-po/Makevars, but not quite the same.
456 rm -f runtime-po
/Makevars
458 /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
459 /^subdir *=.*/s/=.*/= runtime-po/
460 /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
461 /^XGETTEXT_OPTIONS *=/{
464 '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
466 ' po
/Makevars.template
>runtime-po
/Makevars \
467 || die
'cannot generate runtime-po/Makevars'
469 # Copy identical files from po to runtime-po.
470 (cd po
&& cp -p Makefile.
in.
in *-quot *.header
*.
sed *.sin ..
/runtime-po
)
476 echo "$0: done. Now you can run './configure'."
478 # ----------------------------------------------------------------------------
481 # eval: (add-hook 'before-save-hook 'time-stamp)
482 # time-stamp-start: "scriptversion="
483 # time-stamp-format: "%:y-%02m-%02d.%02H"
484 # time-stamp-time-zone: "UTC0"
485 # time-stamp-end: "; # UTC"