summaryrefslogtreecommitdiff
path: root/autogen.sh
blob: 3af53f263855801806fc215123cf31803cd6e08d (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
#!/bin/sh
# Copyright (C) 2003-2015 Free Software Foundation, Inc.
#
# This program 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.
#
# This program 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/>.

# This script populates the build infrastructure in the source tree
# checked-out from VCS.
#
# This script requires:
#   - Autoconf
#   - Automake
#   - Wget
#   - Git
#   - XZ Utils
#
# By default, it fetches Gnulib as a git submodule.  If you already
# have a local copy of Gnulib, you can avoid extra network traffic by
# setting the GNULIB_SRCDIR environment variable pointing to the path.
#
# In addition, it fetches the archive.dir.tar.gz file, which contains
# data files used by the autopoint program.  If you already have the
# file, place it under gettext-tools/misc, before running this script.
#
# Usage: ./autogen.sh [--skip-gnulib]
#
# Usage after a git clone:              ./autogen.sh
# Usage from a released tarball:        ./autogen.sh --skip-gnulib
# This does not use a gnulib checkout.

# Nuisances.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH

skip_gnulib=false
while :; do
  case "$1" in
    --skip-gnulib) skip_gnulib=true; shift;;
    *) break ;;
  esac
done

cleanup_gnulib() {
  status=$?
  rm -fr "$gnulib_path"
  exit $status
}

git_modules_config () {
  test -f .gitmodules && git config --file .gitmodules "$@"
}

gnulib_path=$(git_modules_config submodule.gnulib.path)
test -z "$gnulib_path" && gnulib_path=gnulib

# The tests in gettext-tools/tests are not meant to be executable, because
# they have a TESTS_ENVIRONMENT that specifies the shell explicitly.

if ! $skip_gnulib; then
  # Get gnulib files.
  case ${GNULIB_SRCDIR--} in
  -)
    if git_modules_config submodule.gnulib.url >/dev/null; then
      echo "$0: getting gnulib files..."
      git submodule init || exit $?
      git submodule update || exit $?

    elif [ ! -d "$gnulib_path" ]; then
      echo "$0: getting gnulib files..."

      trap cleanup_gnulib 1 2 13 15

      shallow=
      git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
      git clone $shallow git://git.sv.gnu.org/gnulib "$gnulib_path" ||
        cleanup_gnulib

      trap - 1 2 13 15
    fi
    GNULIB_SRCDIR=$gnulib_path
    ;;
  *)
    # Use GNULIB_SRCDIR as a reference.
    if test -d "$GNULIB_SRCDIR"/.git && \
          git_modules_config submodule.gnulib.url >/dev/null; then
      echo "$0: getting gnulib files..."
      if git submodule -h|grep -- --reference > /dev/null; then
        # Prefer the one-liner available in git 1.6.4 or newer.
        git submodule update --init --reference "$GNULIB_SRCDIR" \
          "$gnulib_path" || exit $?
      else
        # This fallback allows at least git 1.5.5.
        if test -f "$gnulib_path"/gnulib-tool; then
          # Since file already exists, assume submodule init already complete.
          git submodule update || exit $?
        else
          # Older git can't clone into an empty directory.
          rmdir "$gnulib_path" 2>/dev/null
          git clone --reference "$GNULIB_SRCDIR" \
            "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
            && git submodule init && git submodule update \
            || exit $?
        fi
      fi
      GNULIB_SRCDIR=$gnulib_path
    fi
    ;;
  esac
  # Now it should contain a gnulib-tool.
  if test -f "$GNULIB_SRCDIR"/gnulib-tool; then
    GNULIB_TOOL="$GNULIB_SRCDIR"/gnulib-tool
  else
    echo "** warning: gnulib-tool not found" 1>&2
  fi
  # Skip the gnulib-tool step if gnulib-tool was not found.
  if test -n "$GNULIB_TOOL"; then
    # In gettext-runtime:
    GNULIB_MODULES_RUNTIME_FOR_SRC='
      atexit
      basename
      closeout
      error
      getopt-gnu
      gettext-h
      havelib
      memmove
      progname
      propername
      relocatable-prog
      setlocale
      sigpipe
      stdbool
      stdio
      stdlib
      strtoul
      unlocked-io
      xalloc
    '
    GNULIB_MODULES_RUNTIME_OTHER='
      gettext-runtime-misc
      ansi-c++-opt
      csharpcomp-script
      java
      javacomp-script
    '
    $GNULIB_TOOL --dir=gettext-runtime --lib=libgrt --source-base=gnulib-lib --m4-base=gnulib-m4 --no-libtool --local-dir=gnulib-local --local-symlink \
      --import $GNULIB_MODULES_RUNTIME_FOR_SRC $GNULIB_MODULES_RUNTIME_OTHER || exit $?
    # In gettext-runtime/libasprintf:
    GNULIB_MODULES_LIBASPRINTF='
      alloca
      errno
      verify
      xsize
    '
    GNULIB_MODULES_LIBASPRINTF_OTHER='
    '
    $GNULIB_TOOL --dir=gettext-runtime/libasprintf --source-base=. --m4-base=gnulib-m4 --lgpl=2 --makefile-name=Makefile.gnulib --libtool --local-dir=gnulib-local --local-symlink \
      --import $GNULIB_MODULES_LIBASPRINTF $GNULIB_MODULES_LIBASPRINTF_OTHER || exit $?
    $GNULIB_TOOL --copy-file m4/intmax_t.m4 gettext-runtime/libasprintf/gnulib-m4/intmax_t.m4 || exit $?
    # In gettext-tools:
    GNULIB_MODULES_TOOLS_FOR_SRC='
      alloca-opt
      atexit
      backupfile
      basename
      binary-io
      bison-i18n
      byteswap
      c-ctype
      c-strcase
      c-strcasestr
      c-strstr
      clean-temp
      closedir
      closeout
      copy-file
      csharpcomp
      csharpexec
      error
      error-progname
      execute
      fd-ostream
      file-ostream
      filename
      findprog
      fnmatch
      fopen
      fstrcmp
      full-write
      fwriteerror
      gcd
      getline
      getopt-gnu
      gettext-h
      hash
      html-styled-ostream
      iconv
      javacomp
      javaexec
      libunistring-optional
      localcharset
      locale
      localename
      lock
      memmove
      memset
      minmax
      obstack
      open
      opendir
      openmp
      ostream
      pipe-filter-ii
      progname
      propername
      readdir
      relocatable-prog
      relocatable-script
      setlocale
      sh-quote
      sigpipe
      sigprocmask
      spawn-pipe
      stdbool
      stdio
      stdlib
      stpcpy
      stpncpy
      strcspn
      strerror
      strpbrk
      strtol
      strtoul
      styled-ostream
      sys_select
      sys_stat
      sys_time
      term-styled-ostream
      unictype/ctype-space
      unilbrk/ulc-width-linebreaks
      uniname/uniname
      unistd
      unistr/u8-mbtouc
      unistr/u8-mbtoucr
      unistr/u8-uctomb
      unistr/u16-mbtouc
      uniwidth/width
      unlocked-io
      vasprintf
      wait-process
      write
      xalloc
      xconcat-filename
      xmalloca
      xerror
      xsetenv
      xstriconv
      xstriconveh
      xvasprintf
    '
    # Common dependencies of GNULIB_MODULES_TOOLS_FOR_SRC and GNULIB_MODULES_TOOLS_FOR_LIBGREP.
    GNULIB_MODULES_TOOLS_FOR_SRC_COMMON_DEPENDENCIES='
      alloca-opt
      extensions
      gettext-h
      include_next
      locale
      localcharset
      malloc-posix
      mbrtowc
      mbsinit
      multiarch
      snippet/arg-nonnull
      snippet/c++defs
      snippet/warn-on-use
      ssize_t
      stdbool
      stddef
      stdint
      stdlib
      streq
      unistd
      verify
      wchar
      wctype-h
    '
    GNULIB_MODULES_TOOLS_OTHER='
      gettext-tools-misc
      ansi-c++-opt
      csharpcomp-script
      csharpexec-script
      gcj
      java
      javacomp-script
      javaexec-script
      stdint
    '
    GNULIB_MODULES_TOOLS_LIBUNISTRING_TESTS='
      unilbrk/u8-possible-linebreaks-tests
      unilbrk/ulc-width-linebreaks-tests
      unistr/u8-mbtouc-tests
      unistr/u8-mbtouc-unsafe-tests
      uniwidth/width-tests
    '
    $GNULIB_TOOL --dir=gettext-tools --lib=libgettextlib --source-base=gnulib-lib --m4-base=gnulib-m4 --tests-base=gnulib-tests --makefile-name=Makefile.gnulib --libtool --with-tests --local-dir=gnulib-local --local-symlink \
      --import --avoid=hash-tests `for m in $GNULIB_MODULES_TOOLS_LIBUNISTRING_TESTS; do echo --avoid=$m; done` $GNULIB_MODULES_TOOLS_FOR_SRC $GNULIB_MODULES_TOOLS_FOR_SRC_COMMON_DEPENDENCIES $GNULIB_MODULES_TOOLS_OTHER || exit $?
    # In gettext-tools/libgrep:
    GNULIB_MODULES_TOOLS_FOR_LIBGREP='
      mbrlen
      regex
    '
    $GNULIB_TOOL --dir=gettext-tools --macro-prefix=grgl --lib=libgrep --source-base=libgrep --m4-base=libgrep/gnulib-m4 --witness-c-macro=IN_GETTEXT_TOOLS_LIBGREP --makefile-name=Makefile.gnulib --local-dir=gnulib-local --local-symlink \
      --import `for m in $GNULIB_MODULES_TOOLS_FOR_SRC_COMMON_DEPENDENCIES; do if test \`$GNULIB_TOOL --extract-applicability $m\` != all; then echo --avoid=$m; fi; done` $GNULIB_MODULES_TOOLS_FOR_LIBGREP || exit $?
    # In gettext-tools/libgettextpo:
    # This is a subset of the GNULIB_MODULES_FOR_SRC.
    GNULIB_MODULES_LIBGETTEXTPO='
      basename
      close
      c-ctype
      c-strcase
      c-strstr
      error
      error-progname
      file-ostream
      filename
      fopen
      fstrcmp
      fwriteerror
      gcd
      getline
      gettext-h
      hash
      iconv
      libunistring-optional
      minmax
      open
      ostream
      progname
      relocatable-lib
      sigpipe
      stdbool
      stdio
      stdlib
      stpcpy
      stpncpy
      strchrnul
      strerror
      unictype/ctype-space
      unilbrk/ulc-width-linebreaks
      unistr/u8-mbtouc
      unistr/u8-mbtoucr
      unistr/u8-uctomb
      unistr/u16-mbtouc
      uniwidth/width
      unlocked-io
      vasprintf
      xalloc
      xconcat-filename
      xmalloca
      xerror
      xstriconv
      xvasprintf
    '
    GNULIB_MODULES_LIBGETTEXTPO_OTHER='
    '
    $GNULIB_TOOL --dir=gettext-tools --source-base=libgettextpo --m4-base=libgettextpo/gnulib-m4 --macro-prefix=gtpo --makefile-name=Makefile.gnulib --libtool --local-dir=gnulib-local --local-symlink \
      --import $GNULIB_MODULES_LIBGETTEXTPO $GNULIB_MODULES_LIBGETTEXTPO_OTHER || exit $?
    # Import build tools.  We use --copy-file to avoid directory creation.
    $GNULIB_TOOL --copy-file tests/init.sh gettext-tools || exit $?
    $GNULIB_TOOL --copy-file build-aux/git-version-gen || exit $?
  fi
fi

# Fetch config.guess, config.sub.
if test -n "$GNULIB_TOOL"; then
  for file in config.guess config.sub; do
    $GNULIB_TOOL --copy-file build-aux/$file; chmod a+x build-aux/$file || exit $?
  done
else
  for file in config.guess config.sub; do
    echo "$0: getting $file..."
    wget -q --timeout=5 -O build-aux/$file.tmp "http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=build-aux/${file};hb=HEAD" \
      && mv build-aux/$file.tmp build-aux/$file \
      && chmod a+x build-aux/$file
    retval=$?
    rm -f build-aux/$file.tmp
    test $retval -eq 0 || exit $retval
  done
fi

# Fetch gettext-tools/misc/archive.dir.tar.
if ! test -f gettext-tools/misc/archive.dir.tar; then
  if ! test -f gettext-tools/misc/archive.dir.tar.xz; then
    echo "$0: getting gettext-tools/misc/archive.dir.tar..."
    wget -q --timeout=5 -O gettext-tools/misc/archive.dir.tar.xz-t "ftp://alpha.gnu.org/gnu/gettext/archive.dir-latest.tar.xz" \
      && mv gettext-tools/misc/archive.dir.tar.xz-t gettext-tools/misc/archive.dir.tar.xz
    retval=$?
    rm -f gettext-tools/misc/archive.dir.tar.xz-t
    test $retval -eq 0 || exit $retval
  fi
  xz -d -c < gettext-tools/misc/archive.dir.tar.xz > gettext-tools/misc/archive.dir.tar-t \
    && mv gettext-tools/misc/archive.dir.tar-t gettext-tools/misc/archive.dir.tar
  retval=$?
  rm -f gettext-tools/misc/archive.dir.tar-t
  test $retval -eq 0 || exit $retval
fi

# Generate configure script in each subdirectories.
(cd gettext-runtime/libasprintf
 echo "$0: generating configure in gettext-runtime/libasprintf..."
 aclocal -I ../../m4 -I ../m4 -I gnulib-m4
 autoconf
 autoheader && touch config.h.in
 automake --add-missing --copy
)

(cd gettext-runtime
 echo "$0: generating configure in gettext-runtime..."
 aclocal -I m4 -I ../m4 -I gnulib-m4
 autoconf
 autoheader && touch config.h.in
 automake --add-missing --copy
)

(cd gettext-tools/examples
 echo "$0: generating configure in gettext-tools/examples..."
 aclocal -I ../../gettext-runtime/m4 -I ../../m4
 autoconf
 automake --add-missing --copy
)

echo "$0: copying common files from gettext-runtime to gettext-tools..."
cp -p gettext-runtime/ABOUT-NLS gettext-tools/ABOUT-NLS
cp -p gettext-runtime/po/Makefile.in.in gettext-tools/po/Makefile.in.in
cp -p gettext-runtime/po/Rules-quot gettext-tools/po/Rules-quot
cp -p gettext-runtime/po/boldquot.sed gettext-tools/po/boldquot.sed
cp -p gettext-runtime/po/quot.sed gettext-tools/po/quot.sed
cp -p gettext-runtime/po/en@quot.header gettext-tools/po/en@quot.header
cp -p gettext-runtime/po/en@boldquot.header gettext-tools/po/en@boldquot.header
cp -p gettext-runtime/po/insert-header.sin gettext-tools/po/insert-header.sin
cp -p gettext-runtime/po/remove-potcdate.sin gettext-tools/po/remove-potcdate.sin
# Those two files might be newer than Gnulib's.
sed_extract_serial='s/^#.* serial \([^ ]*\).*/\1/p
1q'
for file in intl.m4 po.m4; do
  existing_serial=`sed -n -e "$sed_extract_serial" < "gettext-tools/gnulib-m4/$file"`
  gettext_serial=`sed -n -e "$sed_extract_serial" < "gettext-runtime/m4/$file"`
  if test -n "$existing_serial" && test -n "$gettext_serial" \
        && test "$existing_serial" -ge "$gettext_serial" 2> /dev/null; then
    :
  else
    cp -p "gettext-runtime/m4/$file" "gettext-tools/gnulib-m4/$file"
  fi
done

(cd gettext-tools
 echo "$0: generating configure in gettext-tools..."
 aclocal -I m4 -I ../gettext-runtime/m4 -I ../m4 -I gnulib-m4 -I libgrep/gnulib-m4 -I libgettextpo/gnulib-m4
 autoconf
 autoheader && touch config.h.in
 test -d intl || mkdir intl
 automake --add-missing --copy
)

aclocal -I m4
autoconf
automake