No need to define gl_LOCK.
[platform/upstream/coreutils.git] / bootstrap
1 #! /bin/sh
2
3 # Bootstrap this package from CVS.
4
5 # Copyright (C) 2003, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21
22 # Written by Paul Eggert.
23
24 nl='
25 '
26
27 # Ensure file names are sorted consistently across platforms.
28 # Also, ensure diagnostics are in English, e.g., "wget --help" below.
29 LC_ALL=C
30 export LC_ALL
31
32
33 # Configuration.
34
35 # List of gnulib modules needed.
36 gnulib_modules=
37
38 # Any extra gnulib files needed.
39 gnulib_files=
40
41 # Translation Project URL, for the registry of all projects
42 # and for the translation-team master directory.
43 TP_URL='http://www.iro.umontreal.ca/translation/registry.cgi?domain='
44 TP_PO_URL='http://www.iro.umontreal.ca/translation/teams/PO/'
45
46 extract_package_name='
47   /^AC_INIT(/{
48      /.*,.*,.*,/{
49        s///
50        s/[][]//g
51        p
52        q
53      }
54      s/AC_INIT(\[*//
55      s/]*,.*//
56      s/^GNU //
57      y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
58      s/[^A-Za-z0-9_]/-/g
59      p
60   }
61 '
62 package=`sed -n "$extract_package_name" configure.ac` || exit
63
64 # Extra files from gnulib, which are not part of any module yet.
65 gnulib_extra_files='
66         build-aux/install-sh
67         build-aux/missing
68         build-aux/mdate-sh
69         build-aux/texinfo.tex
70         build-aux/depcomp
71         build-aux/config.guess
72         build-aux/config.sub
73         doc/INSTALL
74 '
75
76 # Other locale categories that need message catalogs.
77 EXTRA_LOCALE_CATEGORIES=
78
79 # Additional xgettext options to use.  Use "\\\newline" to break lines.
80 XGETTEXT_OPTIONS='\\\
81  --flag=_:1:pass-c-format\\\
82  --flag=N_:1:pass-c-format\\\
83  --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
84 '
85
86 # Files we don't want to import.
87 excluded_files=
88
89 # Override the default configuration, if necessary.
90 test -r bootstrap.conf && . ./bootstrap.conf
91
92 # Translate configuration into internal form.
93
94 # Parse options.
95
96 for option
97 do
98   case $option in
99   --help)
100     echo "$0: usage: $0 [--gnulib-srcdir=DIR] [--cvs-user=USERNAME] [--skip-po]"
101     exit;;
102   --gnulib-srcdir=*)
103     GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
104   --cvs-user=*)
105     CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;;
106   --skip-po)
107     SKIP_PO=t;;
108   *)
109     echo >&2 "$0: $option: unknown option"
110     exit 1;;
111   esac
112 done
113
114 echo "$0: Bootstrapping CVS $package..."
115
116 cleanup_gnulib() {
117   status=$?
118   rm -fr gnulib
119   exit $status
120 }
121
122 # Get gnulib files.
123
124 case ${GNULIB_SRCDIR--} in
125 -)
126   if [ ! -d gnulib ]; then
127     echo "$0: getting gnulib files..."
128
129     case ${CVS_AUTH-pserver} in
130     pserver)
131       CVS_PREFIX=':pserver:anonymous@';;
132     ssh)
133       CVS_PREFIX="$CVS_USER${CVS_USER+@}";;
134     *)
135       echo "$0: $CVS_AUTH: Unknown CVS access method" >&2
136       exit 1;;
137     esac
138
139     case $CVS_RSH in
140     '') export CVS_RSH=ssh;;
141     esac
142
143     trap cleanup_gnulib 1 2 13 15
144
145     cvs -z3 -q -d ${CVS_PREFIX}cvs.savannah.gnu.org:/cvsroot/gnulib co gnulib ||
146       cleanup_gnulib
147
148     trap - 1 2 13 15
149   fi
150   GNULIB_SRCDIR=gnulib
151 esac
152
153 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
154 <$gnulib_tool || exit
155
156 # Get translations.
157
158 get_translations() {
159   subdir=$1
160   domain=$2
161
162   echo "$0: getting translations into $subdir for $domain..."
163   (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`) &&
164
165   $WGET_COMMAND -O "$subdir/$domain.html" "$TP_URL$domain" &&
166
167   sed -n 's|.*"http://[^"]*/translation/teams/PO/\([^/"]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\1.\2|p' <"$subdir/$domain.html" |
168   sort -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
169   awk -F. '
170     { if (lang && $1 != lang) print lang, ver }
171     { lang = $1; ver = substr($0, index($0, ".") + 1) }
172     END { if (lang) print lang, ver }
173   ' | awk -v domain="$domain" -v subdir="$subdir" '
174     {
175       lang = $1
176       ver = $2
177       urlfmt = ""
178       printf "{ $WGET_COMMAND -O %s/%s.po '\'"$TP_PO_URL"'/%s/%s-%s.%s.po'\'' &&\n", subdir, lang, lang, domain, ver, lang
179       printf "  msgfmt -c -o /dev/null %s/%s.po || {\n", subdir, lang
180       printf "    echo >&2 '\'"$0"': omitting translation for %s'\''\n", lang
181       printf "    rm -f %s/%s.po; }; } &&\n", subdir, lang
182     }
183     END { print ":" }
184   ' | sh &&
185   ls "$subdir"/*.po | sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
186   rm "$subdir/$domain.html"
187 }
188
189 case $SKIP_PO in
190 '')
191   case `wget --help` in
192   *'--no-cache'*)
193     no_cache='--no-cache';;
194   *'--cache=on/off'*)
195     no_cache='--cache=off';;
196   *)
197     no_cache='';;
198   esac
199
200   WGET_COMMAND="wget -nv $no_cache"
201   export WGET_COMMAND
202
203   get_translations po $package || exit
204
205   if test -d runtime-po; then
206     get_translations runtime-po $package-runtime || exit
207   fi;;
208 esac
209
210
211 slurp() {
212   for dir in . `(cd $1 && find * -type d -print)`; do
213     copied=
214     sep=
215     for file in `ls $1/$dir`; do
216       test -d $1/$dir/$file && continue
217       for excluded_file in $excluded_files; do
218         test "$dir/$file" = "$excluded_file" && continue 2
219       done
220       if test $file = Makefile.am; then
221         copied=$copied${sep}gnulib.mk; sep=$nl
222         echo "$0: Copying $1/$dir/$file to $dir/gnulib.mk ..." &&
223         sed '/^[^#].*\/intl/s/^/#/' $1/$dir/$file >$dir/gnulib.mk
224       elif test -r ${2-no/such/dir}/$dir/$file ||
225            grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
226              grep -q '^/[^/]*/[0-9]'; then
227         echo "$0: $dir/$file overrides $1/$dir/$file"
228       else
229         copied=$copied$sep$file; sep=$nl
230         if test $file = gettext.m4; then
231           echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
232           sed '
233             /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
234               AC_DEFUN([AM_INTL_SUBDIR], [
235             /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
236               AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
237             $a\
238               AC_DEFUN([gl_LOCK_EARLY], [])
239           ' $1/$dir/$file >$dir/$file
240         else
241           cp $1/$dir/$file $dir/$file
242         fi
243       fi || exit
244     done
245
246     ig=$dir/.cvsignore
247     if test -n "$copied" && test -f $ig; then
248       echo "$copied" | sort -u - $ig | cmp -s - $ig ||
249       echo "$copied" | sort -u - $ig -o $ig || exit
250     fi
251   done
252 }
253
254
255 # Create boot temporary directories to import from gnulib and gettext.
256
257 bt='.#bootmp'
258 bt2=${bt}2
259 rm -fr $bt $bt2 &&
260 mkdir $bt $bt2 || exit
261
262 # Import from gnulib.
263
264 gnulib_tool_options="\
265  --import\
266  --no-changelog\
267  --aux-dir $bt/build-aux\
268  --doc-base $bt/doc\
269  --lib lib$package\
270  --m4-base $bt/m4/\
271  --source-base $bt/lib/\
272  --tests-base $bt/tests\
273 "
274 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
275 $gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
276 slurp $bt || exit
277
278
279 # Import from gettext.
280
281 echo "$0: (cd $bt2; autopoint) ..."
282 cp configure.ac $bt2 &&
283 (cd $bt2 && autopoint && rm configure.ac) &&
284 slurp $bt2 $bt || exit
285
286 rm -fr $bt $bt2 || exit
287
288
289 # Reconfigure, getting other files.
290
291 for command in \
292   'aclocal --force -I m4' \
293   'autoconf --force' \
294   'autoheader --force' \
295   'automake --add-missing --copy --force-missing';
296 do
297   echo "$0: $command ..."
298   $command || exit
299 done
300
301
302 # Get some extra files from gnulib, overriding existing files.
303
304 for file in $gnulib_extra_files; do
305   src=$GNULIB_SRCDIR/$file
306   case $file in
307   */INSTALL) dest=.;;
308   *) dest=$file;;
309   esac
310   echo "$0: cp -fp $GNULIB_SRCDIR/$file $dest" &&
311   cp -fp $GNULIB_SRCDIR/$file $dest || exit
312 done
313
314
315 # Create gettext configuration.
316 echo "$0: Creating po/Makevars from po/Makevars.template ..."
317 sed '
318   /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
319   /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
320   /^XGETTEXT_OPTIONS *=/{
321     s/$/ \\/
322     a\
323         '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
324   }
325 ' po/Makevars.template >po/Makevars
326
327 if test -d runtime-po; then
328   # Likewise for runtime-po/Makevars, except also change a few other parameters.
329   sed '
330     s/^\(DOMAIN\) *=.*/\1 = '"$package"'-runtime/
331     s/^\(subdir\) *=.*/\1 = runtime-po/
332     s/^\(XGETTEXT_OPTIONS\) *=.*/\1 = '"$XGETTEXT_OPTIONS_RUNTIME"'/
333   ' <po/Makevars >runtime-po/Makevars
334
335   # Copy identical files from po to runtime-po.
336   (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
337 fi
338
339 echo "$0: done.  Now you can run './configure'."