autopull.sh 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #!/bin/sh
  2. # Convenience script for fetching auxiliary files that are omitted from
  3. # the version control repository of this package.
  4. # Copyright (C) 2003-2023 Free Software Foundation, Inc.
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. # Originally written by Paul Eggert. The canonical version of this
  19. # script is maintained as build-aux/autopull.sh in gnulib. However,
  20. # to be useful to your package, you should place a copy of it under
  21. # version control in the top-level directory of your package. The
  22. # intent is that all customization can be done with a bootstrap.conf
  23. # file also maintained in your version control; gnulib comes with a
  24. # template build-aux/bootstrap.conf to get you started.
  25. #
  26. # Alternatively, you can use an autopull.sh script that is specific
  27. # to your package.
  28. scriptversion=2022-07-24.15; # UTC
  29. me="$0"
  30. medir=`dirname "$me"`
  31. # Read the function library and the configuration.
  32. . "$medir"/bootstrap-funclib.sh
  33. # Ensure that CDPATH is not set. Otherwise, the output from cd
  34. # would cause trouble in at least one use below.
  35. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
  36. usage() {
  37. cat <<EOF
  38. Usage: $me [OPTION]...
  39. Bootstrap this package from the checked-out sources.
  40. Optional environment variables:
  41. GNULIB_SRCDIR Specifies the local directory where gnulib
  42. sources reside. Use this if you already
  43. have gnulib sources on your machine, and
  44. you want to use these sources.
  45. GNULIB_REFDIR Specifies the local directory where a gnulib
  46. repository (with a .git subdirectory) resides.
  47. Use this if you already have gnulib sources
  48. and history on your machine, and do not want
  49. to waste your bandwidth downloading them again.
  50. GNULIB_URL Cloneable URL of the gnulib repository.
  51. Options:
  52. --bootstrap-sync if this bootstrap script is not identical to
  53. the version in the local gnulib sources,
  54. update this script, and then restart it with
  55. /bin/sh or the shell \$CONFIG_SHELL
  56. --no-bootstrap-sync do not check whether bootstrap is out of sync
  57. --force attempt to bootstrap even if the sources seem
  58. not to have been checked out
  59. --no-git do not use git to update gnulib. Requires that
  60. \$GNULIB_SRCDIR or the --gnulib-srcdir option
  61. points to a gnulib repository with the correct
  62. revision
  63. --skip-po do not download po files
  64. EOF
  65. bootstrap_print_option_usage_hook
  66. cat <<EOF
  67. If the file bootstrap.conf exists in the same directory as this script, its
  68. contents are read as shell variables to configure the bootstrap.
  69. For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
  70. are honored.
  71. Gnulib sources can be fetched in various ways:
  72. * If the environment variable GNULIB_SRCDIR is set (either as an
  73. environment variable or via the --gnulib-srcdir option), then sources
  74. are fetched from that local directory. If it is a git repository and
  75. the configuration variable GNULIB_REVISION is set in bootstrap.conf,
  76. then that revision is checked out.
  77. * Otherwise, if this package is in a git repository with a 'gnulib'
  78. submodule configured, then that submodule is initialized and updated
  79. and sources are fetched from there. If GNULIB_REFDIR is set (either
  80. as an environment variable or via the --gnulib-refdir option) and is
  81. a git repository, then it is used as a reference.
  82. * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources
  83. are cloned into that directory using git from \$GNULIB_URL, defaulting
  84. to $default_gnulib_url.
  85. If the configuration variable GNULIB_REVISION is set in bootstrap.conf,
  86. then that revision is checked out.
  87. * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
  88. used. If it is a git repository and the configuration variable
  89. GNULIB_REVISION is set in bootstrap.conf, then that revision is
  90. checked out.
  91. If you maintain a package and want to pin a particular revision of the
  92. Gnulib sources that has been tested with your package, then there are
  93. two possible approaches: either configure a 'gnulib' submodule with the
  94. appropriate revision, or set GNULIB_REVISION (and if necessary
  95. GNULIB_URL) in bootstrap.conf.
  96. Running without arguments will suffice in most cases.
  97. EOF
  98. }
  99. # Parse options.
  100. # Use git to update gnulib sources
  101. use_git=true
  102. for option
  103. do
  104. case $option in
  105. --help)
  106. usage
  107. exit;;
  108. --version)
  109. set -e
  110. echo "autopull.sh $scriptversion"
  111. echo "$copyright"
  112. exit 0
  113. ;;
  114. --skip-po)
  115. SKIP_PO=t;;
  116. --force)
  117. checkout_only_file=;;
  118. --bootstrap-sync)
  119. bootstrap_sync=true;;
  120. --no-bootstrap-sync)
  121. bootstrap_sync=false;;
  122. --no-git)
  123. use_git=false;;
  124. *)
  125. bootstrap_option_hook $option || die "$option: unknown option";;
  126. esac
  127. done
  128. $use_git || test -n "$GNULIB_SRCDIR" \
  129. || die "Error: --no-git requires \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option"
  130. test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \
  131. || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory"
  132. if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
  133. die "Running this script from a non-checked-out distribution is risky."
  134. fi
  135. check_build_prerequisites $use_git
  136. if $use_gnulib || $bootstrap_sync; then
  137. prepare_GNULIB_SRCDIR
  138. if $bootstrap_sync; then
  139. upgrade_bootstrap
  140. fi
  141. fi
  142. # Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
  143. # Also find the compatible sha1 utility on the BSDs
  144. if test x"$SKIP_PO" = x; then
  145. find_tool SHA1SUM sha1sum gsha1sum shasum sha1
  146. fi
  147. # See if we can use gnulib's git-merge-changelog merge driver.
  148. if $use_git && test -d .git && check_exists git; then
  149. if git config merge.merge-changelog.driver >/dev/null ; then
  150. :
  151. elif check_exists git-merge-changelog; then
  152. echo "$0: initializing git-merge-changelog driver"
  153. git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
  154. git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
  155. else
  156. echo "$0: consider installing git-merge-changelog from gnulib"
  157. fi
  158. fi
  159. # ----------------------------- Get translations. -----------------------------
  160. download_po_files() {
  161. subdir=$1
  162. domain=$2
  163. echo "$me: getting translations into $subdir for $domain..."
  164. cmd=$(printf "$po_download_command_format" "$subdir" "$domain")
  165. eval "$cmd"
  166. }
  167. # Mirror .po files to $po_dir/.reference and copy only the new
  168. # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
  169. # Note po files that exist locally only are left in $po_dir but will
  170. # not be included in LINGUAS and hence will not be distributed.
  171. update_po_files() {
  172. # Directory containing primary .po files.
  173. # Overwrite them only when we're sure a .po file is new.
  174. po_dir=$1
  175. domain=$2
  176. # Mirror *.po files into this dir.
  177. # Usually contains *.s1 checksum files.
  178. ref_po_dir="$po_dir/.reference"
  179. test -d $ref_po_dir || mkdir $ref_po_dir || return
  180. download_po_files $ref_po_dir $domain \
  181. && ls "$ref_po_dir"/*.po 2>/dev/null |
  182. sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
  183. langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
  184. test "$langs" = '*' && langs=x
  185. for po in $langs; do
  186. case $po in x) continue;; esac
  187. new_po="$ref_po_dir/$po.po"
  188. cksum_file="$ref_po_dir/$po.s1"
  189. if ! test -f "$cksum_file" ||
  190. ! test -f "$po_dir/$po.po" ||
  191. ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
  192. echo "$me: updated $po_dir/$po.po..."
  193. cp "$new_po" "$po_dir/$po.po" \
  194. && $SHA1SUM < "$new_po" > "$cksum_file" || return
  195. fi
  196. done
  197. }
  198. case $SKIP_PO in
  199. '')
  200. if test -d po; then
  201. update_po_files po $package || exit
  202. fi
  203. if test -d runtime-po; then
  204. update_po_files runtime-po $package-runtime || exit
  205. fi;;
  206. esac
  207. # -----------------------------------------------------------------------------
  208. bootstrap_post_pull_hook \
  209. || die "bootstrap_post_pull_hook failed"
  210. # Don't proceed if there are uninitialized submodules. In particular,
  211. # autogen.sh will remove dangling links, which might be links into
  212. # uninitialized submodules.
  213. # But it's OK if the 'gnulib' submodule is uninitialized, as long as
  214. # GNULIB_SRCDIR is set.
  215. if $use_git; then
  216. # Uninitialized submodules are listed with an initial dash.
  217. uninitialized=`git submodule | grep '^-' | awk '{ print $2 }'`
  218. if test -n "$GNULIB_SRCDIR"; then
  219. uninitialized=`echo "$uninitialized" | grep -v '^gnulib$'`
  220. fi
  221. if test -n "$uninitialized"; then
  222. die "Some git submodules are not initialized: "`echo "$uninitialized" | tr '\n' ',' | sed -e 's|,$|.|'`" Either use option '--no-git', or run 'git submodule update --init' and bootstrap again."
  223. fi
  224. fi
  225. echo "$0: done. Now you can run './autogen.sh'."
  226. # ----------------------------------------------------------------------------
  227. # Local Variables:
  228. # eval: (add-hook 'before-save-hook 'time-stamp)
  229. # time-stamp-start: "scriptversion="
  230. # time-stamp-format: "%:y-%02m-%02d.%02H"
  231. # time-stamp-time-zone: "UTC0"
  232. # time-stamp-end: "; # UTC"
  233. # End: