summaryrefslogtreecommitdiff
path: root/bootstrap
blob: 628b4bd43ea4d4063f26a3984d50f8d7389491b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
#! /bin/sh

# bootstrap (GNU M4) version 2009-05-04
# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software
# Foundation, Inc.
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.

# Written by Gary V. Vaughan  <gary@gnu.org>

# This file is part of GNU M4.
#
# GNU M4 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNU M4 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Usage: $progname [options]

# -f      --force            bootstrap even when sources are not from git
#         --skip-po          skip downloading pofiles
# -v      --version          print version information
# -h,-?   --help             print short or long help message

# You can also set the following variables to help $progname
# locate the right tools:
#   AUTOPOINT, AUTORECONF, AWK, CONFIG_SHELL, GNULIB_SRCDIR, LIBTOOLIZE,
#   M4, RM, SED

# This script bootstraps a git or CVS checkout of GNU M4 by correctly calling
# out to parts of the GNU Build Platform.  Currently this requires GNU
# Gettext 0.16 or better, the latest git Autoconf 2.63b-41 or better,
# GNU M4 1.4.5 or better, Automake 1.10b or better, Libtool 2.2 or better,
# and the latest git or CVS checkout of Gnulib.
# Libtool must be installed; either with the same --prefix as
# automake, or made accessible to aclocal's search path via
# $AUTOMAKE_prefix/share/aclocal/dirlist.

# Report bugs to <bug-m4@gnu.org>

: ${AUTOPOINT=autopoint}
: ${AUTORECONF=autoreconf}
: ${AWK=awk}
: ${CONFIG_SHELL=/bin/sh}
: ${LIBTOOLIZE=libtoolize}
: ${M4=m4}
: ${RM='rm -f'}
: ${SED=sed}

# Ensure file names are sorted consistently across platforms.
# Also, ensure diagnostics are in English.
LC_ALL=C
export LC_ALL

package=m4
ltdldir=ltdl
config_aux_dir=build-aux
config_macro_dir=$ltdldir/m4
bailout_cb=:

# List dependencies here too; we don't extract them, otherwise dependent
# modules could end up being imported to src/ *and* gnu/!
src_modules='getopt version-etc-fsf version-etc xstrtol'

dirname="s,/[^/]*$,,"
basename="s,^.*/,,g"

# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
# is ksh but when the shell is invoked as "sh" and the current value of
# the _XPG environment variable is not equal to 1 (one), the special
# positional parameter $0, within a function call, is the name of the
# function.
progpath="$0"

# The name of this program:
progname=`echo "$progpath" | $SED "$basename"`
PROGRAM=bootstrap

# Detect whether this is a version control system checkout or a tarball
vcs_only_file=HACKING

# func_echo arg...
# Echo program name prefixed message.
func_echo ()
{
    echo $progname: ${1+"$@"}
}

# func_error arg...
# Echo program name prefixed message to standard error.
func_error ()
{
    echo $progname: ${1+"$@"} >&2
}

# func_fatal_error arg...
# Echo program name prefixed message to standard error, and exit.
func_fatal_error ()
{
    func_error ${1+"$@"}
    exit $EXIT_FAILURE
}

# func_verbose arg...
# Echo program name prefixed message in verbose mode only.
func_verbose ()
{
    $opt_verbose && func_error ${1+"$@"}
}

# func_missing_arg argname
# Echo program name prefixed message to standard error and set global
# exit_cmd.
func_missing_arg ()
{
   func_error "missing argument for $1"
   exit_cmd=exit
}

# func_fatal_help arg...
# Echo program name prefixed message to standard error, followed by
# a help hint, and exit.
func_fatal_help ()
{
    func_error ${1+"$@"}
    func_fatal_error "Try \`$progname --help' for more information."
}

# func_missing_arg argname
# Echo program name prefixed message to standard error and set global
# exit_cmd.
func_missing_arg ()
{
   func_error "missing argument for $1"
   exit_cmd=exit
}

# func_usage
# Echo short help message to standard output and exit.
func_usage ()
{
    $SED '/^# Usage:/,/# -h/ {
	s/^# //; s/^# *$//;
	s/\$progname/'$progname'/;
	p;
    }; d' < "$progpath"
    echo
    echo "run \`$progname --help | more' for full usage"
    exit $EXIT_SUCCESS
}

# func_help
# Echo long help message to standard output and exit.
func_help ()
{
    $SED '/^# Usage:/,/# Report bugs to/ {
	s/^# //; s/^# *$//;
	s/\$progname/'$progname'/;
	p;
     }; d' < "$progpath"
    exit $EXIT_SUCCESS
}

# func_version
# Echo version message to standard output and exit.
func_version ()
{
    $SED '/^# '$PROGRAM' (GNU /,/# Written by / {
	s/^# //;
	s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
	p;
     }; d' < "$progpath"
     exit $EXIT_SUCCESS
}

# func_update
# Copy $1 to $2 if it is newer.
func_update ()
{
  if test -f "$2" && cmp -s "$1" "$2" ; then
    func_verbose "$2 is up-to-date"
  else
    func_echo "copying $1 -> $2"
    cp "$1" "$2"
  fi
}

# Parse options once, thoroughly.  This comes as soon as possible in
# the script to make things like `bootstrap --version' happen quickly.
{
  # sed scripts:
  my_sed_single_opt='1s/^\(..\).*$/\1/;q'
  my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
  my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
  my_sed_long_arg='1s/^--[^=]*=//'

  # this just eases exit handling
  while test $# -gt 0; do
    opt="$1"
    shift
    case $opt in
      -f|--force)	vcs_only_file=					;;
      --skip-po)	SKIP_PO=t					;;
      -\?|-h)		func_usage					;;
      --help)		func_help					;;
      --version)	func_version					;;
      --)		break						;;
      -*)		func_fatal_help "unrecognized option \`$opt'"	;;
      *)		set -- "$opt" ${1+"$@"};	break		;;
    esac
  done

  # Bail if the options were screwed
  $exit_cmd $EXIT_FAILURE

  if test -n "$vcs_only_file" && test ! -r "$vcs_only_file"; then
    func_fatal_error \
      "Bootstrapping from a non-version-control distribution is risky."
  fi
}

## --------------------------------------- ##
## Fetch translations.                     ##
## (taken from gnulib build-aux/bootstrap) ##
## --------------------------------------- ##

# The command to download all .po files for a specified domain into
# a specified directory.  Fill in the first %s with the domain name,
# the second with the destination directory.  Use rsync's -L and -r
# options because the latest/%s directory and the .po files within
# are all symlinks.
po_download_command_format=\
"rsync -Lrtvz 'translationproject.org::tp/latest/%s/' '%s'"

func_get_translations()
{
  subdir=$1
  domain=$2

  func_echo "getting translations into $subdir for $domain..."
  cmd=`printf "$po_download_command_format" "$domain" "$subdir"`
  eval "$cmd"
}

## --------------------------------------- ##
## Update translations.                    ##
## (taken from gnulib build-aux/bootstrap) ##
## --------------------------------------- ##

func_update_po ()
{
  # Directory containing primary .po files.
  # Overwrite them only when we're sure a .po file is new.
  po_dir=po
  domain=$package

  # Download *.po files into this dir.
  # Usually contains *.s1 checksum files.
  ref_po_dir="$po_dir/.reference"

  test -d $ref_po_dir || mkdir $ref_po_dir || return

  func_get_translations $ref_po_dir $domain \
    && ls "$ref_po_dir"/*.po 2>/dev/null \
       | sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS"
  langs=`cd $ref_po_dir && echo *.po | sed 's/\.po//g'`

  test "$langs" = '*' && langs=x
  for po in $langs; do
    case $po in x) continue;; esac
    new_po="$ref_po_dir/$po.po"
    cksum_file="$ref_po_dir/$po.s1"
    if ! test -f "$cksum_file" ||
	! test -f "$po_dir/$po.po" ||
	! sha1sum -c --status "$cksum_file" < "$new_po" > /dev/null; then
      echo "updated $po_dir/$po.po..."
      cp "$new_po" "$po_dir/$po.po" && sha1sum < "$new_po" > "$cksum_file"
    fi
  done
}

case $SKIP_PO in
  '')  func_update_po ;;
esac

## ---------------- ##
## Version control. ##
## ---------------- ##

# gnulib-tool updates ltdl/m4/.{git,cvs}ignore and gnu/.{git,cvs}ignore, and
# keeping generated files under version control does not make sense.  Since
# gnu is entirely ignored, we only need to prepopulate the ltdl/m4 ignore
# files with generated files not tracked by gnulib-tool.
if test -f $config_macro_dir/.gitignore ; then
  :
else
  func_echo "creating initial $config_macro_dir/.cvsignore"
  cat > $config_macro_dir/.cvsignore <<\EOF
# files created by gnulib, but that gnulib doesn't track
*~
.cvsignore
.gitignore
gnulib-comp.m4
# files manually imported, rather than using gnulib-tool
getopt.m4
xstrtol.m4
# files created by autopoint
codeset.m4
gettext.m4
glibc2.m4
glibc21.m4
iconv.m4
intdiv0.m4
intl.m4
intldir.m4
intmax.m4
inttypes-pri.m4
inttypes_h.m4
lcmessage.m4
lib-ld.m4
lib-link.m4
lib-prefix.m4
lock.m4
longdouble.m4
longlong.m4
nls.m4
po.m4
printf-posix.m4
progtest.m4
size_max.m4
stdint_h.m4
uintmax_t.m4
ulonglong.m4
visibility.m4
wchar_t.m4
wint_t.m4
xsize.m4
# files created by libtoolize
argz.m4
libtool.m4
ltdl.m4
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
# gnulib-tool edits below here
EOF
  func_echo "creating initial $config_macro_dir/.gitignore"
  cp $config_macro_dir/.cvsignore $config_macro_dir/.gitignore
fi

# See if we can use gnulib's git-merge-changelog merge driver.
if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
  if git config merge.merge-changelog.driver >/dev/null ; then
    :
  elif (git-merge-changelog --version) >/dev/null 2>/dev/null ; then
    func_echo "initializing git-merge-changelog driver"
    git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
    git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
  else
    func_echo "consider installing git-merge-changelog from gnulib"
  fi
  if git config diff.texinfo.funcname >/dev/null ; then
    :
  else
    func_echo "initializing git texinfo diff driver"
    git config diff.texinfo.funcname '^@node[	 ][	 ]*\\([^,][^,]*\\)'
  fi
fi

## ---------- ##
## Autopoint. ##
## ---------- ##

# Released autopoint has the tendency to install macros that have been
# obsoleted in current gnulib, so run this before gnulib-tool.
func_echo "running: $AUTOPOINT --force"
$AUTOPOINT --force

## ----------- ##
## Libtoolize. ##
## ----------- ##

# Autoreconf runs aclocal before libtoolize, which causes spurious
# warnings if the initial aclocal is confused by the libtoolized
# (or worse out-of-date) macro directory.
func_echo "running: $LIBTOOLIZE --copy --install"
${LIBTOOLIZE} --copy --install

## ------------------------------ ##
## Update the gnulib module tree. ##
## ------------------------------ ##

if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
  if test -f gnulib/gnulib-tool ; then
    func_echo "updating gnulib submodule"
    git submodule update \
      || func_fatal_error "Unable to update gnulib"
  else
    # A fresh checkout creates an empty subdirectory gnulib.  However,
    # older git didn't know how to clone into an empty subdir.  If the
    # user provided GNULIB_SRCDIR, then make the initial clone refer
    # to the existing checkout, to save network traffic.
    func_echo "importing gnulib submodule"
    if test -d "$GNULIB_SRCDIR" ; then
      rmdir gnulib 2>/dev/null
      git clone --reference "$GNULIB_SRCDIR" git://git.sv.gnu.org/gnulib.git \
 && git submodule init && git submodule update \
 || func_fatal_error "Unable to update gnulib"
    else
      git submodule update --init \
 || func_fatal_error "Unable to update gnulib"
    fi
  fi
else
  func_echo "git not detected.  If needed, update gnulib subdirectory manually"
fi


## ---------------------- ##
## Import Gnulib modules. ##
## ---------------------- ##

func_echo "running: $CONFIG_SHELL gnulib/gnulib-tool --update"
$CONFIG_SHELL gnulib/gnulib-tool --update \
  || func_fatal_error "gnulib-tool failed"

## --------------------------------- ##
## Copy additional src only modules. ##
## --------------------------------- ##

func_echo "fetching modules for src directory"

for file in `$CONFIG_SHELL gnulib/gnulib-tool --extract-filelist $src_modules`
do

    dest=`echo $file | $SED "$basename"`
    case $file in
	lib/*) dest=src/$dest ;;
	m4/*)  dest=$config_macro_dir/$dest ;;
	*)     func_echo "Unknown file: $file"
	       exit 1
	       ;;
    esac

    # Be sure to show all copying errors before bailing out
    if test -f gnulib/$file; then
	func_echo "copying file \`$dest'"
	cp gnulib/$file $dest
    else
	func_error "gnulib/$file does not exist"
	bailout_cb="exit 1"
    fi
done
$bailout_cb


## ----------- ##
## Autoreconf. ##
## ----------- ##

# Disable autopoint and libtoolize, since they were already done above.
func_echo "running: AUTOPOINT=true LIBTOOLIZE=true " \
    "$AUTORECONF --verbose --install --no-recursive"
AUTOPOINT=true LIBTOOLIZE=true \
    $AUTORECONF --verbose --install --no-recursive \
  || func_fatal_error "autoreconf failed"

## ------- ##
## Wrapup. ##
## ------- ##

if test x"$SKIP_PO" = x; then
  func_echo "If your pofiles are up-to-date, you can rerun bootstrap"
  func_echo "as \`$progname --skip-po' to avoid redownloading."
fi

exit 0

# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "# bootstrap (GNU M4) version "
# time-stamp-format: "%:y-%02m-%02d"
# time-stamp-end: "$"
# End: