Parse EXTCAP lines from the card.
[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     # Locate the cross compiler
55     crossbindir=
56     for host in i586-mingw32msvc i386-mingw32msvc; do
57         if ${host}-gcc --version >/dev/null 2>&1 ; then
58             crossbindir=/usr/${host}/bin
59             conf_CC="CC=${host}-gcc"
60             break;
61         fi
62     done
63     if [ -z "$crossbindir" ]; then
64         echo "Cross compiler kit not installed" >&2
65         echo "Under Debian GNU/Linux, you may install it using" >&2
66         echo "  apt-get install mingw32 mingw32-runtime mingw32-binutils" >&2 
67         echo "Stop." >&2
68         exit 1
69     fi
70    
71     if [ -f "$tsdir/config.log" ]; then
72         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
73             echo "Please run a 'make distclean' first" >&2
74             exit 1
75         fi
76     fi
77
78     disable_foo_tests=""
79     if [ -n "$lib_config_files" ]; then
80         for i in $lib_config_files; do
81             j=`echo $i | tr '[a-z-]' '[A-Z_]'`
82             eval "$j=${crossbindir}/$i"
83             export $j
84             disable_foo_tests="$disable_foo_tests --disable-`echo $i| \
85                            sed 's,-config$,,'`-test"
86             if [ ! -f "${crossbindir}/$i" ]; then                   
87                 echo "$i not installed for MingW32" >&2
88                 DIE=yes
89             fi
90         done
91     fi
92     [ $DIE = yes ] && exit 1
93
94     $tsdir/configure ${conf_CC} --build=${build} --host=${host} \
95                 ${disable_foo_tests}  $*
96     exit $?
97 fi
98
99
100 # This is the special case to build on a ColdFire platform under 
101 # the uClinux kernel.  Tested on a MCF4249C3 board.
102 if test "$1" = "--build-coldfire"; then
103     tmp=`dirname $0`
104     tsdir=`cd "$tmp"; cd ..; pwd`
105     shift
106     if [ $# -lt 1 ]; then
107       echo "usage: autogen.sh --build-coldfire <crossroot>" >&2
108       exit 1
109     fi
110     crossdir="$1"
111     shift
112
113     host=m68k-elf
114     crossprefix=${host}-
115     if [ ! -f $tsdir/scripts/config.guess ]; then
116         echo "$tsdir/scripts/config.guess not found" >&2
117         exit 1
118     fi
119     build=`$tsdir/scripts/config.guess`
120         
121     if [ -f "$tsdir/config.log" ]; then
122         if ! head $tsdir/config.log | grep m68k-elf >/dev/null; then
123             echo "Pease run a 'make distclean' first" >&2
124             exit 1
125         fi
126     fi
127
128     crossbindir=$crossdir/bin
129     CC=${crossbindir}/${crossprefix}gcc
130     CPP=${crossbindir}/cpp
131     AR=${crossbindir}/${crossprefix}ar
132     RANLIB=${crossbindir}/${crossprefix}ranlib
133
134     CFLAGS="-Os -g -fomit-frame-pointer"
135     CFLAGS="$CFLAGS -m5307 -DCONFIG_COLDFIRE"
136     CFLAGS="$CFLAGS -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED"
137     CFLAGS="$CFLAGS -fno-builtin -msep-data"
138     LDFLAGS="-Wl,-elf2flt -Wl,-move-rodata -nostartfiles"
139     LDFLAGS="$LDFLAGS ${crossdir}/m68k-elf/lib/crt0.o"
140     LIBS="-lc"
141
142     disable_foo_tests=""
143     if [ -n "$lib_config_files" ]; then
144         for i in $lib_config_files; do
145             j=`echo $i | tr '[a-z-]' '[A-Z_]'`
146             eval "$j=${crossbindir}/$i"
147             export $j
148             disable_foo_tests="$disable_foo_tests --disable-`echo $i| \
149                            sed 's,-config$,,'`-test"
150             if [ ! -f "${crossbindir}/$i" ]; then                   
151                 echo "$i not installed for ColdFire" >&2
152                 DIE=yes
153             fi
154         done
155     fi
156     [ $DIE = yes ] && exit 1
157
158     $tsdir/configure --build=${build} --host=${host} \
159                 ${disable_foo_tests} \
160                 --disable-dynload \
161                 --disable-exec \
162                 --disable-photo-viewers \
163                 --disable-keyserver-helpers \
164                 --disable-ldap \
165                 --disable-mailto \
166                 --disable-largefile \
167                 --disable-asm \
168                 --disable-nls $* \
169                 CC="$CC" CPP="$CPP" AR="$AR" RANLIB="$RANLIB" \
170                 CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" LIBS="$LIBS"
171     exit $?
172 fi
173
174
175 # This is the special case to build on a ColdFire platform under 
176 # the uClinux kernel with uClinux-dist.  Tested on a MCF4249C3 board.
177 if test "$1" = "--build-uclinux"; then
178     tmp=`dirname $0`
179     tsdir=`cd "$tmp"; cd ..; pwd`
180     shift
181
182     if [ ! -f $tsdir/scripts/config.guess ]; then
183         echo "$tsdir/scripts/config.guess not found" >&2
184         exit 1
185     fi
186     build=`$tsdir/scripts/config.guess`
187     host=m68k-elf
188         
189     if [ -f "$tsdir/config.log" ]; then
190         if ! head $tsdir/config.log | grep m68k-elf >/dev/null; then
191             echo "Please run a 'make distclean' first" >&2
192             exit 1
193         fi
194     fi
195
196     $tsdir/configure --build=${build} --host=${host} \
197                 ${disable_foo_tests} \
198                 --disable-dynload \
199                 --disable-exec \
200                 --disable-photo-viewers \
201                 --disable-keyserver-helpers \
202                 --disable-ldap \
203                 --disable-mailto \
204                 --disable-largefile \
205                 --disable-asm \
206                 --disable-nls $* \
207                 CC="$CC" CPP="$CPP" AR="$AR" RANLIB="$RANLIB" \
208                 CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" LIBS="$LDLIBS"
209     exit $?
210 fi
211
212
213 # Grep the required versions from configure.ac
214 autoconf_vers=`sed -n '/^AC_PREREQ(/ { 
215 s/^.*(\(.*\))/\1/p
216 q
217 }' ${configure_ac}`
218 autoconf_vers_num=`echo "$autoconf_vers" | cvtver`
219
220 automake_vers=`sed -n '/^min_automake_version=/ { 
221 s/^.*="\(.*\)"/\1/p
222 q
223 }' ${configure_ac}`
224 automake_vers_num=`echo "$automake_vers" | cvtver`
225
226 gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ { 
227 s/^.*(\(.*\))/\1/p
228 q
229 }' ${configure_ac}`
230 gettext_vers_num=`echo "$gettext_vers" | cvtver`
231
232
233 if [ -z "$autoconf_vers" -o -z "$automake_vers" -o -z "$gettext_vers" ]
234 then
235   echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2
236   exit 1
237 fi
238
239
240 if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then
241     check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf
242 fi
243 if check_version $AUTOMAKE $automake_vers_num $automake_vers; then
244   check_version $ACLOCAL $automake_vers_num $automake_vers automake
245 fi
246 if check_version $GETTEXT $gettext_vers_num $gettext_vers; then
247   check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext
248 fi
249
250 if test "$DIE" = "yes"; then
251     cat <<EOF
252
253 Note that you may use alternative versions of the tools by setting 
254 the corresponding environment variables; see README.CVS for details.
255                    
256 EOF
257     exit 1
258 fi
259
260
261 echo "Running aclocal -I m4 ${ACLOCAL_FLAGS:+$ACLOCAL_FLAGS }..."
262 $ACLOCAL -I m4 $ACLOCAL_FLAGS
263 echo "Running autoheader..."
264 $AUTOHEADER
265 echo "Running automake --gnu --add-missing..."
266 $AUTOMAKE --gnu --add-missing;
267 echo "Running autoconf..."
268 $AUTOCONF
269
270 echo "You may now run \"./configure --enable-maintainer-mode && make\"."