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