1#! /bin/sh
2# Print a version string.
3scriptversion=2017-09-19.08; # UTC
4
5# Bootstrap this package from checked-out sources.
6
7# Copyright (C) 2003-2018 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/bootstrap in gnulib, however, to
24# be useful to your project, you should place a copy of it under
25# version control in the top-level directory of your project.  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# Please report bugs or propose patches to bug-gnulib@gnu.org.
31
32nl='
33'
34
35# Ensure file names are sorted consistently across platforms.
36LC_ALL=C
37export LC_ALL
38
39# Ensure that CDPATH is not set.  Otherwise, the output from cd
40# would cause trouble in at least one use below.
41(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
42
43local_gl_dir=gl
44
45# Honor $PERL, but work even if there is none.
46PERL="${PERL-perl}"
47
48me=$0
49
50usage() {
51  cat <<EOF
52Usage: $me [OPTION]...
53Bootstrap this package from the checked-out sources.
54
55Options:
56 --gnulib-srcdir=DIRNAME  specify the local directory where gnulib
57                          sources reside.  Use this if you already
58                          have gnulib sources on your machine, and
59                          do not want to waste your bandwidth downloading
60                          them again.  Defaults to \$GNULIB_SRCDIR
61 --bootstrap-sync         if this bootstrap script is not identical to
62                          the version in the local gnulib sources,
63                          update this script, and then restart it with
64                          /bin/sh or the shell \$CONFIG_SHELL
65 --no-bootstrap-sync      do not check whether bootstrap is out of sync
66 --copy                   copy files instead of creating symbolic links
67 --force                  attempt to bootstrap even if the sources seem
68                          not to have been checked out
69 --no-git                 do not use git to update gnulib.  Requires that
70                          --gnulib-srcdir point to a correct gnulib snapshot
71 --skip-po                do not download po files
72
73If the file $me.conf exists in the same directory as this script, its
74contents are read as shell variables to configure the bootstrap.
75
76For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
77are honored.
78
79Running without arguments will suffice in most cases.
80EOF
81}
82
83# warnf_ FORMAT-STRING ARG1...
84warnf_ ()
85{
86  warnf_format_=$1
87  shift
88  nl='
89'
90  case $* in
91    *$nl*) me_=$(printf "$me"|tr "$nl|" '??')
92       printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;;
93    *) printf "$me: $warnf_format_" "$@" ;;
94  esac >&2
95}
96
97# warn_ WORD1...
98warn_ ()
99{
100  # If IFS does not start with ' ', set it and emit the warning in a subshell.
101  case $IFS in
102    ' '*) warnf_ '%s\n' "$*";;
103    *)    (IFS=' '; warn_ "$@");;
104  esac
105}
106
107# die WORD1...
108die() { warn_ "$@"; exit 1; }
109
110# Configuration.
111
112# Name of the Makefile.am
113gnulib_mk=gnulib.mk
114
115# List of gnulib modules needed.
116gnulib_modules=
117
118# Any gnulib files needed that are not in modules.
119gnulib_files=
120
121: ${AUTOPOINT=autopoint}
122: ${AUTORECONF=autoreconf}
123
124# A function to be called right after gnulib-tool is run.
125# Override it via your own definition in bootstrap.conf.
126bootstrap_post_import_hook() { :; }
127
128# A function to be called after everything else in this script.
129# Override it via your own definition in bootstrap.conf.
130bootstrap_epilogue() { :; }
131
132# The command to download all .po files for a specified domain into
133# a specified directory.  Fill in the first %s is the domain name, and
134# the second with the destination directory.  Use rsync's -L and -r
135# options because the latest/%s directory and the .po files within are
136# all symlinks.
137po_download_command_format=\
138"rsync --delete --exclude '*.s1' -Lrtvz \
139 'translationproject.org::tp/latest/%s/' '%s'"
140
141# Fallback for downloading .po files (if rsync fails).
142po_download_command_format2=\
143"wget --mirror -nd -q -np -A.po -P '%s' \
144 https://translationproject.org/latest/%s/"
145
146# Prefer a non-empty tarname (4th argument of AC_INIT if given), else
147# fall back to the package name (1st argument with munging)
148extract_package_name='
149  /^AC_INIT(\[*/{
150     s///
151     /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{
152       s//\1/
153       s/[],)].*//
154       p
155       q
156     }
157     s/[],)].*//
158     s/^GNU //
159     y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
160     s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g
161     p
162  }
163'
164package=$(sed -n "$extract_package_name" configure.ac) \
165  || die 'cannot find package name in configure.ac'
166gnulib_name=lib$package
167
168build_aux=build-aux
169source_base=lib
170m4_base=m4
171doc_base=doc
172tests_base=tests
173gnulib_extra_files=''
174
175# Additional gnulib-tool options to use.  Use "\newline" to break lines.
176gnulib_tool_option_extras=
177
178# Other locale categories that need message catalogs.
179EXTRA_LOCALE_CATEGORIES=
180
181# Additional xgettext options to use.  Use "\\\newline" to break lines.
182XGETTEXT_OPTIONS='\\\
183 --flag=_:1:pass-c-format\\\
184 --flag=N_:1:pass-c-format\\\
185 --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
186'
187
188# Package bug report address and copyright holder for gettext files
189COPYRIGHT_HOLDER='Free Software Foundation, Inc.'
190MSGID_BUGS_ADDRESS=bug-$package@gnu.org
191
192# Files we don't want to import.
193excluded_files=
194
195# File that should exist in the top directory of a checked out hierarchy,
196# but not in a distribution tarball.
197checkout_only_file=README-hacking
198
199# Whether to use copies instead of symlinks.
200copy=false
201
202# Set this to '.cvsignore .gitignore' in bootstrap.conf if you want
203# those files to be generated in directories like lib/, m4/, and po/.
204# Or set it to 'auto' to make this script select which to use based
205# on which version control system (if any) is used in the source directory.
206vc_ignore=auto
207
208# Set this to true in bootstrap.conf to enable --bootstrap-sync by
209# default.
210bootstrap_sync=false
211
212# Use git to update gnulib sources
213use_git=true
214
215check_exists() {
216  if test "$1" = "--verbose"; then
217    ($2 --version </dev/null) >/dev/null 2>&1
218    if test $? -ge 126; then
219      # If not found, run with diagnostics as one may be
220      # presented with env variables to set to find the right version
221      ($2 --version </dev/null)
222    fi
223  else
224    ($1 --version </dev/null) >/dev/null 2>&1
225  fi
226
227  test $? -lt 126
228}
229
230# find_tool ENVVAR NAMES...
231# -------------------------
232# Search for a required program.  Use the value of ENVVAR, if set,
233# otherwise find the first of the NAMES that can be run.
234# If found, set ENVVAR to the program name, die otherwise.
235#
236# FIXME: code duplication, see also gnu-web-doc-update.
237find_tool ()
238{
239  find_tool_envvar=$1
240  shift
241  find_tool_names=$@
242  eval "find_tool_res=\$$find_tool_envvar"
243  if test x"$find_tool_res" = x; then
244    for i; do
245      if check_exists $i; then
246        find_tool_res=$i
247        break
248      fi
249    done
250  fi
251  if test x"$find_tool_res" = x; then
252    warn_ "one of these is required: $find_tool_names;"
253    die   "alternatively set $find_tool_envvar to a compatible tool"
254  fi
255  eval "$find_tool_envvar=\$find_tool_res"
256  eval "export $find_tool_envvar"
257}
258
259# Override the default configuration, if necessary.
260# Make sure that bootstrap.conf is sourced from the current directory
261# if we were invoked as "sh bootstrap".
262case "$0" in
263  */*) test -r "$0.conf" && . "$0.conf" ;;
264  *) test -r "$0.conf" && . ./"$0.conf" ;;
265esac
266
267# Extra files from gnulib, which override files from other sources.
268test -z "${gnulib_extra_files}" && \
269  gnulib_extra_files="
270        build-aux/install-sh
271        build-aux/mdate-sh
272        build-aux/texinfo.tex
273        build-aux/depcomp
274        build-aux/config.guess
275        build-aux/config.sub
276        doc/INSTALL
277"
278
279if test "$vc_ignore" = auto; then
280  vc_ignore=
281  test -d .git && vc_ignore=.gitignore
282  test -d CVS && vc_ignore="$vc_ignore .cvsignore"
283fi
284
285# Translate configuration into internal form.
286
287# Parse options.
288
289for option
290do
291  case $option in
292  --help)
293    usage
294    exit;;
295  --gnulib-srcdir=*)
296    GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
297  --skip-po)
298    SKIP_PO=t;;
299  --force)
300    checkout_only_file=;;
301  --copy)
302    copy=true;;
303  --bootstrap-sync)
304    bootstrap_sync=true;;
305  --no-bootstrap-sync)
306    bootstrap_sync=false;;
307  --no-git)
308    use_git=false;;
309  *)
310    die "$option: unknown option";;
311  esac
312done
313
314$use_git || test -d "$GNULIB_SRCDIR" \
315  || die "Error: --no-git requires --gnulib-srcdir"
316
317if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
318  die "Bootstrapping from a non-checked-out distribution is risky."
319fi
320
321# Strip blank and comment lines to leave significant entries.
322gitignore_entries() {
323  sed '/^#/d; /^$/d' "$@"
324}
325
326# If $STR is not already on a line by itself in $FILE, insert it at the start.
327# Entries are inserted at the start of the ignore list to ensure existing
328# entries starting with ! are not overridden.  Such entries support
329# whitelisting exceptions after a more generic blacklist pattern.
330insert_if_absent() {
331  file=$1
332  str=$2
333  test -f $file || touch $file
334  test -r $file || die "Error: failed to read ignore file: $file"
335  duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
336  if [ "$duplicate_entries" ] ; then
337    die "Error: Duplicate entries in $file: " $duplicate_entries
338  fi
339  linesold=$(gitignore_entries $file | wc -l)
340  linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
341  if [ $linesold != $linesnew ] ; then
342    { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
343      || die "insert_if_absent $file $str: failed"
344  fi
345}
346
347# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
348# insert_if_absent.
349insert_vc_ignore() {
350  vc_ignore_file="$1"
351  pattern="$2"
352  case $vc_ignore_file in
353  *.gitignore)
354    # A .gitignore entry that does not start with '/' applies
355    # recursively to subdirectories, so prepend '/' to every
356    # .gitignore entry.
357    pattern=$(echo "$pattern" | sed s,^,/,);;
358  esac
359  insert_if_absent "$vc_ignore_file" "$pattern"
360}
361
362# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
363found_aux_dir=no
364grep '^[	 ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
365    >/dev/null && found_aux_dir=yes
366grep '^[	 ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
367    >/dev/null && found_aux_dir=yes
368test $found_aux_dir = yes \
369  || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
370
371# If $build_aux doesn't exist, create it now, otherwise some bits
372# below will malfunction.  If creating it, also mark it as ignored.
373if test ! -d $build_aux; then
374  mkdir $build_aux
375  for dot_ig in x $vc_ignore; do
376    test $dot_ig = x && continue
377    insert_vc_ignore $dot_ig $build_aux
378  done
379fi
380
381# Note this deviates from the version comparison in automake
382# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
383# but this should suffice as we won't be specifying old
384# version formats or redundant trailing .0 in bootstrap.conf.
385# If we did want full compatibility then we should probably
386# use m4_version_compare from autoconf.
387sort_ver() { # sort -V is not generally available
388  ver1="$1"
389  ver2="$2"
390
391  # split on '.' and compare each component
392  i=1
393  while : ; do
394    p1=$(echo "$ver1" | cut -d. -f$i)
395    p2=$(echo "$ver2" | cut -d. -f$i)
396    if [ ! "$p1" ]; then
397      echo "$1 $2"
398      break
399    elif [ ! "$p2" ]; then
400      echo "$2 $1"
401      break
402    elif [ ! "$p1" = "$p2" ]; then
403      if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison
404        echo "$2 $1"
405      elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison
406        echo "$1 $2"
407      else # numeric, then lexicographic comparison
408        lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1)
409        if [ "$lp" = "$p2" ]; then
410          echo "$1 $2"
411        else
412          echo "$2 $1"
413        fi
414      fi
415      break
416    fi
417    i=$(($i+1))
418  done
419}
420
421get_version_sed='
422# Move version to start of line.
423s/.*[v ]\([0-9]\)/\1/
424
425# Skip lines that do not start with version.
426/^[0-9]/!d
427
428# Remove characters after the version.
429s/[^.a-z0-9-].*//
430
431# The first component must be digits only.
432s/^\([0-9]*\)[a-z-].*/\1/
433
434#the following essentially does s/5.005/5.5/
435s/\.0*\([1-9]\)/.\1/g
436p
437q'
438
439get_version() {
440  app=$1
441
442  $app --version >/dev/null 2>&1 || { $app --version; return 1; }
443
444  $app --version 2>&1 | sed -n "$get_version_sed"
445}
446
447check_versions() {
448  ret=0
449
450  while read app req_ver; do
451    # We only need libtoolize from the libtool package.
452    if test "$app" = libtool; then
453      app=libtoolize
454    fi
455    # Exempt git if --no-git is in effect.
456    if test "$app" = git; then
457      $use_git || continue
458    fi
459    # Honor $APP variables ($TAR, $AUTOCONF, etc.)
460    appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
461    test "$appvar" = TAR && appvar=AMTAR
462    case $appvar in
463        GZIP) ;; # Do not use $GZIP:  it contains gzip options.
464        PERL::*) ;; # Keep perl modules as-is
465        *) eval "app=\${$appvar-$app}" ;;
466    esac
467
468    # Handle the still-experimental Automake-NG programs specially.
469    # They remain named as the mainstream Automake programs ("automake",
470    # and "aclocal") to avoid gratuitous incompatibilities with
471    # pre-existing usages (by, say, autoreconf, or custom autogen.sh
472    # scripts), but correctly identify themselves (as being part of
473    # "GNU automake-ng") when asked their version.
474    case $app in
475      automake-ng|aclocal-ng)
476        app=${app%-ng}
477        ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
478          warn_ "Error: '$app' not found or not from Automake-NG"
479          ret=1
480          continue
481        } ;;
482      # Another check is for perl modules.  These can be written as
483      # e.g. perl::XML::XPath in case of XML::XPath module, etc.
484      perl::*)
485        # Extract module name
486        app="${app#perl::}"
487        if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
488          warn_ "Error: perl module '$app' not found"
489          ret=1
490        fi
491        continue
492        ;;
493    esac
494    if [ "$req_ver" = "-" ]; then
495      # Merely require app to exist; not all prereq apps are well-behaved
496      # so we have to rely on $? rather than get_version.
497      if ! check_exists --verbose $app; then
498        warn_ "Error: '$app' not found"
499        ret=1
500      fi
501    else
502      # Require app to produce a new enough version string.
503      inst_ver=$(get_version $app)
504      if [ ! "$inst_ver" ]; then
505        warn_ "Error: '$app' not found"
506        ret=1
507      else
508        latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
509        if [ ! "$latest_ver" = "$inst_ver" ]; then
510          warnf_ '%s\n'                                        \
511              "Error: '$app' version == $inst_ver is too old"  \
512              "       '$app' version >= $req_ver is required"
513          ret=1
514        fi
515      fi
516    fi
517  done
518
519  return $ret
520}
521
522print_versions() {
523  echo "Program    Min_version"
524  echo "----------------------"
525  printf %s "$buildreq"
526  echo "----------------------"
527  # can't depend on column -t
528}
529
530# Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
531# Also find the compatible sha1 utility on the BSDs
532if test x"$SKIP_PO" = x; then
533  find_tool SHA1SUM sha1sum gsha1sum shasum sha1
534fi
535
536use_libtool=0
537# We'd like to use grep -E, to see if any of LT_INIT,
538# AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
539# but that's not portable enough (e.g., for Solaris).
540grep '^[	 ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
541  && use_libtool=1
542grep '^[	 ]*LT_INIT' configure.ac >/dev/null \
543  && use_libtool=1
544if test $use_libtool = 1; then
545  find_tool LIBTOOLIZE glibtoolize libtoolize
546fi
547
548# gnulib-tool requires at least automake and autoconf.
549# If either is not listed, add it (with minimum version) as a prerequisite.
550case $buildreq in
551  *automake*) ;;
552  *) buildreq="automake 1.9
553$buildreq" ;;
554esac
555case $buildreq in
556  *autoconf*) ;;
557  *) buildreq="autoconf 2.59
558$buildreq" ;;
559esac
560
561# When we can deduce that gnulib-tool will require patch,
562# and when patch is not already listed as a prerequisite, add it, too.
563if test -d "$local_gl_dir" \
564    && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
565  case $buildreq in
566    *patch*) ;;
567    *) buildreq="patch -
568$buildreq" ;;
569  esac
570fi
571
572if ! printf "$buildreq" | check_versions; then
573  echo >&2
574  if test -f README-prereq; then
575    die "See README-prereq for how to get the prerequisite programs"
576  else
577    die "Please install the prerequisite programs"
578  fi
579fi
580
581# Warn the user if autom4te appears to be broken; this causes known
582# issues with at least gettext 0.18.3.
583probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
584if test "x$probe" != xhi; then
585  warn_ "WARNING: your autom4te wrapper eats stdin;"
586  warn_ "if bootstrap fails, consider upgrading your autotools"
587fi
588
589echo "$0: Bootstrapping from checked-out $package sources..."
590
591# See if we can use gnulib's git-merge-changelog merge driver.
592if $use_git && test -d .git && check_exists git; then
593  if git config merge.merge-changelog.driver >/dev/null ; then
594    :
595  elif check_exists git-merge-changelog; then
596    echo "$0: initializing git-merge-changelog driver"
597    git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
598    git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
599  else
600    echo "$0: consider installing git-merge-changelog from gnulib"
601  fi
602fi
603
604
605cleanup_gnulib() {
606  status=$?
607  rm -fr "$gnulib_path"
608  exit $status
609}
610
611git_modules_config () {
612  test -f .gitmodules && git config --file .gitmodules "$@"
613}
614
615if $use_git; then
616  gnulib_path=$(git_modules_config submodule.gnulib.path)
617  test -z "$gnulib_path" && gnulib_path=gnulib
618fi
619
620# Get gnulib files.  Populate $GNULIB_SRCDIR, possibly updating a
621# submodule, for use in the rest of the script.
622
623case ${GNULIB_SRCDIR--} in
624-)
625  # Note that $use_git is necessarily true in this case.
626  if git_modules_config submodule.gnulib.url >/dev/null; then
627    echo "$0: getting gnulib files..."
628    git submodule init -- "$gnulib_path" || exit $?
629    git submodule update -- "$gnulib_path" || exit $?
630
631  elif [ ! -d "$gnulib_path" ]; then
632    echo "$0: getting gnulib files..."
633
634    trap cleanup_gnulib 1 2 13 15
635
636    shallow=
637    git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
638    git clone $shallow git://git.sv.gnu.org/gnulib "$gnulib_path" ||
639      cleanup_gnulib
640
641    trap - 1 2 13 15
642  fi
643  GNULIB_SRCDIR=$gnulib_path
644  ;;
645*)
646  # Use GNULIB_SRCDIR directly or as a reference.
647  if $use_git && test -d "$GNULIB_SRCDIR"/.git && \
648        git_modules_config submodule.gnulib.url >/dev/null; then
649    echo "$0: getting gnulib files..."
650    if git submodule -h|grep -- --reference > /dev/null; then
651      # Prefer the one-liner available in git 1.6.4 or newer.
652      git submodule update --init --reference "$GNULIB_SRCDIR" \
653        "$gnulib_path" || exit $?
654    else
655      # This fallback allows at least git 1.5.5.
656      if test -f "$gnulib_path"/gnulib-tool; then
657        # Since file already exists, assume submodule init already complete.
658        git submodule update -- "$gnulib_path" || exit $?
659      else
660        # Older git can't clone into an empty directory.
661        rmdir "$gnulib_path" 2>/dev/null
662        git clone --reference "$GNULIB_SRCDIR" \
663          "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
664          && git submodule init -- "$gnulib_path" \
665          && git submodule update -- "$gnulib_path" \
666          || exit $?
667      fi
668    fi
669    GNULIB_SRCDIR=$gnulib_path
670  fi
671  ;;
672esac
673
674# $GNULIB_SRCDIR now points to the version of gnulib to use, and
675# we no longer need to use git or $gnulib_path below here.
676
677if $bootstrap_sync; then
678  cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || {
679    echo "$0: updating bootstrap and restarting..."
680    case $(sh -c 'echo "$1"' -- a) in
681      a) ignored=--;;
682      *) ignored=ignored;;
683    esac
684    exec sh -c \
685      'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
686      $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \
687      "$0" "$@" --no-bootstrap-sync
688  }
689fi
690
691gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
692<$gnulib_tool || exit $?
693
694# Get translations.
695
696download_po_files() {
697  subdir=$1
698  domain=$2
699  echo "$me: getting translations into $subdir for $domain..."
700  cmd=$(printf "$po_download_command_format" "$domain" "$subdir")
701  eval "$cmd" && return
702  # Fallback to HTTPS.
703  cmd=$(printf "$po_download_command_format2" "$subdir" "$domain")
704  eval "$cmd"
705}
706
707# Mirror .po files to $po_dir/.reference and copy only the new
708# or modified ones into $po_dir.  Also update $po_dir/LINGUAS.
709# Note po files that exist locally only are left in $po_dir but will
710# not be included in LINGUAS and hence will not be distributed.
711update_po_files() {
712  # Directory containing primary .po files.
713  # Overwrite them only when we're sure a .po file is new.
714  po_dir=$1
715  domain=$2
716
717  # Mirror *.po files into this dir.
718  # Usually contains *.s1 checksum files.
719  ref_po_dir="$po_dir/.reference"
720
721  test -d $ref_po_dir || mkdir $ref_po_dir || return
722  download_po_files $ref_po_dir $domain \
723    && ls "$ref_po_dir"/*.po 2>/dev/null |
724      sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
725
726  langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
727  test "$langs" = '*' && langs=x
728  for po in $langs; do
729    case $po in x) continue;; esac
730    new_po="$ref_po_dir/$po.po"
731    cksum_file="$ref_po_dir/$po.s1"
732    if ! test -f "$cksum_file" ||
733        ! test -f "$po_dir/$po.po" ||
734        ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
735      echo "$me: updated $po_dir/$po.po..."
736      cp "$new_po" "$po_dir/$po.po" \
737          && $SHA1SUM < "$new_po" > "$cksum_file" || return
738    fi
739  done
740}
741
742case $SKIP_PO in
743'')
744  if test -d po; then
745    update_po_files po $package || exit
746  fi
747
748  if test -d runtime-po; then
749    update_po_files runtime-po $package-runtime || exit
750  fi;;
751esac
752
753symlink_to_dir()
754{
755  src=$1/$2
756  dst=${3-$2}
757
758  test -f "$src" && {
759
760    # If the destination directory doesn't exist, create it.
761    # This is required at least for "lib/uniwidth/cjk.h".
762    dst_dir=$(dirname "$dst")
763    if ! test -d "$dst_dir"; then
764      mkdir -p "$dst_dir"
765
766      # If we've just created a directory like lib/uniwidth,
767      # tell version control system(s) it's ignorable.
768      # FIXME: for now, this does only one level
769      parent=$(dirname "$dst_dir")
770      for dot_ig in x $vc_ignore; do
771        test $dot_ig = x && continue
772        ig=$parent/$dot_ig
773        insert_vc_ignore $ig "${dst_dir##*/}"
774      done
775    fi
776
777    if $copy; then
778      {
779        test ! -h "$dst" || {
780          echo "$me: rm -f $dst" &&
781          rm -f "$dst"
782        }
783      } &&
784      test -f "$dst" &&
785      cmp -s "$src" "$dst" || {
786        echo "$me: cp -fp $src $dst" &&
787        cp -fp "$src" "$dst"
788      }
789    else
790      # Leave any existing symlink alone, if it already points to the source,
791      # so that broken build tools that care about symlink times
792      # aren't confused into doing unnecessary builds.  Conversely, if the
793      # existing symlink's timestamp is older than the source, make it afresh,
794      # so that broken tools aren't confused into skipping needed builds.  See
795      # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
796      test -h "$dst" &&
797      src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
798      dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
799      test "$src_i" = "$dst_i" &&
800      both_ls=$(ls -dt "$src" "$dst") &&
801      test "X$both_ls" = "X$dst$nl$src" || {
802        dot_dots=
803        case $src in
804        /*) ;;
805        *)
806          case /$dst/ in
807          *//* | */../* | */./* | /*/*/*/*/*/)
808             die "invalid symlink calculation: $src -> $dst";;
809          /*/*/*/*/)    dot_dots=../../../;;
810          /*/*/*/)      dot_dots=../../;;
811          /*/*/)        dot_dots=../;;
812          esac;;
813        esac
814
815        echo "$me: ln -fs $dot_dots$src $dst" &&
816        ln -fs "$dot_dots$src" "$dst"
817      }
818    fi
819  }
820}
821
822version_controlled_file() {
823  parent=$1
824  file=$2
825  if test -d .git; then
826    git rm -n "$file" > /dev/null 2>&1
827  elif test -d .svn; then
828    svn log -r HEAD "$file" > /dev/null 2>&1
829  elif test -d CVS; then
830    grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
831             grep '^/[^/]*/[0-9]' > /dev/null
832  else
833    warn_ "no version control for $file?"
834    false
835  fi
836}
837
838# NOTE: we have to be careful to run both autopoint and libtoolize
839# before gnulib-tool, since gnulib-tool is likely to provide newer
840# versions of files "installed" by these two programs.
841# Then, *after* gnulib-tool (see below), we have to be careful to
842# run autoreconf in such a way that it does not run either of these
843# two just-pre-run programs.
844
845# Import from gettext.
846with_gettext=yes
847grep '^[	 ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
848    with_gettext=no
849
850if test $with_gettext = yes || test $use_libtool = 1; then
851
852  tempbase=.bootstrap$$
853  trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
854
855  > $tempbase.0 > $tempbase.1 &&
856  find . ! -type d -print | sort > $tempbase.0 || exit
857
858  if test $with_gettext = yes; then
859    # Released autopoint has the tendency to install macros that have been
860    # obsoleted in current gnulib, so run this before gnulib-tool.
861    echo "$0: $AUTOPOINT --force"
862    $AUTOPOINT --force || exit
863  fi
864
865  # Autoreconf runs aclocal before libtoolize, which causes spurious
866  # warnings if the initial aclocal is confused by the libtoolized
867  # (or worse out-of-date) macro directory.
868  # libtoolize 1.9b added the --install option; but we support back
869  # to libtoolize 1.5.22, where the install action was default.
870  if test $use_libtool = 1; then
871    install=
872    case $($LIBTOOLIZE --help) in
873      *--install*) install=--install ;;
874    esac
875    echo "running: $LIBTOOLIZE $install --copy"
876    $LIBTOOLIZE $install --copy
877  fi
878
879  find . ! -type d -print | sort >$tempbase.1
880  old_IFS=$IFS
881  IFS=$nl
882  for file in $(comm -13 $tempbase.0 $tempbase.1); do
883    IFS=$old_IFS
884    parent=${file%/*}
885    version_controlled_file "$parent" "$file" || {
886      for dot_ig in x $vc_ignore; do
887        test $dot_ig = x && continue
888        ig=$parent/$dot_ig
889        insert_vc_ignore "$ig" "${file##*/}"
890      done
891    }
892  done
893  IFS=$old_IFS
894
895  rm -f $tempbase.0 $tempbase.1
896  trap - 1 2 13 15
897fi
898
899# Import from gnulib.
900
901gnulib_tool_options="\
902 --import\
903 --no-changelog\
904 --aux-dir $build_aux\
905 --doc-base $doc_base\
906 --lib $gnulib_name\
907 --m4-base $m4_base/\
908 --source-base $source_base/\
909 --tests-base $tests_base\
910 --local-dir $local_gl_dir\
911 $gnulib_tool_option_extras\
912"
913if test $use_libtool = 1; then
914  case "$gnulib_tool_options " in
915    *' --libtool '*) ;;
916    *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
917  esac
918fi
919echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
920$gnulib_tool $gnulib_tool_options --import $gnulib_modules \
921  || die "gnulib-tool failed"
922
923for file in $gnulib_files; do
924  symlink_to_dir "$GNULIB_SRCDIR" $file \
925    || die "failed to symlink $file"
926done
927
928bootstrap_post_import_hook \
929  || die "bootstrap_post_import_hook failed"
930
931# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
932# gnulib-populated directories.  Such .m4 files would cause aclocal to fail.
933# The following requires GNU find 4.2.3 or newer.  Considering the usual
934# portability constraints of this script, that may seem a very demanding
935# requirement, but it should be ok.  Ignore any failure, which is fine,
936# since this is only a convenience to help developers avoid the relatively
937# unusual case in which a symlinked-to .m4 file is git-removed from gnulib
938# between successive runs of this script.
939find "$m4_base" "$source_base" \
940  -depth \( -name '*.m4' -o -name '*.[ch]' \) \
941  -type l -xtype l -delete > /dev/null 2>&1
942
943# Invoke autoreconf with --force --install to ensure upgrades of tools
944# such as ylwrap.
945AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
946
947# Some systems (RHEL 5) are using ancient autotools, for which the
948# --no-recursive option had not been invented.  Detect that lack and
949# omit the option when it's not supported.  FIXME in 2017: remove this
950# hack when RHEL 5 autotools are updated, or when they become irrelevant.
951case $($AUTORECONF --help) in
952  *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";;
953esac
954
955# Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
956echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
957AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \
958  || die "autoreconf failed"
959
960# Get some extra files from gnulib, overriding existing files.
961for file in $gnulib_extra_files; do
962  case $file in
963  */INSTALL) dst=INSTALL;;
964  build-aux/*) dst=$build_aux/${file#build-aux/};;
965  *) dst=$file;;
966  esac
967  symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
968    || die "failed to symlink $file"
969done
970
971if test $with_gettext = yes; then
972  # Create gettext configuration.
973  echo "$0: Creating po/Makevars from po/Makevars.template ..."
974  rm -f po/Makevars
975  sed '
976    /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
977    /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
978    /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
979    /^XGETTEXT_OPTIONS *=/{
980      s/$/ \\/
981      a\
982          '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
983    }
984  ' po/Makevars.template >po/Makevars \
985    || die 'cannot generate po/Makevars'
986
987  # If the 'gettext' module is in use, grab the latest Makefile.in.in.
988  # If only the 'gettext-h' module is in use, assume autopoint already
989  # put the correct version of this file into place.
990  case $gnulib_modules in
991  *gettext-h*) ;;
992  *gettext*)
993    cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
994      || die "cannot create po/Makefile.in.in"
995    ;;
996  esac
997
998  if test -d runtime-po; then
999    # Similarly for runtime-po/Makevars, but not quite the same.
1000    rm -f runtime-po/Makevars
1001    sed '
1002      /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
1003      /^subdir *=.*/s/=.*/= runtime-po/
1004      /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
1005      /^XGETTEXT_OPTIONS *=/{
1006        s/$/ \\/
1007        a\
1008            '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
1009      }
1010    ' po/Makevars.template >runtime-po/Makevars \
1011    || die 'cannot generate runtime-po/Makevars'
1012
1013    # Copy identical files from po to runtime-po.
1014    (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
1015  fi
1016fi
1017
1018bootstrap_epilogue
1019
1020echo "$0: done.  Now you can run './configure'."
1021
1022# Local variables:
1023# eval: (add-hook 'write-file-hooks 'time-stamp)
1024# time-stamp-start: "scriptversion="
1025# time-stamp-format: "%:y-%02m-%02d.%02H"
1026# time-stamp-time-zone: "UTC0"
1027# time-stamp-end: "; # UTC"
1028# End:
1029