autopoint 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. # This file is meant for authors, maintainers, co-maintainers or installers
  19. # of packages which are internationalized with the help of GNU gettext. For
  20. # further information how to use it consult the GNU gettext manual.
  21. progname=$0
  22. package=gettext-tools
  23. version=0.17
  24. # Set variables
  25. # - gettext_dir directory where the sources are stored.
  26. prefix="/usr"
  27. datarootdir="${prefix}/share"
  28. gettext_dir="/usr/share/gettext"
  29. # func_tmpdir
  30. # creates a temporary directory.
  31. # Sets variable
  32. # - tmp pathname of freshly created temporary directory
  33. func_tmpdir ()
  34. {
  35. # Use the environment variable TMPDIR, falling back to /tmp. This allows
  36. # users to specify a different temporary directory, for example, if their
  37. # /tmp is filled up or too small.
  38. : ${TMPDIR=/tmp}
  39. {
  40. # Use the mktemp program if available. If not available, hide the error
  41. # message.
  42. tmp=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
  43. test -n "$tmp" && test -d "$tmp"
  44. } ||
  45. {
  46. # Use a simple mkdir command. It is guaranteed to fail if the directory
  47. # already exists. $RANDOM is bash specific and expands to empty in shells
  48. # other than bash, ksh and zsh. Its use does not increase security;
  49. # rather, it minimizes the probability of failure in a very cluttered /tmp
  50. # directory.
  51. tmp=$TMPDIR/gt$$-$RANDOM
  52. (umask 077 && mkdir "$tmp")
  53. } ||
  54. {
  55. echo "$0: cannot create a temporary directory in $TMPDIR" >&2
  56. { (exit 1); exit 1; }
  57. }
  58. }
  59. # Support for relocatability.
  60. func_find_curr_installdir ()
  61. {
  62. # Determine curr_installdir, even taking into account symlinks.
  63. curr_executable="$0"
  64. case "$curr_executable" in
  65. */* | *\\*) ;;
  66. *) # Need to look in the PATH.
  67. if test "${PATH_SEPARATOR+set}" != set; then
  68. func_tmpdir
  69. { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
  70. chmod +x "$tmp"/conf.sh
  71. if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
  72. PATH_SEPARATOR=';'
  73. else
  74. PATH_SEPARATOR=:
  75. fi
  76. rm -rf "$tmp"
  77. fi
  78. save_IFS="$IFS"; IFS="$PATH_SEPARATOR"
  79. for dir in $PATH; do
  80. IFS="$save_IFS"
  81. test -z "$dir" && dir=.
  82. for exec_ext in ''; do
  83. if test -f "$dir/$curr_executable$exec_ext"; then
  84. curr_executable="$dir/$curr_executable$exec_ext"
  85. break 2
  86. fi
  87. done
  88. done
  89. IFS="$save_IFS"
  90. ;;
  91. esac
  92. # Make absolute.
  93. case "$curr_executable" in
  94. /* | ?:/* | ?:\\*) ;;
  95. *) curr_executable=`pwd`/"$curr_executable" ;;
  96. esac
  97. # Resolve symlinks.
  98. sed_dirname='s,/[^/]*$,,'
  99. sed_linkdest='s,^.* -> \(.*\),\1,p'
  100. while : ; do
  101. lsline=`LC_ALL=C ls -l "$curr_executable"`
  102. case "$lsline" in
  103. *" -> "*)
  104. linkdest=`echo "$lsline" | sed -n -e "$sed_linkdest"`
  105. case "$linkdest" in
  106. /* | ?:/* | ?:\\*) curr_executable="$linkdest" ;;
  107. *) curr_executable=`echo "$curr_executable" | sed -e "$sed_dirname"`/"$linkdest" ;;
  108. esac ;;
  109. *) break ;;
  110. esac
  111. done
  112. curr_installdir=`echo "$curr_executable" | sed -e 's,/[^/]*$,,'`
  113. # Canonicalize.
  114. curr_installdir=`cd "$curr_installdir" && pwd`
  115. }
  116. func_find_prefixes ()
  117. {
  118. # Compute the original/current installation prefixes by stripping the
  119. # trailing directories off the original/current installation directories.
  120. orig_installprefix="$orig_installdir"
  121. curr_installprefix="$curr_installdir"
  122. while true; do
  123. orig_last=`echo "$orig_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
  124. curr_last=`echo "$curr_installprefix" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
  125. if test -z "$orig_last" || test -z "$curr_last"; then
  126. break
  127. fi
  128. if test "$orig_last" != "$curr_last"; then
  129. break
  130. fi
  131. orig_installprefix=`echo "$orig_installprefix" | sed -e 's,/[^/]*$,,'`
  132. curr_installprefix=`echo "$curr_installprefix" | sed -e 's,/[^/]*$,,'`
  133. done
  134. }
  135. if test "no" = yes; then
  136. exec_prefix="/usr"
  137. bindir="/usr/bin"
  138. orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables
  139. func_find_curr_installdir # determine curr_installdir
  140. func_find_prefixes
  141. # Relocate the directory variables that we use.
  142. gettext_dir=`echo "$gettext_dir/" | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" | sed -e 's,/$,,'`
  143. fi
  144. # func_usage
  145. # outputs to stdout the --help usage message.
  146. func_usage ()
  147. {
  148. echo "\
  149. Usage: autopoint [OPTION]...
  150. Copies standard gettext infrastructure files into a source package.
  151. Options:
  152. --help print this help and exit
  153. --version print version information and exit
  154. -f, --force force overwriting of files that already exist
  155. -n, --dry-run print modifications but don't perform them"
  156. # echo "\
  157. # -V version copy the infrastructure of the specified gettext version
  158. # (dangerous)"
  159. echo "
  160. Report bugs to <bug-gnu-gettext@gnu.org>."
  161. }
  162. # func_version
  163. # outputs to stdout the --version message.
  164. func_version ()
  165. {
  166. echo "$progname (GNU $package) $version"
  167. echo "Copyright (C) 2002-2007 Free Software Foundation, Inc.
  168. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  169. This is free software: you are free to change and redistribute it.
  170. There is NO WARRANTY, to the extent permitted by law."
  171. echo "Written by" "Bruno Haible"
  172. }
  173. # func_fatal_error message
  174. # outputs to stderr a fatal error message, and terminates the program.
  175. func_fatal_error ()
  176. {
  177. echo "autopoint: *** $1" 1>&2
  178. echo "autopoint: *** Stop." 1>&2
  179. exit 1
  180. }
  181. # Command-line option processing.
  182. # Removes the OPTIONS from the arguments. Sets the variables:
  183. # - force yes if --force was given, empty otherwise
  184. # - ver gettext version if -V was given, empty otherwise
  185. # - doit false if --dry-run was given, : otherwise
  186. {
  187. force=
  188. ver=
  189. doit=:
  190. while test $# -gt 0; do
  191. case "$1" in
  192. -n | --dry-run | --dry-ru | --dry-r | --dry- | --dry | --dr | --d )
  193. shift
  194. doit=false ;;
  195. -f | --force | --forc | --for | --fo | --f )
  196. shift
  197. force=yes ;;
  198. --help | --hel | --he | --h )
  199. func_usage; exit 0 ;;
  200. # -V ) # Some people put a space between -V and the version number.
  201. # shift
  202. # if test $# = 0; then
  203. # func_usage 1>&2
  204. # exit 1
  205. # fi
  206. # ver=$1;
  207. # shift ;;
  208. # -V*) # Some people omit the space between -V and the version number.
  209. # ver=`echo "X$1" | sed -e 's/^X-V//'`
  210. # shift ;;
  211. --version | --versio | --versi | --vers | --ver | --ve | --v )
  212. func_version
  213. exit 0 ;;
  214. -- ) # Stop option prcessing
  215. shift; break ;;
  216. -* )
  217. echo "autopoint: unknown option $1" 1>&2
  218. echo "Try 'autopoint --help' for more information." 1>&2
  219. exit 1 ;;
  220. * )
  221. break ;;
  222. esac
  223. done
  224. }
  225. # Command-line argument processing.
  226. # Analyzes the remaining arguments.
  227. {
  228. if test $# -gt 0; then
  229. func_usage 1>&2
  230. exit 1
  231. fi
  232. }
  233. srcdir=`pwd`
  234. # The current directory is now $srcdir.
  235. # Check integrity of package: A configure.in/ac must be present. Sets variable
  236. # - configure_in name of configure.in/ac file.
  237. if test -f configure.in; then
  238. configure_in=configure.in
  239. else
  240. if test -f configure.ac; then
  241. configure_in=configure.ac
  242. else
  243. # KDE specific convention: configure.in.in
  244. if test -f configure.in.in; then
  245. configure_in=configure.in.in
  246. else
  247. func_fatal_error "Missing configure.in or configure.ac, please cd to your package first."
  248. fi
  249. fi
  250. fi
  251. # Check whether the -V option and the version number in configure.in match.
  252. # At least one of the two must be given. If both are given, they must agree.
  253. xver=`cat "$configure_in" | grep '^AM_GNU_GETTEXT_VERSION(' | sed -e 's/^AM_GNU_GETTEXT_VERSION(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
  254. if test -z "$xver" && test -f intl/VERSION; then
  255. xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'`
  256. fi
  257. if test -n "$xver"; then
  258. if test -n "$ver"; then
  259. if test "X$ver" != "X$xver"; then
  260. func_fatal_error "Version mismatch: specified -V $ver but the package uses gettext version $xver"
  261. fi
  262. else
  263. ver="$xver"
  264. fi
  265. else
  266. if test -z "$ver"; then
  267. 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"
  268. fi
  269. fi
  270. # Check whether the version number is supported.
  271. case "$ver" in
  272. 0.10.35 | 0.10.36 | 0.10.37 | 0.10.38 | 0.10.39 | 0.10.40 | \
  273. 0.11 | 0.11.1 | 0.11.2 | 0.11.3 | 0.11.4 | 0.11.5 | \
  274. 0.12 | 0.12.1 | \
  275. 0.13 | 0.13.1 | \
  276. 0.14 | 0.14.1 | 0.14.2 | 0.14.3 | 0.14.4 | 0.14.5 | 0.14.6 | \
  277. 0.15 | \
  278. 0.16 | 0.16.1 | \
  279. 0.17 )
  280. ;;
  281. *)
  282. func_fatal_error "The AM_GNU_GETTEXT_VERSION declaration in your $configure_in\
  283. file requires the infrastructure from gettext-$ver but this version\
  284. is older. Please upgrade to gettext-$ver or newer."
  285. ;;
  286. esac
  287. # We distribute the many different versions of the files in a CVS repository.
  288. # This guarantees a good compression rate:
  289. #
  290. # Including version size in KB of
  291. # "du autopoint-files/archive"
  292. # 0.10.35 240
  293. # 0.10.36 428
  294. # 0.10.37 436
  295. # 0.10.38 488
  296. # 0.10.39 500
  297. # 0.10.40 528
  298. # 0.11 720
  299. # 0.11.1 740
  300. # 0.11.2 748
  301. # 0.11.3 804
  302. # 0.11.4 864
  303. # 0.11.5 880
  304. # 0.12 1032
  305. # 0.12.1 1032
  306. # 0.13 1220
  307. # 0.13.1 1236
  308. # 0.14 1296
  309. # 0.14.1 1300
  310. # 0.14.2 1420
  311. # 0.14.3 1428
  312. # 0.14.4 1464
  313. # 0.14.5 1508
  314. # 0.14.6 1580
  315. # 0.15 1760
  316. # 0.16 1808
  317. # 0.16.1 1812
  318. # 0.17 2128
  319. #
  320. # The requirement that the user must have the CVS program available is not
  321. # a severe restrictions, because most of the people who use autopoint are
  322. # users of CVS.
  323. #
  324. # Check availability of the CVS program.
  325. (cvs -v) >/dev/null 2>/dev/null || func_fatal_error "cvs program not found"
  326. # Check in which directory config.rpath, mkinstalldirs etc. belong.
  327. 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`
  328. if test -n "$auxdir"; then
  329. auxdir="$auxdir/"
  330. fi
  331. # Check in which directory the *.m4 macros belong.
  332. m4dir=m4
  333. if test -f Makefile.am; then
  334. # A package using automake.
  335. # Extract the macro directory name from Makefile.am.
  336. aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[ ]*=' Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[ ]*=\(.*\)$/\1/'`
  337. m4dir_is_next=
  338. for arg in $aclocal_amflags; do
  339. if test -n "$m4dir_is_next"; then
  340. m4dir="$arg"
  341. break
  342. else
  343. if test "X$arg" = "X-I"; then
  344. m4dir_is_next=yes
  345. else
  346. m4dir_is_next=
  347. fi
  348. fi
  349. done
  350. fi
  351. # Check whether to omit the intl/ directory.
  352. omitintl=`cat "$configure_in" | grep '^AM_GNU_GETTEXT' | sed -n -e 's/^AM_GNU_GETTEXT(\([^(),]*\).*$/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
  353. omitintl=`if test 'external' = "$omitintl"; then echo yes; fi`
  354. # Set up a temporary CVS repository and a temporary checkout directory.
  355. # We need the temporary CVS repository because any checkout needs write
  356. # access to the CVSROOT/history file, so it cannot be under $gettext_dir.
  357. # We need the temporary checkout directory because when --force was not
  358. # given, we need to compare the existing files with the checked out ones.
  359. # Set variables
  360. # - cvs_dir directory containing the temporary repository
  361. # - work_dir directory containing the temporary checkout
  362. cvs_dir=tmpcvs$$
  363. work_dir=tmpwrk$$
  364. # Use an umask of 077, to avoid attacks that work by overwriting files in the
  365. # "$CVSROOT"/CVSROOT directory.
  366. (umask 077 && mkdir "$cvs_dir") || {
  367. if test -d "$cvs_dir"; then
  368. func_fatal_error "directory $cvs_dir already exists"
  369. else
  370. func_fatal_error "cannot create directory $cvs_dir"
  371. fi
  372. }
  373. mkdir "$work_dir" || {
  374. if test -d "$work_dir"; then
  375. func_fatal_error "directory $work_dir already exists"
  376. else
  377. func_fatal_error "cannot create directory $work_dir"
  378. fi
  379. }
  380. CVSROOT="$srcdir/$cvs_dir"
  381. export CVSROOT
  382. unset CVS_CLIENT_LOG
  383. unset CVS_CLIENT_PORT
  384. unset CVS_IGNORE_REMOTE_ROOT
  385. unset CVS_PASSFILE
  386. unset CVS_PASSWORD
  387. unset CVS_RCMD_PORT
  388. unset CVS_RSH
  389. unset CVS_SERVER
  390. unset CVS_SERVER_SLEEP
  391. unset CVSIGNORE
  392. unset CVSREAD
  393. unset CVSUMASK
  394. unset CVSWRAPPERS
  395. # Need to pass -d "$CVSROOT", because there may be a CVS directory in the
  396. # current directory.
  397. cvs -d "$CVSROOT" init
  398. gzip -d -c < "$gettext_dir/archive.tar.gz" | (cd "$cvs_dir" && tar xf -)
  399. cd "$work_dir"
  400. cvsver=gettext-`echo "$ver" | sed -e 's/\./_/g'`
  401. (cvs checkout -r"$cvsver" archive > /dev/null) 2>&1 | grep -v '^cvs checkout: Updating'
  402. find archive -name CVS -type d -print | xargs rm -rf
  403. # Check that really all CVS directories are gone, otherwise we would overwrite
  404. # the contents of the user's CVS directories.
  405. if test `find archive -name CVS -type d -print | wc -l` != 0; then
  406. cd ..
  407. rm -rf "$cvs_dir" "$work_dir"
  408. func_fatal_error "failed to remove all CVS subdirectories"
  409. fi
  410. if test `find archive -type f -print | wc -l` = 0; then
  411. cd ..
  412. rm -rf "$cvs_dir" "$work_dir"
  413. func_fatal_error "infrastructure files for version $ver not found; this is autopoint from GNU $package $version"
  414. fi
  415. cd ..
  416. # func_destfile file
  417. # determines the destination file, relative to the package's top level
  418. # directory, for a given file name, relative to archive.
  419. # Sets variables
  420. # - destfile relative destination file name, or
  421. # empty if the file shall be omitted
  422. # - sharedowner yes if the file is not only owned by GNU gettext but may
  423. # be installed by automake or other tools, otherwise empty
  424. func_destfile ()
  425. {
  426. # There are five categories of files:
  427. # ABOUT_NLS -> top level directory
  428. # config.rpath mkinstalldirs -> $auxdir
  429. # m4/* -> $m4dir/
  430. # intl/* -> intl/
  431. # po/* -> po/
  432. sharedowner=
  433. case `echo "$1" | sed -e 's,[^/]*$,,'` in
  434. "" )
  435. case "$1" in
  436. config.rpath ) destfile="$auxdir$1" ;;
  437. mkinstalldirs ) destfile="$auxdir$1" sharedowner=yes ;;
  438. * ) destfile="$1" ;;
  439. esac
  440. ;;
  441. m4/ ) destfile=`echo "$1" | sed -e "s,^m4/,$m4dir/,"` ;;
  442. intl/ ) if test -n "$omitintl"; then destfile=""; else destfile="$1"; fi ;;
  443. * ) destfile="$1" ;;
  444. esac
  445. }
  446. # If some files have been locally modified and we have not been requested
  447. # to overwrite them, then bail out. This is better than leaving a source
  448. # package around where half of the files are locally modified and half are
  449. # original - too great risk of version mismatch.
  450. if test -z "$force"; then
  451. mismatch=
  452. func_tmpdir
  453. mismatchfile="$tmp"/autopoint.diff
  454. for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
  455. func_destfile "$file"
  456. if test -n "$destfile"; then
  457. if test -f "$destfile"; then
  458. if cmp -s "$work_dir/archive/$file" "$destfile"; then
  459. :
  460. else
  461. if test -n "$sharedowner"; then
  462. echo "autopoint: warning: File $destfile has been locally modified." 1>&2
  463. else
  464. echo "autopoint: File $destfile has been locally modified." 1>&2
  465. mismatch=yes
  466. diff -c "$work_dir/archive/$file" "$destfile" | sed -e "1s,$work_dir/archive/,," >> "$mismatchfile"
  467. fi
  468. fi
  469. fi
  470. fi
  471. done
  472. if test -n "$mismatch"; then
  473. rm -rf "$cvs_dir" "$work_dir"
  474. 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'."
  475. fi
  476. rm -rf "$tmp"
  477. fi
  478. # func_mkdir_for to
  479. # ensures the directory that would the given file exists.
  480. # 'to' is a relative pathname, relative to the current directory.
  481. func_mkdir_for ()
  482. {
  483. base=`echo "$1" | sed -e 's,/[^/]*$,,'`
  484. if test "X$base" != "X$1" && test -n "$base"; then
  485. func_mkdir_for "$base"
  486. # Recompute base. It was clobbered by the recursive call.
  487. base=`echo "$1" | sed -e 's,/[^/]*$,,'`
  488. test -d "$base" || { echo "Creating directory $base"; mkdir "$base"; }
  489. fi
  490. }
  491. # func_copy from to
  492. # copies a file.
  493. # 'from' is a relative pathname, relative to the current directory.
  494. # 'to' is a relative pathname, relative to the current directory.
  495. func_copy ()
  496. {
  497. if $doit; then
  498. func_mkdir_for "$2"
  499. rm -f "$2"
  500. echo "Copying file $2"
  501. cp "$1" "$2"
  502. else
  503. echo "Copy file $2"
  504. fi
  505. }
  506. # func_backup to
  507. # makes a backup of a file that is about to be overwritten or replaced.
  508. # 'to' is a relative pathname, relative to the current directory.
  509. func_backup ()
  510. {
  511. if $doit; then
  512. if test -f "$1"; then
  513. rm -f "$1~"
  514. cp -p "$1" "$1~"
  515. fi
  516. fi
  517. }
  518. # Now copy the files.
  519. for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
  520. func_destfile "$file"
  521. mustcopy=
  522. if test -n "$destfile"; then
  523. if test -f "$destfile"; then
  524. if cmp -s "$work_dir/archive/$file" "$destfile"; then
  525. :
  526. else
  527. if test -n "$force"; then
  528. # Overwrite locally modified file.
  529. mustcopy=yes
  530. fi
  531. # If --force is not specified, don't overwrite locally modified files
  532. # for which GNU gettext is a shared owner.
  533. fi
  534. else
  535. mustcopy=yes
  536. fi
  537. fi
  538. if test -n "$mustcopy"; then
  539. func_backup "$destfile"
  540. func_copy "$work_dir/archive/$file" "$destfile"
  541. fi
  542. done
  543. # That's it.
  544. rm -rf "$cvs_dir" "$work_dir"
  545. exit 0