1#! /bin/sh 2# 3# Copyright (C) 2002-2020 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 <https://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=@PACKAGE@ 25version=@VERSION@ 26archive_version=@ARCHIVE_VERSION@ 27 28# Set variables 29# - gettext_datadir directory where the data files are stored. 30prefix="@prefix@" 31datarootdir="@datarootdir@" 32: ${gettext_datadir="@datadir@/gettext"} 33: ${AUTOM4TE=autom4te} 34 35# func_tmpdir 36# creates a temporary directory. 37# Sets variable 38# - tmp pathname of freshly created temporary directory 39func_tmpdir () 40{ 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. 44 : ${TMPDIR=/tmp} 45 { 46 # Use the mktemp program if available. If not available, hide the error 47 # message. 48 tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` && 49 test -n "$tmp" && test -d "$tmp" 50 } || 51 { 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 56 # directory. 57 tmp=$TMPDIR/gt$$-$RANDOM 58 (umask 077 && mkdir "$tmp") 59 } || 60 { 61 echo "$0: cannot create a temporary directory in $TMPDIR" >&2 62 { (exit 1); exit 1; } 63 } 64} 65 66# Support for relocatability. 67func_find_curr_installdir () 68{ 69 # Determine curr_installdir, even taking into account symlinks. 70 curr_executable="$0" 71 case "$curr_executable" in 72 */* | *\\*) ;; 73 *) # Need to look in the PATH. 74 save_IFS="$IFS"; IFS="${PATH_SEPARATOR='@PATH_SEPARATOR@'}" 75 for dir in $PATH; do 76 IFS="$save_IFS" 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" 81 break 2 82 fi 83 done 84 done 85 IFS="$save_IFS" 86 ;; 87 esac 88 # Make absolute. 89 case "$curr_executable" in 90 /* | ?:/* | ?:\\*) ;; 91 *) curr_executable=`pwd`/"$curr_executable" ;; 92 esac 93 # Resolve symlinks. 94 sed_dirname='s,/[^/]*$,,' 95 sed_linkdest='s,^.* -> \(.*\),\1,p' 96 while : ; do 97 lsline=`LC_ALL=C ls -l "$curr_executable"` 98 case "$lsline" in 99 *" -> "*) 100 linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"` 101 case "$linkdest" in 102 /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;; 103 *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;; 104 esac ;; 105 *) break ;; 106 esac 107 done 108 curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'` 109 # Canonicalize. 110 curr_installdir=`cd "$curr_installdir" && pwd` 111} 112func_find_prefixes () 113{ 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" 118 while true; do 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 122 break 123 fi 124 if test "$orig_last" != "$curr_last"; then 125 break 126 fi 127 orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'` 128 curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'` 129 done 130} 131if test "@RELOCATABLE@" = yes; then 132 exec_prefix="@exec_prefix@" 133 bindir="@bindir@" 134 orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables 135 func_find_curr_installdir # determine curr_installdir 136 func_find_prefixes 137 # Relocate the directory variables that we use. 138 gettext_datadir=`echo "$gettext_datadir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'` 139fi 140 141# func_trace_autoconf macro configure.ac 142# traces an Autoconf macro call and outputs the arguments to stdout, 143# using autom4te. 144func_trace_autoconf () 145{ 146 echo '\ 147dnl replace macros which may abort autom4te with a no-op variant 148m4_pushdef([m4_assert]) 149m4_pushdef([m4_fatal]) 150m4_pushdef([m4_warn]) 151m4_pushdef([m4_errprintn]) 152m4_pushdef([m4_exit]) 153m4_pushdef([m4_include]) 154m4_pushdef([m4_esyscmd]) 155' \ 156 | "$AUTOM4TE" --no-cache --language=Autoconf-without-aclocal-m4 \ 157 --trace="$1":\$% - "$2" 2>/dev/null 158} 159 160# func_trace_sed macro configure.ac 161# traces an Autoconf macro call and outputs the arguments to stdout, 162# using sed. 163func_trace_sed () 164{ 165 sed_extract_arguments=' 166s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,; 167/'"$1"'(/ { 168 ta 169 :a 170 s/)/)/ 171 tb 172 s/\\$// 173 N 174 ba 175 :b 176 s,^.*'"$1"'([[ ]*\([^]"$`\\)]*\).*$,\1,p 177} 178d' 179 sed -e "$sed_extract_arguments" "$2" 180} 181 182# func_usage 183# outputs to stdout the --help usage message. 184func_usage () 185{ 186 echo "\ 187Usage: autopoint [OPTION]... 188 189Copies standard gettext infrastructure files into a source package. 190 191Options: 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" 196# echo "\ 197# -V version copy the infrastructure of the specified gettext version 198# (dangerous)" 199 echo " 200Report bugs in the bug tracker at <https://savannah.gnu.org/projects/gettext> 201or by email to <bug-gettext@gnu.org>." 202} 203 204# func_version 205# outputs to stdout the --version message. 206func_version () 207{ 208 echo "$progname (GNU $package) $version" 209 echo "Uses a versions archive in @ARCHIVE_FORMAT@ format." 210 echo "Copyright (C) 2002-2020 Free Software Foundation, Inc. 211License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> 212This is free software: you are free to change and redistribute it. 213There is NO WARRANTY, to the extent permitted by law." 214 echo "Written by" "Bruno Haible" 215} 216 217# func_fatal_error message 218# outputs to stderr a fatal error message, and terminates the program. 219func_fatal_error () 220{ 221 echo "autopoint: *** $1" 1>&2 222 echo "autopoint: *** Stop." 1>&2 223 exit 1 224} 225 226# Nuisances. 227(unset CDPATH) >/dev/null 2>&1 && unset CDPATH 228 229# Unset more variables known to interfere with behavior of common tools. 230CLICOLOR_FORCE= GREP_OPTIONS= 231unset CLICOLOR_FORCE GREP_OPTIONS 232 233# Command-line option processing. 234# Removes the OPTIONS from the arguments. Sets the variables: 235# - force yes if --force was given, empty otherwise 236# - ver gettext version if -V was given, empty otherwise 237# - doit false if --dry-run was given, : otherwise 238{ 239 force= 240 ver= 241 doit=: 242 243 while test $# -gt 0; do 244 case "$1" in 245 -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d ) 246 shift 247 doit=false ;; 248 -f | --force | --forc | --for | --fo | --f ) 249 shift 250 force=yes ;; 251 --help | --hel | --he | --h ) 252 func_usage; exit 0 ;; 253# -V ) # Some people put a space between -V and the version number. 254# shift 255# if test $# = 0; then 256# func_usage 1>&2 257# exit 1 258# fi 259# ver=$1; 260# shift ;; 261# -V*) # Some people omit the space between -V and the version number. 262# ver=`echo "X$1" | sed -e 's/^X-V//'` 263# shift ;; 264 --version | --versio | --versi | --vers | --ver | --ve | --v ) 265 func_version 266 exit 0 ;; 267 -- ) # Stop option prcessing 268 shift; break ;; 269 -* ) 270 echo "autopoint: unknown option $1" 1>&2 271 echo "Try 'autopoint --help' for more information." 1>&2 272 exit 1 ;; 273 * ) 274 break ;; 275 esac 276 done 277} 278 279# Command-line argument processing. 280# Analyzes the remaining arguments. 281{ 282 if test $# -gt 0; then 283 func_usage 1>&2 284 exit 1 285 fi 286} 287 288srcdir=`pwd` 289# The current directory is now $srcdir. 290 291# Check integrity of package: A configure.in/ac must be present. Sets variable 292# - configure_in name of configure.in/ac file. 293if test -f configure.in; then 294 configure_in=configure.in 295else 296 if test -f configure.ac; then 297 configure_in=configure.ac 298 else 299 # KDE specific convention: configure.in.in 300 if test -f configure.in.in; then 301 configure_in=configure.in.in 302 else 303 func_fatal_error "Missing configure.in or configure.ac, please cd to your package first." 304 fi 305 fi 306fi 307 308# Select the method for Autoconf macro tracing. func_trace_autoconf 309# is more accurate than func_trace_sed, but it only works with 310# autoconf >= 2.69. 311if echo "AC_PREREQ([2.69])" \ 312 | "$AUTOM4TE" --no-cache --language=Autoconf-without-aclocal-m4 - 2>&1; then 313 func_trace=func_trace_autoconf 314else 315 func_trace=func_trace_sed 316fi 317 318# func_version_prereq required_version version 319# compares the required version and the latest archive version. 320func_version_prereq () 321{ 322 req="$1" 323 ver="$2" 324 echo "m4_if(m4_version_compare([$ver], [$req]), [-1], [m4_exit([1])])" \ 325 | "$AUTOM4TE" --language=M4sugar >/dev/null 326} 327 328# If AM_GNU_GETTEXT_REQUIRE_VERSION is used and archive_version is newer than 329# that, use archive_version. 330xreq=`func_trace_sed AM_GNU_GETTEXT_REQUIRE_VERSION "$configure_in"` 331 332# Need to use func_trace_sed instead of $func_trace, since 333# AM_GNU_GETTEXT_VERSION is not a standard Autoconf trace. 334xver=`func_trace_sed AM_GNU_GETTEXT_VERSION "$configure_in"` 335 336# Prefer AM_GNU_GETTEXT_REQUIRE_VERSION over AM_GNU_GETTEXT_VERSION if both are 337# specified. 338if test -n "$xreq" && test -n "$xver"; then 339 echo "autopoint: using AM_GNU_GETTEXT_REQUIRE_VERSION instead of AM_GNU_GETTEXT_VERSION" 340fi 341 342if test -n "$xreq"; then 343 if func_version_prereq "$xreq" "$archive_version"; then 344 ver="$archive_version" 345 else 346 func_fatal_error "gettext version $xreq or newer is required" 347 fi 348else 349 if test -z "$xver" && test -f intl/VERSION; then 350 xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'` 351 fi 352 353 # Check whether the -V option and the version number in configure.in match. 354 # At least one of the two must be given. If both are given, they must agree. 355 356 if test -n "$xver"; then 357 if test -n "$ver"; then 358 if test "X$ver" != "X$xver"; then 359 func_fatal_error "Version mismatch: specified -V $ver but the package uses gettext version $xver" 360 fi 361 else 362 ver="$xver" 363 fi 364 fi 365fi 366 367if test -z "$ver"; then 368 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" 369fi 370 371# Check whether the version number is supported. 372case "$ver" in 373 0.10.35 | 0.10.36 | 0.10.37 | 0.10.38 | 0.10.39 | 0.10.40 | \ 374 0.11 | 0.11.1 | 0.11.2 | 0.11.3 | 0.11.4 | 0.11.5 | \ 375 0.12 | 0.12.1 | \ 376 0.13 | 0.13.1 | \ 377 0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 | \ 378 0.15 | \ 379 0.16 | 0.16.1 | \ 380 0.17 | \ 381 0.18 | 0.18.1 | 0.18.2 | 0.18.3 | \ 382 0.19 | 0.19.1 | 0.19.2 | 0.19.3 | 0.19.4 | 0.19.5 | 0.19.6 | 0.19.7 | 0.19.8 | \ 383 0.20 | 0.20.2 | \ 384 0.21 ) 385 ;; 386 *) 387 func_fatal_error "The AM_GNU_GETTEXT_VERSION declaration in your $configure_in 388 file requires the infrastructure from gettext-$ver but this version 389 is older. Please upgrade to gettext-$ver or newer." 390 ;; 391esac 392 393# Check in which directory config.rpath, mkinstalldirs etc. belong. 394auxdir=`"$func_trace" AC_CONFIG_AUX_DIR "$configure_in"` 395if test -n "$auxdir"; then 396 auxdir="$auxdir/" 397fi 398 399# Check in which directory the *.m4 macros belong. 400macrodirs=`"$func_trace" AC_CONFIG_MACRO_DIR_TRACE "$configure_in"` 401if test -z "$macrodirs"; then 402 macrodirs=`"$func_trace" AC_CONFIG_MACRO_DIR "$configure_in"` 403fi 404for arg in $macrodirs; do 405 m4dir="$arg" 406 break 407done 408 409if test -z "$m4dir" && test -f Makefile.am; then 410 # A package using automake. 411 # Extract the macro directory name from Makefile.am. 412 aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'` 413 m4dir_is_next= 414 for arg in $aclocal_amflags; do 415 if test -n "$m4dir_is_next"; then 416 m4dir="$arg" 417 break 418 else 419 if test "X$arg" = "X-I"; then 420 m4dir_is_next=yes 421 else 422 m4dir_is_next= 423 fi 424 fi 425 done 426fi 427 428if test -z "$m4dir"; then 429 m4dir=m4 430fi 431 432# Check whether to omit the intl/ directory. 433omitintl= 434# Need to use func_trace_sed instead of $func_trace, since 435# AM_GNU_GETTEXT is not a standard Autoconf trace. 436xargs=`func_trace_sed AM_GNU_GETTEXT "$configure_in"` 437save_IFS="$IFS"; IFS=: 438for arg in $xargs; do 439 if test 'external' = "$arg"; then 440 omitintl=yes 441 break 442 fi 443done 444IFS="$save_IFS" 445 446if test -z "$omitintl"; then 447 case "$ver" in 448 0.1[0-9] | 0.1[0-9].* ) ;; 449 *) func_fatal_error "AM_GNU_GETTEXT without 'external' argument is no longer supported in version $ver" ;; 450 esac 451fi 452 453# Check in which directory or directories the po/* infrastructure belongs. 454configfiles=`"$func_trace" AC_CONFIG_FILES "$configure_in"` 455# PO directories have a Makefile.in generated from Makefile.in.in. 456# Treat a directory as a PO directory if and only if it has a 457# POTFILES.in file. This allows packages to have multiple PO 458# directories under different names or in different locations. 459sed_remove_Makefile_in='s,/Makefile\.in$,,' 460podirs=`for f in $configfiles; do case "$f" in */Makefile.in) echo $f;; esac; done | sed -e "$sed_remove_Makefile_in"` 461if test -z "$podirs"; then 462 # If we cannot get the list of PO directories from configure.ac, assume the 463 # common default. 464 podirs="po" 465fi 466 467# Set up a temporary checkout directory. 468# Set variables 469# - work_dir directory containing the temporary checkout 470work_dir=tmpwrk$$ 471mkdir "$work_dir" || { 472 if test -d "$work_dir"; then 473 func_fatal_error "directory $work_dir already exists" 474 else 475 func_fatal_error "cannot create directory $work_dir" 476 fi 477} 478 479# We support three archive formats. 480# 481# Format | Size (KiB) for gettext-0.17 | Extra tools needed | 482# -------+-----------------------------+--------------------+ 483# dir | 3000 | -- | 484# cvs | 356 | cvs | 485# git | 484 | git | 486# -------+-----------------------------+--------------------+ 487 488case "@ARCHIVE_FORMAT@" in 489 dir*) 490 # The archive of different versions is very large (unless xz compression is 491 # used), but using it does not require special tools. 492 case "@ARCHIVE_FORMAT@" in 493 dirgz) gzip -d -c < "$gettext_datadir/archive.dir.tar.gz" ;; 494 dirbz2) bzip2 -d -c < "$gettext_datadir/archive.dir.tar.bz2" ;; 495 dirxz) xz -d -c < "$gettext_datadir/archive.dir.tar.xz" ;; 496 esac \ 497 | (cd "$work_dir" && tar xf - "gettext-$ver") 498 if test `find "$work_dir" -type f -print | wc -l` = 0; then 499 rm -rf "$work_dir" 500 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" 501 fi 502 mv "$work_dir/gettext-$ver" "$work_dir/archive" 503 ;; 504 505 cvs) 506 # We distributed the many different versions of the files in a CVS 507 # repository. This guaranteed a good compression rate: 508 # 509 # Including version size in KB of 510 # "du autopoint-files/archive" 511 # 0.10.35 240 512 # 0.10.36 428 513 # 0.10.37 436 514 # 0.10.38 488 515 # 0.10.39 500 516 # 0.10.40 528 517 # 0.11 720 518 # 0.11.1 740 519 # 0.11.2 748 520 # 0.11.3 804 521 # 0.11.4 864 522 # 0.11.5 880 523 # 0.12 1032 524 # 0.12.1 1032 525 # 0.13 1220 526 # 0.13.1 1236 527 # 0.14 1296 528 # 0.14.1 1300 529 # 0.14.2 1420 530 # 0.14.3 1428 531 # 0.14.4 1464 532 # 0.14.5 1508 533 # 0.14.6 1580 534 # 0.15 1760 535 # 0.16 1808 536 # 0.16.1 1812 537 # 0.17 2128 538 # 0.18 2656 539 # 540 # The requirement that the user must have the CVS program available is not 541 # a severe restrictions, because most of the people who use autopoint are 542 # users of CVS. 543 # 544 # But the CVS format is now deprecated, because "cvs init" does not work in 545 # all circumstances 546 # (see <https://lists.gnu.org/archive/html/bug-cvs/2010-05/msg00003.html>) 547 # and we are not allowed to distribute the cvs infrastructure files 548 # ourselves 549 # (see <https://lists.gnu.org/archive/html/bug-cvs/2010-06/msg00011.html>). 550 # 551 # Check availability of the CVS program. 552 (cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found" 553 554 # Set up a temporary CVS repository. 555 # We need the temporary CVS repository because any checkout needs write 556 # access to the CVSROOT/history file, so it cannot be under $gettext_datadir. 557 # We need the temporary checkout directory because when --force was not 558 # given, we need to compare the existing files with the checked out ones. 559 # Set variables 560 # - cvs_dir directory containing the temporary repository 561 cvs_dir=tmpcvs$$ 562 # Use an umask of 077, to avoid attacks that work by overwriting files in 563 # the "$CVSROOT"/CVSROOT directory. 564 (umask 077 && mkdir "$cvs_dir") || { 565 if test -d "$cvs_dir"; then 566 func_fatal_error "directory $cvs_dir already exists" 567 else 568 func_fatal_error "cannot create directory $cvs_dir" 569 fi 570 } 571 CVSROOT="$srcdir/$cvs_dir" 572 unset CVS_CLIENT_LOG 573 unset CVS_CLIENT_PORT 574 unset CVS_IGNORE_REMOTE_ROOT 575 unset CVS_LOCAL_BRANCH_NUM 576 unset CVS_NOBASES 577 unset CVS_PASSFILE 578 unset CVS_PASSWORD 579 unset CVS_PROXY_PORT 580 unset CVS_RCMD_PORT 581 unset CVS_RSH 582 unset CVS_SERVER 583 unset CVS_SERVER_SLEEP 584 CVS_SIGN_COMMITS= 585 export CVS_SIGN_COMMITS 586 unset CVS_SSH 587 unset CVS_VERIFY_CHECKOUTS 588 unset CVS_VERIFY_TEMPLATE 589 unset CVSIGNORE 590 unset CVSREAD 591 unset CVSREADONLYFS 592 unset CVSUMASK 593 unset CVSWRAPPERS 594 595 # Need to pass -d "$CVSROOT", because there may be a CVS directory in the 596 # current directory. 597 cvs -d "$CVSROOT" init 598 gzip -d -c < "$gettext_datadir/archive.cvs.tar.gz" | (cd "$cvs_dir" && tar xf -) 599 600 cd "$work_dir" 601 cvsver=gettext-`echo "$ver" | sed -e 's/\./_/g'` 602 (cvs -d "$CVSROOT" checkout -r"$cvsver" archive > /dev/null) 2>&1 | grep -v '^cvs checkout: Updating' 603 find archive -name CVS -type d -print | xargs rm -rf 604 cd .. 605 rm -rf "$cvs_dir" 606 # Check that really all CVS directories are gone, otherwise we would overwrite 607 # the contents of the user's CVS directories. 608 if test `find $work_dir/archive -name CVS -type d -print | wc -l` != 0; then 609 rm -rf "$work_dir" 610 func_fatal_error "failed to remove all CVS subdirectories" 611 fi 612 if test `find $work_dir/archive -type f -print | wc -l` = 0; then 613 rm -rf "$work_dir" 614 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" 615 fi 616 ;; 617 618 git) 619 # Check availability of the git program. 620 (git --version) >/dev/null 2>/dev/null || func_fatal_error "git program not found" 621 mkdir "$work_dir/archive" 622 gzip -d -c < "$gettext_datadir/archive.git.tar.gz" | (cd "$work_dir/archive" && tar xf -) 623 (unset GIT_CONFIG 624 unset XDG_CONFIG_HOME 625 unset HOME 626 GIT_CONFIG_NOSYSTEM=1; export GIT_CONFIG_NOSYSTEM 627 cd "$work_dir/archive" && git checkout -q "gettext-$ver" 628 ) || { 629 rm -rf "$work_dir" 630 func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version" 631 } 632 (cd "$work_dir/archive" && rm -rf .git .gitignore) 633 ;; 634esac 635 636# func_destfile file 637# determines the destination file, relative to the package's top level 638# directory, for a given file name, relative to archive. 639# Sets variables 640# - destfile relative destination file name, or 641# empty if the file shall be omitted 642# - sharedowner yes if the file is not only owned by GNU gettext but may 643# be installed by automake or other tools, otherwise empty 644# - allpodirs yes if the file is to be installed in every dir in $podirs 645func_destfile () 646{ 647 # There are five categories of files: 648 # ABOUT-NLS -> top level directory 649 # config.rpath mkinstalldirs -> $auxdir 650 # m4/* -> $m4dir/ 651 # intl/* -> intl/ 652 # po/* -> 653 sharedowner= 654 allpodirs= 655 case `echo "$1" | sed -e 's,[^/]*$,,'` in 656 "" ) 657 case "$1" in 658 config.rpath ) destfile="$auxdir$1" ;; 659 mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;; 660 * ) destfile="$1" ;; 661 esac 662 ;; 663 m4/ ) destfile=`echo "$1" | sed -e "s,^m4/,$m4dir/,"` ;; 664 intl/ ) if test -n "$omitintl"; then destfile=""; else destfile="$1"; fi ;; 665 po/ ) destfile=`echo "$1" | sed -e "s,^po/,,"` allpodirs=yes ;; 666 * ) destfile="$1" ;; 667 esac 668} 669 670# func_compare existingfile gettextfile 671# compares the existing file and the file from gettext, and decides whether the 672# existing file should be overwritten with the file from gettext. Returns 0 if 673# it should be overwritten, or 1 if it should be skipped. 674sed_extract_serial='s/^#.* serial \([^ ]*\).*/\1/p 6751q' 676func_compare () 677{ 678 if cmp -s "$1" "$2"; then 679 false 680 else 681 case "$2" in 682 *.m4) 683 # For interoperability with gnulib. gnulib often has newer versions of 684 # the *.m4 files than the latest gettext release. Don't overwrite a 685 # newer version from gnulib with an older version from the gettext 686 # release. The version can be retrieved from the first line, which 687 # looks like this: # file.m4 serial NN ... 688 existing_serial=`sed -n -e "$sed_extract_serial" < "$1"` 689 gettext_serial=`sed -n -e "$sed_extract_serial" < "$2"` 690 if test -n "$existing_serial" && test -n "$gettext_serial" \ 691 && test "$existing_serial" -ge "$gettext_serial" 2> /dev/null; then 692 false 693 else 694 true 695 fi 696 ;; 697 *) 698 true 699 ;; 700 esac 701 fi 702} 703 704# If some files have been locally modified and we have not been requested 705# to overwrite them, then bail out. This is better than leaving a source 706# package around where half of the files are locally modified and half are 707# original - too great risk of version mismatch. 708if test -z "$force"; then 709 mismatch= 710 func_tmpdir 711 mismatchfile="$tmp"/autopoint.diff 712 for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do 713 func_destfile "$file" 714 if test -n "$destfile"; then 715 func_compare_to_destfile () 716 { 717 finaldestfile="$1" 718 if test -f "$finaldestfile"; then 719 if func_compare "$finaldestfile" "$work_dir/archive/$file"; then 720 if test -n "$sharedowner"; then 721 echo "autopoint: warning: File $finaldestfile has been locally modified." 1>&2 722 else 723 echo "autopoint: File $finaldestfile has been locally modified." 1>&2 724 mismatch=yes 725 diff -c "$work_dir/archive/$file" "$finaldestfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile" 726 fi 727 fi 728 fi 729 } 730 if test -n "$allpodirs"; then 731 for dir in $podirs; do 732 func_compare_to_destfile "$dir/$destfile" 733 done 734 else 735 func_compare_to_destfile "$destfile" 736 fi 737 fi 738 done 739 if test -n "$mismatch"; then 740 rm -rf "$work_dir" 741 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'." 742 fi 743 rm -rf "$tmp" 744fi 745 746# func_mkdir_for to 747# ensures the directory that would the given file exists. 748# 'to' is a relative pathname, relative to the current directory. 749func_mkdir_for () 750{ 751 base=`echo "$1" | sed -e 's,/[^/]*$,,'` 752 if test "X$base" != "X$1" && test -n "$base"; then 753 func_mkdir_for "$base" 754 # Recompute base. It was clobbered by the recursive call. 755 base=`echo "$1" | sed -e 's,/[^/]*$,,'` 756 test -d "$base" || { echo "Creating directory $base"; mkdir "$base"; } 757 fi 758} 759 760# func_copy from to 761# copies a file. 762# 'from' is a relative pathname, relative to the current directory. 763# 'to' is a relative pathname, relative to the current directory. 764func_copy () 765{ 766 if $doit; then 767 func_mkdir_for "$2" 768 rm -f "$2" 769 echo "Copying file $2" 770 cp "$1" "$2" 771 else 772 echo "Copy file $2" 773 fi 774} 775 776# func_backup to 777# makes a backup of a file that is about to be overwritten or replaced. 778# 'to' is a relative pathname, relative to the current directory. 779func_backup () 780{ 781 if $doit; then 782 if test -f "$1"; then 783 rm -f "$1~" 784 cp -p "$1" "$1~" 785 fi 786 fi 787} 788 789# Now copy the files. 790for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do 791 func_destfile "$file" 792 if test -n "$destfile"; then 793 func_copy_to_destfile () 794 { 795 finaldestfile="$1" 796 mustcopy= 797 if test -f "$finaldestfile"; then 798 if func_compare "$finaldestfile" "$work_dir/archive/$file"; then 799 if test -n "$force"; then 800 # Overwrite locally modified file. 801 mustcopy=yes 802 fi 803 # If --force is not specified, don't overwrite locally modified files 804 # for which GNU gettext is a shared owner. 805 fi 806 else 807 mustcopy=yes 808 fi 809 if test -n "$mustcopy"; then 810 func_backup "$finaldestfile" 811 func_copy "$work_dir/archive/$file" "$finaldestfile" 812 fi 813 } 814 if test -n "$allpodirs"; then 815 for dir in $podirs; do 816 func_copy_to_destfile "$dir/$destfile" 817 done 818 else 819 func_copy_to_destfile "$destfile" 820 fi 821 fi 822done 823 824# That's it. 825rm -rf "$work_dir" 826exit 0 827