Ensure that buildconf runs from the subdirectory where configure.ac lives
[platform/upstream/curl.git] / buildconf
1 #!/bin/sh
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
10 #
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://curl.haxx.se/docs/copyright.html.
14 #
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
18 #
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
21 #
22 # $Id$
23 ###########################################################################
24
25 die(){
26         echo "$@"
27         exit
28 }
29
30 # this works as 'which' but we use a different name to make it more obvious we
31 # aren't using 'which'! ;-)
32 findtool(){
33   file="$1"
34
35   IFS=":"
36   for path in $PATH
37   do
38     # echo "checks for $file in $path" >&2
39     if test -f "$path/$file"; then
40       echo "$path/$file"
41       return
42     fi
43   done
44 }
45
46 #--------------------------------------------------------------------------
47 # Ensure that buildconf runs from the subdirectory where configure.ac lives
48 #
49 if test ! -f configure.ac ||
50   test ! -f src/main.c ||
51   test ! -f lib/urldata.h ||
52   test ! -f include/curl/curl.h; then
53   echo "Can not run buildconf from outside of curl's source subdirectory!"
54   echo "Change to the subdirectory where buildconf is found, and try again."
55   exit 1
56 fi
57
58 #--------------------------------------------------------------------------
59 # autoconf 2.57 or newer
60 #
61 need_autoconf="2.57"
62 ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|head -n 1| sed -e 's/^[^0-9]*//' -e 's/[a-z]* *$//'`
63 if test -z "$ac_version"; then
64   echo "buildconf: autoconf not found."
65   echo "            You need autoconf version $need_autoconf or newer installed."
66   exit 1
67 fi
68 IFS=.; set $ac_version; IFS=' '
69 if test "$1" = "2" -a "$2" -lt "57" || test "$1" -lt "2"; then
70   echo "buildconf: autoconf version $ac_version found."
71   echo "            You need autoconf version $need_autoconf or newer installed."
72   echo "            If you have a sufficient autoconf installed, but it"
73   echo "            is not named 'autoconf', then try setting the"
74   echo "            AUTOCONF environment variable."
75   exit 1
76 fi
77
78 echo "buildconf: autoconf version $ac_version (ok)"
79
80 #--------------------------------------------------------------------------
81 # autoheader 2.50 or newer
82 #
83 ah_version=`${AUTOHEADER:-autoheader} --version 2>/dev/null|head -n 1| sed -e 's/^[^0-9]*//' -e 's/[a-z]* *$//'`
84 if test -z "$ah_version"; then
85   echo "buildconf: autoheader not found."
86   echo "            You need autoheader version 2.50 or newer installed."
87   exit 1
88 fi
89 IFS=.; set $ah_version; IFS=' '
90 if test "$1" = "2" -a "$2" -lt "50" || test "$1" -lt "2"; then
91   echo "buildconf: autoheader version $ah_version found."
92   echo "            You need autoheader version 2.50 or newer installed."
93   echo "            If you have a sufficient autoheader installed, but it"
94   echo "            is not named 'autoheader', then try setting the"
95   echo "            AUTOHEADER environment variable."
96   exit 1
97 fi
98
99 echo "buildconf: autoheader version $ah_version (ok)"
100
101 #--------------------------------------------------------------------------
102 # automake 1.7 or newer
103 #
104 need_automake="1.7"
105 am_version=`${AUTOMAKE:-automake} --version 2>/dev/null|head -n 1| sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//' -e 's/\(.*\)\(-p.*\)/\1/'`
106 if test -z "$am_version"; then
107   echo "buildconf: automake not found."
108   echo "            You need automake version $need_automake or newer installed."
109   exit 1
110 fi
111 IFS=.; set $am_version; IFS=' '
112 if test "$1" = "1" -a "$2" -lt "7" || test "$1" -lt "1"; then
113   echo "buildconf: automake version $am_version found."
114   echo "            You need automake version $need_automake or newer installed."
115   echo "            If you have a sufficient automake installed, but it"
116   echo "            is not named 'automake', then try setting the"
117   echo "            AUTOMAKE environment variable."
118   exit 1
119 fi
120
121 echo "buildconf: automake version $am_version (ok)"
122
123 ac=`findtool ${ACLOCAL:-aclocal}`
124 if test -z "$ac"; then
125   echo "buildconf: aclocal not found. Weird automake installation!"
126   exit 1
127 else
128   echo "buildconf: aclocal found"
129 fi
130
131 #--------------------------------------------------------------------------
132 # libtool check
133 #
134 LIBTOOL_WANTED_MAJOR=1
135 LIBTOOL_WANTED_MINOR=4
136 LIBTOOL_WANTED_PATCH=2
137 LIBTOOL_WANTED_VERSION=1.4.2
138
139 # this approach that tries 'glibtool' first is some kind of work-around for
140 # some BSD-systems I believe that use to provide the GNU libtool named
141 # glibtool, with 'libtool' being something completely different.
142 libtool=`findtool glibtool 2>/dev/null`
143 if test ! -x "$libtool"; then
144   libtool=`findtool ${LIBTOOL:-libtool}`
145 fi
146
147 if test -z "$LIBTOOLIZE"; then
148   # set the LIBTOOLIZE here so that glibtoolize is used if glibtool was found
149   # $libtool is already the full path
150   libtoolize="${libtool}ize"
151 else
152   libtoolize=`findtool $LIBTOOLIZE`
153 fi
154
155 lt_pversion=`$libtool --version 2>/dev/null|head -n 2|sed -e 's/^[^0-9]*//g' -e 's/[- ].*//'`
156 if test -z "$lt_pversion"; then
157   echo "buildconf: libtool not found."
158   echo "            You need libtool version $LIBTOOL_WANTED_VERSION or newer installed"
159   exit 1
160 fi
161 lt_version=`echo $lt_pversion|sed -e 's/\([a-z]*\)$//'`
162 IFS=.; set $lt_version; IFS=' '
163 lt_status="good"
164
165 major=$1
166 minor=$2
167 patch=$3
168
169 if test "$major" = "$LIBTOOL_WANTED_MAJOR"; then
170    if test "$minor" -lt "$LIBTOOL_WANTED_MINOR"; then
171       lt_status="bad"
172    elif test -n "$LIBTOOL_WANTED_PATCH"; then
173        if test "$minor" -gt "$LIBTOOL_WANTED_MINOR"; then
174          lt_status="good"
175        elif test -n "$patch"; then
176           if test "$patch" -lt "$LIBTOOL_WANTED_PATCH"; then
177              lt_status="bad"
178           fi
179        else
180           lt_status="bad"
181        fi
182    fi
183 fi
184 if test $lt_status != "good"; then
185   echo "buildconf: libtool version $lt_pversion found."
186   echo "            You need libtool version $LIBTOOL_WANTED_VERSION or newer installed"
187   exit 1
188 fi
189
190 echo "buildconf: libtool version $lt_version (ok)"
191
192 if test -f "$libtoolize"; then
193   echo "buildconf: libtoolize found"
194 else
195   echo "buildconf: libtoolize not found. Weird libtool installation!"
196   exit 1
197 fi
198
199 #--------------------------------------------------------------------------
200 # m4 check
201 #
202 m4=`${M4:-m4} --version 2>/dev/null|head -n 1`;
203 m4_version=`echo $m4 | sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//'`
204
205 if { echo $m4 | grep "GNU" >/dev/null 2>&1; } then
206   echo "buildconf: GNU m4 version $m4_version (ok)"
207 else
208   echo "buildconf: m4 version $m4 found. You need a GNU m4 installed!"
209   exit 1
210 fi
211
212 #--------------------------------------------------------------------------
213 # perl check
214 #
215 PERL=`findtool ${PERL:-perl}`
216
217 #--------------------------------------------------------------------------
218 # Remove files generated on previous buildconf/configure run.
219 #
220 for fname in aclocal.m4 \
221              aclocal.m4.bak \
222              config.guess \
223              config.log \
224              config.status \
225              config.sub \
226              configure \
227              depcomp \
228              libtool \
229              ltmain.sh \
230              Makefile \
231              Makefile.in ; do
232   if test -f "$fname" ; then
233     rm -f "$fname"
234   fi
235 done
236 if test -d autom4te.cache; then
237   rm -f -r autom4te.cache
238 fi
239 if test -d docs/examples/.deps; then
240   rm -f -r docs/examples/.deps
241 fi
242 if test -d lib/.deps; then
243   rm -f -r lib/.deps
244 fi
245 if test -d src/.deps; then
246   rm -f -r src/.deps
247 fi
248 if test -d tests/libtest/.deps; then
249   rm -f -r tests/libtest/.deps
250 fi
251 if test -d tests/server/.deps; then
252   rm -f -r tests/server/.deps
253 fi
254
255 #--------------------------------------------------------------------------
256 # Remove files generated in ares subdir on previous buildconf/configure run.
257 #
258 if test -d ares; then
259   cd ares
260   for fname in aclocal.m4 \
261                aclocal.m4.bak \
262                compile \
263                config.h \
264                config.h.in \
265                config.guess \
266                config.log \
267                config.status \
268                config.sub \
269                configure \
270                depcomp \
271                libtool \
272                ltmain.sh \
273                missing \
274                Makefile \
275                Makefile.in ; do
276     if test -f "$fname" ; then
277       rm -f "$fname"
278     fi
279   done
280   if test -d autom4te.cache; then
281     rm -f -r autom4te.cache
282   fi
283   if test -d .deps; then
284     rm -f -r .deps
285   fi
286   cd ..
287 fi
288
289 #--------------------------------------------------------------------------
290 # run the correct scripts now
291 #
292
293 if test -z "$ACLOCAL_FLAGS"; then
294   ACLOCAL_FLAGS="-I m4"
295 else
296   ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4"
297 fi
298
299 tmp_host_type=`uname -a | sed '/SunOS/s/.*\(SunOS\).*/\1/'`
300 if test "x$tmp_host_type" = "xSunOS"; then
301   ACLOCAL_FLAGS="$ACLOCAL_FLAGS --verbose"
302 fi
303
304 export ACLOCAL_FLAGS
305 echo "buildconf: using ACLOCAL_FLAGS: $ACLOCAL_FLAGS"
306
307 echo "buildconf: running libtoolize"
308 $libtoolize --copy --automake --force || die "The libtoolize command failed"
309 echo "buildconf: running aclocal"
310 ${ACLOCAL:-aclocal} $ACLOCAL_FLAGS || die "The aclocal command line failed"
311 if test -n "$PERL"; then
312   echo "buildconf: running aclocal hack to convert all mv to mv -f"
313   $PERL -i.bak -pe 's/\bmv +([^-\s])/mv -f $1/g' aclocal.m4
314 else
315   echo "buildconf: perl not found"
316   exit 1
317 fi
318 echo "buildconf: running autoheader"
319 ${AUTOHEADER:-autoheader} || die "The autoheader command failed"
320 echo "buildconf: cp lib/config.h.in src/config.h.in"
321 cp lib/config.h.in src/config.h.in
322 echo "buildconf: running autoconf"
323 ${AUTOCONF:-autoconf}     || die "The autoconf command failed"
324
325 if test -d ares; then
326   cd ares
327   echo "buildconf: running in ares"
328   ./buildconf
329   cd ..
330 fi
331
332 echo "buildconf: running automake"
333 ${AUTOMAKE:-automake} -a -c  || die "The automake command failed"
334
335 echo "buildconf: OK"
336 exit 0