OSDN Git Service

Updated COPYING file to the GNU General Public License version 3. Updated boilerplat...
[android-x86/external-parted.git] / bootstrap
1 #! /bin/sh
2
3 # Bootstrap this package from CVS.
4
5 # Copyright (C) 2003, 2004, 2005, 2006, 2007 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 3, 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, see <http://www.gnu.org/licenses/>.
19
20 # Written by Paul Eggert.
21
22 nl='
23 '
24
25 # Ensure file names are sorted consistently across platforms.
26 # Also, ensure diagnostics are in English, e.g., "wget --help" below.
27 LC_ALL=C
28 export LC_ALL
29
30 # Temporary directory names.
31 bt='._bootmp'
32 bt_regex=`echo "$bt"| sed 's/\./[.]/g'`
33 bt2=${bt}2
34
35 usage() {
36   echo >&2 "\
37 Usage: $0 [OPTION]...
38 Bootstrap this package from the checked-out sources.
39
40 Options:
41  --gnulib-srcdir=DIRNAME  Specify the local directory where gnulib
42                           sources reside.  Use this if you already
43                           have gnulib sources on your machine, and
44                           do not want to waste your bandwidth downloading
45                           them again.
46  --copy                   Copy files instead of creating symbolic links.
47  --force                  Attempt to bootstrap even if the sources seem
48                           not to have been checked out.
49  --skip-po                Do not download po files.
50  --cvs-user=USERNAME      Set the CVS username to be used when accessing
51                           the gnulib repository.
52
53 If the file .bootstrap.conf exists in the current working directory, its
54 contents are read as shell variables to configure the bootstrap.
55
56 Running without arguments will suffice in most cases.
57 "
58 }
59
60 # Configuration.
61
62 # List of gnulib modules needed.
63 gnulib_modules=
64
65 # Any gnulib files needed that are not in modules.
66 gnulib_files=
67
68 # Translation Project URL, for the registry of all projects
69 # and for the translation-team master directory.
70 TP_URL='http://www.iro.umontreal.ca/translation/registry.cgi?domain='
71 TP_PO_URL='http://www.iro.umontreal.ca/translation/teams/PO/'
72
73 extract_package_name='
74   /^AC_INIT(/{
75      /.*,.*,.*,/{
76        s///
77        s/[][]//g
78        p
79        q
80      }
81      s/AC_INIT(\[*//
82      s/]*,.*//
83      s/^GNU //
84      y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
85      s/[^A-Za-z0-9_]/-/g
86      p
87   }
88 '
89 package=`sed -n "$extract_package_name" configure.ac` || exit
90
91 # Extra files from gnulib, which override files from other sources.
92 gnulib_extra_files='
93         build-aux/install-sh
94         build-aux/missing
95         build-aux/mdate-sh
96         build-aux/texinfo.tex
97         build-aux/depcomp
98         build-aux/config.guess
99         build-aux/config.sub
100         doc/INSTALL
101 '
102
103 # Other locale categories that need message catalogs.
104 EXTRA_LOCALE_CATEGORIES=
105
106 # Additional xgettext options to use.  Use "\\\newline" to break lines.
107 XGETTEXT_OPTIONS='\\\
108  --flag=_:1:pass-c-format\\\
109  --flag=N_:1:pass-c-format\\\
110  --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
111 '
112
113 # Files we don't want to import.
114 excluded_files=
115
116 # File that should exist in the top directory of a checked out hierarchy,
117 # but not in a distribution tarball.
118 CVS_only_file=README-hacking
119
120 # Whether to use copies instead of symlinks.
121 copy=false
122
123 # Override the default configuration, if necessary.
124 test -r bootstrap.conf && . ./bootstrap.conf
125
126 # Translate configuration into internal form.
127
128 # Parse options.
129
130 for option
131 do
132   case $option in
133   --help)
134     usage
135     exit;;
136   --gnulib-srcdir=*)
137     GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
138   --cvs-user=*)
139     CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;;
140   --skip-po)
141     SKIP_PO=t;;
142   --force)
143     CVS_only_file=;;
144   --copy)
145     copy=true;;
146   *)
147     echo >&2 "$0: $option: unknown option"
148     exit 1;;
149   esac
150 done
151
152 if test -n "$CVS_only_file" && test ! -r "$CVS_only_file"; then
153   echo "$0: Bootstrapping from a non-checked-out distribution is risky." >&2
154   exit 1
155 fi
156
157 test -d build-aux || mkdir build-aux
158
159 echo "$0: Bootstrapping CVS $package..."
160
161 cleanup_gnulib() {
162   status=$?
163   rm -fr gnulib
164   exit $status
165 }
166
167 # Get gnulib files.
168
169 case ${GNULIB_SRCDIR--} in
170 -)
171   if [ ! -d gnulib ]; then
172     echo "$0: getting gnulib files..."
173
174     case ${CVS_AUTH-pserver} in
175     pserver)
176       CVS_PREFIX=':pserver:anonymous@';;
177     ssh)
178       CVS_PREFIX="$CVS_USER${CVS_USER+@}";;
179     *)
180       echo "$0: $CVS_AUTH: Unknown CVS access method" >&2
181       exit 1;;
182     esac
183
184     case $CVS_RSH in
185     '') CVS_RSH=ssh; export CVS_RSH;;
186     esac
187
188     trap cleanup_gnulib 1 2 13 15
189
190     cvs -z3 -q -d ${CVS_PREFIX}cvs.savannah.gnu.org:/cvsroot/gnulib co gnulib ||
191       cleanup_gnulib
192
193     trap - 1 2 13 15
194   fi
195   GNULIB_SRCDIR=gnulib
196 esac
197
198 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
199 <$gnulib_tool || exit
200
201 # Get translations.
202
203 get_translations() {
204   subdir=$1
205   domain=$2
206
207   case $WGET_COMMAND in
208   '')
209     echo "$0: wget not available; skipping translations";;
210   ?*)
211     echo "$0: getting translations into $subdir for $domain..." &&
212
213     (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`) &&
214     $WGET_COMMAND -O "$subdir/$domain.html" "$TP_URL$domain" &&
215
216     sed -n 's|.*"http://[^"]*/translation/teams/PO/\([^/"]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\1.\2|p' <"$subdir/$domain.html" |
217     sort -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
218     awk -F. '
219       { if (lang && $1 != lang) print lang, ver }
220       { lang = $1; ver = substr($0, index($0, ".") + 1) }
221       END { if (lang) print lang, ver }
222     ' | awk -v domain="$domain" -v subdir="$subdir" '
223       {
224         lang = $1
225         ver = $2
226         urlfmt = ""
227         printf "{ $WGET_COMMAND -O %s/%s.po '\'"$TP_PO_URL"'/%s/%s-%s.%s.po'\'' &&\n", subdir, lang, lang, domain, ver, lang
228         printf "  msgfmt -c -o /dev/null %s/%s.po || {\n", subdir, lang
229         printf "    echo >&2 '\'"$0"': omitting translation for %s'\''\n", lang
230         printf "    rm -f %s/%s.po; }; } &&\n", subdir, lang
231       }
232       END { print ":" }
233     ' | WGET_COMMAND="$WGET_COMMAND" sh;;
234   esac &&
235   ls "$subdir"/*.po 2>/dev/null |
236     sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
237   rm -f "$subdir/$domain.html"
238 }
239
240 case $SKIP_PO in
241 '')
242   case `wget --help` in
243   *'--no-cache'*)
244     WGET_COMMAND='wget -nv --no-cache';;
245   *'--cache=on/off'*)
246     WGET_COMMAND='wget -nv --cache=off';;
247   *'--non-verbose'*)
248     WGET_COMMAND='wget -nv';;
249   *)
250     WGET_COMMAND='';;
251   esac
252
253   if test -d po; then
254     get_translations po $package || exit
255   fi
256
257   if test -d runtime-po; then
258     get_translations runtime-po $package-runtime || exit
259   fi;;
260 esac
261
262 symlink_to_gnulib()
263 {
264   src=$GNULIB_SRCDIR/$1
265   dst=${2-$1}
266
267   test -f "$src" && {
268     if $copy; then
269       {
270         test ! -h "$dst" || {
271           echo "$0: rm -f $dst" &&
272           rm -f "$dst"
273         }
274       } &&
275       test -f "$dst" &&
276       cmp -s "$src" "$dst" || {
277         echo "$0: cp -fp $src $dst" &&
278         cp -fp "$src" "$dst"
279       }
280     else
281       test -h "$dst" &&
282       src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
283       dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
284       test "$src_i" = "$dst_i" || {
285         dot_dots=
286         case $src in
287         /*) ;;
288         *)
289           case /$dst/ in
290           *//* | */../* | */./* | /*/*/*/*/*/)
291              echo >&2 "$0: invalid symlink calculation: $src -> $dst"
292              exit 1;;
293           /*/*/*/*/)    dot_dots=../../../;;
294           /*/*/*/)      dot_dots=../../;;
295           /*/*/)        dot_dots=../;;
296           esac;;
297         esac
298
299         echo "$0: ln -fs $dot_dots$src $dst" &&
300         ln -fs "$dot_dots$src" "$dst"
301       }
302     fi
303   }
304 }
305
306 cp_mark_as_generated()
307 {
308   cp_src=$1
309   cp_dst=$2
310
311   if cmp -s "$cp_src" "$GNULIB_SRCDIR/$cp_dst"; then
312     symlink_to_gnulib "$cp_dst"
313   else
314     case $cp_dst in
315       *.[ch])             c1='/* '; c2=' */';;
316       *.texi)             c1='@c '; c2=     ;;
317       *.m4|*/Make*|Make*) c1='# ' ; c2=     ;;
318       *)                  c1=     ; c2=     ;;
319     esac
320
321     if test -z "$c1"; then
322       cmp -s "$cp_src" "$cp_dst" || {
323         echo "$0: cp -f $cp_src $cp_dst" &&
324         rm -f "$cp_dst" &&
325         sed "s!$bt_regex/!!g" "$cp_src" > "$cp_dst"
326       }
327     else
328       # Copy the file first to get proper permissions if it
329       # doesn't already exist.  Then overwrite the copy.
330       cp "$cp_src" "$cp_dst-t" &&
331       (
332         echo "$c1-*- buffer-read-only: t -*- vi: set ro:$c2" &&
333         echo "${c1}DO NOT EDIT! GENERATED AUTOMATICALLY!$c2" &&
334         sed "s!$bt_regex/!!g" "$cp_src"
335       ) > $cp_dst-t &&
336       if cmp -s "$cp_dst-t" "$cp_dst"; then
337         rm -f "$cp_dst-t"
338       else
339         echo "$0: cp $cp_src $cp_dst # with edits" &&
340         mv -f "$cp_dst-t" "$cp_dst"
341       fi
342     fi
343   fi
344 }
345
346 version_controlled_file() {
347   dir=$1
348   file=$2
349   found=no
350   if test -d CVS; then
351     grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
352              grep '^/[^/]*/[0-9]' > /dev/null && found=yes
353   elif test -d .git; then
354     git-rm -n "$dir/$file" > /dev/null 2>&1 && found=yes
355   else
356     echo "$0: no version control for $dir/$file?" >&2
357   fi
358   test $found = yes
359 }
360
361 # If $STR is not already on a line by itself in $FILE, insert it,
362 # sorting the new contents of the file and replacing $FILE with the result.
363 insert_sorted_if_absent() {
364   file=$1
365   str=$2
366   echo "$str" | sort -u - $file | cmp -s - $file \
367     || echo "$str" | sort -u - $file -o $file \
368     || exit
369 }
370
371 slurp() {
372   for dir in . `(cd $1 && find * -type d -print)`; do
373     copied=
374     sep=
375     for file in `ls $1/$dir`; do
376       test -d $1/$dir/$file && continue
377       for excluded_file in $excluded_files; do
378         test "$dir/$file" = "$excluded_file" && continue 2
379       done
380       if test $file = Makefile.am; then
381         copied=$copied${sep}gnulib.mk; sep=$nl
382         remove_intl='/^[^#].*\/intl/s/^/#/;'"s!$bt_regex/!!g"
383         sed "$remove_intl" $1/$dir/$file | cmp -s - $dir/gnulib.mk || {
384           echo "$0: Copying $1/$dir/$file to $dir/gnulib.mk ..." &&
385           rm -f $dir/gnulib.mk &&
386           sed "$remove_intl" $1/$dir/$file >$dir/gnulib.mk
387         }
388       elif { test "${2+set}" = set && test -r $2/$dir/$file; } ||
389            version_controlled_file $dir $file; then
390         echo "$0: $dir/$file overrides $1/$dir/$file"
391       else
392         copied=$copied$sep$file; sep=$nl
393         if test $file = gettext.m4; then
394           echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
395           rm -f $dir/$file
396           sed '
397             /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
398               AC_DEFUN([AM_INTL_SUBDIR], [
399             /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
400               AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
401             $a\
402               AC_DEFUN([gl_LOCK_EARLY], [])
403           ' $1/$dir/$file >$dir/$file
404         else
405           cp_mark_as_generated $1/$dir/$file $dir/$file
406         fi
407       fi || exit
408     done
409
410     for dot_ig in .cvsignore .gitignore; do
411       ig=$dir/$dot_ig
412       if test -n "$copied" && test -f $ig; then
413         insert_sorted_if_absent $ig "$copied"
414         # If an ignored file name ends with _.h, then also add
415         # the name with just ".h".  Many gnulib headers are generated,
416         # e.g., stdint_.h -> stdint.h, dirent_.h ->..., etc.
417         f=`echo "$copied"|sed 's/_\.h$/.h/'`
418         insert_sorted_if_absent $ig "$f"
419       fi
420     done
421   done
422 }
423
424
425 # Create boot temporary directories to import from gnulib and gettext.
426 rm -fr $bt $bt2 &&
427 mkdir $bt $bt2 || exit
428
429 # Import from gnulib.
430
431 gnulib_tool_options="\
432  --import\
433  --no-changelog\
434  --aux-dir $bt/build-aux\
435  --doc-base $bt/doc\
436  --lib lib$package\
437  --m4-base $bt/m4/\
438  --source-base $bt/lib/\
439  --tests-base $bt/tests\
440  --local-dir gl\
441 "
442 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
443 $gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
444 slurp $bt || exit
445
446 for file in $gnulib_files; do
447   symlink_to_gnulib $file || exit
448 done
449
450
451 # Import from gettext.
452
453 echo "$0: (cd $bt2; autopoint) ..."
454 cp configure.ac $bt2 &&
455 (cd $bt2 && autopoint && rm configure.ac) &&
456 slurp $bt2 $bt || exit
457
458 rm -fr $bt $bt2 || exit
459
460 # If there is no ChangeLog file, create it.
461 if test -d .git; then
462   test -e ChangeLog ||
463     git log --pretty=medium | fold -s > ChangeLog
464 fi
465
466 # Reconfigure, getting other files.
467
468 for command in \
469   'libtoolize -c -f' \
470   'aclocal --force -I m4' \
471   'autoconf --force' \
472   'autoheader --force' \
473   'automake --add-missing --copy --force-missing';
474 do
475   echo "$0: $command ..."
476   $command || exit
477 done
478
479
480 # Get some extra files from gnulib, overriding existing files.
481
482 for file in $gnulib_extra_files; do
483   case $file in
484   */INSTALL) dst=INSTALL;;
485   *) dst=$file;;
486   esac
487   symlink_to_gnulib $file $dst || exit
488 done
489
490
491 # Create gettext configuration.
492 echo "$0: Creating po/Makevars from po/Makevars.template ..."
493 rm -f po/Makevars
494 sed '
495   /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
496   /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
497   /^XGETTEXT_OPTIONS *=/{
498     s/$/ \\/
499     a\
500         '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
501   }
502 ' po/Makevars.template >po/Makevars
503
504 if test -d runtime-po; then
505   # Similarly for runtime-po/Makevars, but not quite the same.
506   rm -f runtime-po/Makevars
507   sed '
508     /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
509     /^subdir *=.*/s/=.*/= runtime-po/
510     /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
511     /^XGETTEXT_OPTIONS *=/{
512       s/$/ \\/
513       a\
514           '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
515     }
516   ' <po/Makevars.template >runtime-po/Makevars
517
518   # Copy identical files from po to runtime-po.
519   (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
520 fi
521
522 echo "$0: done.  Now you can run './configure'."