Moved aux build files inot build-aux
[findutils.git] / import-gnulib.sh
blob5ffbceabaad3ff11ab90a4705e223a182685697b
1 #! /bin/sh
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)
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, 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 ".".
32 unset CDPATH
34 ## Defaults
35 # cvsdir=/doesnotexist
36 configfile="./import-gnulib.config"
37 need_checkout=yes
40 usage() {
41 cat >&2 <<EOF
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.
51 EOF
55 do_checkout () {
56 local cvsdir="$1"
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
61 exit 1
65 if ! [ -d "$cvsdir" ] ; then
66 if mkdir "$cvsdir" ; then
67 echo "Created $cvsdir"
68 else
69 echo "Failed to create $cvsdir" >&2
70 exit 1
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
78 # Looks like a date.
79 cvs_sticky_option="-D"
80 else
81 echo "Warning: assuming $gnulib_version is a CVS tag rather than a date" >&2
82 cvs_sticky_option="-r"
84 else
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.
95 cd $cvsdir
96 if test -d gnulib/CVS ; then
97 cd gnulib
98 cmd=update
99 root="" # use previous
100 else
101 root="-d :pserver:anonymous@cvs.sv.gnu.org:/sources/gnulib"
102 cmd=checkout
103 args=gnulib
105 set -x
106 cvs -q -z3 $root $cmd $cvs_sticky_option "$gnulib_version" $args
107 set +x
111 run_gnulib_tool() {
112 local tool="$1"
113 if test -f "$tool"
114 then
115 true
116 else
117 echo "$tool does not exist, did you specify the right directory?" >&2
118 exit 1
121 if test -x "$tool"
122 then
123 true
124 else
125 echo "$tool is not executable" >&2
126 exit 1
130 if [ -d gnulib ]
131 then
132 echo "Warning: directory gnulib already exists, removing it." >&2
133 rm -rf gnulib
135 mkdir gnulib
137 set -x
138 if "$tool" --import --symlink --with-tests --dir=. --lib=libgnulib --source-base=gnulib/lib --m4-base=gnulib/m4 $modules
139 then
140 set +x
141 else
142 set +x
143 echo "$tool failed, exiting." >&2
144 exit 1
149 hack_gnulib_tool_output() {
150 local gnulibdir="${1}"
151 for file in $extra_files; do
152 case $file in
153 */mdate-sh | */texinfo.tex) dest=doc;;
154 *) dest=build-aux;;
155 esac
156 cp -fp "${gnulibdir}"/"$file" "$dest" || exit
157 done
162 cat > gnulib/Makefile.am <<EOF
163 # Copyright (C) 2004 Free Software Foundation, Inc.
165 # This file is free software, distributed under the terms of the GNU
166 # General Public License. As a special exception to the GNU General
167 # Public License, this file may be distributed as part of a program
168 # that contains a configuration script generated by Automake, under
169 # the same distribution terms as the rest of that program.
171 # This file was generated by $0 $@.
173 SUBDIRS = lib
178 refresh_output_files() {
179 aclocal -I m4 -I gnulib/m4 &&
180 autoheader &&
181 autoconf &&
182 automake --add-missing --copy
186 main() {
187 ## Option parsing
188 local gnulibdir=/doesnotexist
189 while getopts "d:" opt
191 case "$opt" in
192 d) gnulibdir="$OPTARG" ; need_checkout=no ;;
193 **) usage; exit 1;;
194 esac
195 done
197 # We need the config file to tell us which modules
198 # to use, even if we don't want to know the CVS version.
199 . $configfile || exit 1
201 ## If -d was not given, do CVS checkout/update
202 if [ $need_checkout = yes ] ; then
203 do_checkout gnulib-cvs
204 gnulibdir=gnulib-cvs/gnulib
205 else
206 echo "Warning: using gnulib code which already exists in $gnulibdir" >&2
209 ## Invoke gnulib-tool to import the code.
210 local tool="${gnulibdir}"/gnulib-tool
212 run_gnulib_tool "${tool}" &&
213 hack_gnulib_tool_output "${gnulibdir}" &&
214 refresh_output_files && echo Done.
217 main "$@"