New method of checking out and configuring gnulib - define which version we need...
[findutils.git] / import-gnulib.sh
blob4b65b141f9156b7f74aed65b06fcac8bd3baeea5
1 #! /bin/sh
3 # import-gnulib.sh -- imports a copy of gnulib into findutils
4 # Copyright (C) 2003,2004,2005,2006 Free Software Foundation, Inc.
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 2, or (at your option)
9 # any later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 # USA.
21 ##########################################################################
23 # This script is intended to populate the "gnulib" directory
24 # with a subset of the gnulib code, as provided by "gnulib-tool".
26 # To use it, run this script, speficying the location of the
27 # gnulib code as the only argument. Some sanity-checking is done
28 # before we commit to modifying things. The gnulib code is placed
29 # in the "gnulib" subdirectory, which is where the buid files expect
30 # it to be.
33 # If CDPATH is set, it will sometimes print the name of the directory
34 # to which you have moved. Unsetting CDPATH prevents this, as does
35 # prefixing it with ".".
36 unset CDPATH
37 configfile="./import-gnulib.config"
38 cvsdir="gnulib-cvs"
40 source $configfile
42 if [ -z "$gnulib_version" ]
43 then
44 echo "Error: There should be a gnulib_version setting in $configfile, but there is not." >&2
45 exit 1
49 if ! [ -d "$cvsdir" ] ; then
50 if mkdir "$cvsdir" ; then
51 echo "Created $cvsdir"
52 else
53 echo "Failed to create $cvsdir" >&2
54 exit 1
58 # Decide if gnulib_version is probably a date or probably a tag.
59 if date -d yesterday >/dev/null ; then
60 # It looks like GNU date is available
61 if date -d "$gnulib_version" >/dev/null ; then
62 # Looks like a date.
63 cvs_sticky_option="-D"
64 else
65 echo "Warning: assuming $gnulib_version is a CVS tag rather than a date" >&2
66 cvs_sticky_option="-r"
68 else
69 # GNU date unavailable, assume the version is a date
70 cvs_sticky_option="-D"
76 # Change directory unconditionally (rater than using checkout -d) so that
77 # cvs does not pick up defaults from ./CVS. Those defaults refer to our
78 # own CVS repository for our code, not to gnulib.
79 cd $cvsdir
80 if test -d gnulib/CVS ; then
81 cd gnulib
82 cmd=update
83 root="" # use previous
84 else
85 root="-d :pserver:anonymous@cvs.sv.gnu.org:/sources/gnulib"
86 cmd=checkout
87 args=gnulib
89 set -x
90 cvs -q -z3 $root $cmd $cvs_sticky_option "$gnulib_version" $args
91 set +x
94 set x $cvsdir/gnulib ; shift
96 if test -f "$1"/gnulib-tool
97 then
98 true
99 else
100 echo "$1/gnulib-tool does not exist, did you specify the right directory?" >&2
101 exit 1
104 if test -x "$1"/gnulib-tool
105 then
106 true
107 else
108 echo "$1/gnulib-tool is not executable" >&2
109 exit 1
113 if [ -d gnulib ]
114 then
115 echo "Warning: directory gnulib already exists, removing it." >&2
116 rm -rf gnulib
118 mkdir gnulib
121 if "$1"/gnulib-tool --import --symlink --dir=. --lib=libgnulib --source-base=gnulib/lib --m4-base=gnulib/m4 $modules
122 then
123 : OK
124 else
125 echo "gnulib-tool failed, exiting." >&2
126 exit 1
130 for file in $extra_files; do
131 case $file in
132 */mdate-sh | */texinfo.tex) dest=doc;;
133 *) dest=.;;
134 esac
135 cp -fp "$1"/$file $dest || exit
136 done
141 cat > gnulib/Makefile.am <<EOF
142 # Copyright (C) 2004 Free Software Foundation, Inc.
144 # This file is free software, distributed under the terms of the GNU
145 # General Public License. As a special exception to the GNU General
146 # Public License, this file may be distributed as part of a program
147 # that contains a configuration script generated by Automake, under
148 # the same distribution terms as the rest of that program.
150 # This file was generated by $0 $@.
152 SUBDIRS = lib
156 # Now regenerate things...
157 aclocal -I m4 -I gnulib/m4 &&
158 autoheader &&
159 autoconf &&
160 automake --add-missing --copy &&
161 echo Done.