Allow tools to be defined with full path in buildconf
[platform/upstream/curl.git] / buildconf
1 #!/bin/sh
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2009, 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 ###########################################################################
23
24 die(){
25         echo "$@"
26         exit
27 }
28
29 #--------------------------------------------------------------------------
30 # findtool works as 'which' but we use a different name to make it more
31 # obvious we aren't using 'which'! ;-)
32 #
33 findtool(){
34   file="$1"
35
36   if test -f "$file"; then
37     echo "$file"
38     return
39   fi
40
41   old_IFS=$IFS; IFS=':'
42   for path in $PATH
43   do
44     IFS=$old_IFS
45     # echo "checks for $file in $path" >&2
46     if test -f "$path/$file"; then
47       echo "$path/$file"
48       return
49     fi
50   done
51   IFS=$old_IFS
52 }
53
54 #--------------------------------------------------------------------------
55 # removethis() removes all files and subdirectories with the given name,
56 # inside and below the current subdirectory at invocation time.
57 #
58 removethis(){
59   if test "$#" = "1"; then
60     find . -depth -name $1 -print > buildconf.tmp.$$
61     while read fdname
62     do
63       if test -f "$fdname"; then
64         rm -f "$fdname"
65       elif test -d "$fdname"; then
66         rm -f -r "$fdname"
67       fi
68     done < buildconf.tmp.$$
69     rm -f buildconf.tmp.$$
70   fi
71 }
72
73 #--------------------------------------------------------------------------
74 # Ensure that buildconf runs from the subdirectory where configure.ac lives
75 #
76 if test ! -f configure.ac ||
77   test ! -f src/main.c ||
78   test ! -f lib/urldata.h ||
79   test ! -f include/curl/curl.h; then
80   echo "Can not run buildconf from outside of curl's source subdirectory!"
81   echo "Change to the subdirectory where buildconf is found, and try again."
82   exit 1
83 fi
84
85 #--------------------------------------------------------------------------
86 # autoconf 2.57 or newer
87 #
88 need_autoconf="2.57"
89 ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|head -n 1| sed -e 's/^[^0-9]*//' -e 's/[a-z]* *$//'`
90 if test -z "$ac_version"; then
91   echo "buildconf: autoconf not found."
92   echo "            You need autoconf version $need_autoconf or newer installed."
93   exit 1
94 fi
95 old_IFS=$IFS; IFS='.'; set $ac_version; IFS=$old_IFS
96 if test "$1" = "2" -a "$2" -lt "57" || test "$1" -lt "2"; then
97   echo "buildconf: autoconf version $ac_version found."
98   echo "            You need autoconf version $need_autoconf or newer installed."
99   echo "            If you have a sufficient autoconf installed, but it"
100   echo "            is not named 'autoconf', then try setting the"
101   echo "            AUTOCONF environment variable."
102   exit 1
103 fi
104
105 echo "buildconf: autoconf version $ac_version (ok)"
106
107 am4te_version=`${AUTOM4TE:-autom4te} --version 2>/dev/null|head -n 1| sed -e 's/autom4te\(.*\)/\1/' -e 's/^[^0-9]*//' -e 's/[a-z]* *$//'`
108 if test -z "$am4te_version"; then
109   echo "buildconf: autom4te not found. Weird autoconf installation!"
110   exit 1
111 fi
112 if test "$am4te_version" = "$ac_version"; then
113   echo "buildconf: autom4te version $am4te_version (ok)"
114 else
115   echo "buildconf: autom4te version $am4te_version (ERROR: does not match autoconf version)"
116   exit 1
117 fi
118
119 #--------------------------------------------------------------------------
120 # autoheader 2.50 or newer
121 #
122 ah_version=`${AUTOHEADER:-autoheader} --version 2>/dev/null|head -n 1| sed -e 's/^[^0-9]*//' -e 's/[a-z]* *$//'`
123 if test -z "$ah_version"; then
124   echo "buildconf: autoheader not found."
125   echo "            You need autoheader version 2.50 or newer installed."
126   exit 1
127 fi
128 old_IFS=$IFS; IFS='.'; set $ah_version; IFS=$old_IFS
129 if test "$1" = "2" -a "$2" -lt "50" || test "$1" -lt "2"; then
130   echo "buildconf: autoheader version $ah_version found."
131   echo "            You need autoheader version 2.50 or newer installed."
132   echo "            If you have a sufficient autoheader installed, but it"
133   echo "            is not named 'autoheader', then try setting the"
134   echo "            AUTOHEADER environment variable."
135   exit 1
136 fi
137
138 echo "buildconf: autoheader version $ah_version (ok)"
139
140 #--------------------------------------------------------------------------
141 # automake 1.7 or newer
142 #
143 need_automake="1.7"
144 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/'`
145 if test -z "$am_version"; then
146   echo "buildconf: automake not found."
147   echo "            You need automake version $need_automake or newer installed."
148   exit 1
149 fi
150 old_IFS=$IFS; IFS='.'; set $am_version; IFS=$old_IFS
151 if test "$1" = "1" -a "$2" -lt "7" || test "$1" -lt "1"; then
152   echo "buildconf: automake version $am_version found."
153   echo "            You need automake version $need_automake or newer installed."
154   echo "            If you have a sufficient automake installed, but it"
155   echo "            is not named 'automake', then try setting the"
156   echo "            AUTOMAKE environment variable."
157   exit 1
158 fi
159
160 echo "buildconf: automake version $am_version (ok)"
161
162 acloc_version=`${ACLOCAL:-aclocal} --version 2>/dev/null|head -n 1| sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//' -e 's/\(.*\)\(-p.*\)/\1/'`
163 if test -z "$acloc_version"; then
164   echo "buildconf: aclocal not found. Weird automake installation!"
165   exit 1
166 fi
167 if test "$acloc_version" = "$am_version"; then
168   echo "buildconf: aclocal version $acloc_version (ok)"
169 else
170   echo "buildconf: aclocal version $acloc_version (ERROR: does not match automake version)"
171   exit 1
172 fi
173
174 #--------------------------------------------------------------------------
175 # libtool check
176 #
177 LIBTOOL_WANTED_MAJOR=1
178 LIBTOOL_WANTED_MINOR=4
179 LIBTOOL_WANTED_PATCH=2
180 LIBTOOL_WANTED_VERSION=1.4.2
181
182 # this approach that tries 'glibtool' first is some kind of work-around for
183 # some BSD-systems I believe that use to provide the GNU libtool named
184 # glibtool, with 'libtool' being something completely different.
185 libtool=`findtool glibtool 2>/dev/null`
186 if test ! -x "$libtool"; then
187   libtool=`findtool ${LIBTOOL:-libtool}`
188 fi
189
190 if test -z "$LIBTOOLIZE"; then
191   # set the LIBTOOLIZE here so that glibtoolize is used if glibtool was found
192   # $libtool is already the full path
193   libtoolize="${libtool}ize"
194 else
195   libtoolize=`findtool $LIBTOOLIZE`
196 fi
197
198 lt_pver=`$libtool --version 2>/dev/null|head -n 1`
199 lt_qver=`echo $lt_pver|sed -e "s/([^)]*)//g" -e "s/^[^0-9]*//g"`
200 lt_version=`echo $lt_qver|sed -e "s/[- ].*//" -e "s/\([a-z]*\)$//"`
201 if test -z "$lt_version"; then
202   echo "buildconf: libtool not found."
203   echo "            You need libtool version $LIBTOOL_WANTED_VERSION or newer installed"
204   exit 1
205 fi
206 old_IFS=$IFS; IFS='.'; set $lt_version; IFS=$old_IFS
207 lt_major=$1
208 lt_minor=$2
209 lt_patch=$3
210 lt_status="good"
211
212 if test "$lt_major" = "$LIBTOOL_WANTED_MAJOR"; then
213    if test "$lt_minor" -lt "$LIBTOOL_WANTED_MINOR"; then
214       lt_status="bad"
215    elif test -n "$LIBTOOL_WANTED_PATCH"; then
216        if test "$lt_minor" -gt "$LIBTOOL_WANTED_MINOR"; then
217          lt_status="good"
218        elif test -n "$lt_patch"; then
219           if test "$lt_patch" -lt "$LIBTOOL_WANTED_PATCH"; then
220              lt_status="bad"
221           fi
222        else
223           lt_status="bad"
224        fi
225    fi
226 fi
227 if test $lt_status != "good"; then
228   echo "buildconf: libtool version $lt_version found."
229   echo "            You need libtool version $LIBTOOL_WANTED_VERSION or newer installed"
230   exit 1
231 fi
232
233 echo "buildconf: libtool version $lt_version (ok)"
234
235 if test -f "$libtoolize"; then
236   echo "buildconf: libtoolize found"
237 else
238   echo "buildconf: libtoolize not found. Weird libtool installation!"
239   exit 1
240 fi
241
242 #--------------------------------------------------------------------------
243 # m4 check
244 #
245 m4=`${M4:-m4} --version 2>/dev/null|head -n 1`;
246 m4_version=`echo $m4 | sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//'`
247
248 if { echo $m4 | grep "GNU" >/dev/null 2>&1; } then
249   echo "buildconf: GNU m4 version $m4_version (ok)"
250 else
251   echo "buildconf: m4 version $m4 found. You need a GNU m4 installed!"
252   exit 1
253 fi
254
255 #--------------------------------------------------------------------------
256 # perl check
257 #
258 PERL=`findtool ${PERL:-perl}`
259
260 #--------------------------------------------------------------------------
261 # Remove files generated on previous buildconf/configure run.
262 #
263 for fname in .deps \
264     .libs \
265     *.la \
266     *.lo \
267     *.a \
268     *.o \
269     Makefile \
270     Makefile.in \
271     aclocal.m4 \
272     aclocal.m4.bak \
273     ares_build.h \
274     ares_config.h \
275     ares_config.h.in \
276     autom4te.cache \
277     compile \
278     config.guess \
279     curl_config.h \
280     curl_config.h.in \
281     config.log \
282     config.lt \
283     config.status \
284     config.sub \
285     configure \
286     curl-config \
287     curlbuild.h \
288     depcomp \
289     libcares.pc \
290     libcurl.pc \
291     libtool \
292     libtool.m4 \
293     ltmain.sh \
294     ltoptions.m4 \
295     ltsugar.m4 \
296     ltversion.m4 \
297     lt~obsolete.m4 \
298     stamp-h1 \
299     stamp-h2 \
300     stamp-h3 ; do
301   removethis "$fname"
302 done
303
304 #--------------------------------------------------------------------------
305 # run the correct scripts now
306 #
307
308 echo "buildconf: running libtoolize"
309 $libtoolize --copy --automake --force || die "The libtoolize command failed"
310
311 if test ! -f m4/curl-functions.m4; then
312   echo "buildconf: cURL m4 macros not found"
313   exit 1
314 fi
315
316 echo "buildconf: running aclocal"
317 ${ACLOCAL:-aclocal} -I m4 $ACLOCAL_FLAGS || die "The aclocal command line failed"
318
319 if test -n "$PERL"; then
320   echo "buildconf: running aclocal hack to convert all mv to mv -f"
321   $PERL -i.bak -pe 's/\bmv +([^-\s])/mv -f $1/g' aclocal.m4
322 else
323   echo "buildconf: perl not found"
324   exit 1
325 fi
326
327 echo "buildconf: running autoheader"
328 ${AUTOHEADER:-autoheader} || die "The autoheader command failed"
329
330 echo "buildconf: cp lib/curl_config.h.in src/curl_config.h.in"
331 cp lib/curl_config.h.in src/curl_config.h.in
332
333 echo "buildconf: running autoconf"
334 ${AUTOCONF:-autoconf}     || die "The autoconf command failed"
335
336 if test -d ares; then
337   cd ares
338   echo "buildconf: running in ares"
339   ./buildconf
340   cd ..
341 fi
342
343 echo "buildconf: running automake"
344 ${AUTOMAKE:-automake} -a -c  || die "The automake command failed"
345
346 #--------------------------------------------------------------------------
347 # Depending on the libtool and automake versions being used, config.guess
348 # might not be installed in the subdirectory until automake has finished.
349 # So we can not attempt to use it until this very last buildconf stage.
350 #
351
352 if test ! -f ./config.guess; then
353   echo "buildconf: config.guess not found"
354 else
355   buildhost=`./config.guess 2>/dev/null|head -n 1`
356   case $buildhost in
357     *-*-hpux*)
358       need_lt_major=1
359       need_lt_minor=5
360       need_lt_patch=24
361       need_lt_check="yes"
362       ;;
363   esac
364   if test ! -z "$need_lt_check"; then
365     if test -z "$lt_major"; then
366       lt_status="bad"
367     elif test "$lt_major" -gt "$need_lt_major"; then
368       lt_status="good"
369     elif test "$lt_major" -lt "$need_lt_major"; then
370       lt_status="bad"
371     elif test -z "$lt_minor"; then
372       lt_status="bad"
373     elif test "$lt_minor" -gt "$need_lt_minor"; then
374       lt_status="good"
375     elif test "$lt_minor" -lt "$need_lt_minor"; then
376       lt_status="bad"
377     elif test -z "$lt_patch"; then
378       lt_status="bad"
379     elif test "$lt_patch" -gt "$need_lt_patch"; then
380       lt_status="good"
381     elif test "$lt_patch" -lt "$need_lt_patch"; then
382       lt_status="bad"
383     else
384       lt_status="good"
385     fi
386     if test "$lt_status" != "good"; then
387       need_lt_version="$need_lt_major.$need_lt_minor.$need_lt_patch"
388       echo "buildconf: libtool version $lt_version found."
389       echo "            $buildhost requires libtool $need_lt_version or newer installed."
390       rm -f configure
391       exit 1
392     fi
393   fi
394 fi
395
396 #--------------------------------------------------------------------------
397 # Finished succesfully.
398 #
399
400 echo "buildconf: OK"
401 exit 0