ares.h: there is no ares_free_soa function
[platform/upstream/c-ares.git] / buildconf
1 #!/bin/sh
2
3 #--------------------------------------------------------------------------
4 # die prints argument string to stdout and exits this shell script.
5 #
6 die(){
7   echo "buildconf: $@"
8   exit 1
9 }
10
11 #--------------------------------------------------------------------------
12 # findtool works as 'which' but we use a different name to make it more
13 # obvious we aren't using 'which'! ;-)
14 #
15 findtool(){
16   file="$1"
17
18   if { echo "$file" | grep "/" >/dev/null 2>&1; } then
19     # when file is given with a path check it first
20     if test -f "$file"; then
21       echo "$file"
22       return
23     fi
24   fi
25
26   old_IFS=$IFS; IFS=':'
27   for path in $PATH
28   do
29     IFS=$old_IFS
30     # echo "checks for $file in $path" >&2
31     if test -f "$path/$file"; then
32       echo "$path/$file"
33       return
34     fi
35   done
36   IFS=$old_IFS
37 }
38
39 #--------------------------------------------------------------------------
40 # removethis() removes all files and subdirectories with the given name,
41 # inside and below the current subdirectory at invocation time.
42 #
43 removethis(){
44   if test "$#" = "1"; then
45     find . -depth -name $1 -print > buildconf.tmp.$$
46     while read fdname
47     do
48       if test -f "$fdname"; then
49         rm -f "$fdname"
50       elif test -d "$fdname"; then
51         rm -f -r "$fdname"
52       fi
53     done < buildconf.tmp.$$
54     rm -f buildconf.tmp.$$
55   fi
56 }
57
58 #--------------------------------------------------------------------------
59 # Ensure that buildconf runs from the subdirectory where configure.ac lives
60 #
61 if test ! -f configure.ac ||
62   test ! -f ares_init.c ||
63   test ! -f m4/cares-functions.m4; then
64   echo "Can not run buildconf from outside of c-ares source subdirectory!"
65   echo "Change to the subdirectory where buildconf is found, and try again."
66   exit 1
67 fi
68
69 #--------------------------------------------------------------------------
70 # GNU libtool preliminary check
71 #
72 want_lt_major=1
73 want_lt_minor=4
74 want_lt_patch=2
75 want_lt_version=1.4.2
76
77 # This approach that tries 'glibtool' first is intended for systems that
78 # have GNU libtool named as 'glibtool' and libtool not being GNU's.
79
80 libtool=`findtool glibtool 2>/dev/null`
81 if test ! -x "$libtool"; then
82   libtool=`findtool ${LIBTOOL:-libtool}`
83 fi
84 if test -z "$libtool"; then
85   echo "buildconf: libtool not found."
86   echo "            You need GNU libtool $want_lt_version or newer installed."
87   exit 1
88 fi
89
90 lt_pver=`$libtool --version 2>/dev/null|head -n 1`
91 lt_qver=`echo $lt_pver|sed -e "s/([^)]*)//g" -e "s/^[^0-9]*//g"`
92 lt_version=`echo $lt_qver|sed -e "s/[- ].*//" -e "s/\([a-z]*\)$//"`
93 if test -z "$lt_version"; then
94   echo "buildconf: libtool not found."
95   echo "            You need GNU libtool $want_lt_version or newer installed."
96   exit 1
97 fi
98 old_IFS=$IFS; IFS='.'; set $lt_version; IFS=$old_IFS
99 lt_major=$1
100 lt_minor=$2
101 lt_patch=$3
102
103 if test -z "$lt_major"; then
104   lt_status="bad"
105 elif test "$lt_major" -gt "$want_lt_major"; then
106   lt_status="good"
107 elif test "$lt_major" -lt "$want_lt_major"; then
108   lt_status="bad"
109 elif test -z "$lt_minor"; then
110   lt_status="bad"
111 elif test "$lt_minor" -gt "$want_lt_minor"; then
112   lt_status="good"
113 elif test "$lt_minor" -lt "$want_lt_minor"; then
114   lt_status="bad"
115 elif test -z "$lt_patch"; then
116   lt_status="bad"
117 elif test "$lt_patch" -gt "$want_lt_patch"; then
118   lt_status="good"
119 elif test "$lt_patch" -lt "$want_lt_patch"; then
120   lt_status="bad"
121 else
122   lt_status="good"
123 fi
124 if test "$lt_status" != "good"; then
125   echo "buildconf: libtool version $lt_version found."
126   echo "            You need GNU libtool $want_lt_version or newer installed."
127   exit 1
128 fi
129
130 #--------------------------------------------------------------------------
131 # GNU libtoolize check
132 #
133 if test -z "$LIBTOOLIZE"; then
134   # use (g)libtoolize from same location as (g)libtool
135   libtoolize="${libtool}ize"
136 else
137   libtoolize=`findtool $LIBTOOLIZE`
138 fi
139 if test ! -f "$libtoolize"; then
140   echo "buildconf: libtoolize not found."
141   echo "            You need GNU libtoolize $want_lt_version or newer installed."
142   exit 1
143 fi
144
145 #--------------------------------------------------------------------------
146 # perl check
147 #
148 PERL=`findtool ${PERL:-perl}`
149 if test -z "$PERL"; then
150   echo "buildconf: perl not found"
151   exit 1
152 fi
153
154 #--------------------------------------------------------------------------
155 # Remove files generated on previous buildconf/configure run.
156 #
157 for fname in .deps \
158     .libs \
159     *.la \
160     *.lo \
161     *.a \
162     *.o \
163     Makefile \
164     Makefile.in \
165     aclocal.m4 \
166     aclocal.m4.bak \
167     ares_build.h \
168     ares_config.h \
169     ares_config.h.in \
170     autom4te.cache \
171     compile \
172     config.guess \
173     config.log \
174     config.lt \
175     config.status \
176     config.sub \
177     configure \
178     depcomp \
179     libcares.pc \
180     libtool \
181     libtool.m4 \
182     libtool.m4.tmp \
183     ltmain.sh \
184     ltoptions.m4 \
185     ltsugar.m4 \
186     ltversion.m4 \
187     lt~obsolete.m4 \
188     missing \
189     stamp-h1 \
190     stamp-h2 ; do
191   removethis "$fname"
192 done
193
194 #--------------------------------------------------------------------------
195 # run the correct scripts now
196 #
197
198 echo "buildconf: running libtoolize"
199 ${libtoolize} --copy --automake --force || die "libtoolize command failed"
200
201 # When using libtool 1.5.X (X < 26) we copy libtool.m4 to our local m4
202 # subdirectory and this local copy is patched to fix some warnings that
203 # are triggered when running aclocal and using autoconf 2.62 or later.
204
205 if test "$lt_major" = "1" && test "$lt_minor" = "5"; then
206   if test -z "$lt_patch" || test "$lt_patch" -lt "26"; then
207     echo "buildconf: copying libtool.m4 to local m4 subdir"
208     ac_dir=`${ACLOCAL:-aclocal} --print-ac-dir`
209     if test -f $ac_dir/libtool.m4; then
210       cp -f $ac_dir/libtool.m4 m4/libtool.m4
211     else
212       echo "buildconf: $ac_dir/libtool.m4 not found"
213     fi
214     if test -f m4/libtool.m4; then
215       echo "buildconf: renaming some variables in local m4/libtool.m4"
216       $PERL -i.tmp -pe \
217         's/lt_prog_compiler_pic_works/lt_cv_prog_compiler_pic_works/g; \
218          s/lt_prog_compiler_static_works/lt_cv_prog_compiler_static_works/g;' \
219         m4/libtool.m4
220       rm -f m4/libtool.m4.tmp
221     fi
222   fi
223 fi
224
225 if test -f m4/libtool.m4; then
226   echo "buildconf: converting all mv to mv -f in local m4/libtool.m4"
227   $PERL -i.tmp -pe 's/\bmv +([^-\s])/mv -f $1/g' m4/libtool.m4
228   rm -f m4/libtool.m4.tmp
229 fi
230
231 echo "buildconf: running aclocal"
232 ${ACLOCAL:-aclocal} -I m4 $ACLOCAL_FLAGS || die "aclocal command failed"
233
234 echo "buildconf: converting all mv to mv -f in local aclocal.m4"
235 $PERL -i.bak -pe 's/\bmv +([^-\s])/mv -f $1/g' aclocal.m4
236
237 echo "buildconf: running autoheader"
238 ${AUTOHEADER:-autoheader} || die "autoheader command failed"
239
240 echo "buildconf: running autoconf"
241 ${AUTOCONF:-autoconf} || die "autoconf command failed"
242
243 echo "buildconf: running automake"
244 ${AUTOMAKE:-automake} --add-missing --copy || die "automake command failed"
245
246 #--------------------------------------------------------------------------
247 # GNU libtool complementary check
248 #
249 # Depending on the libtool and automake versions being used, config.guess
250 # might not be installed in the subdirectory until automake has finished.
251 # So we can not attempt to use it until this very last buildconf stage.
252 #
253 if test ! -f ./config.guess; then
254   echo "buildconf: config.guess not found"
255 else
256   buildhost=`./config.guess 2>/dev/null|head -n 1`
257   case $buildhost in
258     *-*-darwin*)
259       need_lt_major=1
260       need_lt_minor=5
261       need_lt_patch=26
262       need_lt_check="yes"
263       ;;
264     *-*-hpux*)
265       need_lt_major=1
266       need_lt_minor=5
267       need_lt_patch=24
268       need_lt_check="yes"
269       ;;
270   esac
271   if test ! -z "$need_lt_check"; then
272     if test -z "$lt_major"; then
273       lt_status="bad"
274     elif test "$lt_major" -gt "$need_lt_major"; then
275       lt_status="good"
276     elif test "$lt_major" -lt "$need_lt_major"; then
277       lt_status="bad"
278     elif test -z "$lt_minor"; then
279       lt_status="bad"
280     elif test "$lt_minor" -gt "$need_lt_minor"; then
281       lt_status="good"
282     elif test "$lt_minor" -lt "$need_lt_minor"; then
283       lt_status="bad"
284     elif test -z "$lt_patch"; then
285       lt_status="bad"
286     elif test "$lt_patch" -gt "$need_lt_patch"; then
287       lt_status="good"
288     elif test "$lt_patch" -lt "$need_lt_patch"; then
289       lt_status="bad"
290     else
291       lt_status="good"
292     fi
293     if test "$lt_status" != "good"; then
294       need_lt_version="$need_lt_major.$need_lt_minor.$need_lt_patch"
295       echo "buildconf: libtool version $lt_version found."
296       echo "            $buildhost requires GNU libtool $need_lt_version or newer installed."
297       rm -f configure
298       exit 1
299     fi
300   fi
301 fi
302
303 #--------------------------------------------------------------------------
304 # Finished successfully.
305 #
306 echo "buildconf: OK"
307 exit 0