Add -lm dependency for gettextlib to fix LTO build
[platform/upstream/gettext.git] / autogen.sh
1 #!/bin/sh
2 # Copyright (C) 2003-2015 Free Software Foundation, Inc.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # This script populates the build infrastructure in the source tree
18 # checked-out from VCS.
19 #
20 # This script requires:
21 #   - Autoconf
22 #   - Automake
23 #   - Wget
24 #   - Git
25 #   - XZ Utils
26 #
27 # By default, it fetches Gnulib as a git submodule.  If you already
28 # have a local copy of Gnulib, you can avoid extra network traffic by
29 # setting the GNULIB_SRCDIR environment variable pointing to the path.
30 #
31 # In addition, it fetches the archive.dir.tar.gz file, which contains
32 # data files used by the autopoint program.  If you already have the
33 # file, place it under gettext-tools/misc, before running this script.
34 #
35 # Usage: ./autogen.sh [--skip-gnulib]
36 #
37 # Usage after a git clone:              ./autogen.sh
38 # Usage from a released tarball:        ./autogen.sh --skip-gnulib
39 # This does not use a gnulib checkout.
40
41 # Nuisances.
42 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
43
44 skip_gnulib=false
45 while :; do
46   case "$1" in
47     --skip-gnulib) skip_gnulib=true; shift;;
48     *) break ;;
49   esac
50 done
51
52 cleanup_gnulib() {
53   status=$?
54   rm -fr "$gnulib_path"
55   exit $status
56 }
57
58 git_modules_config () {
59   test -f .gitmodules && git config --file .gitmodules "$@"
60 }
61
62 gnulib_path=$(git_modules_config submodule.gnulib.path)
63 test -z "$gnulib_path" && gnulib_path=gnulib
64
65 # The tests in gettext-tools/tests are not meant to be executable, because
66 # they have a TESTS_ENVIRONMENT that specifies the shell explicitly.
67
68 if ! $skip_gnulib; then
69   # Get gnulib files.
70   case ${GNULIB_SRCDIR--} in
71   -)
72     if git_modules_config submodule.gnulib.url >/dev/null; then
73       echo "$0: getting gnulib files..."
74       git submodule init || exit $?
75       git submodule update || exit $?
76
77     elif [ ! -d "$gnulib_path" ]; then
78       echo "$0: getting gnulib files..."
79
80       trap cleanup_gnulib 1 2 13 15
81
82       shallow=
83       git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
84       git clone $shallow git://git.sv.gnu.org/gnulib "$gnulib_path" ||
85         cleanup_gnulib
86
87       trap - 1 2 13 15
88     fi
89     GNULIB_SRCDIR=$gnulib_path
90     ;;
91   *)
92     # Use GNULIB_SRCDIR as a reference.
93     if test -d "$GNULIB_SRCDIR"/.git && \
94           git_modules_config submodule.gnulib.url >/dev/null; then
95       echo "$0: getting gnulib files..."
96       if git submodule -h|grep -- --reference > /dev/null; then
97         # Prefer the one-liner available in git 1.6.4 or newer.
98         git submodule update --init --reference "$GNULIB_SRCDIR" \
99           "$gnulib_path" || exit $?
100       else
101         # This fallback allows at least git 1.5.5.
102         if test -f "$gnulib_path"/gnulib-tool; then
103           # Since file already exists, assume submodule init already complete.
104           git submodule update || exit $?
105         else
106           # Older git can't clone into an empty directory.
107           rmdir "$gnulib_path" 2>/dev/null
108           git clone --reference "$GNULIB_SRCDIR" \
109             "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
110             && git submodule init && git submodule update \
111             || exit $?
112         fi
113       fi
114       GNULIB_SRCDIR=$gnulib_path
115     fi
116     ;;
117   esac
118   # Now it should contain a gnulib-tool.
119   if test -f "$GNULIB_SRCDIR"/gnulib-tool; then
120     GNULIB_TOOL="$GNULIB_SRCDIR"/gnulib-tool
121   else
122     echo "** warning: gnulib-tool not found" 1>&2
123   fi
124   # Skip the gnulib-tool step if gnulib-tool was not found.
125   if test -n "$GNULIB_TOOL"; then
126     # In gettext-runtime:
127     GNULIB_MODULES_RUNTIME_FOR_SRC='
128       atexit
129       basename
130       closeout
131       error
132       getopt-gnu
133       gettext-h
134       havelib
135       memmove
136       progname
137       propername
138       relocatable-prog
139       setlocale
140       sigpipe
141       stdbool
142       stdio
143       stdlib
144       strtoul
145       unlocked-io
146       xalloc
147     '
148     GNULIB_MODULES_RUNTIME_OTHER='
149       gettext-runtime-misc
150       ansi-c++-opt
151       csharpcomp-script
152       java
153       javacomp-script
154     '
155     $GNULIB_TOOL --dir=gettext-runtime --lib=libgrt --source-base=gnulib-lib --m4-base=gnulib-m4 --no-libtool --local-dir=gnulib-local --local-symlink \
156       --import $GNULIB_MODULES_RUNTIME_FOR_SRC $GNULIB_MODULES_RUNTIME_OTHER || exit $?
157     # In gettext-runtime/libasprintf:
158     GNULIB_MODULES_LIBASPRINTF='
159       alloca
160       errno
161       verify
162       xsize
163     '
164     GNULIB_MODULES_LIBASPRINTF_OTHER='
165     '
166     $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 \
167       --import $GNULIB_MODULES_LIBASPRINTF $GNULIB_MODULES_LIBASPRINTF_OTHER || exit $?
168     $GNULIB_TOOL --copy-file m4/intmax_t.m4 gettext-runtime/libasprintf/gnulib-m4/intmax_t.m4 || exit $?
169     # In gettext-tools:
170     GNULIB_MODULES_TOOLS_FOR_SRC='
171       alloca-opt
172       atexit
173       backupfile
174       basename
175       binary-io
176       bison-i18n
177       byteswap
178       c-ctype
179       c-strcase
180       c-strcasestr
181       c-strstr
182       clean-temp
183       closedir
184       closeout
185       copy-file
186       csharpcomp
187       csharpexec
188       error
189       error-progname
190       execute
191       fd-ostream
192       file-ostream
193       filename
194       findprog
195       fnmatch
196       fopen
197       fstrcmp
198       full-write
199       fwriteerror
200       gcd
201       getline
202       getopt-gnu
203       gettext-h
204       hash
205       html-styled-ostream
206       iconv
207       javacomp
208       javaexec
209       libunistring-optional
210       localcharset
211       locale
212       localename
213       lock
214       memmove
215       memset
216       minmax
217       obstack
218       open
219       opendir
220       openmp
221       ostream
222       pipe-filter-ii
223       progname
224       propername
225       readdir
226       relocatable-prog
227       relocatable-script
228       setlocale
229       sh-quote
230       sigpipe
231       sigprocmask
232       spawn-pipe
233       stdbool
234       stdio
235       stdlib
236       stpcpy
237       stpncpy
238       strcspn
239       strerror
240       strpbrk
241       strtol
242       strtoul
243       styled-ostream
244       sys_select
245       sys_stat
246       sys_time
247       term-styled-ostream
248       trim
249       unictype/ctype-space
250       unilbrk/ulc-width-linebreaks
251       uniname/uniname
252       unistd
253       unistr/u8-mbtouc
254       unistr/u8-mbtoucr
255       unistr/u8-uctomb
256       unistr/u16-mbtouc
257       uniwidth/width
258       unlocked-io
259       vasprintf
260       wait-process
261       write
262       xalloc
263       xconcat-filename
264       xmalloca
265       xerror
266       xsetenv
267       xstriconv
268       xstriconveh
269       xvasprintf
270     '
271     # Common dependencies of GNULIB_MODULES_TOOLS_FOR_SRC and GNULIB_MODULES_TOOLS_FOR_LIBGREP.
272     GNULIB_MODULES_TOOLS_FOR_SRC_COMMON_DEPENDENCIES='
273       alloca-opt
274       extensions
275       gettext-h
276       include_next
277       locale
278       localcharset
279       malloc-posix
280       mbrtowc
281       mbsinit
282       multiarch
283       snippet/arg-nonnull
284       snippet/c++defs
285       snippet/warn-on-use
286       ssize_t
287       stdbool
288       stddef
289       stdint
290       stdlib
291       streq
292       unistd
293       verify
294       wchar
295       wctype-h
296     '
297     GNULIB_MODULES_TOOLS_OTHER='
298       gettext-tools-misc
299       ansi-c++-opt
300       csharpcomp-script
301       csharpexec-script
302       gcj
303       java
304       javacomp-script
305       javaexec-script
306       stdint
307     '
308     GNULIB_MODULES_TOOLS_LIBUNISTRING_TESTS='
309       unilbrk/u8-possible-linebreaks-tests
310       unilbrk/ulc-width-linebreaks-tests
311       unistr/u8-mbtouc-tests
312       unistr/u8-mbtouc-unsafe-tests
313       uniwidth/width-tests
314     '
315     $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 \
316       --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 $?
317     # In gettext-tools/libgrep:
318     GNULIB_MODULES_TOOLS_FOR_LIBGREP='
319       mbrlen
320       regex
321     '
322     $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 \
323       --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 $?
324     # In gettext-tools/libgettextpo:
325     # This is a subset of the GNULIB_MODULES_FOR_SRC.
326     GNULIB_MODULES_LIBGETTEXTPO='
327       basename
328       close
329       c-ctype
330       c-strcase
331       c-strstr
332       error
333       error-progname
334       file-ostream
335       filename
336       fopen
337       fstrcmp
338       fwriteerror
339       gcd
340       getline
341       gettext-h
342       hash
343       iconv
344       libunistring-optional
345       markup
346       minmax
347       open
348       ostream
349       progname
350       relocatable-lib
351       sigpipe
352       stdbool
353       stdio
354       stdlib
355       stpcpy
356       stpncpy
357       strchrnul
358       strerror
359       unictype/ctype-space
360       unilbrk/ulc-width-linebreaks
361       unistr/u8-mbtouc
362       unistr/u8-mbtoucr
363       unistr/u8-uctomb
364       unistr/u16-mbtouc
365       uniwidth/width
366       unlocked-io
367       vasprintf
368       xalloc
369       xconcat-filename
370       xmalloca
371       xerror
372       xstriconv
373       xvasprintf
374     '
375     GNULIB_MODULES_LIBGETTEXTPO_OTHER='
376     '
377     $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 \
378       --import $GNULIB_MODULES_LIBGETTEXTPO $GNULIB_MODULES_LIBGETTEXTPO_OTHER || exit $?
379     # Import build tools.  We use --copy-file to avoid directory creation.
380     $GNULIB_TOOL --copy-file tests/init.sh gettext-tools || exit $?
381     $GNULIB_TOOL --copy-file build-aux/git-version-gen || exit $?
382     $GNULIB_TOOL --copy-file build-aux/gitlog-to-changelog || exit $?
383   fi
384 fi
385
386 # Fetch config.guess, config.sub.
387 if test -n "$GNULIB_TOOL"; then
388   for file in config.guess config.sub; do
389     $GNULIB_TOOL --copy-file build-aux/$file; chmod a+x build-aux/$file || exit $?
390   done
391 else
392   for file in config.guess config.sub; do
393     echo "$0: getting $file..."
394     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" \
395       && mv build-aux/$file.tmp build-aux/$file \
396       && chmod a+x build-aux/$file
397     retval=$?
398     rm -f build-aux/$file.tmp
399     test $retval -eq 0 || exit $retval
400   done
401 fi
402
403 # Fetch gettext-tools/misc/archive.dir.tar.
404 if ! test -f gettext-tools/misc/archive.dir.tar; then
405   if ! test -f gettext-tools/misc/archive.dir.tar.xz; then
406     echo "$0: getting gettext-tools/misc/archive.dir.tar..."
407     wget -q --timeout=5 -O gettext-tools/misc/archive.dir.tar.xz-t "ftp://alpha.gnu.org/gnu/gettext/archive.dir-latest.tar.xz" \
408       && mv gettext-tools/misc/archive.dir.tar.xz-t gettext-tools/misc/archive.dir.tar.xz
409     retval=$?
410     rm -f gettext-tools/misc/archive.dir.tar.xz-t
411     test $retval -eq 0 || exit $retval
412   fi
413   xz -d -c < gettext-tools/misc/archive.dir.tar.xz > gettext-tools/misc/archive.dir.tar-t \
414     && mv gettext-tools/misc/archive.dir.tar-t gettext-tools/misc/archive.dir.tar
415   retval=$?
416   rm -f gettext-tools/misc/archive.dir.tar-t
417   test $retval -eq 0 || exit $retval
418 fi
419
420 # Automake requires that ChangeLog exist.
421 for dir in . gettext-runtime gettext-runtime/libasprintf \
422            gettext-tools gettext-tools/examples \
423            gettext-runtime/intl gettext-runtime/po gettext-tools/po; do
424   cat > "$dir/ChangeLog" <<\EOF
425 No more ChangeLog files
426 ========================
427 Do not modify any of the ChangeLog files in gettext.  Starting on
428 October 14th, 2015 we put changelog information only in the git commit
429 log, and generate a top-level ChangeLog file from logs at "make dist"
430 time.
431
432 Local Variables:
433 buffer-read-only: t
434 mode: text
435 End:
436 EOF
437 done
438
439 # Generate configure script in each subdirectories.
440 (cd gettext-runtime/libasprintf
441  echo "$0: generating configure in gettext-runtime/libasprintf..."
442  aclocal -I ../../m4 -I ../m4 -I gnulib-m4
443  autoconf
444  autoheader && touch config.h.in
445  automake --add-missing --copy
446 )
447
448 (cd gettext-runtime
449  echo "$0: generating configure in gettext-runtime..."
450  aclocal -I m4 -I ../m4 -I gnulib-m4
451  autoconf
452  autoheader && touch config.h.in
453  automake --add-missing --copy
454 )
455
456 (cd gettext-tools/examples
457  echo "$0: generating configure in gettext-tools/examples..."
458  aclocal -I ../../gettext-runtime/m4 -I ../../m4
459  autoconf
460  automake --add-missing --copy
461 )
462
463 echo "$0: copying common files from gettext-runtime to gettext-tools..."
464 cp -p gettext-runtime/ABOUT-NLS gettext-tools/ABOUT-NLS
465 cp -p gettext-runtime/po/Makefile.in.in gettext-tools/po/Makefile.in.in
466 cp -p gettext-runtime/po/Rules-quot gettext-tools/po/Rules-quot
467 cp -p gettext-runtime/po/boldquot.sed gettext-tools/po/boldquot.sed
468 cp -p gettext-runtime/po/quot.sed gettext-tools/po/quot.sed
469 cp -p gettext-runtime/po/en@quot.header gettext-tools/po/en@quot.header
470 cp -p gettext-runtime/po/en@boldquot.header gettext-tools/po/en@boldquot.header
471 cp -p gettext-runtime/po/insert-header.sin gettext-tools/po/insert-header.sin
472 cp -p gettext-runtime/po/remove-potcdate.sin gettext-tools/po/remove-potcdate.sin
473 # Those two files might be newer than Gnulib's.
474 sed_extract_serial='s/^#.* serial \([^ ]*\).*/\1/p
475 1q'
476 for file in intl.m4 po.m4; do
477   existing_serial=`sed -n -e "$sed_extract_serial" < "gettext-tools/gnulib-m4/$file"`
478   gettext_serial=`sed -n -e "$sed_extract_serial" < "gettext-runtime/m4/$file"`
479   if test -n "$existing_serial" && test -n "$gettext_serial" \
480         && test "$existing_serial" -ge "$gettext_serial" 2> /dev/null; then
481     :
482   else
483     cp -p "gettext-runtime/m4/$file" "gettext-tools/gnulib-m4/$file"
484   fi
485 done
486
487 (cd gettext-tools
488  echo "$0: generating configure in gettext-tools..."
489  aclocal -I m4 -I ../gettext-runtime/m4 -I ../m4 -I gnulib-m4 -I libgrep/gnulib-m4 -I libgettextpo/gnulib-m4
490  autoconf
491  autoheader && touch config.h.in
492  test -d intl || mkdir intl
493  automake --add-missing --copy
494 )
495
496 aclocal -I m4
497 autoconf
498 automake