about to release 1.4.3rc1
[gnupg.git] / scripts / autogen.sh
1 #!/bin/sh
2 # Run this to generate all the initial makefiles, etc.
3 #
4 # Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
5 #
6 # This file is free software; as a special exception the author gives
7 # unlimited permission to copy and/or distribute it, with or without
8 # modifications, as long as this notice is preserved.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
12 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 configure_ac="configure.ac"
15
16 cvtver () {
17   awk 'NR==1 {split($NF,A,".");X=1000000*A[1]+1000*A[2]+A[3];print X;exit 0}'
18 }
19
20 check_version () {
21     if [ `("$1" --version || echo "0") | cvtver` -ge "$2" ]; then
22        return 0
23     fi
24     echo "**Error**: "\`$1\'" not installed or too old." >&2
25     echo '           Version '$3' or newer is required.' >&2
26     [ -n "$4" ] && echo '           Note that this is part of '\`$4\''.' >&2
27     DIE="yes"
28     return 1
29 }
30
31 # Allow to override the default tool names
32 AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX}
33 AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX}
34
35 AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX}
36 ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX}
37
38 GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX}
39 MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX}
40
41 DIE=no
42
43 # Used to cross-compile GnuPG for Windows.
44 if test "$1" = "--build-w32"; then
45     tmp=`dirname $0`
46     tsdir=`cd "$tmp"; cd ..; pwd`
47     shift
48     if [ ! -f $tsdir/scripts/config.guess ]; then
49         echo "$tsdir/scripts/config.guess not found" >&2
50         exit 1
51     fi
52     build=`$tsdir/scripts/config.guess`
53
54     # See whether we have the Debian cross compiler package or the
55     # old mingw32/cpd system
56     if i586-mingw32msvc-gcc --version >/dev/null 2>&1 ; then
57        host=i586-mingw32msvc
58        crossbindir=/usr/$host/bin
59        conf_CC="CC=${host}-gcc"
60     else
61        host=i386--mingw32
62        if ! mingw32 --version >/dev/null; then
63           echo "We need at least version 0.3 of MingW32/CPD" >&2
64           exit 1
65        fi
66        crossbindir=`mingw32 --install-dir`/bin
67        # Old autoconf version required us to setup the environment
68        # with the proper tool names.
69        CC=`mingw32 --get-path gcc`
70        CPP=`mingw32 --get-path cpp`
71        AR=`mingw32 --get-path ar`
72        RANLIB=`mingw32 --get-path ranlib`
73        export CC CPP AR RANLIB 
74        conf_CC=""
75     fi
76    
77     if [ -f "$tsdir/config.log" ]; then
78         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
79             echo "Pease run a 'make distclean' first" >&2
80             exit 1
81         fi
82     fi
83
84     disable_foo_tests=""
85     if [ -n "$lib_config_files" ]; then
86         for i in $lib_config_files; do
87             j=`echo $i | tr '[a-z-]' '[A-Z_]'`
88             eval "$j=${crossbindir}/$i"
89             export $j
90             disable_foo_tests="$disable_foo_tests --disable-`echo $i| \
91                            sed 's,-config$,,'`-test"
92             if [ ! -f "${crossbindir}/$i" ]; then                   
93                 echo "$i not installed for MingW32" >&2
94                 DIE=yes
95             fi
96         done
97     fi
98     [ $DIE = yes ] && exit 1
99
100     $tsdir/configure ${conf_CC} --build=${build} --host=${host} \
101                 ${disable_foo_tests}  $*
102     exit $?
103 fi
104
105
106 # This is the special case to build on a ColdFire platform under 
107 # the uClinux kernel.  Tested on a MCF4249C3 board.
108 if test "$1" = "--build-coldfire"; then
109     tmp=`dirname $0`
110     tsdir=`cd "$tmp"; cd ..; pwd`
111     shift
112     if [ $# -lt 1 ]; then
113       echo "usage: autogen.sh --build-coldfire <crossroot>" >&2
114       exit 1
115     fi
116     crossdir="$1"
117     shift
118
119     host=m68k-elf
120     crossprefix=${host}-
121     if [ ! -f $tsdir/scripts/config.guess ]; then
122         echo "$tsdir/scripts/config.guess not found" >&2
123         exit 1
124     fi
125     build=`$tsdir/scripts/config.guess`
126         
127     if [ -f "$tsdir/config.log" ]; then
128         if ! head $tsdir/config.log | grep m68k-elf >/dev/null; then
129             echo "Pease run a 'make distclean' first" >&2
130             exit 1
131         fi
132     fi
133
134     crossbindir=$crossdir/bin
135     CC=${crossbindir}/${crossprefix}gcc
136     CPP=${crossbindir}/cpp
137     AR=${crossbindir}/${crossprefix}ar
138     RANLIB=${crossbindir}/${crossprefix}ranlib
139
140     CFLAGS="-Os -g -fomit-frame-pointer"
141     CFLAGS="$CFLAGS -m5307 -DCONFIG_COLDFIRE"
142     CFLAGS="$CFLAGS -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED"
143     CFLAGS="$CFLAGS -fno-builtin -msep-data"
144     LDFLAGS="-Wl,-elf2flt -Wl,-move-rodata -nostartfiles"
145     LDFLAGS="$LDFLAGS ${crossdir}/m68k-elf/lib/crt0.o"
146     LIBS="-lc"
147
148     disable_foo_tests=""
149     if [ -n "$lib_config_files" ]; then
150         for i in $lib_config_files; do
151             j=`echo $i | tr '[a-z-]' '[A-Z_]'`
152             eval "$j=${crossbindir}/$i"
153             export $j
154             disable_foo_tests="$disable_foo_tests --disable-`echo $i| \
155                            sed 's,-config$,,'`-test"
156             if [ ! -f "${crossbindir}/$i" ]; then                   
157                 echo "$i not installed for ColdFire" >&2
158                 DIE=yes
159             fi
160         done
161     fi
162     [ $DIE = yes ] && exit 1
163
164     $tsdir/configure --build=${build} --host=${host} \
165                 ${disable_foo_tests} \
166                 --disable-dynload \
167                 --disable-exec \
168                 --disable-photo-viewers \
169                 --disable-keyserver-helpers \
170                 --disable-ldap \
171                 --disable-mailto \
172                 --disable-largefile \
173                 --disable-asm \
174                 --disable-nls $* \
175                 CC="$CC" CPP="$CPP" AR="$AR" RANLIB="$RANLIB" \
176                 CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" LIBS="$LIBS"
177     exit $?
178 fi
179
180
181 # This is the special case to build on a ColdFire platform under 
182 # the uClinux kernel with uClinux-dist.  Tested on a MCF4249C3 board.
183 if test "$1" = "--build-uclinux"; then
184     tmp=`dirname $0`
185     tsdir=`cd "$tmp"; cd ..; pwd`
186     shift
187
188     if [ ! -f $tsdir/scripts/config.guess ]; then
189         echo "$tsdir/scripts/config.guess not found" >&2
190         exit 1
191     fi
192     build=`$tsdir/scripts/config.guess`
193     host=m68k-elf
194         
195     if [ -f "$tsdir/config.log" ]; then
196         if ! head $tsdir/config.log | grep m68k-elf >/dev/null; then
197             echo "Please run a 'make distclean' first" >&2
198             exit 1
199         fi
200     fi
201
202     $tsdir/configure --build=${build} --host=${host} \
203                 ${disable_foo_tests} \
204                 --disable-dynload \
205                 --disable-exec \
206                 --disable-photo-viewers \
207                 --disable-keyserver-helpers \
208                 --disable-ldap \
209                 --disable-mailto \
210                 --disable-largefile \
211                 --disable-asm \
212                 --disable-nls $* \
213                 CC="$CC" CPP="$CPP" AR="$AR" RANLIB="$RANLIB" \
214                 CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" LIBS="$LDLIBS"
215     exit $?
216 fi
217
218
219 # Grep the required versions from configure.ac
220 autoconf_vers=`sed -n '/^AC_PREREQ(/ { 
221 s/^.*(\(.*\))/\1/p
222 q
223 }' ${configure_ac}`
224 autoconf_vers_num=`echo "$autoconf_vers" | cvtver`
225
226 automake_vers=`sed -n '/^min_automake_version=/ { 
227 s/^.*="\(.*\)"/\1/p
228 q
229 }' ${configure_ac}`
230 automake_vers_num=`echo "$automake_vers" | cvtver`
231
232 gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ { 
233 s/^.*(\(.*\))/\1/p
234 q
235 }' ${configure_ac}`
236 gettext_vers_num=`echo "$gettext_vers" | cvtver`
237
238
239 if [ -z "$autoconf_vers" -o -z "$automake_vers" -o -z "$gettext_vers" ]
240 then
241   echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2
242   exit 1
243 fi
244
245
246 if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then
247     check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf
248 fi
249 if check_version $AUTOMAKE $automake_vers_num $automake_vers; then
250   check_version $ACLOCAL $automake_vers_num $automake_vers automake
251 fi
252 if check_version $GETTEXT $gettext_vers_num $gettext_vers; then
253   check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext
254 fi
255
256 if test "$DIE" = "yes"; then
257     cat <<EOF
258
259 Note that you may use alternative versions of the tools by setting 
260 the corresponding environment variables; see README.CVS for details.
261                    
262 EOF
263     exit 1
264 fi
265
266
267 echo "Running aclocal -I m4 ${ACLOCAL_FLAGS:+$ACLOCAL_FLAGS }..."
268 $ACLOCAL -I m4 $ACLOCAL_FLAGS
269 echo "Running autoheader..."
270 $AUTOHEADER
271 echo "Running automake --gnu --add-missing..."
272 $AUTOMAKE --gnu --add-missing;
273 echo "Running autoconf..."
274 $AUTOCONF
275
276 echo "You may now run \"./configure --enable-maintainer-mode && make\"."