3 # import-gnulib.sh -- imports a copy of gnulib into findutils
4 # Copyright (C) 2003,2004,2005,2006,2007 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)
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,
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, just run this script with the top-level sourec directory
27 # as your working directory.
29 # If CDPATH is set, it will sometimes print the name of the directory
30 # to which you have moved. Unsetting CDPATH prevents this, as does
31 # prefixing it with ".".
35 # cvsdir=/doesnotexist
36 configfile
="./import-gnulib.config"
42 usage: $0 [-d gnulib-directory]
44 The default behaviour is to check out the Gnulib code via anonymous
45 CVS (or update it if there is a version already checked out). The
46 checkout or update is performed to the gnulib version indicated in
47 the configuration file $configfile.
49 If you wish to work with a different version of gnulib, use the -d option
50 to specify the directory containing the gnulib code.
57 echo checking out gnulib from CVS
in $cvsdir
59 if [ -z "$gnulib_version" ] ; then
60 echo "Error: There should be a gnulib_version setting in $configfile, but there is not." >&2
65 if ! [ -d "$cvsdir" ] ; then
66 if mkdir
"$cvsdir" ; then
67 echo "Created $cvsdir"
69 echo "Failed to create $cvsdir" >&2
74 # Decide if gnulib_version is probably a date or probably a tag.
75 if date -d yesterday
>/dev
/null
; then
76 # It looks like GNU date is available
77 if date -d "$gnulib_version" >/dev
/null
; then
79 cvs_sticky_option
="-D"
81 echo "Warning: assuming $gnulib_version is a CVS tag rather than a date" >&2
82 cvs_sticky_option
="-r"
85 # GNU date unavailable, assume the version is a date
86 cvs_sticky_option
="-D"
92 # Change directory unconditionally (rater than using checkout -d) so that
93 # cvs does not pick up defaults from ./CVS. Those defaults refer to our
94 # own CVS repository for our code, not to gnulib.
96 if test -d gnulib
/CVS
; then
99 root
="" # use previous
101 root
="-d :pserver:anonymous@cvs.sv.gnu.org:/sources/gnulib"
106 cvs
-q -z3 $root $cmd $cvs_sticky_option "$gnulib_version" $args
117 echo "$tool does not exist, did you specify the right directory?" >&2
125 echo "$tool is not executable" >&2
132 echo "Warning: directory gnulib already exists." >&2
138 if "$tool" --import --symlink --with-tests --dir=.
--lib=libgnulib
--source-base=gnulib
/lib
--m4-base=gnulib
/m4 $modules
143 echo "$tool failed, exiting." >&2
147 # gnulib-tool does not remove broken symlinks leftover from previous runs;
148 # this assumes GNU find, but should be a safe no-op if it is not
149 find -L gnulib
-lname '*' -delete 2>/dev
/null ||
:
153 hack_gnulib_tool_output
() {
154 local gnulibdir
="${1}"
155 for file in $extra_files; do
157 */mdate-sh |
*/texinfo.tex
) dest
=doc
;;
160 cp -fp "${gnulibdir}"/"$file" "$dest" ||
exit
166 cat > gnulib
/Makefile.am
<<EOF
167 # Copyright (C) 2004 Free Software Foundation, Inc.
169 # This file is free software, distributed under the terms of the GNU
170 # General Public License. As a special exception to the GNU General
171 # Public License, this file may be distributed as part of a program
172 # that contains a configuration script generated by Automake, under
173 # the same distribution terms as the rest of that program.
175 # This file was generated by $0 $@.
182 refresh_output_files
() {
183 aclocal
-I m4 -I gnulib
/m4 &&
186 automake
--add-missing --copy
190 update_version_file
() {
192 outfile
="lib/gnulib-version.c"
193 if [ -z "$gnulib_version" ] ; then
194 ver
="unknown (locally modified code; no version number available)"
196 ver
="$gnulib_version"
200 cat > "${outfile}".new
<<EOF
201 /* This file is automatically generated by $0 and simply records which version of gnulib we used. */
202 const char * const gnulib_version = "$ver";
204 if test -f "$outfile" ; then
205 if diff "${outfile}".new
"${outfile}" > /dev
/null
; then
210 mv "${outfile}".new
"${outfile}"
216 local gnulibdir
=/doesnotexist
217 while getopts "d:a" opt
220 d
) gnulibdir
="$OPTARG" ; need_checkout
=no
;;
221 a
) refresh_output_files
; exit $?
;;
226 # We need the config file to tell us which modules
227 # to use, even if we don't want to know the CVS version.
228 .
$configfile ||
exit 1
230 ## If -d was not given, do CVS checkout/update
231 if [ $need_checkout = yes ] ; then
232 do_checkout gnulib-cvs
233 gnulibdir
=gnulib-cvs
/gnulib
235 echo "Warning: using gnulib code which already exists in $gnulibdir" >&2
238 ## Invoke gnulib-tool to import the code.
239 local tool
="${gnulibdir}"/gnulib-tool
241 if run_gnulib_tool
"${tool}" &&
242 hack_gnulib_tool_output
"${gnulibdir}" &&
243 refresh_output_files
&&
244 update_version_file
; then