7b355efa0db7f81951fd6c32548962da88a6a8ca
[debian/tar] / bootstrap
1 #! /bin/sh
2
3 # Bootstrap 'tar' from CVS.
4
5 # Copyright (C) 2003, 2004 Free Software Foundation, Inc.
6
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 2, or (at your option)
10 # any later version.
11
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.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 # 02111-1307, USA.
21
22 # Written by Paul Eggert.
23
24 # URL of our text domain page in Translation Project
25 TP_URL="http://www2.iro.umontreal.ca/~gnutra/po/maint/tar/"
26
27 usage() {
28  cat <<EOF
29  usage: $0 [--gnulib-srcdir=DIR][--cvs-auth=AUTH-METHOD][--cvs-user=USERNAME][--no-po]
30  Options are:
31  --gnulib-srcdir=DIRNAME      Specify the local directory where gnulib
32                               sources reside. Use this if you already
33                               have gnulib sources on your machine, and
34                               do not want to waste your bandwidth dowloading
35                               them again.
36  --cvs-auth=METHOD            Set the CVS access method used for downloading
37                               gnulib files. METHOD is one of the keywords
38                               accepted by cvs -d option (see info cvs
39                               repository).
40  --cvs-user=USERNAME          Set the CVS username to be used when accessing
41                               the gnulib repository.
42  --no-po                      Do not download po files.
43  --update-po                  Update po files and exit.
44  
45 Running without arguments will suffice in most cases. It is equivalent
46 to
47
48     ./bootstrap --cvs-auth=ext --cvs-user=anoncvs
49
50 EOF
51 }
52
53 update_po() {
54   echo "$0: getting translations into po..."
55   (cd po &&
56    rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'` &&
57     wget -nv -nd -r -l 1 -A .po -C off $TP_URL &&
58     ls *.po | sed 's/\.po$//' >LINGUAS
59   ) || exit
60 }
61
62 # Parse options.
63
64 DOWNLOAD_PO=yes
65 for option
66 do
67   case $option in
68   --help)
69     usage
70     exit;;
71   --gnulib-srcdir=*)
72     GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
73   --cvs-auth=*)
74     CVS_AUTH=`expr "$option" : '--cvs-auth=\(.*\)'`;;
75   --cvs-user=*)
76     CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;;
77   --no-po)
78     DOWNLOAD_PO=no;;
79   --update-po)
80     DOWNLOAD_PO=only;;
81   *)
82     echo >&2 "$0: $option: unknown option"
83     exit 1;;
84   esac
85 done
86
87 if [ "$DOWNLOAD_PO" = "only" ]; then
88     update_po
89     exit 0
90 fi      
91
92 echo "$0: Bootstrapping CVS tar..."
93
94 build_cvs_prefix() {
95   CVS_PREFIX=:${1}:
96   if [ "${2}" != - ]; then
97     CVS_PREFIX=${CVS_PREFIX}${2}@
98   fi
99   if [ "$1" = "ext" ]; then
100     if [ -z "${CVS_RSH}" ]; then
101        CVS_RSH=ssh
102        export CVS_RSH
103     fi
104   fi
105 }
106
107 # Get gnulib files.
108
109 case ${GNULIB_SRCDIR--} in
110 -)
111   if [ ! -d gnulib ]; then
112     echo "$0: getting gnulib files..."
113
114     trap exit 1 2 13 15
115     trap 'rm -fr gnulib; exit 1' 0
116
117     case "${CVS_AUTH--}" in
118     -)       build_cvs_prefix ext anoncvs;;
119     pserver) build_cvs_prefix $CVS_AUTH ${CVS_USER:-anoncvs};;
120     gserver|server)
121              build_cvs_prefix $CVS_AUTH ${CVS_USER--};;
122     ext)     build_cvs_prefix $CVS_AUTH ${CVS_USER--};;
123     *)       echo "$0: Unknown CVS access method" >&2
124              exit 1;;
125     esac
126     if [ "${CVS_AUTH--}" = "pserver" ]; then
127       cvs -d ${CVS_PREFIX}subversions.gnu.org:/cvsroot/gnulib login || exit
128     fi
129     cvs -q -d ${CVS_PREFIX}subversions.gnu.org:/cvsroot/gnulib co gnulib || exit
130
131     trap 0
132   fi
133   GNULIB_SRCDIR=gnulib
134 esac
135
136 <$GNULIB_SRCDIR/gnulib-tool || exit
137
138 gnulib_modules='
139 alloca
140 argmatch
141 argp
142 backupfile
143 dirname
144 error
145 exclude
146 fileblocks
147 fnmatch-gnu
148 ftruncate
149 full-write
150 getdate
151 getline
152 getopt
153 gettext
154 gettime
155 hash
156 human
157 lchown
158 memset
159 modechange
160 obstack
161 quote
162 quotearg
163 rmdir
164 safe-read
165 save-cwd
166 savedir
167 stdbool
168 stpcpy
169 strtol
170 strtoul
171 timespec
172 unlocked-io
173 utime
174 xalloc
175 xgetcwd
176 xstrtoumax
177 '
178
179 previous_gnulib_modules=
180 while [ "$gnulib_modules" != "$previous_gnulib_modules" ]; do
181   previous_gnulib_modules=$gnulib_modules
182   gnulib_modules=`
183     (echo "$gnulib_modules"
184      for gnulib_module in $gnulib_modules; do
185        $GNULIB_SRCDIR/gnulib-tool --extract-dependencies $gnulib_module
186      done) | sort -u
187   `
188 done
189
190 gnulib_files=`
191   (for gnulib_module in $gnulib_modules; do
192      $GNULIB_SRCDIR/gnulib-tool --extract-filelist $gnulib_module
193    done) | sort -u
194 `
195
196 gnulib_dirs=`echo "$gnulib_files" | sed 's,/[^/]*$,,' | sort -u`
197 mkdir -p $gnulib_dirs || exit
198
199 for gnulib_file in $gnulib_files; do
200   dest=$gnulib_file
201
202   case $gnulib_file in
203   m4/codeset.m4) continue;;
204   m4/intdiv0.m4) continue;;
205   m4/inttypes-pri.m4) continue;;
206   m4/isc-posix.m4) continue;;
207   m4/lcmessage.m4) continue;;
208   m4/onceonly_2_57.m4) dest=m4/onceonly.m4;;
209   # These will be overwritten by autopoint, which still uses
210   # old jm_.* macro names, so we have to keep both copies.
211   m4/ulonglong.m4) dest=m4/ulonglong_gl.m4;;
212   m4/inttypes_h.m4) dest=m4/inttypes_h_gl.m4;;
213   m4/stdint_h.m4) dest=m4/stdint_h_gl.m4;;
214   m4/uintmax_t.m4) dest=m4/uintmax_t_gl.m4;;
215   esac
216
217   rm -f $dest &&
218   echo "$0: Copying file $GNULIB_SRCDIR/$gnulib_file" &&
219   cp -p $GNULIB_SRCDIR/$gnulib_file $dest || exit
220 done
221
222 if [ -d patches ]; then
223     echo "$0: Patching gnulib"
224     for file in patches/*.diff
225     do
226       patch -p0 < $file
227     done
228 fi
229
230 echo "$0: Creating m4/gnulib.m4"
231 (echo "# This file is generated automatically. Please, do not edit."
232  echo "#"
233  echo "AC_DEFUN([tar_GNULIB],["
234  for gnulib_module in $gnulib_modules; do
235     echo "# $gnulib_module"
236     $GNULIB_SRCDIR/gnulib-tool --extract-autoconf-snippet $gnulib_module
237  done | sed '/AM_GNU_GETTEXT/d'
238  echo "])") > ./m4/gnulib.m4
239
240 echo "$0: Creating lib/Makefile.am"
241 (cat lib/Makefile.tmpl
242  
243  for gnulib_module in $gnulib_modules; do
244     echo "# $gnulib_module"
245     $GNULIB_SRCDIR/gnulib-tool --extract-automake-snippet $gnulib_module
246  done | sed 's/lib_SOURCES/libtar_a_SOURCES/g' ) > lib/Makefile.am
247
248 # Get translations.
249 if test "$DOWNLOAD_PO" = "yes"; then
250   update_po
251 fi
252
253 # Reconfigure, getting other files.
254
255 echo "$0: autoreconf --verbose --install --force ..."
256 autoreconf --verbose --install --force
257
258
259 echo "$0: done.  Now you can run './configure'."