Fix BSD license name
[platform/upstream/libgcrypt.git] / autogen.sh
1 #! /bin/sh
2 # autogen.sh
3 # Copyright (C) 2003, 2014 g10 Code GmbH
4 #
5 # This file is free software; as a special exception the author gives
6 # unlimited permission to copy and/or distribute it, with or without
7 # modifications, as long as this notice is preserved.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
11 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 #
13 # This is a generic script to create the configure script and handle cross
14 # build environments.  It requires the presence of a autogen.rc file to
15 # configure it for the respective package.  It is maintained as part of
16 # GnuPG and source copied by other packages.
17 #
18 # Version: 2014-01-10
19
20 configure_ac="configure.ac"
21
22 cvtver () {
23   awk 'NR==1 {split($NF,A,".");X=1000000*A[1]+1000*A[2]+A[3];print X;exit 0}'
24 }
25
26 check_version () {
27     if [ $(( `("$1" --version || echo "0") | cvtver` >= $2 )) = 1 ]; then
28        return 0
29     fi
30     echo "**Error**: "\`$1\'" not installed or too old." >&2
31     echo '           Version '$3' or newer is required.' >&2
32     [ -n "$4" ] && echo '           Note that this is part of '\`$4\''.' >&2
33     DIE="yes"
34     return 1
35 }
36
37 fatal () {
38     echo "autogen.sh:" "$*" >&2
39     DIE=yes
40 }
41
42 info () {
43     if [ -z "${SILENT}" ]; then
44       echo "autogen.sh:" "$*"
45     fi
46 }
47
48 die_p () {
49   if [ "$DIE" = "yes" ]; then
50     echo "autogen.sh: Stop." >&2
51     exit 1
52   fi
53 }
54
55 replace_sysroot () {
56     configure_opts=$(echo $configure_opts | sed "s#@SYSROOT@#${w32root}#g")
57     extraoptions=$(echo $extraoptions | sed "s#@SYSROOT@#${w32root}#g")
58 }
59
60 # Allow to override the default tool names
61 AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX}
62 AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX}
63
64 AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX}
65 ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX}
66
67 GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX}
68 MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX}
69
70 DIE=no
71 FORCE=
72 SILENT=
73 tmp=$(dirname "$0")
74 tsdir=$(cd "${tmp}"; pwd)
75
76 if [ -n "${AUTOGEN_SH_SILENT}" ]; then
77   SILENT=" --silent"
78 fi
79 if test x"$1" = x"--help"; then
80   echo "usage: ./autogen.sh [--silent] [--force] [--build-TYPE] [ARGS]"
81   exit 0
82 fi
83 if test x"$1" = x"--silent"; then
84   SILENT=" --silent"
85   shift
86 fi
87 if test x"$1" = x"--force"; then
88   FORCE=" --force"
89   shift
90 fi
91
92
93 # Reject unsafe characters in $HOME, $tsdir and cwd.  We consider spaces
94 # as unsafe because it is too easy to get scripts wrong in this regard.
95 am_lf='
96 '
97 case `pwd` in
98   *[\;\\\"\#\$\&\'\`$am_lf\ \   ]*)
99     fatal "unsafe working directory name" ;;
100 esac
101 case $tsdir in
102   *[\;\\\"\#\$\&\'\`$am_lf\ \   ]*)
103     fatal "unsafe source directory: \`$tsdir'" ;;
104 esac
105 case $HOME in
106   *[\;\\\"\#\$\&\'\`$am_lf\ \   ]*)
107     fatal "unsafe home directory: \`$HOME'" ;;
108 esac
109 die_p
110
111
112 # List of variables sourced from autogen.rc.  The strings '@SYSROOT@' in
113 # these variables are replaced by the actual system root.
114 configure_opts=
115 extraoptions=
116 # List of optional variables sourced from autogen.rc and ~/.gnupg-autogen.rc
117 w32_toolprefixes=
118 w32_extraoptions=
119 w32ce_toolprefixes=
120 w32ce_extraoptions=
121 w64_toolprefixes=
122 w64_extraoptions=
123 amd64_toolprefixes=
124 # End list of optional variables sourced from ~/.gnupg-autogen.rc
125 # What follows are variables which are sourced but default to
126 # environment variables or lacking them hardcoded values.
127 #w32root=
128 #w32ce_root=
129 #w64root=
130 #amd64root=
131
132 # Convenience option to use certain configure options for some hosts.
133 myhost=""
134 myhostsub=""
135 case "$1" in
136     --build-w32)
137         myhost="w32"
138         shift
139         ;;
140     --build-w32ce)
141         myhost="w32"
142         myhostsub="ce"
143         shift
144         ;;
145     --build-w64)
146         myhost="w32"
147         myhostsub="64"
148         shift
149         ;;
150     --build-amd64)
151         myhost="amd64"
152         shift
153         ;;
154     --build*)
155         fatal "**Error**: invalid build option $1"
156         shift
157         ;;
158     *)
159         ;;
160 esac
161 die_p
162
163
164 # Source our configuration
165 if [ -f "${tsdir}/autogen.rc" ]; then
166     . "${tsdir}/autogen.rc"
167 fi
168
169 # Source optional site specific configuration
170 if [ -f "$HOME/.gnupg-autogen.rc" ]; then
171     info "sourcing extra definitions from $HOME/.gnupg-autogen.rc"
172     . "$HOME/.gnupg-autogen.rc"
173 fi
174
175 # ******************
176 #  W32 build script
177 # ******************
178 if [ "$myhost" = "w32" ]; then
179     if [ ! -f "$tsdir/build-aux/config.guess" ]; then
180         fatal "$tsdir/build-aux/config.guess not found"
181         exit 1
182     fi
183     build=`$tsdir/build-aux/config.guess`
184
185     case $myhostsub in
186         ce)
187           w32root="$w32ce_root"
188           [ -z "$w32root" ] && w32root="$HOME/w32ce_root"
189           toolprefixes="$w32ce_toolprefixes arm-mingw32ce"
190           extraoptions="$extraoptions $w32ce_extraoptions"
191           ;;
192         64)
193           w32root="$w64root"
194           [ -z "$w32root" ] && w32root="$HOME/w64root"
195           toolprefixes="$w64_toolprefixes x86_64-w64-mingw32"
196           extraoptions="$extraoptions $w64_extraoptions"
197           ;;
198         *)
199           [ -z "$w32root" ] && w32root="$HOME/w32root"
200           toolprefixes="$w32_toolprefixes i686-w64-mingw32 i586-mingw32msvc"
201           toolprefixes="$toolprefixes i386-mingw32msvc mingw32"
202           extraoptions="$extraoptions $w32_extraoptions"
203           ;;
204     esac
205     info "Using $w32root as standard install directory"
206     replace_sysroot
207
208     # Locate the cross compiler
209     crossbindir=
210     for host in $toolprefixes; do
211         if ${host}-gcc --version >/dev/null 2>&1 ; then
212             crossbindir=/usr/${host}/bin
213             conf_CC="CC=${host}-gcc"
214             break;
215         fi
216     done
217     if [ -z "$crossbindir" ]; then
218         fatal "cross compiler kit not installed"
219         if [ -z "$myhostsub" ]; then
220           info "Under Debian GNU/Linux, you may install it using"
221           info "  apt-get install mingw32 mingw32-runtime mingw32-binutils"
222         fi
223         die_p
224     fi
225
226     if [ -f "$tsdir/config.log" ]; then
227         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
228             fatal "Please run a 'make distclean' first"
229             die_p
230         fi
231     fi
232
233     $tsdir/configure --enable-maintainer-mode ${SILENT} \
234              --prefix=${w32root}  \
235              --host=${host} --build=${build} \
236              ${configure_opts} ${extraoptions} "$@"
237     rc=$?
238     exit $rc
239 fi
240 # ***** end W32 build script *******
241
242 # ***** AMD64 cross build script *******
243 # Used to cross-compile for AMD64 (for testing)
244 if [ "$myhost" = "amd64" ]; then
245     shift
246     if [ ! -f $tsdir/build-aux/config.guess ]; then
247         echo "$tsdir/build-aux/config.guess not found" >&2
248         exit 1
249     fi
250     build=`$tsdir/build-aux/config.guess`
251
252     [ -z "$amd64root" ] && amd64root="$HOME/amd64root"
253     info "Using $amd64root as standard install directory"
254     replace_sysroot
255
256     toolprefixes="$amd64_toolprefixes x86_64-linux-gnu amd64-linux-gnu"
257
258     # Locate the cross compiler
259     crossbindir=
260     for host in $toolprefixes ; do
261         if ${host}-gcc --version >/dev/null 2>&1 ; then
262             crossbindir=/usr/${host}/bin
263             conf_CC="CC=${host}-gcc"
264             break;
265         fi
266     done
267     if [ -z "$crossbindir" ]; then
268         echo "Cross compiler kit not installed" >&2
269         echo "Stop." >&2
270         exit 1
271     fi
272
273     if [ -f "$tsdir/config.log" ]; then
274         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
275             echo "Please run a 'make distclean' first" >&2
276             exit 1
277         fi
278     fi
279
280     $tsdir/configure --enable-maintainer-mode ${SILENT} \
281              --prefix=${amd64root}  \
282              --host=${host} --build=${build} \
283              ${configure_opts} ${extraoptions} "$@"
284     rc=$?
285     exit $rc
286 fi
287 # ***** end AMD64 cross build script *******
288
289
290 # Grep the required versions from configure.ac
291 autoconf_vers=`sed -n '/^AC_PREREQ(/ {
292 s/^.*(\(.*\))/\1/p
293 q
294 }' ${configure_ac}`
295 autoconf_vers_num=`echo "$autoconf_vers" | cvtver`
296
297 automake_vers=`sed -n '/^min_automake_version=/ {
298 s/^.*="\(.*\)"/\1/p
299 q
300 }' ${configure_ac}`
301 automake_vers_num=`echo "$automake_vers" | cvtver`
302
303 if [ -d "${tsdir}/po" ]; then
304   gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ {
305 s/^.*\[\(.*\)])/\1/p
306 q
307 }' ${configure_ac}`
308   gettext_vers_num=`echo "$gettext_vers" | cvtver`
309 else
310   gettext_vers="n/a"
311 fi
312
313 if [ -z "$autoconf_vers" -o -z "$automake_vers" -o -z "$gettext_vers" ]
314 then
315   echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2
316   exit 1
317 fi
318
319
320 if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then
321     check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf
322 fi
323 if check_version $AUTOMAKE $automake_vers_num $automake_vers; then
324   check_version $ACLOCAL $automake_vers_num $autoconf_vers automake
325 fi
326 if [ "$gettext_vers" != "n/a" ]; then
327   if check_version $GETTEXT $gettext_vers_num $gettext_vers; then
328     check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext
329   fi
330 fi
331
332 if [ "$DIE" = "yes" ]; then
333     cat <<EOF
334
335 Note that you may use alternative versions of the tools by setting
336 the corresponding environment variables; see README.GIT for details.
337
338 EOF
339     die_p
340 fi
341
342 # Check the git setup.
343 if [ -d .git ]; then
344   CP="cp -a"
345   [ -z "${SILENT}" ] && CP="$CP -v"
346   if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
347     [ -z "${SILENT}" ] && cat <<EOF
348 *** Activating trailing whitespace git pre-commit hook. ***
349     For more information see this thread:
350       http://mail.gnome.org/archives/desktop-devel-list/2009-May/msg00084html
351     To deactivate this pre-commit hook again move .git/hooks/pre-commit
352     and .git/hooks/pre-commit.sample out of the way.
353 EOF
354       $CP .git/hooks/pre-commit.sample .git/hooks/pre-commit
355       chmod +x  .git/hooks/pre-commit
356   fi
357
358   if [ "$gettext_vers" != "n/a" ]; then
359     tmp=$(git config --get filter.cleanpo.clean)
360     if [ "$tmp" != \
361           "awk '/^\"POT-Creation-Date:/&&!s{s=1;next};!/^#: /{print}'" ]
362     then
363       info "*** Adding GIT filter.cleanpo.clean configuration."
364       git config --add filter.cleanpo.clean \
365         "awk '/^\"POT-Creation-Date:/&&!s{s=1;next};!/^#: /{print}'"
366     fi
367   fi
368   if [ -f build-aux/git-hooks/commit-msg -a ! -f .git/hooks/commit-msg ] ; then
369       [ -z "${SILENT}" ] && cat <<EOF
370 *** Activating commit log message check hook. ***
371 EOF
372       $CP build-aux/git-hooks/commit-msg .git/hooks/commit-msg
373       chmod +x  .git/hooks/commit-msg
374   fi
375 fi
376
377 aclocal_flags="-I m4"
378 if [ -n "${extra_aclocal_flags}" ]; then
379   aclocal_flags="${aclocal_flags} ${extra_aclocal_flags}"
380 fi
381 if [ -n "${ACLOCAL_FLAGS}" ]; then
382   aclocal_flags="${aclocal_flags} ${ACLOCAL_FLAGS}"
383 fi
384 info "Running $ACLOCAL ${aclocal_flags} ..."
385 $ACLOCAL ${aclocal_flags}
386 info "Running autoheader..."
387 $AUTOHEADER
388 info "Running automake --gnu ..."
389 $AUTOMAKE --gnu;
390 info "Running autoconf${FORCE} ..."
391 $AUTOCONF${FORCE}
392
393 info "You may now run:${am_lf}  ${final_info}"