allow more evironment variables to control what tools to check for and use
[platform/upstream/curl.git] / buildconf
1 #!/bin/sh
2
3 die(){
4         echo "$@"
5         exit
6 }
7
8 # this works as 'which' but we use a different name to make it more obvious we
9 # aren't using 'which'! ;-)
10 findtool(){
11   file="$1"
12
13   IFS=":"
14   for path in $PATH
15   do
16     # echo "checks for $file in $path" >&2
17     if test -f "$path/$file"; then
18       echo "$path/$file"
19       return
20     fi
21   done
22 }
23
24 #--------------------------------------------------------------------------
25 # autoconf 2.57 or newer
26 #
27 need_autoconf="2.57"
28 ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|head -n 1| sed -e 's/^[^0-9]*//' -e 's/[a-z]* *$//'`
29 if test -z "$ac_version"; then
30   echo "buildconf: autoconf not found."
31   echo "            You need autoconf version $need_autoconf or newer installed."
32   exit 1
33 fi
34 IFS=.; set $ac_version; IFS=' '
35 if test "$1" = "2" -a "$2" -lt "57" || test "$1" -lt "2"; then
36   echo "buildconf: autoconf version $ac_version found."
37   echo "            You need autoconf version $need_autoconf or newer installed."
38   echo "            If you have a sufficient autoconf installed, but it"
39   echo "            is not named 'autoconf', then try setting the"
40   echo "            AUTOCONF environment variable."
41   exit 1
42 fi
43
44 echo "buildconf: autoconf version $ac_version (ok)"
45
46 #--------------------------------------------------------------------------
47 # autoheader 2.50 or newer
48 #
49 ah_version=`${AUTOHEADER:-autoheader} --version 2>/dev/null|head -n 1| sed -e 's/^[^0-9]*//' -e 's/[a-z]* *$//'`
50 if test -z "$ah_version"; then
51   echo "buildconf: autoheader not found."
52   echo "            You need autoheader version 2.50 or newer installed."
53   exit 1
54 fi
55 IFS=.; set $ah_version; IFS=' '
56 if test "$1" = "2" -a "$2" -lt "50" || test "$1" -lt "2"; then
57   echo "buildconf: autoheader version $ah_version found."
58   echo "            You need autoheader version 2.50 or newer installed."
59   echo "            If you have a sufficient autoheader installed, but it"
60   echo "            is not named 'autoheader', then try setting the"
61   echo "            AUTOHEADER environment variable."
62   exit 1
63 fi
64
65 echo "buildconf: autoheader version $ah_version (ok)"
66
67 #--------------------------------------------------------------------------
68 # automake 1.7 or newer
69 #
70 need_automake="1.7"
71 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/'`
72 if test -z "$am_version"; then
73   echo "buildconf: automake not found."
74   echo "            You need automake version $need_automake or newer installed."
75   exit 1
76 fi
77 IFS=.; set $am_version; IFS=' '
78 if test "$1" = "1" -a "$2" -lt "7" || test "$1" -lt "1"; then
79   echo "buildconf: automake version $am_version found."
80   echo "            You need automake version $need_automake or newer installed."
81   echo "            If you have a sufficient automake installed, but it"
82   echo "            is not named 'automake', then try setting the"
83   echo "            AUTOMAKE environment variable."
84   exit 1
85 fi
86
87 echo "buildconf: automake version $am_version (ok)"
88
89 ac=`findtool ${ACLOCAL:-aclocal}`
90 if test -z "$ac"; then
91   echo "buildconf: aclocal not found. Weird automake installation!"
92   exit 1
93 else
94   echo "buildconf: aclocal found"
95 fi
96
97 #--------------------------------------------------------------------------
98 # libtool check
99 #
100 LIBTOOL_WANTED_MAJOR=1
101 LIBTOOL_WANTED_MINOR=4
102 LIBTOOL_WANTED_PATCH=2
103 LIBTOOL_WANTED_VERSION=1.4.2
104
105 # this approach that tries 'glibtool' first is some kind of work-around for
106 # some BSD-systems I believe that use to provide the GNU libtool named
107 # glibtool, with 'libtool' being something completely different.
108 libtool=`findtool glibtool 2>/dev/null`
109 if test ! -x "$libtool"; then
110   libtool=`findtool ${LIBTOOL:-libtool}`
111 fi
112
113 if test -z "$LIBTOOLIZE"; then
114   # set the LIBTOOLIZE here so that glibtoolize is used if glibtool was found
115   # $libtool is already the full path
116   libtoolize="${libtool}ize"
117 else
118   libtoolize=`findtool $LIBTOOLIZE`
119 fi
120
121 lt_pversion=`$libtool --version 2>/dev/null|head -n 1|sed -e 's/^[^0-9]*//g' -e 's/[- ].*//'`
122 if test -z "$lt_pversion"; then
123   echo "buildconf: libtool not found."
124   echo "            You need libtool version $LIBTOOL_WANTED_VERSION or newer installed"
125   exit 1
126 fi
127 lt_version=`echo $lt_pversion|sed -e 's/\([a-z]*\)$//'`
128 IFS=.; set $lt_version; IFS=' '
129 lt_status="good"
130
131 major=$1
132 minor=$2
133 patch=$3
134
135 if test "$major" = "$LIBTOOL_WANTED_MAJOR"; then
136    if test "$minor" -lt "$LIBTOOL_WANTED_MINOR"; then
137       lt_status="bad"
138    elif test -n "$LIBTOOL_WANTED_PATCH"; then
139        if test "$minor" -gt "$LIBTOOL_WANTED_MINOR"; then
140          lt_status="good"
141        elif test -n "$patch"; then
142           if test "$patch" -lt "$LIBTOOL_WANTED_PATCH"; then
143              lt_status="bad"
144           fi
145        else
146           lt_status="bad"
147        fi
148    fi
149 fi
150 if test $lt_status != "good"; then
151   echo "buildconf: libtool version $lt_pversion found."
152   echo "            You need libtool version $LIBTOOL_WANTED_VERSION or newer installed"
153   exit 1
154 fi
155
156 echo "buildconf: libtool version $lt_version (ok)"
157
158 if test -f "$libtoolize"; then
159   echo "buildconf: libtoolize found"
160 else
161   echo "buildconf: libtoolize not found. Weird libtool installation!"
162   exit 1
163 fi
164
165 #--------------------------------------------------------------------------
166 # m4 check
167 #
168 m4=`${M4:-m4} --version 2>/dev/null|head -n 1`;
169 m4_version=`echo $m4 | sed -e 's/^.* \([0-9]\)/\1/' -e 's/[a-z]* *$//'`
170
171 if { echo $m4 | grep "GNU" >/dev/null 2>&1; } then
172   echo "buildconf: GNU m4 version $m4_version (ok)"
173 else
174   echo "buildconf: m4 version $m4 found. You need a GNU m4 installed!"
175   exit 1
176 fi
177
178 #--------------------------------------------------------------------------
179 # perl check
180 #
181 PERL=`findtool ${PERL:-perl}`
182
183 # ------------------------------------------------------------
184
185 # run the correct scripts now
186
187 echo "buildconf: running libtoolize"
188 $libtoolize --copy --automake --force || die "The libtoolize command failed"
189 echo "buildconf: running aclocal"
190 ${ACLOCAL:-aclocal} $ACLOCAL_FLAGS || die "The aclocal command line failed"
191 if test -n "$PERL"; then
192   echo "buildconf: running aclocal hack to convert all mv to mv -f"
193   $PERL -i.bak -pe 's/\bmv +([^-\s])/mv -f $1/g' aclocal.m4
194 else
195   echo "buildconf: perl not found"
196   exit 1
197 fi
198 echo "buildconf: running autoheader"
199 ${AUTOHEADER:-autoheader} || die "The autoheader command failed"
200 echo "buildconf: cp lib/config.h.in src/config.h.in"
201 cp lib/config.h.in src/config.h.in
202 echo "buildconf: running autoconf"
203 ${AUTOCONF:-autoconf}     || die "The autoconf command failed"
204
205 if test -d ares; then
206   cd ares
207   echo "buildconf: running ares/libtoolize"
208 $libtoolize --copy --automake --force || die "The libtoolize command failed"
209   echo "buildconf: running ares/aclocal"
210   ${ACLOCAL:-aclocal} $ACLOCAL_FLAGS || die "The ares aclocal command failed"
211   echo "buildconf: running ares/autoconf"
212   ${AUTOCONF:-autoconf}     || die "The ares autoconf command failed"
213   cd ..
214 fi
215
216 echo "buildconf: running automake"
217 ${AUTOMAKE:-automake} -a -c  || die "The automake command failed"
218
219 echo "buildconf: OK"
220 exit 0