Tizen 2.1 base
[external/libgpg-error.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 DIE=no
32 FORCE=
33 if test "$1" = "--force"; then
34   FORCE=" --force"
35   shift
36 fi
37
38 # ***** W32 build script *******
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     # Locate the cross compiler
54     crossbindir=
55     for host in i586-mingw32msvc i386-mingw32msvc; do
56         if ${host}-gcc --version >/dev/null 2>&1 ; then
57             crossbindir=/usr/${host}/bin
58             conf_CC="CC=${host}-gcc"
59             break;
60         fi
61     done
62     if [ -z "$crossbindir" ]; then
63         echo "Cross compiler kit not installed" >&2
64         echo "Under Debian GNU/Linux, you may install it using" >&2
65         echo "  apt-get install mingw32 mingw32-runtime mingw32-binutils" >&2 
66         echo "Stop." >&2
67         exit 1
68     fi
69    
70     if [ -f "$tsdir/config.log" ]; then
71         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
72             echo "Pease run a 'make distclean' first" >&2
73             exit 1
74         fi
75     fi
76
77     ./configure --enable-maintainer-mode  --prefix=${w32root}  \
78             --host=${host} --build=${build} 
79
80     exit $?
81 fi
82 # ***** end W32 build script *******
83
84
85 # ***** AMD64 cross build script *******
86 # Used to cross-compile for AMD64 (for testing)
87 if test "$1" = "--build-amd64"; then
88     tmp=`dirname $0`
89     tsdir=`cd "$tmp"; pwd`
90     shift
91     if [ ! -f $tsdir/config.guess ]; then
92         echo "$tsdir/config.guess not found" >&2
93         exit 1
94     fi
95     build=`$tsdir/config.guess`
96
97     [ -z "$amd64root" ] && amd64root="$HOME/amd64root"
98     echo "Using $amd64root as standard install directory" >&2
99     
100     # Locate the cross compiler
101     crossbindir=
102     for host in x86_64-linux-gnu amd64-linux-gnu; do
103         if ${host}-gcc --version >/dev/null 2>&1 ; then
104             crossbindir=/usr/${host}/bin
105             conf_CC="CC=${host}-gcc"
106             break;
107         fi
108     done
109     if [ -z "$crossbindir" ]; then
110         echo "Cross compiler kit not installed" >&2
111         echo "Stop." >&2
112         exit 1
113     fi
114    
115     if [ -f "$tsdir/config.log" ]; then
116         if ! head $tsdir/config.log | grep "$host" >/dev/null; then
117             echo "Please run a 'make distclean' first" >&2
118             exit 1
119         fi
120     fi
121
122     $tsdir/configure --enable-maintainer-mode --prefix=${amd64root}  \
123              --host=${host} --build=${build}
124     rc=$?
125     exit $rc
126 fi
127 # ***** end AMD64 cross build script *******
128
129
130
131 # Grep the required versions from configure.ac
132 autoconf_vers=`sed -n '/^AC_PREREQ(/ { 
133 s/^.*(\(.*\))/\1/p
134 q
135 }' ${configure_ac}`
136 autoconf_vers_num=`echo "$autoconf_vers" | cvtver`
137
138 automake_vers=`sed -n '/^min_automake_version=/ { 
139 s/^.*="\(.*\)"/\1/p
140 q
141 }' ${configure_ac}`
142 automake_vers_num=`echo "$automake_vers" | cvtver`
143
144 gettext_vers=`sed -n '/^AM_GNU_GETTEXT_VERSION(/ { 
145 s/^.*(\(.*\))/\1/p
146 q
147 }' ${configure_ac}`
148 gettext_vers_num=`echo "$gettext_vers" | cvtver`
149
150
151 if [ -z "$autoconf_vers" -o -z "$automake_vers" -o -z "$gettext_vers" ]
152 then
153   echo "**Error**: version information not found in "\`${configure_ac}\'"." >&2
154   exit 1
155 fi
156
157 # Allow to override the default tool names
158 AUTOCONF=${AUTOCONF_PREFIX}${AUTOCONF:-autoconf}${AUTOCONF_SUFFIX}
159 AUTOHEADER=${AUTOCONF_PREFIX}${AUTOHEADER:-autoheader}${AUTOCONF_SUFFIX}
160
161 AUTOMAKE=${AUTOMAKE_PREFIX}${AUTOMAKE:-automake}${AUTOMAKE_SUFFIX}
162 ACLOCAL=${AUTOMAKE_PREFIX}${ACLOCAL:-aclocal}${AUTOMAKE_SUFFIX}
163
164 GETTEXT=${GETTEXT_PREFIX}${GETTEXT:-gettext}${GETTEXT_SUFFIX}
165 MSGMERGE=${GETTEXT_PREFIX}${MSGMERGE:-msgmerge}${GETTEXT_SUFFIX}
166
167
168 if check_version $AUTOCONF $autoconf_vers_num $autoconf_vers ; then
169     check_version $AUTOHEADER $autoconf_vers_num $autoconf_vers autoconf
170 fi
171 if check_version $AUTOMAKE $automake_vers_num $automake_vers; then
172   check_version $ACLOCAL $automake_vers_num $autoconf_vers automake
173 fi
174 if check_version $GETTEXT $gettext_vers_num $gettext_vers; then
175   check_version $MSGMERGE $gettext_vers_num $gettext_vers gettext
176 fi
177
178 if test "$DIE" = "yes"; then
179     cat <<EOF
180
181 Note that you may use alternative versions of the tools by setting 
182 the corresponding environment variables; see README.CVS for details.
183                    
184 EOF
185     exit 1
186 fi
187
188 echo "Running aclocal -I m4 ${ACLOCAL_FLAGS:+$ACLOCAL_FLAGS }..."
189 $ACLOCAL -I m4 $ACLOCAL_FLAGS
190 echo "Running autoheader..."
191 $AUTOHEADER
192 echo "Running automake --gnu ..."
193 $AUTOMAKE --gnu;
194 echo "Running autoconf${FORCE} ..."
195 $AUTOCONF${FORCE}
196
197 echo "You may now run \"./configure --enable-maintainer-mode && make\"."