1#! /bin/sh
2#
3# Copyright (C) 2002-2010 Free Software Foundation, Inc.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17#
18
19# This file is meant for authors, maintainers, co-maintainers or installers
20# of packages which are internationalized with the help of GNU gettext.  For
21# further information how to use it consult the GNU gettext manual.
22
23progname=$0
24package=gettext-tools
25version=0.18.1
26
27# Set variables
28# - gettext_dir     directory where the sources are stored.
29prefix="/usr/local/x86_64-w64-mingw32/stow/gettext-0.18.1.1"
30datarootdir="${prefix}/share"
31gettext_dir="${datarootdir}/gettext"
32
33# func_tmpdir
34# creates a temporary directory.
35# Sets variable
36# - tmp             pathname of freshly created temporary directory
37func_tmpdir ()
38{
39  # Use the environment variable TMPDIR, falling back to /tmp. This allows
40  # users to specify a different temporary directory, for example, if their
41  # /tmp is filled up or too small.
42  : ${TMPDIR=/tmp}
43  {
44    # Use the mktemp program if available. If not available, hide the error
45    # message.
46    tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
47    test -n "$tmp" && test -d "$tmp"
48  } ||
49  {
50    # Use a simple mkdir command. It is guaranteed to fail if the directory
51    # already exists.  $RANDOM is bash specific and expands to empty in shells
52    # other than bash, ksh and zsh.  Its use does not increase security;
53    # rather, it minimizes the probability of failure in a very cluttered /tmp
54    # directory.
55    tmp=$TMPDIR/gt$$-$RANDOM
56    (umask 077 && mkdir "$tmp")
57  } ||
58  {
59    echo "$0: cannot create a temporary directory in $TMPDIR" >&2
60    { (exit 1); exit 1; }
61  }
62}
63
64# Support for relocatability.
65func_find_curr_installdir ()
66{
67  # Determine curr_installdir, even taking into account symlinks.
68  curr_executable="$0"
69  case "$curr_executable" in
70    */* | *\\*) ;;
71    *) # Need to look in the PATH.
72      if test "${PATH_SEPARATOR+set}" != set; then
73        func_tmpdir
74        { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
75        chmod +x "$tmp"/conf.sh
76        if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
77          PATH_SEPARATOR=';'
78        else
79          PATH_SEPARATOR=:
80        fi
81        rm -rf "$tmp"
82      fi
83      save_IFS="$IFS"; IFS="$PATH_SEPARATOR"
84      for dir in $PATH; do
85        IFS="$save_IFS"
86        test -z "$dir" && dir=.
87        for exec_ext in ''; do
88          if test -f "$dir/$curr_executable$exec_ext"; then
89            curr_executable="$dir/$curr_executable$exec_ext"
90            break 2
91          fi
92        done
93      done
94      IFS="$save_IFS"
95      ;;
96  esac
97  # Make absolute.
98  case "$curr_executable" in
99    /* | ?:/* | ?:\\*) ;;
100    *) curr_executable=`pwd`/"$curr_executable" ;;
101  esac
102  # Resolve symlinks.
103  sed_dirname='s,/[^/]*$,,'
104  sed_linkdest='s,^.* -> \(.*\),\1,p'
105  while : ; do
106    lsline=`LC_ALL=C ls -l "$curr_executable"`
107    case "$lsline" in
108      *" -> "*)
109        linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"`
110        case "$linkdest" in
111          /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;;
112          *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;;
113        esac ;;
114      *) break ;;
115    esac
116  done
117  curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'`
118  # Canonicalize.
119  curr_installdir=`cd "$curr_installdir" && pwd`
120}
121func_find_prefixes ()
122{
123  # Compute the original/current installation prefixes by stripping the
124  # trailing directories off the original/current installation directories.
125  orig_installprefix="$orig_installdir"
126  curr_installprefix="$curr_installdir"
127  while true; do
128    orig_last=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
129    curr_last=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
130    if test -z "$orig_last" || test -z "$curr_last"; then
131      break
132    fi
133    if test "$orig_last" != "$curr_last"; then
134      break
135    fi
136    orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'`
137    curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'`
138  done
139}
140if test "no" = yes; then
141  exec_prefix="${prefix}"
142  bindir="${exec_prefix}/bin"
143  orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables
144  func_find_curr_installdir # determine curr_installdir
145  func_find_prefixes
146  # Relocate the directory variables that we use.
147  gettext_dir=`echo "$gettext_dir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'`
148fi
149
150# func_usage
151# outputs to stdout the --help usage message.
152func_usage ()
153{
154  echo "\
155Usage: autopoint [OPTION]...
156
157Copies standard gettext infrastructure files into a source package.
158
159Options:
160      --help           print this help and exit
161      --version        print version information and exit
162  -f, --force          force overwriting of files that already exist
163  -n, --dry-run        print modifications but don't perform them"
164#  echo "\
165#  -V version           copy the infrastructure of the specified gettext version
166#                         (dangerous)"
167  echo "
168Report bugs to <bug-gnu-gettext@gnu.org>."
169}
170
171# func_version
172# outputs to stdout the --version message.
173func_version ()
174{
175  echo "$progname (GNU $package) $version"
176  echo "Uses a versions archive in git format."
177  echo "Copyright (C) 2002-2010 Free Software Foundation, Inc.
178License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
179This is free software: you are free to change and redistribute it.
180There is NO WARRANTY, to the extent permitted by law."
181  echo "Written by" "Bruno Haible"
182}
183
184# func_fatal_error message
185# outputs to stderr a fatal error message, and terminates the program.
186func_fatal_error ()
187{
188  echo "autopoint: *** $1" 1>&2
189  echo "autopoint: *** Stop." 1>&2
190  exit 1
191}
192
193# Command-line option processing.
194# Removes the OPTIONS from the arguments. Sets the variables:
195# - force           yes if --force was given, empty otherwise
196# - ver             gettext version if -V was given, empty otherwise
197# - doit            false if --dry-run was given, : otherwise
198{
199  force=
200  ver=
201  doit=:
202
203  while test $# -gt 0; do
204    case "$1" in
205      -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d )
206        shift
207        doit=false ;;
208      -f | --force | --forc | --for | --fo | --f )
209        shift
210        force=yes ;;
211      --help | --hel | --he | --h )
212        func_usage; exit 0 ;;
213#      -V ) # Some people put a space between -V and the version number.
214#        shift
215#        if test $# = 0; then
216#          func_usage 1>&2
217#          exit 1
218#        fi
219#        ver=$1;
220#        shift ;;
221#      -V*) # Some people omit the space between -V and the version number.
222#        ver=`echo "X$1" | sed -e 's/^X-V//'`
223#        shift ;;
224      --version | --versio | --versi | --vers | --ver | --ve | --v )
225        func_version
226        exit 0 ;;
227      -- ) # Stop option prcessing
228        shift; break ;;
229      -* )
230        echo "autopoint: unknown option $1" 1>&2
231        echo "Try 'autopoint --help' for more information." 1>&2
232        exit 1 ;;
233      * )
234        break ;;
235    esac
236  done
237}
238
239# Command-line argument processing.
240# Analyzes the remaining arguments.
241{
242  if test $# -gt 0; then
243    func_usage 1>&2
244    exit 1
245  fi
246}
247
248srcdir=`pwd`
249# The current directory is now $srcdir.
250
251# Check integrity of package: A configure.in/ac must be present. Sets variable
252# - configure_in    name of configure.in/ac file.
253if test -f configure.in; then
254  configure_in=configure.in
255else
256  if test -f configure.ac; then
257    configure_in=configure.ac
258  else
259    # KDE specific convention: configure.in.in
260    if test -f configure.in.in; then
261      configure_in=configure.in.in
262    else
263      func_fatal_error "Missing configure.in or configure.ac, please cd to your package first."
264    fi
265  fi
266fi
267
268# Check whether the -V option and the version number in configure.in match.
269# At least one of the two must be given. If both are given, they must agree.
270sed_extract_AM_GNU_GETTEXT_VERSION_argument='s/^AM_GNU_GETTEXT_VERSION(\([^()]*\)).*$/\1/'
271sed_remove_outer_brackets='s/^\[\(.*\)\]$/\1/'
272xver=`cat "$configure_in" | grep '^AM_GNU_GETTEXT_VERSION(' | sed -n -e "$sed_extract_AM_GNU_GETTEXT_VERSION_argument"p | sed -e "$sed_remove_outer_brackets" | sed -e 1q`
273if test -z "$xver" && test -f intl/VERSION; then
274  xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'`
275fi
276if test -n "$xver"; then
277  if test -n "$ver"; then
278    if test "X$ver" != "X$xver"; then
279      func_fatal_error "Version mismatch: specified -V $ver but the package uses gettext version $xver"
280    fi
281  else
282    ver="$xver"
283  fi
284else
285  if test -z "$ver"; then
286    func_fatal_error "Missing version: please specify in $configure_in through a line 'AM_GNU_GETTEXT_VERSION(x.yy.zz)' the gettext version the package is using"
287  fi
288fi
289
290# Check whether the version number is supported.
291case "$ver" in
292  0.10.35 | 0.10.36 | 0.10.37 | 0.10.38 | 0.10.39 | 0.10.40 | \
293  0.11 | 0.11.1 | 0.11.2 | 0.11.3 | 0.11.4 | 0.11.5 | \
294  0.12 | 0.12.1 | \
295  0.13 | 0.13.1 | \
296  0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 | \
297  0.15 | \
298  0.16 | 0.16.1 | \
299  0.17 | \
300  0.18 | 0.18.1 )
301    ;;
302  *)
303    func_fatal_error "The AM_GNU_GETTEXT_VERSION declaration in your $configure_in
304               file requires the infrastructure from gettext-$ver but this version
305               is older. Please upgrade to gettext-$ver or newer."
306    ;;
307esac
308
309# Check in which directory config.rpath, mkinstalldirs etc. belong.
310auxdir=`cat "$configure_in" | grep '^AC_CONFIG_AUX_DIR' | sed -n -e 's/AC_CONFIG_AUX_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
311if test -n "$auxdir"; then
312  auxdir="$auxdir/"
313fi
314
315# Check in which directory the *.m4 macros belong.
316m4dir=m4
317if test -f Makefile.am; then
318  # A package using automake.
319  # Extract the macro directory name from Makefile.am.
320  aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ 	]*=' Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ 	]*=\(.*\)$/\1/'`
321  m4dir_is_next=
322  for arg in $aclocal_amflags; do
323    if test -n "$m4dir_is_next"; then
324      m4dir="$arg"
325      break
326    else
327      if test "X$arg" = "X-I"; then
328        m4dir_is_next=yes
329      else
330        m4dir_is_next=
331      fi
332    fi
333  done
334fi
335
336# Check whether to omit the intl/ directory.
337omitintl=`cat "$configure_in" | grep '^AM_GNU_GETTEXT' | sed -n -e 's/^AM_GNU_GETTEXT(\([^(),]*\).*$/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
338omitintl=`if test 'external' = "$omitintl"; then echo yes; fi`
339
340# Check in which directory or directories the po/* infrastructure belongs.
341sed_extract_config_files='s,#.*$,,
342s,^dnl .*$,,
343s, dnl .*$,,
344/AC_CONFIG_FILES(/ {
345  ta
346  :a
347    s/)/)/
348    tb
349    s/\\$//
350    N
351    ba
352  :b
353  s,^.*AC_CONFIG_FILES([[ ]*\([^]"$`\\)]*\).*$,\1,p
354}'
355configfiles=`cat "$configure_in" | sed -n -e "$sed_extract_config_files"`
356# PO directories have a Makefile.in generated from Makefile.in.in.
357# Treat a directory as a PO directory if and only if it has a
358# POTFILES.in file. This allows packages to have multiple PO
359# directories under different names or in different locations.
360sed_remove_Makefile_in='s,/Makefile\.in$,,'
361podirs=`for f in $configfiles; do case "$f" in */Makefile.in) echo $f;; esac; done | sed -e "$sed_remove_Makefile_in"`
362if test -z "$podirs"; then
363  # If we cannot get the list of PO directories from configure.ac, assume the
364  # common default.
365  podirs="po"
366fi
367
368# Set up a temporary checkout directory.
369# Set variables
370# - work_dir        directory containing the temporary checkout
371work_dir=tmpwrk$$
372mkdir "$work_dir" || {
373  if test -d "$work_dir"; then
374    func_fatal_error "directory $work_dir already exists"
375  else
376    func_fatal_error "cannot create directory $work_dir"
377  fi
378}
379
380# We support three archive formats.
381#
382# Format | Size (KiB) for gettext-0.17 | Extra tools needed |
383# -------+-----------------------------+--------------------+
384#  dir   |            3000             |         --         |
385#  cvs   |             356             |         cvs        |
386#  git   |             484             |         git        |
387# -------+-----------------------------+--------------------+
388
389case "git" in
390  dir)
391    # The archive of different versions is very large, but using it does not
392    # require special tools.
393    gzip -d -c < "$gettext_dir/archive.dir.tar.gz" | (cd "$work_dir" && tar xf - "gettext-$ver")
394    if test `find "$work_dir" -type f -print | wc -l` = 0; then
395      rm -rf "$work_dir"
396      func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
397    fi
398    mv "$work_dir/gettext-$ver" "$work_dir/archive"
399    ;;
400
401  cvs)
402    # We distributed the many different versions of the files in a CVS
403    # repository. This guaranteed a good compression rate:
404    #
405    #   Including version    size in KB of
406    #                       "du autopoint-files/archive"
407    #      0.10.35                  240
408    #      0.10.36                  428
409    #      0.10.37                  436
410    #      0.10.38                  488
411    #      0.10.39                  500
412    #      0.10.40                  528
413    #      0.11                     720
414    #      0.11.1                   740
415    #      0.11.2                   748
416    #      0.11.3                   804
417    #      0.11.4                   864
418    #      0.11.5                   880
419    #      0.12                    1032
420    #      0.12.1                  1032
421    #      0.13                    1220
422    #      0.13.1                  1236
423    #      0.14                    1296
424    #      0.14.1                  1300
425    #      0.14.2                  1420
426    #      0.14.3                  1428
427    #      0.14.4                  1464
428    #      0.14.5                  1508
429    #      0.14.6                  1580
430    #      0.15                    1760
431    #      0.16                    1808
432    #      0.16.1                  1812
433    #      0.17                    2128
434    #      0.18                    2656
435    #
436    # The requirement that the user must have the CVS program available is not
437    # a severe restrictions, because most of the people who use autopoint are
438    # users of CVS.
439    #
440    # But the CVS format is now deprecated, because "cvs init" does not work in
441    # all circumstances
442    # (see <http://lists.gnu.org/archive/html/bug-cvs/2010-05/msg00003.html>)
443    # and we are not allowed to distribute the cvs infrastructure files
444    # ourselves
445    # (see <http://lists.gnu.org/archive/html/bug-cvs/2010-06/msg00011.html>).
446    #
447    # Check availability of the CVS program.
448    (cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found"
449
450    # Set up a temporary CVS repository.
451    # We need the temporary CVS repository because any checkout needs write
452    # access to the CVSROOT/history file, so it cannot be under $gettext_dir.
453    # We need the temporary checkout directory because when --force was not
454    # given, we need to compare the existing files with the checked out ones.
455    # Set variables
456    # - cvs_dir         directory containing the temporary repository
457    cvs_dir=tmpcvs$$
458    # Use an umask of 077, to avoid attacks that work by overwriting files in
459    # the "$CVSROOT"/CVSROOT directory.
460    (umask 077 && mkdir "$cvs_dir") || {
461      if test -d "$cvs_dir"; then
462        func_fatal_error "directory $cvs_dir already exists"
463      else
464        func_fatal_error "cannot create directory $cvs_dir"
465      fi
466    }
467    CVSROOT="$srcdir/$cvs_dir"
468    unset CVS_CLIENT_LOG
469    unset CVS_CLIENT_PORT
470    unset CVS_IGNORE_REMOTE_ROOT
471    unset CVS_LOCAL_BRANCH_NUM
472    unset CVS_NOBASES
473    unset CVS_PASSFILE
474    unset CVS_PASSWORD
475    unset CVS_PROXY_PORT
476    unset CVS_RCMD_PORT
477    unset CVS_RSH
478    unset CVS_SERVER
479    unset CVS_SERVER_SLEEP
480    CVS_SIGN_COMMITS=
481    export CVS_SIGN_COMMITS
482    unset CVS_SSH
483    unset CVS_VERIFY_CHECKOUTS
484    unset CVS_VERIFY_TEMPLATE
485    unset CVSIGNORE
486    unset CVSREAD
487    unset CVSREADONLYFS
488    unset CVSUMASK
489    unset CVSWRAPPERS
490
491    # Need to pass -d "$CVSROOT", because there may be a CVS directory in the
492    # current directory.
493    cvs -d "$CVSROOT" init
494    gzip -d -c < "$gettext_dir/archive.cvs.tar.gz" | (cd "$cvs_dir" && tar xf -)
495
496    cd "$work_dir"
497    cvsver=gettext-`echo "$ver" | sed -e 's/\./_/g'`
498    (cvs -d "$CVSROOT" checkout -r"$cvsver" archive > /dev/null) 2>&1 | grep -v '^cvs checkout: Updating'
499    find archive -name CVS -type d -print | xargs rm -rf
500    cd ..
501    rm -rf "$cvs_dir"
502    # Check that really all CVS directories are gone, otherwise we would overwrite
503    # the contents of the user's CVS directories.
504    if test `find $work_dir/archive -name CVS -type d -print | wc -l` != 0; then
505      rm -rf "$work_dir"
506      func_fatal_error "failed to remove all CVS subdirectories"
507    fi
508    if test `find $work_dir/archive -type f -print | wc -l` = 0; then
509      rm -rf "$work_dir"
510      func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
511    fi
512    ;;
513
514  git)
515    # Check availability of the git program.
516    (git --version) >/dev/null 2>/dev/null || func_fatal_error "git program not found"
517    mkdir "$work_dir/archive"
518    gzip -d -c < "$gettext_dir/archive.git.tar.gz" | (cd "$work_dir/archive" && tar xf -)
519    (cd "$work_dir/archive" && git checkout -q "gettext-$ver") || {
520      rm -rf "$work_dir"
521      func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
522    }
523    (cd "$work_dir/archive" && rm -rf .git .gitignore)
524    ;;
525esac
526
527# func_destfile file
528# determines the destination file, relative to the package's top level
529# directory, for a given file name, relative to archive.
530# Sets variables
531# - destfile        relative destination file name, or
532#                   empty if the file shall be omitted
533# - sharedowner     yes if the file is not only owned by GNU gettext but may
534#                   be installed by automake or other tools, otherwise empty
535# - allpodirs       yes if the file is to be installed in every dir in $podirs
536func_destfile ()
537{
538  # There are five categories of files:
539  # ABOUT_NLS -> top level directory
540  # config.rpath mkinstalldirs -> $auxdir
541  # m4/* -> $m4dir/
542  # intl/* -> intl/
543  # po/* ->
544  sharedowner=
545  allpodirs=
546  case `echo "$1" | sed -e 's,[^/]*$,,'` in
547    "" )
548      case "$1" in
549        config.rpath ) destfile="$auxdir$1" ;;
550        mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;;
551        * ) destfile="$1" ;;
552      esac
553      ;;
554    m4/ ) destfile=`echo "$1" | sed -e "s,^m4/,$m4dir/,"` ;;
555    intl/ ) if test -n "$omitintl"; then destfile=""; else destfile="$1"; fi ;;
556    po/ ) destfile=`echo "$1" | sed -e "s,^po/,,"` allpodirs=yes ;;
557    * ) destfile="$1" ;;
558  esac
559}
560
561# func_compare existingfile gettextfile
562# compares the existing file and the file from gettext, and decides whether the
563# existing file should be overwritten with the file from gettext. Returns 0 if
564# it should be overwritten, or 1 if it should be skipped.
565sed_extract_serial='s/^#.* serial \([^ ]*\).*/\1/p
5661q'
567func_compare ()
568{
569  if cmp -s "$1" "$2"; then
570    false
571  else
572    case "$2" in
573      *.m4)
574        # For interoperability with gnulib. gnulib often has newer versions of
575        # the *.m4 files than the latest gettext release. Don't overwrite a
576        # newer version from gnulib with an older version from the gettext
577        # release. The version can be retrieved from the first line, which
578        # looks like this:   # file.m4 serial NN ...
579        existing_serial=`sed -n -e "$sed_extract_serial" < "$1"`
580        gettext_serial=`sed -n -e "$sed_extract_serial" < "$2"`
581        if test -n "$existing_serial" && test -n "$gettext_serial" \
582           && test "$existing_serial" -ge "$gettext_serial" 2> /dev/null; then
583          false
584        else
585          true
586        fi
587        ;;
588      *)
589        true
590        ;;
591    esac
592  fi
593}
594
595# If some files have been locally modified and we have not been requested
596# to overwrite them, then bail out. This is better than leaving a source
597# package around where half of the files are locally modified and half are
598# original - too great risk of version mismatch.
599if test -z "$force"; then
600  mismatch=
601  func_tmpdir
602  mismatchfile="$tmp"/autopoint.diff
603  for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
604    func_destfile "$file"
605    if test -n "$destfile"; then
606      func_compare_to_destfile ()
607      {
608        finaldestfile="$1"
609        if test -f "$finaldestfile"; then
610          if func_compare "$finaldestfile" "$work_dir/archive/$file"; then
611            if test -n "$sharedowner"; then
612              echo "autopoint: warning: File $finaldestfile has been locally modified." 1>&2
613            else
614              echo "autopoint: File $finaldestfile has been locally modified." 1>&2
615              mismatch=yes
616              diff -c "$work_dir/archive/$file" "$finaldestfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile"
617            fi
618          fi
619        fi
620      }
621      if test -n "$allpodirs"; then
622        for dir in $podirs; do
623          func_compare_to_destfile "$dir/$destfile"
624        done
625      else
626        func_compare_to_destfile "$destfile"
627      fi
628    fi
629  done
630  if test -n "$mismatch"; then
631    rm -rf "$work_dir"
632    func_fatal_error "Some files have been locally modified. Not overwriting them because --force has not been specified. For your convenience, you find the local modifications in the file '$mismatchfile'."
633  fi
634  rm -rf "$tmp"
635fi
636
637# func_mkdir_for to
638# ensures the directory that would the given file exists.
639# 'to' is a relative pathname, relative to the current directory.
640func_mkdir_for ()
641{
642  base=`echo "$1" | sed -e 's,/[^/]*$,,'`
643  if test "X$base" != "X$1" && test -n "$base"; then
644    func_mkdir_for "$base"
645    # Recompute base. It was clobbered by the recursive call.
646    base=`echo "$1" | sed -e 's,/[^/]*$,,'`
647    test -d "$base" || { echo "Creating directory $base"; mkdir "$base"; }
648  fi
649}
650
651# func_copy from to
652# copies a file.
653# 'from' is a relative pathname, relative to the current directory.
654# 'to' is a relative pathname, relative to the current directory.
655func_copy ()
656{
657  if $doit; then
658    func_mkdir_for "$2"
659    rm -f "$2"
660    echo "Copying file $2"
661    cp "$1" "$2"
662  else
663    echo "Copy file $2"
664  fi
665}
666
667# func_backup to
668# makes a backup of a file that is about to be overwritten or replaced.
669# 'to' is a relative pathname, relative to the current directory.
670func_backup ()
671{
672  if $doit; then
673    if test -f "$1"; then
674      rm -f "$1~"
675      cp -p "$1" "$1~"
676    fi
677  fi
678}
679
680# Now copy the files.
681for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
682  func_destfile "$file"
683  if test -n "$destfile"; then
684    func_copy_to_destfile ()
685    {
686      finaldestfile="$1"
687      mustcopy=
688      if test -f "$finaldestfile"; then
689        if func_compare "$finaldestfile" "$work_dir/archive/$file"; then
690          if test -n "$force"; then
691            # Overwrite locally modified file.
692            mustcopy=yes
693          fi
694          # If --force is not specified, don't overwrite locally modified files
695          # for which GNU gettext is a shared owner.
696        fi
697      else
698        mustcopy=yes
699      fi
700      if test -n "$mustcopy"; then
701        func_backup "$finaldestfile"
702        func_copy "$work_dir/archive/$file" "$finaldestfile"
703      fi
704    }
705    if test -n "$allpodirs"; then
706      for dir in $podirs; do
707        func_copy_to_destfile "$dir/$destfile"
708      done
709    else
710      func_copy_to_destfile "$destfile"
711    fi
712  fi
713done
714
715# That's it.
716rm -rf "$work_dir"
717exit 0
718