3 # import-gnulib.sh -- imports a copy of gnulib into findutils
4 # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009, 2010,
5 # 2011 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##########################################################################
22 # This script is intended to populate the "gl" directory
23 # with a subset of the gnulib code, as provided by "gnulib-tool".
25 # To use it, just run this script with the top-level source directory
26 # as your working directory.
28 # If CDPATH is set, it will sometimes print the name of the directory
29 # to which you have moved. Unsetting CDPATH prevents this, as does
30 # prefixing it with ".".
34 configfile="./import-gnulib.config"
38 # If $GIT_CLONE_DEPTH is not set, apply a default.
39 : ${GIT_CLONE_DEPTH:=4}
42 # Remember arguments for comments we inject into output files
43 original_cmd_line_args="$@"
47 usage: $0 [-d gnulib-directory] [-a]
49 The default behaviour is to check out the Gnulib code via anonymous
50 CVS (or update it if there is a version already checked out). The
51 checkout or update is performed to the gnulib version indicated in
52 the configuration file $configfile.
54 If you wish to work with a different version of gnulib, use the -d option
55 to specify the directory containing the gnulib code.
57 The -a option skips the import of the gnulib code, and just generates
58 the output files (for example 'configure').
64 if test -f .gitmodules; then
65 if git config --file \
66 .gitmodules "submodule.${sm_name}.url" >/dev/null; then
67 # Submodule config in .gitmodules is already in place.
68 # Copy the submodule config into .git.
69 git submodule init || exit $?
70 # Update the gnulib module.
71 git submodule update || exit $?
73 # .gitmodules should include gnulib.
75 The .gitmodules file is present, but does not list ${sm_name}.
76 This version of findutils expects it to be there.
77 Please report this as a bug to bug-findutils@gnu.org.
78 The .gitmodules file contains this:
84 # findutils should have .gitmodules
86 The .gitmodules file is missing. This version of findutils expects it
87 to be there. Please report this as a bug to bug-findutils@gnu.org.
99 echo "$tool does not exist, did you specify the right directory?" >&2
107 echo "$tool is not executable" >&2
112 if [ -d "${gldest}" ]
114 echo "Warning: directory ${gldest} already exists." >&2
120 if "$tool" --import --symlink --with-tests \
121 --dir=. --lib=libgnulib \
122 --source-base="${gldest}"/lib \
123 --m4-base="${gldest}"/m4 --local-dir=gnulib-local $modules
128 echo "$tool failed, exiting." >&2
132 # gnulib-tool does not remove broken symlinks leftover from previous runs;
133 # this assumes GNU find, but should be a safe no-op if it is not
134 find -L "${gldest}" -lname '*' -delete 2>/dev/null || :
138 printf "Updating the license of $1... "
139 # Use cp to get the permissions right first
142 's/Free Software Foundation\([;,]\) either ''version [2]/Free Software Foundation\1 either version 3/' < "$1" > "$1".new
143 if cmp "$1" "$1".new >/dev/null
145 echo "no change needed."
148 rm -f "$1" && mv "$1".new "$1"
161 dst="$dst"/"$(basename $src)"
163 cp -fp "$src" "$dst" && rehack "$dst"
168 for f in $gpl3_update_files
176 hack_gnulib_tool_output() {
177 local gnulibdir="${1}"
178 for file in $extra_files
181 */mdate-sh | */texinfo.tex) dest=doc;;
184 copyhack "${gnulibdir}"/"$file" "$dest" || exit
187 cat > gl/Makefile.am <<EOF
188 # Copyright (C) 2004, 2009 Free Software Foundation, Inc.
190 # This file is free software, distributed under the terms of the GNU
191 # General Public License. As a special exception to the GNU General
192 # Public License, this file may be distributed as part of a program
193 # that contains a configuration script generated by Automake, under
194 # the same distribution terms as the rest of that program.
196 # This file was generated by $0 $original_cmd_line_args.
199 EXTRA_DIST = m4/gnulib-cache.m4
204 refresh_output_files() {
206 aclocal -I m4 -I gl/m4 &&
209 automake --add-missing --copy
213 update_version_file() {
214 local gnulib_git_dir="$1"
216 local outfile="lib/gnulib-version.c"
217 local gnulib_version="$( cd ${gnulib_git_dir} && git show-ref -s HEAD )"
219 if [ -z "$gnulib_version" ] ; then
220 ver="unknown (locally modified code; no version number available)"
222 ver="$gnulib_version"
226 cat > "${outfile}".new <<EOF
227 /* This file is automatically generated by $0 and simply records which version of gnulib we used. */
228 const char * const gnulib_version = "$ver";
230 if test -f "$outfile" ; then
231 if diff "${outfile}".new "${outfile}" > /dev/null ; then
236 mv "${outfile}".new "${outfile}"
240 check_merge_driver() {
241 local config_file=".git/config"
244 We recommend that you use a git merge driver for the ChangeLog file.
245 This simplifies the task of merging branches.
246 Please see the README section in gnulib/gnulib/lib/git-merge-changelog.c
248 If you've read that and don't want to use it, just set the environment variable
249 DO_NOT_WANT_CHANGELOG_DRIVER.
252 git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
253 git config merge.merge-changelog.driver '/usr/local/bin/git-merge-changelog %O %A %B'
254 echo 'ChangeLog merge=merge-changelog' >> .gitattributes
256 if [ -z "$DO_NOT_WANT_CHANGELOG_DRIVER" ] ; then
257 if git branch | egrep -q '\* *(master|rel-)'; then
258 # We are on the master branch or a release branch.
259 # Perhaps the user is simply building from git sources.
260 # Issue our message as a warning rather than an error.
271 if git config --get merge.merge-changelog.name >/dev/null ; then
272 driver="$(git config --get merge.merge-changelog.driver |
274 if [ $? -eq 0 ]; then
275 if ! [ -x "$driver" ]; then
276 echo "ERROR: Merge driver $driver is not executable." >&2
277 echo "ERROR: Please fix $config_file or install $driver" >&2
278 # Always fatal - if configured, the merge driver should work.
281 if [ -f .gitattributes ] ; then
282 echo "The ChangeLog merge driver configuration seems OK."
284 echo "$label"': you have no .gitattributes file' >&2
292 echo "$label"': There is no driver specified in [merge "merge-changelog"] in' "$config_file" >&2
299 echo "$label"': There is no name specified in [merge "merge-changelog"] in' "$config_file" >&2
308 record_config_change() {
309 # $1: name of the import-gnulib.config file
310 # $2: name of the last.config file
311 echo "Recording current config from $1 in $2"
312 if ! cp "$1" "$2"; then
319 check_old_gnulib_dir_layout() {
320 # We used to keep the gnulib git repo in ./gnulib-git/ and use
321 # ./gnulib/ as the destination directory into which we installed
322 # (part of) the gnulib code. This changed and now ./gnulib/
323 # contains the gnulib submodule and the destination directory is
324 # ./gl/. In other words, ./gnulib/ used to be the destination,
325 # but now it is the source.
327 Findutils now manages the gnulib source code as a git submodule.
329 If you are still using the directory layout in which the git tree for
330 gnulib lives in ./gnulib-git/, please fix this and re-run import-gnulib.sh.
331 The fix is very simple; please delete both ./gnulib/ and ./gnulib-git.
333 This wasn't done automatically for you just in case you had any local changes.
336 if test -d ./gl/; then
337 # Looks like we're already in the new directory layout.
339 elif test -d ./gnulib-git/; then
341 You still have a ./gnulib-git directory.
347 # No ./gl/ and no ./gnulib-git/. If ./gnulib/ exists, it might
348 # be either. If there is no ./gnulib/ we are safe to proceed anyway.
349 if test -d ./gnulib/; then
350 if test -e ./gnulib/.git; then
351 # Looks like it is the submodule.
355 You have a ./gnulib directory which does not appear to be a submodule.
362 # No ./gl/, no ./gnulib/, no ./gnulib-git/.
363 # It is safe to proceed anyway.
371 local gnulibdir=/doesnotexist
372 while getopts "d:a" opt
375 d) gnulibdir="$OPTARG" ; need_checkout=no ;;
376 a) refresh_output_files && update_licenses ; exit $? ;;
381 # We need the config file to tell us which modules
382 # to use, even if we don't want to know the gnulib version.
383 . $configfile || exit 1
385 ## If -d was not given, do update
386 if [ $need_checkout = yes ] ; then
387 if ! git version > /dev/null; then
389 You now need the tool 'git' in order to check out the correct version
390 of the gnulib code. See http://git.or.cz/ for more information about git.
395 # Check for the old directory layout.
396 echo "Checking the submodule directory layout... "
397 check_old_gnulib_dir_layout || exit 1
398 echo "The submodule directory layout looks OK."
404 echo "Warning: using gnulib code which already exists in $gnulibdir" >&2
407 local tool="${gnulibdir}"/gnulib-tool
408 if run_gnulib_tool "${tool}" &&
409 hack_gnulib_tool_output "${gnulibdir}" &&
410 refresh_output_files &&
412 update_version_file "${gnulibdir}"