Add a git revision number
[gpgme.git] / autogen.sh
1 #! /bin/sh
2 # Run this to generate all the initial makefiles, etc. 
3 #
4 # Copyright (C) 2003 g10 Code GmbH
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
32 DIE=no
33 FORCE=
34 if test x"$1" = x"--force"; then
35   FORCE=" --force"
36   shift
37 fi
38
39 # Begin list of optional variables sourced from ~/.gnupg-autogen.rc
40 w32_toolprefixes=
41 w32_extraoptions=
42 w32ce_toolprefixes=
43 w32ce_extraoptions=
44 amd64_toolprefixes=
45 # End list of optional variables sourced from ~/.gnupg-autogen.rc
46 # What follows are variables which are sourced but default to 
47 # environment variables or lacking them hardcoded values.
48 #w32root=
49 #w32ce_root=
50 #amd64root=
51
52 if [ -f "$HOME/.gnupg-autogen.rc" ]; then
53     echo "sourcing extra definitions from $HOME/.gnupg-autogen.rc"
54     . "$HOME/.gnupg-autogen.rc"
55 fi
56
57 # Convenience option to use certain configure options for some hosts.
58 myhost="" 
59 myhostsub=""
60 case "$1" in
61     --build-w32)
62         myhost="w32"
63         ;;
64     --build-w32ce)
65         myhost="w32"
66         myhostsub="ce"
67         ;;
68     --build-amd64)
69         myhost="amd64"
70         ;;
71     --build*)
72         echo "**Error**: invalid build option $1" >&2
73         exit 1
74         ;;
75     *)
76         ;;
77 esac
78
79
80 # ***** W32 build script *******
81 # Used to cross-compile for Windows.
82 if [ "$myhost" = "w32" ]; then
83     tmp=`dirname $0`
84     tsdir=`cd "$tmp"; pwd`
85     shift
86     if [ ! -f $tsdir/config.guess ]; then
87         echo "$tsdir/config.guess not found" >&2
88         exit 1
89     fi
90     build=`$tsdir/config.guess`
91
92     case $myhostsub in
93         ce)
94           w32root="$w32ce_root"
95           [ -z "$w32root" ] && w32root="$HOME/w32ce_root"
96           toolprefixes="arm-mingw32ce"
97           ;;
98         *)
99           [ -z "$w32root" ] && w32root="$HOME/w32root"
100           toolprefixes="i586-mingw32msvc i386-mingw32msvc"
101           ;;
102     esac
103     echo "Using $w32root as standard install directory" >&2
104     
105     crossbindir=
106     for host in $toolprefixes; do
107         if ${host}-gcc --version >/dev/null 2>&1 ; then
108             crossbindir=/usr/${host}/bin
109             conf_CC="CC=${host}-gcc"
110             break;
111         fi
112     done
113     if [ -z "$crossbindir" ]; then
114         echo "Cross compiler kit not installed" >&2
115         if [ -z "$sub" ]; then 
116           echo "Under Debian GNU/Linux, you may install it using" >&2
117           echo "  apt-get install mingw32 mingw32-runtime mingw32-binutils" >&2 
118         fi
119         echo "Stop." >&2
120         exit 1
121     fi
122    
123     if [ -f "$tsdir/config.log" ]; then
124         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
125             echo "Pease run a 'make distclean' first" >&2
126             exit 1
127         fi
128     fi
129
130     $tsdir/configure --enable-maintainer-mode  --prefix=${w32root}  \
131             --host=${host} --build=${build} \
132             --with-gpg-error-prefix=${w32root} \
133             --with-libassuan-prefix=${w32root} "$@"
134
135     exit $?
136 fi
137 # ***** end W32 build script *******
138
139
140 # ***** AMD64 cross build script *******
141 # Used to cross-compile for AMD64 (for testing)
142 if [ "$myhost" = "amd64" ]; then
143     tmp=`dirname $0`
144     tsdir=`cd "$tmp"; pwd`
145     shift
146     if [ ! -f $tsdir/config.guess ]; then
147         echo "$tsdir/config.guess not found" >&2
148         exit 1
149     fi
150     build=`$tsdir/config.guess`
151
152     [ -z "$amd64root" ] && amd64root="$HOME/amd64root"
153     echo "Using $amd64root as standard install directory" >&2
154     
155     # Locate the cross compiler
156     crossbindir=
157     for host in x86_64-linux-gnu amd64-linux-gnu; do
158         if ${host}-gcc --version >/dev/null 2>&1 ; then
159             crossbindir=/usr/${host}/bin
160             conf_CC="CC=${host}-gcc"
161             break;
162         fi
163     done
164     if [ -z "$crossbindir" ]; then
165         echo "Cross compiler kit not installed" >&2
166         echo "Stop." >&2
167         exit 1
168     fi
169    
170     if [ -f "$tsdir/config.log" ]; then
171         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
172             echo "Please run a 'make distclean' first" >&2
173             exit 1
174         fi
175     fi
176
177     $tsdir/configure --enable-maintainer-mode --prefix=${amd64root}  \
178              --host=${host} --build=${build} 
179     rc=$?
180     exit $rc
181 fi
182 # ***** end AMD64 cross build script *******
183
184
185
186 # Grep the required versions from configure.ac
187 autoconf_vers=`sed -n '/^AC_PREREQ(/ { 
188 s/^.*(\(.*\))/\1/p
189 q
190 }' ${configure_ac}`
191 autoconf_vers_num=`echo "$autoconf_vers" | cvtver`
192
193 automake_vers=`sed -n '/^min_automake_version=/ { 
194 s/^.*="\(.*\)"/\1/p
195 q
196 }' ${configure_ac}`
197 automake_vers_num=`echo "$automake_vers" | cvtver`
198
199 #gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ { 
200 #s/^.*(\(.*\))/\1/p
201 #q
202 #}' ${configure_ac}`
203 #gettext_vers_num=`echo "$gettext_vers" | cvtver`
204
205
206 if [ -z "$autoconf_vers" -o -z "$automake_vers" ]
207 then
208   echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2
209   exit 1
210 fi
211
212 # Allow to override the default tool names
213 AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX}
214 AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX}
215
216 AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX}
217 ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX}
218
219 #GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX}
220 #MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX}
221
222
223 if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then
224     check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf
225 fi
226 if check_version $AUTOMAKE $automake_vers_num $automake_vers; then
227   check_version $ACLOCAL $automake_vers_num $autoconf_vers automake
228 fi
229 #if check_version $GETTEXT $gettext_vers_num $gettext_vers; then
230 #  check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext
231 #fi
232
233 if test "$DIE" = "yes"; then
234     cat <<EOF
235
236 Note that you may use alternative versions of the tools by setting 
237 the corresponding environment variables; see README.CVS for details.
238                    
239 EOF
240     exit 1
241 fi
242
243 echo "Running aclocal -I m4 ${ACLOCAL_FLAGS:+$ACLOCAL_FLAGS }..."
244 $ACLOCAL -I m4 $ACLOCAL_FLAGS
245 echo "Running autoheader..."
246 $AUTOHEADER
247 echo "Running automake --gnu ..."
248 $AUTOMAKE --gnu;
249 echo "Running autoconf${FORCE} ..."
250 $AUTOCONF${FORCE}
251
252 echo "You may now run 
253   ./configure --enable-maintainer-mode && make
254 "