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