autopoint 26 KB

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