3 # Copyright (C) 2002-2015 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.
26 archive_version=@ARCHIVE_VERSION@
29 # - gettext_datadir directory where the data files are stored.
31 datarootdir="@datarootdir@"
32 : ${gettext_datadir="@datadir@/gettext"}
33 : ${AUTOM4TE=autom4te}
36 # creates a temporary directory.
38 # - tmp pathname of freshly created temporary directory
41 # Use the environment variable TMPDIR, falling back to /tmp. This allows
42 # users to specify a different temporary directory, for example, if their
43 # /tmp is filled up or too small.
46 # Use the mktemp program if available. If not available, hide the error
48 tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
49 test -n "$tmp" && test -d "$tmp"
52 # Use a simple mkdir command. It is guaranteed to fail if the directory
53 # already exists. $RANDOM is bash specific and expands to empty in shells
54 # other than bash, ksh and zsh. Its use does not increase security;
55 # rather, it minimizes the probability of failure in a very cluttered /tmp
57 tmp=$TMPDIR/gt$$-$RANDOM
58 (umask 077 && mkdir "$tmp")
61 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
66 # Support for relocatability.
67 func_find_curr_installdir ()
69 # Determine curr_installdir, even taking into account symlinks.
71 case "$curr_executable" in
73 *) # Need to look in the PATH.
74 save_IFS="$IFS"; IFS="${PATH_SEPARATOR='@PATH_SEPARATOR@'}"
77 test -z "$dir" && dir=.
78 for exec_ext in ''; do
79 if test -f "$dir/$curr_executable$exec_ext"; then
80 curr_executable="$dir/$curr_executable$exec_ext"
89 case "$curr_executable" in
91 *) curr_executable=`pwd`/"$curr_executable" ;;
94 sed_dirname='s,/[^/]*$,,'
95 sed_linkdest='s,^.* -> \(.*\),\1,p'
97 lsline=`LC_ALL=C ls -l "$curr_executable"`
100 linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"`
102 /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;;
103 *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;;
108 curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'`
110 curr_installdir=`cd "$curr_installdir" && pwd`
112 func_find_prefixes ()
114 # Compute the original/current installation prefixes by stripping the
115 # trailing directories off the original/current installation directories.
116 orig_installprefix="$orig_installdir"
117 curr_installprefix="$curr_installdir"
119 orig_last=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
120 curr_last=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
121 if test -z "$orig_last" || test -z "$curr_last"; then
124 if test "$orig_last" != "$curr_last"; then
127 orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'`
128 curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'`
131 if test "@RELOCATABLE@" = yes; then
132 exec_prefix="@exec_prefix@"
134 orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables
135 func_find_curr_installdir # determine curr_installdir
137 # Relocate the directory variables that we use.
138 gettext_datadir=`echo "$gettext_datadir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'`
141 # func_trace_autoconf macro configure.ac
142 # traces an Autoconf macro call and outputs the arguments to stdout,
144 func_trace_autoconf ()
147 dnl replace macros which may abort autom4te with a no-op variant
148 m4_pushdef([m4_assert])
149 m4_pushdef([m4_fatal])
150 m4_pushdef([m4_warn])
151 m4_pushdef([m4_errprintn])
152 m4_pushdef([m4_exit])
153 m4_pushdef([m4_include])
154 m4_pushdef([m4_esyscmd])
156 | "$AUTOM4TE" --no-cache --language=Autoconf-without-aclocal-m4 \
157 --trace="$1":\$% - "$2" 2>/dev/null
160 # func_trace_sed macro configure.ac
161 # traces an Autoconf macro call and outputs the arguments to stdout,
165 sed_extract_arguments='
166 s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
176 s,^.*'"$1"'([[ ]*\([^]"$`\\)]*\).*$,\1,p
179 sed -e "$sed_extract_arguments" "$2"
183 # outputs to stdout the --help usage message.
187 Usage: autopoint [OPTION]...
189 Copies standard gettext infrastructure files into a source package.
192 --help print this help and exit
193 --version print version information and exit
194 -f, --force force overwriting of files that already exist
195 -n, --dry-run print modifications but don't perform them"
197 # -V version copy the infrastructure of the specified gettext version
200 Report bugs to <bug-gnu-gettext@gnu.org>."
204 # outputs to stdout the --version message.
207 echo "$progname (GNU $package) $version"
208 echo "Uses a versions archive in @ARCHIVE_FORMAT@ format."
209 echo "Copyright (C) 2002-2013 Free Software Foundation, Inc.
210 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
211 This is free software: you are free to change and redistribute it.
212 There is NO WARRANTY, to the extent permitted by law."
213 echo "Written by" "Bruno Haible"
216 # func_fatal_error message
217 # outputs to stderr a fatal error message, and terminates the program.
220 echo "autopoint: *** $1" 1>&2
221 echo "autopoint: *** Stop." 1>&2
226 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
228 # Unset more variables known to interfere with behavior of common tools.
229 CLICOLOR_FORCE= GREP_OPTIONS=
230 unset CLICOLOR_FORCE GREP_OPTIONS
232 # Command-line option processing.
233 # Removes the OPTIONS from the arguments. Sets the variables:
234 # - force yes if --force was given, empty otherwise
235 # - ver gettext version if -V was given, empty otherwise
236 # - doit false if --dry-run was given, : otherwise
242 while test $# -gt 0; do
244 -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d )
247 -f | --force | --forc | --for | --fo | --f )
250 --help | --hel | --he | --h )
251 func_usage; exit 0 ;;
252 # -V ) # Some people put a space between -V and the version number.
254 # if test $# = 0; then
260 # -V*) # Some people omit the space between -V and the version number.
261 # ver=`echo "X$1" | sed -e 's/^X-V//'`
263 --version | --versio | --versi | --vers | --ver | --ve | --v )
266 -- ) # Stop option prcessing
269 echo "autopoint: unknown option $1" 1>&2
270 echo "Try 'autopoint --help' for more information." 1>&2
278 # Command-line argument processing.
279 # Analyzes the remaining arguments.
281 if test $# -gt 0; then
288 # The current directory is now $srcdir.
290 # Check integrity of package: A configure.in/ac must be present. Sets variable
291 # - configure_in name of configure.in/ac file.
292 if test -f configure.in; then
293 configure_in=configure.in
295 if test -f configure.ac; then
296 configure_in=configure.ac
298 # KDE specific convention: configure.in.in
299 if test -f configure.in.in; then
300 configure_in=configure.in.in
302 func_fatal_error "Missing configure.in or configure.ac, please cd to your package first."
307 # Select the method for Autoconf macro tracing. func_trace_autoconf
308 # is more accurate than func_trace_sed, but it only works with
310 if echo "AC_PREREQ([2.69])" \
311 | "$AUTOM4TE" --no-cache --language=Autoconf-without-aclocal-m4 - 2>&1; then
312 func_trace=func_trace_autoconf
314 func_trace=func_trace_sed
317 # func_version_prereq required_version version
318 # compares the required version and the latest archive version.
319 func_version_prereq ()
323 echo "m4_if(m4_version_compare([$ver], [$req]), [-1], [m4_exit([1])])" \
324 | "$AUTOM4TE" --language=M4sugar 2>&1 >/dev/null
327 # If AM_GNU_GETTEXT_REQUIRE_VERSION is used and archive_version is newer than
328 # that, use archive_version.
329 xreq=`func_trace_sed AM_GNU_GETTEXT_REQUIRE_VERSION "$configure_in"`
331 # Need to use func_trace_sed instead of $func_trace, since
332 # AM_GNU_GETTEXT_VERSION is not a standard Autoconf trace.
333 xver=`func_trace_sed AM_GNU_GETTEXT_VERSION "$configure_in"`
335 # Prefer AM_GNU_GETTEXT_REQUIRE_VERSION over AM_GNU_GETTEXT_VERSION if both are
337 if test -n "$xreq" && test -n "$xver"; then
338 echo "autopoint: using AM_GNU_GETTEXT_REQUIRE_VERSION instead of AM_GNU_GETTEXT_VERSION"
341 if test -n "$xreq"; then
342 if func_version_prereq "$xreq" "$archive_version"; then
343 ver="$archive_version"
345 func_fatal_error "gettext version $xreq or newer is required"
348 if test -z "$xver" && test -f intl/VERSION; then
349 xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'`
352 # Check whether the -V option and the version number in configure.in match.
353 # At least one of the two must be given. If both are given, they must agree.
355 if test -n "$xver"; then
356 if test -n "$ver"; then
357 if test "X$ver" != "X$xver"; then
358 func_fatal_error "Version mismatch: specified -V $ver but the package uses gettext version $xver"
366 if test -z "$ver"; then
367 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"
370 # Check whether the version number is supported.
372 0.10.35 | 0.10.36 | 0.10.37 | 0.10.38 | 0.10.39 | 0.10.40 | \
373 0.11 | 0.11.1 | 0.11.2 | 0.11.3 | 0.11.4 | 0.11.5 | \
376 0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 | \
380 0.18 | 0.18.1 | 0.18.2 | 0.18.3 | \
381 0.19 | 0.19.1 | 0.19.2 | 0.19.3 | 0.19.4 | 0.19.5 | 0.19.6 | 0.19.7 )
384 func_fatal_error "The AM_GNU_GETTEXT_VERSION declaration in your $configure_in
385 file requires the infrastructure from gettext-$ver but this version
386 is older. Please upgrade to gettext-$ver or newer."
390 # Check in which directory config.rpath, mkinstalldirs etc. belong.
391 auxdir=`"$func_trace" AC_CONFIG_AUX_DIR "$configure_in"`
392 if test -n "$auxdir"; then
396 # Check in which directory the *.m4 macros belong.
397 macrodirs=`"$func_trace" AC_CONFIG_MACRO_DIR_TRACE "$configure_in"`
398 if test -z "$macrodirs"; then
399 macrodirs=`"$func_trace" AC_CONFIG_MACRO_DIR "$configure_in"`
401 for arg in $macrodirs; do
406 if test -z "$m4dir" && test -f Makefile.am; then
407 # A package using automake.
408 # Extract the macro directory name from Makefile.am.
409 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
411 for arg in $aclocal_amflags; do
412 if test -n "$m4dir_is_next"; then
416 if test "X$arg" = "X-I"; then
425 if test -z "$m4dir"; then
429 # Check whether to omit the intl/ directory.
431 # Need to use func_trace_sed instead of $func_trace, since
432 # AM_GNU_GETTEXT is not a standard Autoconf trace.
433 xargs=`func_trace_sed AM_GNU_GETTEXT "$configure_in"`
434 save_IFS="$IFS"; IFS=:
435 for arg in $xargs; do
436 if test 'external' = "$arg"; then
443 # Check in which directory or directories the po/* infrastructure belongs.
444 configfiles=`"$func_trace" AC_CONFIG_FILES "$configure_in"`
445 # PO directories have a Makefile.in generated from Makefile.in.in.
446 # Treat a directory as a PO directory if and only if it has a
447 # POTFILES.in file. This allows packages to have multiple PO
448 # directories under different names or in different locations.
449 sed_remove_Makefile_in='s,/Makefile\.in$,,'
450 podirs=`for f in $configfiles; do case "$f" in */Makefile.in) echo $f;; esac; done | sed -e "$sed_remove_Makefile_in"`
451 if test -z "$podirs"; then
452 # If we cannot get the list of PO directories from configure.ac, assume the
457 # Set up a temporary checkout directory.
459 # - work_dir directory containing the temporary checkout
461 mkdir "$work_dir" || {
462 if test -d "$work_dir"; then
463 func_fatal_error "directory $work_dir already exists"
465 func_fatal_error "cannot create directory $work_dir"
469 # We support three archive formats.
471 # Format | Size (KiB) for gettext-0.17 | Extra tools needed |
472 # -------+-----------------------------+--------------------+
476 # -------+-----------------------------+--------------------+
478 case "@ARCHIVE_FORMAT@" in
480 # The archive of different versions is very large (unless xz compression is
481 # used), but using it does not require special tools.
482 case "@ARCHIVE_FORMAT@" in
483 dirgz) gzip -d -c < "$gettext_datadir/archive.dir.tar.gz" ;;
484 dirbz2) bzip2 -d -c < "$gettext_datadir/archive.dir.tar.bz2" ;;
485 dirxz) xz -d -c < "$gettext_datadir/archive.dir.tar.xz" ;;
487 | (cd "$work_dir" && tar xf - "gettext-$ver")
488 if test `find "$work_dir" -type f -print | wc -l` = 0; then
490 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
492 mv "$work_dir/gettext-$ver" "$work_dir/archive"
496 # We distributed the many different versions of the files in a CVS
497 # repository. This guaranteed a good compression rate:
499 # Including version size in KB of
500 # "du autopoint-files/archive"
530 # The requirement that the user must have the CVS program available is not
531 # a severe restrictions, because most of the people who use autopoint are
534 # But the CVS format is now deprecated, because "cvs init" does not work in
536 # (see <http://lists.gnu.org/archive/html/bug-cvs/2010-05/msg00003.html>)
537 # and we are not allowed to distribute the cvs infrastructure files
539 # (see <http://lists.gnu.org/archive/html/bug-cvs/2010-06/msg00011.html>).
541 # Check availability of the CVS program.
542 (cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found"
544 # Set up a temporary CVS repository.
545 # We need the temporary CVS repository because any checkout needs write
546 # access to the CVSROOT/history file, so it cannot be under $gettext_datadir.
547 # We need the temporary checkout directory because when --force was not
548 # given, we need to compare the existing files with the checked out ones.
550 # - cvs_dir directory containing the temporary repository
552 # Use an umask of 077, to avoid attacks that work by overwriting files in
553 # the "$CVSROOT"/CVSROOT directory.
554 (umask 077 && mkdir "$cvs_dir") || {
555 if test -d "$cvs_dir"; then
556 func_fatal_error "directory $cvs_dir already exists"
558 func_fatal_error "cannot create directory $cvs_dir"
561 CVSROOT="$srcdir/$cvs_dir"
563 unset CVS_CLIENT_PORT
564 unset CVS_IGNORE_REMOTE_ROOT
565 unset CVS_LOCAL_BRANCH_NUM
573 unset CVS_SERVER_SLEEP
575 export CVS_SIGN_COMMITS
577 unset CVS_VERIFY_CHECKOUTS
578 unset CVS_VERIFY_TEMPLATE
585 # Need to pass -d "$CVSROOT", because there may be a CVS directory in the
587 cvs -d "$CVSROOT" init
588 gzip -d -c < "$gettext_datadir/archive.cvs.tar.gz" | (cd "$cvs_dir" && tar xf -)
591 cvsver=gettext-`echo "$ver" | sed -e 's/\./_/g'`
592 (cvs -d "$CVSROOT" checkout -r"$cvsver" archive > /dev/null) 2>&1 | grep -v '^cvs checkout: Updating'
593 find archive -name CVS -type d -print | xargs rm -rf
596 # Check that really all CVS directories are gone, otherwise we would overwrite
597 # the contents of the user's CVS directories.
598 if test `find $work_dir/archive -name CVS -type d -print | wc -l` != 0; then
600 func_fatal_error "failed to remove all CVS subdirectories"
602 if test `find $work_dir/archive -type f -print | wc -l` = 0; then
604 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
609 # Check availability of the git program.
610 (git --version) >/dev/null 2>/dev/null || func_fatal_error "git program not found"
611 mkdir "$work_dir/archive"
612 gzip -d -c < "$gettext_datadir/archive.git.tar.gz" | (cd "$work_dir/archive" && tar xf -)
613 (cd "$work_dir/archive" && git checkout -q "gettext-$ver") || {
615 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
617 (cd "$work_dir/archive" && rm -rf .git .gitignore)
622 # determines the destination file, relative to the package's top level
623 # directory, for a given file name, relative to archive.
625 # - destfile relative destination file name, or
626 # empty if the file shall be omitted
627 # - sharedowner yes if the file is not only owned by GNU gettext but may
628 # be installed by automake or other tools, otherwise empty
629 # - allpodirs yes if the file is to be installed in every dir in $podirs
632 # There are five categories of files:
633 # ABOUT_NLS -> top level directory
634 # config.rpath mkinstalldirs -> $auxdir
640 case `echo "$1" | sed -e 's,[^/]*$,,'` in
643 config.rpath ) destfile="$auxdir$1" ;;
644 mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;;
648 m4/ ) destfile=`echo "$1" | sed -e "s,^m4/,$m4dir/,"` ;;
649 intl/ ) if test -n "$omitintl"; then destfile=""; else destfile="$1"; fi ;;
650 po/ ) destfile=`echo "$1" | sed -e "s,^po/,,"` allpodirs=yes ;;
655 # func_compare existingfile gettextfile
656 # compares the existing file and the file from gettext, and decides whether the
657 # existing file should be overwritten with the file from gettext. Returns 0 if
658 # it should be overwritten, or 1 if it should be skipped.
659 sed_extract_serial='s/^#.* serial \([^ ]*\).*/\1/p
663 if cmp -s "$1" "$2"; then
668 # For interoperability with gnulib. gnulib often has newer versions of
669 # the *.m4 files than the latest gettext release. Don't overwrite a
670 # newer version from gnulib with an older version from the gettext
671 # release. The version can be retrieved from the first line, which
672 # looks like this: # file.m4 serial NN ...
673 existing_serial=`sed -n -e "$sed_extract_serial" < "$1"`
674 gettext_serial=`sed -n -e "$sed_extract_serial" < "$2"`
675 if test -n "$existing_serial" && test -n "$gettext_serial" \
676 && test "$existing_serial" -ge "$gettext_serial" 2> /dev/null; then
689 # If some files have been locally modified and we have not been requested
690 # to overwrite them, then bail out. This is better than leaving a source
691 # package around where half of the files are locally modified and half are
692 # original - too great risk of version mismatch.
693 if test -z "$force"; then
696 mismatchfile="$tmp"/autopoint.diff
697 for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
698 func_destfile "$file"
699 if test -n "$destfile"; then
700 func_compare_to_destfile ()
703 if test -f "$finaldestfile"; then
704 if func_compare "$finaldestfile" "$work_dir/archive/$file"; then
705 if test -n "$sharedowner"; then
706 echo "autopoint: warning: File $finaldestfile has been locally modified." 1>&2
708 echo "autopoint: File $finaldestfile has been locally modified." 1>&2
710 diff -c "$work_dir/archive/$file" "$finaldestfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile"
715 if test -n "$allpodirs"; then
716 for dir in $podirs; do
717 func_compare_to_destfile "$dir/$destfile"
720 func_compare_to_destfile "$destfile"
724 if test -n "$mismatch"; then
726 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'."
732 # ensures the directory that would the given file exists.
733 # 'to' is a relative pathname, relative to the current directory.
736 base=`echo "$1" | sed -e 's,/[^/]*$,,'`
737 if test "X$base" != "X$1" && test -n "$base"; then
738 func_mkdir_for "$base"
739 # Recompute base. It was clobbered by the recursive call.
740 base=`echo "$1" | sed -e 's,/[^/]*$,,'`
741 test -d "$base" || { echo "Creating directory $base"; mkdir "$base"; }
747 # 'from' is a relative pathname, relative to the current directory.
748 # 'to' is a relative pathname, relative to the current directory.
754 echo "Copying file $2"
762 # makes a backup of a file that is about to be overwritten or replaced.
763 # 'to' is a relative pathname, relative to the current directory.
767 if test -f "$1"; then
774 # Now copy the files.
775 for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
776 func_destfile "$file"
777 if test -n "$destfile"; then
778 func_copy_to_destfile ()
782 if test -f "$finaldestfile"; then
783 if func_compare "$finaldestfile" "$work_dir/archive/$file"; then
784 if test -n "$force"; then
785 # Overwrite locally modified file.
788 # If --force is not specified, don't overwrite locally modified files
789 # for which GNU gettext is a shared owner.
794 if test -n "$mustcopy"; then
795 func_backup "$finaldestfile"
796 func_copy "$work_dir/archive/$file" "$finaldestfile"
799 if test -n "$allpodirs"; then
800 for dir in $podirs; do
801 func_copy_to_destfile "$dir/$destfile"
804 func_copy_to_destfile "$destfile"