Allow the native W32 version to properly work with sockets.
[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 "$1" = "--force"; then
35   FORCE=" --force"
36   shift
37 fi
38
39 # Used to cross-compile for Windows.
40 if test "$1" = "--build-w32"; then
41     tmp=`dirname $0`
42     tsdir=`cd "$tmp"; pwd`
43     shift
44     if [ ! -f $tsdir/config.guess ]; then
45         echo "$tsdir/config.guess not found" >&2
46         exit 1
47     fi
48     build=`$tsdir/config.guess`
49
50     [ -z "$w32root" ] && w32root="$HOME/w32root"
51     echo "Using $w32root as standard install directory" >&2
52     
53     # See whether we have the Debian cross compiler package or the
54     # old mingw32/cpd system
55     if i586-mingw32msvc-gcc --version >/dev/null 2>&1 ; then
56         host=i586-mingw32msvc
57         crossbindir=/usr/$host/bin
58     else
59        host=i386--mingw32
60        if ! mingw32 --version >/dev/null; then
61           echo "We need at least version 0.3 of MingW32/CPD" >&2
62           exit 1
63        fi
64        crossbindir=`mingw32 --install-dir`/bin
65        # Old autoconf version required us to setup the environment
66        # with the proper tool names.
67        CC=`mingw32 --get-path gcc`
68        CPP=`mingw32 --get-path cpp`
69        AR=`mingw32 --get-path ar`
70        RANLIB=`mingw32 --get-path ranlib`
71        export CC CPP AR RANLIB 
72     fi
73    
74     if [ -f "$tsdir/config.log" ]; then
75         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
76             echo "Pease run a 'make distclean' first" >&2
77             exit 1
78         fi
79     fi
80
81     ./configure --enable-maintainer-mode  --prefix=${w32root}  \
82             --host=i586-mingw32msvc --build=${build} \
83             --with-gpg-error-prefix=${w32root} \
84             --with-libassuan-prefix=${w32root} \
85             --enable-shared --enable-static --enable-w32-glib \
86             PKG_CONFIG_LIBDIR="$w32root/lib/pkgconfig"
87
88     exit $?
89 fi
90
91
92
93
94
95 # Grep the required versions from configure.ac
96 autoconf_vers=`sed -n '/^AC_PREREQ(/ { 
97 s/^.*(\(.*\))/\1/p
98 q
99 }' ${configure_ac}`
100 autoconf_vers_num=`echo "$autoconf_vers" | cvtver`
101
102 automake_vers=`sed -n '/^min_automake_version=/ { 
103 s/^.*="\(.*\)"/\1/p
104 q
105 }' ${configure_ac}`
106 automake_vers_num=`echo "$automake_vers" | cvtver`
107
108 #gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ { 
109 #s/^.*(\(.*\))/\1/p
110 #q
111 #}' ${configure_ac}`
112 #gettext_vers_num=`echo "$gettext_vers" | cvtver`
113
114
115 if [ -z "$autoconf_vers" -o -z "$automake_vers" ]
116 then
117   echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2
118   exit 1
119 fi
120
121 # Allow to override the default tool names
122 AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX}
123 AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX}
124
125 AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX}
126 ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX}
127
128 #GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX}
129 #MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX}
130
131 DIE=no
132
133
134 if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then
135     check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf
136 fi
137 if check_version $AUTOMAKE $automake_vers_num $automake_vers; then
138     check_version $ACLOCAL $automake_vers_num $automake_vers automake
139 fi
140 #if check_version $GETTEXT $gettext_vers_num $gettext_vers; then
141 #  check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext
142 #fi
143
144 if test "$DIE" = "yes"; then
145     cat <<EOF
146
147 Note that you may use alternative versions of the tools by setting 
148 the corresponding environment variables; see README.CVS for details.
149                    
150 EOF
151     exit 1
152 fi
153
154 echo "Running aclocal -I m4 ${ACLOCAL_FLAGS:+$ACLOCAL_FLAGS }..."
155 $ACLOCAL -I m4 $ACLOCAL_FLAGS
156 echo "Running autoheader..."
157 $AUTOHEADER
158 echo "Running automake --gnu ..."
159 $AUTOMAKE --gnu;
160 echo "Running autoconf${FORCE} ..."
161 $AUTOCONF${FORCE}
162
163 echo "You may now run:
164   ./configure --enable-maintainer-mode && make
165 "
166