• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/ap/gpl/timemachine/gettext-0.17/gettext-tools/misc/
1#! /bin/sh
2#
3# Copyright (C) 2002-2007 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.17
26
27# Set variables
28# - gettext_dir     directory where the sources are stored.
29prefix="/usr"
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 "Copyright (C) 2002-2007 Free Software Foundation, Inc.
177License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
178This is free software: you are free to change and redistribute it.
179There is NO WARRANTY, to the extent permitted by law."
180  echo "Written by" "Bruno Haible"
181}
182
183# func_fatal_error message
184# outputs to stderr a fatal error message, and terminates the program.
185func_fatal_error ()
186{
187  echo "autopoint: *** $1" 1>&2
188  echo "autopoint: *** Stop." 1>&2
189  exit 1
190}
191
192# Command-line option processing.
193# Removes the OPTIONS from the arguments. Sets the variables:
194# - force           yes if --force was given, empty otherwise
195# - ver             gettext version if -V was given, empty otherwise
196# - doit            false if --dry-run was given, : otherwise
197{
198  force=
199  ver=
200  doit=:
201
202  while test $# -gt 0; do
203    case "$1" in
204      -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d )
205        shift
206        doit=false ;;
207      -f | --force | --forc | --for | --fo | --f )
208        shift
209        force=yes ;;
210      --help | --hel | --he | --h )
211        func_usage; exit 0 ;;
212#      -V ) # Some people put a space between -V and the version number.
213#        shift
214#        if test $# = 0; then
215#          func_usage 1>&2
216#          exit 1
217#        fi
218#        ver=$1;
219#        shift ;;
220#      -V*) # Some people omit the space between -V and the version number.
221#        ver=`echo "X$1" | sed -e 's/^X-V//'`
222#        shift ;;
223      --version | --versio | --versi | --vers | --ver | --ve | --v )
224        func_version
225        exit 0 ;;
226      -- ) # Stop option prcessing
227        shift; break ;;
228      -* )
229        echo "autopoint: unknown option $1" 1>&2
230        echo "Try 'autopoint --help' for more information." 1>&2
231        exit 1 ;;
232      * )
233        break ;;
234    esac
235  done
236}
237
238# Command-line argument processing.
239# Analyzes the remaining arguments.
240{
241  if test $# -gt 0; then
242    func_usage 1>&2
243    exit 1
244  fi
245}
246
247srcdir=`pwd`
248# The current directory is now $srcdir.
249
250# Check integrity of package: A configure.in/ac must be present. Sets variable
251# - configure_in    name of configure.in/ac file.
252if test -f configure.in; then
253  configure_in=configure.in
254else
255  if test -f configure.ac; then
256    configure_in=configure.ac
257  else
258    # KDE specific convention: configure.in.in
259    if test -f configure.in.in; then
260      configure_in=configure.in.in
261    else
262      func_fatal_error "Missing configure.in or configure.ac, please cd to your package first."
263    fi
264  fi
265fi
266
267# Check whether the -V option and the version number in configure.in match.
268# At least one of the two must be given. If both are given, they must agree.
269xver=`cat "$configure_in" | grep '^AM_GNU_GETTEXT_VERSION(' | sed -e 's/^AM_GNU_GETTEXT_VERSION(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
270if test -z "$xver" && test -f intl/VERSION; then
271  xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'`
272fi
273if test -n "$xver"; then
274  if test -n "$ver"; then
275    if test "X$ver" != "X$xver"; then
276      func_fatal_error "Version mismatch: specified -V $ver but the package uses gettext version $xver"
277    fi
278  else
279    ver="$xver"
280  fi
281else
282  if test -z "$ver"; then
283    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"
284  fi
285fi
286
287# Check whether the version number is supported.
288case "$ver" in
289  0.10.35 | 0.10.36 | 0.10.37 | 0.10.38 | 0.10.39 | 0.10.40 | \
290  0.11 | 0.11.1 | 0.11.2 | 0.11.3 | 0.11.4 | 0.11.5 | \
291  0.12 | 0.12.1 | \
292  0.13 | 0.13.1 | \
293  0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 | \
294  0.15 | \
295  0.16 | 0.16.1 | \
296  0.17 )
297    ;;
298  *)
299    func_fatal_error "The AM_GNU_GETTEXT_VERSION declaration in your $configure_in\
300               file requires the infrastructure from gettext-$ver but this version\
301               is older. Please upgrade to gettext-$ver or newer."
302    ;;
303esac
304
305# We distribute the many different versions of the files in a CVS repository.
306# This guarantees a good compression rate:
307#
308#   Including version    size in KB of
309#                       "du autopoint-files/archive"
310#      0.10.35                  240
311#      0.10.36                  428
312#      0.10.37                  436
313#      0.10.38                  488
314#      0.10.39                  500
315#      0.10.40                  528
316#      0.11                     720
317#      0.11.1                   740
318#      0.11.2                   748
319#      0.11.3                   804
320#      0.11.4                   864
321#      0.11.5                   880
322#      0.12                    1032
323#      0.12.1                  1032
324#      0.13                    1220
325#      0.13.1                  1236
326#      0.14                    1296
327#      0.14.1                  1300
328#      0.14.2                  1420
329#      0.14.3                  1428
330#      0.14.4                  1464
331#      0.14.5                  1508
332#      0.14.6                  1580
333#      0.15                    1760
334#      0.16                    1808
335#      0.16.1                  1812
336#      0.17                    2128
337#
338# The requirement that the user must have the CVS program available is not
339# a severe restrictions, because most of the people who use autopoint are
340# users of CVS.
341#
342# Check availability of the CVS program.
343(cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found"
344
345# Check in which directory config.rpath, mkinstalldirs etc. belong.
346auxdir=`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`
347if test -n "$auxdir"; then
348  auxdir="$auxdir/"
349fi
350
351# Check in which directory the *.m4 macros belong.
352m4dir=m4
353if test -f Makefile.am; then
354  # A package using automake.
355  # Extract the macro directory name from Makefile.am.
356  aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ 	]*=' Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ 	]*=\(.*\)$/\1/'`
357  m4dir_is_next=
358  for arg in $aclocal_amflags; do
359    if test -n "$m4dir_is_next"; then
360      m4dir="$arg"
361      break
362    else
363      if test "X$arg" = "X-I"; then
364        m4dir_is_next=yes
365      else
366        m4dir_is_next=
367      fi
368    fi
369  done
370fi
371
372# Check whether to omit the intl/ directory.
373omitintl=`cat "$configure_in" | grep '^AM_GNU_GETTEXT' | sed -n -e 's/^AM_GNU_GETTEXT(\([^(),]*\).*$/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
374omitintl=`if test 'external' = "$omitintl"; then echo yes; fi`
375
376# Set up a temporary CVS repository and a temporary checkout directory.
377# We need the temporary CVS repository because any checkout needs write
378# access to the CVSROOT/history file, so it cannot be under $gettext_dir.
379# We need the temporary checkout directory because when --force was not
380# given, we need to compare the existing files with the checked out ones.
381# Set variables
382# - cvs_dir         directory containing the temporary repository
383# - work_dir        directory containing the temporary checkout
384cvs_dir=tmpcvs$$
385work_dir=tmpwrk$$
386# Use an umask of 077, to avoid attacks that work by overwriting files in the
387# "$CVSROOT"/CVSROOT directory.
388(umask 077 && mkdir "$cvs_dir") || {
389  if test -d "$cvs_dir"; then
390    func_fatal_error "directory $cvs_dir already exists"
391  else
392    func_fatal_error "cannot create directory $cvs_dir"
393  fi
394}
395mkdir "$work_dir" || {
396  if test -d "$work_dir"; then
397    func_fatal_error "directory $work_dir already exists"
398  else
399    func_fatal_error "cannot create directory $work_dir"
400  fi
401}
402CVSROOT="$srcdir/$cvs_dir"
403export CVSROOT
404unset CVS_CLIENT_LOG
405unset CVS_CLIENT_PORT
406unset CVS_IGNORE_REMOTE_ROOT
407unset CVS_PASSFILE
408unset CVS_PASSWORD
409unset CVS_RCMD_PORT
410unset CVS_RSH
411unset CVS_SERVER
412unset CVS_SERVER_SLEEP
413unset CVSIGNORE
414unset CVSREAD
415unset CVSUMASK
416unset CVSWRAPPERS
417
418# Need to pass -d "$CVSROOT", because there may be a CVS directory in the
419# current directory.
420cvs -d "$CVSROOT" init
421gzip -d -c < "$gettext_dir/archive.tar.gz" | (cd "$cvs_dir" && tar xf -)
422
423cd "$work_dir"
424cvsver=gettext-`echo "$ver" | sed -e 's/\./_/g'`
425(cvs checkout -r"$cvsver" archive > /dev/null) 2>&1 | grep -v '^cvs checkout: Updating'
426find archive -name CVS -type d -print | xargs rm -rf
427if test `find archive -type f -print | wc -l` = 0; then
428  cd ..
429  rm -rf "$cvs_dir" "$work_dir"
430  func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
431fi
432cd ..
433
434# func_destfile file
435# determines the destination file, relative to the package's top level
436# directory, for a given file name, relative to archive.
437# Sets variables
438# - destfile        relative destination file name, or
439#                   empty if the file shall be omitted
440# - sharedowner     yes if the file is not only owned by GNU gettext but may
441#                   be installed by automake or other tools, otherwise empty
442func_destfile ()
443{
444  # There are five categories of files:
445  # ABOUT_NLS -> top level directory
446  # config.rpath mkinstalldirs -> $auxdir
447  # m4/* -> $m4dir/
448  # intl/* -> intl/
449  # po/* -> po/
450  sharedowner=
451  case `echo "$1" | sed -e 's,[^/]*$,,'` in
452    "" )
453      case "$1" in
454        config.rpath ) destfile="$auxdir$1" ;;
455        mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;;
456        * ) destfile="$1" ;;
457      esac
458      ;;
459    m4/ ) destfile=`echo "$1" | sed -e "s,^m4/,$m4dir/,"` ;;
460    intl/ ) if test -n "$omitintl"; then destfile=""; else destfile="$1"; fi ;;
461    * ) destfile="$1" ;;
462  esac
463}
464
465# If some files have been locally modified and we have not been requested
466# to overwrite them, then bail out. This is better than leaving a source
467# package around where half of the files are locally modified and half are
468# original - too great risk of version mismatch.
469if test -z "$force"; then
470  mismatch=
471  func_tmpdir
472  mismatchfile="$tmp"/autopoint.diff
473  for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
474    func_destfile "$file"
475    if test -n "$destfile"; then
476      if test -f "$destfile"; then
477        if cmp -s "$work_dir/archive/$file" "$destfile"; then
478          :
479        else
480          if test -n "$sharedowner"; then
481            echo "autopoint: warning: File $destfile has been locally modified." 1>&2
482          else
483            echo "autopoint: File $destfile has been locally modified." 1>&2
484            mismatch=yes
485            diff -c "$work_dir/archive/$file" "$destfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile"
486          fi
487        fi
488      fi
489    fi
490  done
491  if test -n "$mismatch"; then
492    rm -rf "$cvs_dir" "$work_dir"
493    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'."
494  fi
495  rm -rf "$tmp"
496fi
497
498# func_mkdir_for to
499# ensures the directory that would the given file exists.
500# 'to' is a relative pathname, relative to the current directory.
501func_mkdir_for ()
502{
503  base=`echo "$1" | sed -e 's,/[^/]*$,,'`
504  if test "X$base" != "X$1" && test -n "$base"; then
505    func_mkdir_for "$base"
506    # Recompute base. It was clobbered by the recursive call.
507    base=`echo "$1" | sed -e 's,/[^/]*$,,'`
508    test -d "$base" || { echo "Creating directory $base"; mkdir "$base"; }
509  fi
510}
511
512# func_copy from to
513# copies a file.
514# 'from' is a relative pathname, relative to the current directory.
515# 'to' is a relative pathname, relative to the current directory.
516func_copy ()
517{
518  if $doit; then
519    func_mkdir_for "$2"
520    rm -f "$2"
521    echo "Copying file $2"
522    cp "$1" "$2"
523  else
524    echo "Copy file $2"
525  fi
526}
527
528# func_backup to
529# makes a backup of a file that is about to be overwritten or replaced.
530# 'to' is a relative pathname, relative to the current directory.
531func_backup ()
532{
533  if $doit; then
534    if test -f "$1"; then
535      rm -f "$1~"
536      cp -p "$1" "$1~"
537    fi
538  fi
539}
540
541# Now copy the files.
542for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
543  func_destfile "$file"
544  mustcopy=
545  if test -n "$destfile"; then
546    if test -f "$destfile"; then
547      if cmp -s "$work_dir/archive/$file" "$destfile"; then
548        :
549      else
550        if test -n "$force"; then
551          # Overwrite locally modified file.
552          mustcopy=yes
553        fi
554        # If --force is not specified, don't overwrite locally modified files
555        # for which GNU gettext is a shared owner.
556      fi
557    else
558      mustcopy=yes
559    fi
560  fi
561  if test -n "$mustcopy"; then
562    func_backup "$destfile"
563    func_copy "$work_dir/archive/$file" "$destfile"
564  fi
565done
566
567# That's it.
568rm -rf "$cvs_dir" "$work_dir"
569exit 0
570