3 # Copyright (C) 2002-2010 Free Software Foundation, Inc.
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.
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.
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/>.
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.
28 # - gettext_dir directory where the sources are stored.
30 datarootdir="@datarootdir@"
31 gettext_dir="@datadir@/gettext"
34 # creates a temporary directory.
36 # - tmp pathname of freshly created temporary directory
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.
44 # Use the mktemp program if available. If not available, hide the error
46 tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
47 test -n "$tmp" && test -d "$tmp"
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
55 tmp=$TMPDIR/gt$$-$RANDOM
56 (umask 077 && mkdir "$tmp")
59 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
64 # Support for relocatability.
65 func_find_curr_installdir ()
67 # Determine curr_installdir, even taking into account symlinks.
69 case "$curr_executable" in
71 *) # Need to look in the PATH.
72 if test "${PATH_SEPARATOR+set}" != set; then
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
83 save_IFS="$IFS"; IFS="$PATH_SEPARATOR"
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"
98 case "$curr_executable" in
100 *) curr_executable=`pwd`/"$curr_executable" ;;
103 sed_dirname='s,/[^/]*$,,'
104 sed_linkdest='s,^.* -> \(.*\),\1,p'
106 lsline=`LC_ALL=C ls -l "$curr_executable"`
109 linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"`
111 /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;;
112 *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;;
117 curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'`
119 curr_installdir=`cd "$curr_installdir" && pwd`
121 func_find_prefixes ()
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"
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
133 if test "$orig_last" != "$curr_last"; then
136 orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'`
137 curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'`
140 if test "@RELOCATABLE@" = yes; then
141 exec_prefix="@exec_prefix@"
143 orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables
144 func_find_curr_installdir # determine curr_installdir
146 # Relocate the directory variables that we use.
147 gettext_dir=`echo "$gettext_dir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'`
151 # outputs to stdout the --help usage message.
155 Usage: autopoint [OPTION]...
157 Copies standard gettext infrastructure files into a source package.
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"
165 # -V version copy the infrastructure of the specified gettext version
168 Report bugs to <bug-gnu-gettext@gnu.org>."
172 # outputs to stdout the --version message.
175 echo "$progname (GNU $package) $version"
176 echo "Uses a versions archive in @ARCHIVE_FORMAT@ format."
177 echo "Copyright (C) 2002-2010 Free Software Foundation, Inc.
178 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
179 This is free software: you are free to change and redistribute it.
180 There is NO WARRANTY, to the extent permitted by law."
181 echo "Written by" "Bruno Haible"
184 # func_fatal_error message
185 # outputs to stderr a fatal error message, and terminates the program.
188 echo "autopoint: *** $1" 1>&2
189 echo "autopoint: *** Stop." 1>&2
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
203 while test $# -gt 0; do
205 -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d )
208 -f | --force | --forc | --for | --fo | --f )
211 --help | --hel | --he | --h )
212 func_usage; exit 0 ;;
213 # -V ) # Some people put a space between -V and the version number.
215 # if test $# = 0; then
221 # -V*) # Some people omit the space between -V and the version number.
222 # ver=`echo "X$1" | sed -e 's/^X-V//'`
224 --version | --versio | --versi | --vers | --ver | --ve | --v )
227 -- ) # Stop option prcessing
230 echo "autopoint: unknown option $1" 1>&2
231 echo "Try 'autopoint --help' for more information." 1>&2
239 # Command-line argument processing.
240 # Analyzes the remaining arguments.
242 if test $# -gt 0; then
249 # The current directory is now $srcdir.
251 # Check integrity of package: A configure.in/ac must be present. Sets variable
252 # - configure_in name of configure.in/ac file.
253 if test -f configure.in; then
254 configure_in=configure.in
256 if test -f configure.ac; then
257 configure_in=configure.ac
259 # KDE specific convention: configure.in.in
260 if test -f configure.in.in; then
261 configure_in=configure.in.in
263 func_fatal_error "Missing configure.in or configure.ac, please cd to your package first."
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.
270 sed_extract_AM_GNU_GETTEXT_VERSION_argument='s/^AM_GNU_GETTEXT_VERSION(\([^()]*\)).*$/\1/'
271 sed_remove_outer_brackets='s/^\[\(.*\)\]$/\1/'
272 xver=`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`
273 if 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'`
276 if 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"
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"
290 # Check whether the version number is supported.
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 | \
296 0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 | \
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."
309 # Check in which directory config.rpath, mkinstalldirs etc. belong.
310 auxdir=`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`
311 if test -n "$auxdir"; then
315 # Check in which directory the *.m4 macros belong.
317 if 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/'`
322 for arg in $aclocal_amflags; do
323 if test -n "$m4dir_is_next"; then
327 if test "X$arg" = "X-I"; then
336 # Check whether to omit the intl/ directory.
337 omitintl=`cat "$configure_in" | grep '^AM_GNU_GETTEXT' | sed -n -e 's/^AM_GNU_GETTEXT(\([^(),]*\).*$/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
338 omitintl=`if test 'external' = "$omitintl"; then echo yes; fi`
340 # Check in which directory or directories the po/* infrastructure belongs.
341 sed_extract_config_files='s,#.*$,,
353 s,^.*AC_CONFIG_FILES([[ ]*\([^]"$`\\)]*\).*$,\1,p
355 configfiles=`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.
360 sed_remove_Makefile_in='s,/Makefile\.in$,,'
361 podirs=`for f in $configfiles; do case "$f" in */Makefile.in) echo $f;; esac; done | sed -e "$sed_remove_Makefile_in"`
362 if test -z "$podirs"; then
363 # If we cannot get the list of PO directories from configure.ac, assume the
368 # Set up a temporary checkout directory.
370 # - work_dir directory containing the temporary checkout
372 mkdir "$work_dir" || {
373 if test -d "$work_dir"; then
374 func_fatal_error "directory $work_dir already exists"
376 func_fatal_error "cannot create directory $work_dir"
380 # We support three archive formats.
382 # Format | Size (KiB) for gettext-0.17 | Extra tools needed |
383 # -------+-----------------------------+--------------------+
387 # -------+-----------------------------+--------------------+
389 case "@ARCHIVE_FORMAT@" in
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
396 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
398 mv "$work_dir/gettext-$ver" "$work_dir/archive"
402 # We distributed the many different versions of the files in a CVS
403 # repository. This guaranteed a good compression rate:
405 # Including version size in KB of
406 # "du autopoint-files/archive"
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
440 # But the CVS format is now deprecated, because "cvs init" does not work in
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
445 # (see <http://lists.gnu.org/archive/html/bug-cvs/2010-06/msg00011.html>).
447 # Check availability of the CVS program.
448 (cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found"
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.
456 # - cvs_dir directory containing the temporary repository
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"
464 func_fatal_error "cannot create directory $cvs_dir"
467 CVSROOT="$srcdir/$cvs_dir"
469 unset CVS_CLIENT_PORT
470 unset CVS_IGNORE_REMOTE_ROOT
471 unset CVS_LOCAL_BRANCH_NUM
479 unset CVS_SERVER_SLEEP
481 export CVS_SIGN_COMMITS
483 unset CVS_VERIFY_CHECKOUTS
484 unset CVS_VERIFY_TEMPLATE
491 # Need to pass -d "$CVSROOT", because there may be a CVS directory in the
493 cvs -d "$CVSROOT" init
494 gzip -d -c < "$gettext_dir/archive.cvs.tar.gz" | (cd "$cvs_dir" && tar xf -)
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
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
506 func_fatal_error "failed to remove all CVS subdirectories"
508 if test `find $work_dir/archive -type f -print | wc -l` = 0; then
510 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
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") || {
521 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
523 (cd "$work_dir/archive" && rm -rf .git .gitignore)
528 # determines the destination file, relative to the package's top level
529 # directory, for a given file name, relative to archive.
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
538 # There are five categories of files:
539 # ABOUT_NLS -> top level directory
540 # config.rpath mkinstalldirs -> $auxdir
546 case `echo "$1" | sed -e 's,[^/]*$,,'` in
549 config.rpath ) destfile="$auxdir$1" ;;
550 mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;;
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 ;;
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.
565 sed_extract_serial='s/^#.* serial \([^ ]*\).*/\1/p
569 if cmp -s "$1" "$2"; then
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
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.
599 if test -z "$force"; then
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 ()
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
614 echo "autopoint: File $finaldestfile has been locally modified." 1>&2
616 diff -c "$work_dir/archive/$file" "$finaldestfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile"
621 if test -n "$allpodirs"; then
622 for dir in $podirs; do
623 func_compare_to_destfile "$dir/$destfile"
626 func_compare_to_destfile "$destfile"
630 if test -n "$mismatch"; then
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'."
638 # ensures the directory that would the given file exists.
639 # 'to' is a relative pathname, relative to the current directory.
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"; }
653 # 'from' is a relative pathname, relative to the current directory.
654 # 'to' is a relative pathname, relative to the current directory.
660 echo "Copying file $2"
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.
673 if test -f "$1"; then
680 # Now copy the files.
681 for 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 ()
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.
694 # If --force is not specified, don't overwrite locally modified files
695 # for which GNU gettext is a shared owner.
700 if test -n "$mustcopy"; then
701 func_backup "$finaldestfile"
702 func_copy "$work_dir/archive/$file" "$finaldestfile"
705 if test -n "$allpodirs"; then
706 for dir in $podirs; do
707 func_copy_to_destfile "$dir/$destfile"
710 func_copy_to_destfile "$destfile"