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