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