]> git.ipfire.org Git - thirdparty/tar.git/blob - autogen.sh
Update copyright years
[thirdparty/tar.git] / autogen.sh
1 #!/bin/sh
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.
6
7 # Copyright (C) 2003-2023 Free Software Foundation, Inc.
8 #
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.
13 #
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.
18 #
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/>.
21
22 # Originally written by Paul Eggert. The canonical version of this
23 # script is maintained as build-aux/autogen.sh in gnulib. However,
24 # to be useful to your package, you should place a copy of it under
25 # version control in the top-level directory of your package. The
26 # intent is that all customization can be done with a bootstrap.conf
27 # file also maintained in your version control; gnulib comes with a
28 # template build-aux/bootstrap.conf to get you started.
29 #
30 # Alternatively, you can use an autogen.sh script that is specific
31 # to your package.
32
33 scriptversion=2022-07-24.15; # UTC
34
35 me="$0"
36 medir=`dirname "$me"`
37
38 # Read the function library and the configuration.
39 . "$medir"/bootstrap-funclib.sh
40
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
44
45 # Environment variables that may be set by the user.
46 : "${AUTOPOINT=autopoint}"
47 : "${AUTORECONF=autoreconf}"
48
49 if test "$vc_ignore" = auto; then
50 vc_ignore=
51 test -d .git && vc_ignore=.gitignore
52 test -d CVS && vc_ignore="$vc_ignore .cvsignore"
53 fi
54
55 usage() {
56 cat <<EOF
57 Usage: $me [OPTION]...
58 Bootstrap this package from the checked-out sources.
59
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.
65
66 Options:
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
70 EOF
71 bootstrap_print_option_usage_hook
72 cat <<EOF
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.
75
76 For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
77 are honored.
78
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.
83
84 Running without arguments will suffice in most cases.
85 EOF
86 }
87
88 # Parse options.
89
90 # Whether to use copies instead of symlinks.
91 copy=false
92
93 for option
94 do
95 case $option in
96 --help)
97 usage
98 exit;;
99 --version)
100 set -e
101 echo "autogen.sh $scriptversion"
102 echo "$copyright"
103 exit 0
104 ;;
105 --force)
106 checkout_only_file=;;
107 --copy)
108 copy=true;;
109 *)
110 bootstrap_option_hook $option || die "$option: unknown option";;
111 esac
112 done
113
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"
116
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."
119 fi
120
121 if $use_gnulib; then
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
126 fi
127 fi
128
129 version_controlled_file() {
130 parent=$1
131 file=$2
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
139 else
140 warn_ "no version control for $file?"
141 false
142 fi
143 }
144
145 # Strip blank and comment lines to leave significant entries.
146 gitignore_entries() {
147 sed '/^#/d; /^$/d' "$@"
148 }
149
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.
154 insert_if_absent() {
155 file=$1
156 str=$2
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
162 fi
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"
168 fi
169 }
170
171 # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
172 # insert_if_absent.
173 insert_vc_ignore() {
174 vc_ignore_file="$1"
175 pattern="$2"
176 case $vc_ignore_file in
177 *.gitignore)
178 # A .gitignore entry that does not start with '/' applies
179 # recursively to subdirectories, so prepend '/' to every
180 # .gitignore entry.
181 pattern=$(echo "$pattern" | sed s,^,/,);;
182 esac
183 insert_if_absent "$vc_ignore_file" "$pattern"
184 }
185
186 symlink_to_dir()
187 {
188 src=$1/$2
189 dst=${3-$2}
190
191 test -f "$src" && {
192
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
197 mkdir -p "$dst_dir"
198
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
205 ig=$parent/$dot_ig
206 insert_vc_ignore $ig "${dst_dir##*/}"
207 done
208 fi
209
210 if $copy; then
211 {
212 test ! -h "$dst" || {
213 echo "$me: rm -f $dst" &&
214 rm -f "$dst"
215 }
216 } &&
217 test -f "$dst" &&
218 cmp -s "$src" "$dst" || {
219 echo "$me: cp -fp $src $dst" &&
220 cp -fp "$src" "$dst"
221 }
222 else
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>.
229 test -h "$dst" &&
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" || {
235 dot_dots=
236 case $src in
237 /*) ;;
238 *)
239 case /$dst/ in
240 *//* | */../* | */./* | /*/*/*/*/*/)
241 die "invalid symlink calculation: $src -> $dst";;
242 /*/*/*/*/) dot_dots=../../../;;
243 /*/*/*/) dot_dots=../../;;
244 /*/*/) dot_dots=../;;
245 esac;;
246 esac
247
248 echo "$me: ln -fs $dot_dots$src $dst" &&
249 ln -fs "$dot_dots$src" "$dst"
250 }
251 fi
252 }
253 }
254
255 # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
256 found_aux_dir=no
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"
263
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
267 mkdir $build_aux
268 for dot_ig in x $vc_ignore; do
269 test $dot_ig = x && continue
270 insert_vc_ignore $dot_ig $build_aux
271 done
272 fi
273
274 check_build_prerequisites false
275
276 use_libtool=0
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 \
281 && use_libtool=1
282 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
283 && use_libtool=1
284 if test $use_libtool = 1; then
285 find_tool LIBTOOLIZE glibtoolize libtoolize
286 fi
287
288 if $use_gnulib; then
289 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
290 <$gnulib_tool || exit $?
291 fi
292
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.
299
300 # Import from gettext.
301 with_gettext=yes
302 grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
303 with_gettext=no
304
305 if test $with_gettext = yes || test $use_libtool = 1; then
306
307 tempbase=.bootstrap$$
308 trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
309
310 > $tempbase.0 > $tempbase.1 &&
311 find . ! -type d -print | sort > $tempbase.0 || exit
312
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
318 fi
319
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
326 install=
327 case $($LIBTOOLIZE --help) in
328 *--install*) install=--install ;;
329 esac
330 echo "running: $LIBTOOLIZE $install --copy"
331 $LIBTOOLIZE $install --copy
332 fi
333
334 find . ! -type d -print | sort >$tempbase.1
335 old_IFS=$IFS
336 IFS=$nl
337 for file in $(comm -13 $tempbase.0 $tempbase.1); do
338 IFS=$old_IFS
339 parent=${file%/*}
340 version_controlled_file "$parent" "$file" || {
341 for dot_ig in x $vc_ignore; do
342 test $dot_ig = x && continue
343 ig=$parent/$dot_ig
344 insert_vc_ignore "$ig" "${file##*/}"
345 done
346 }
347 done
348 IFS=$old_IFS
349
350 rm -f $tempbase.0 $tempbase.1
351 trap - 1 2 13 15
352 fi
353
354 # Import from gnulib.
355
356 if $use_gnulib; then
357 gnulib_tool_options="\
358 --no-changelog\
359 --aux-dir=$build_aux\
360 --doc-base=$doc_base\
361 --lib=$gnulib_name\
362 --m4-base=$m4_base/\
363 --source-base=$source_base/\
364 --tests-base=$tests_base\
365 --local-dir=$local_gl_dir\
366 $gnulib_tool_option_extras\
367 "
368 if test $use_libtool = 1; then
369 case "$gnulib_tool_options " in
370 *' --libtool '*) ;;
371 *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
372 esac
373 fi
374 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
375 $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
376 || die "gnulib-tool failed"
377
378 for file in $gnulib_files; do
379 symlink_to_dir "$GNULIB_SRCDIR" $file \
380 || die "failed to symlink $file"
381 done
382 fi
383
384 bootstrap_post_import_hook \
385 || die "bootstrap_post_import_hook failed"
386
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
398
399 # Invoke autoreconf with --force --install to ensure upgrades of tools
400 # such as ylwrap.
401 AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
402
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";;
409 esac
410
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"
415
416 # Get some extra files from gnulib, overriding existing files.
417 for file in $gnulib_extra_files; do
418 case $file in
419 */INSTALL) dst=INSTALL;;
420 build-aux/*) dst=$build_aux/${file#build-aux/};;
421 *) dst=$file;;
422 esac
423 symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
424 || die "failed to symlink $file"
425 done
426
427 if test $with_gettext = yes; then
428 # Create gettext configuration.
429 echo "$0: Creating po/Makevars from po/Makevars.template ..."
430 rm -f po/Makevars
431 sed '
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 *=/{
436 s/$/ \\/
437 a\
438 '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
439 }
440 ' po/Makevars.template >po/Makevars \
441 || die 'cannot generate po/Makevars'
442
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
447 *gettext-h*) ;;
448 *gettext*)
449 cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
450 || die "cannot create po/Makefile.in.in"
451 ;;
452 esac
453
454 if test -d runtime-po; then
455 # Similarly for runtime-po/Makevars, but not quite the same.
456 rm -f runtime-po/Makevars
457 sed '
458 /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
459 /^subdir *=.*/s/=.*/= runtime-po/
460 /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
461 /^XGETTEXT_OPTIONS *=/{
462 s/$/ \\/
463 a\
464 '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
465 }
466 ' po/Makevars.template >runtime-po/Makevars \
467 || die 'cannot generate runtime-po/Makevars'
468
469 # Copy identical files from po to runtime-po.
470 (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
471 fi
472 fi
473
474 bootstrap_epilogue
475
476 echo "$0: done. Now you can run './configure'."
477
478 # ----------------------------------------------------------------------------
479
480 # Local Variables:
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"
486 # End: