2008-10-23 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / acinclude.m4
blobe0083b9dd13bba610f3c20250f65fe2a9e95b47b
1 dnl dolt, a replacement for libtool
2 dnl Copyright © 2007-2008 Josh Triplett <josh@freedesktop.org>
3 dnl Copying and distribution of this file, with or without modification,
4 dnl are permitted in any medium without royalty provided the copyright
5 dnl notice and this notice are preserved.
6 dnl
7 dnl To use dolt, invoke the DOLT macro immediately after the libtool macros.
8 dnl Optionally, copy this file into acinclude.m4, to avoid the need to have it
9 dnl installed when running autoconf on your project.
11 AC_DEFUN([DOLT], [
12 AC_REQUIRE([AC_CANONICAL_HOST])
13 # dolt, a replacement for libtool
14 # Josh Triplett <josh@freedesktop.org>
15 AC_PATH_PROG(DOLT_BASH, bash)
16 AC_MSG_CHECKING([if dolt supports this host])
17 dolt_supported=yes
18 if test x$DOLT_BASH = x; then
19     dolt_supported=no
21 if test x$GCC != xyes; then
22     dolt_supported=no
24 case $host in
25 i?86-*-linux*|x86_64-*-linux*|powerpc-*-linux* \
26 |amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*)
27     pic_options='-fPIC'
28     ;;
29 i?86-apple-darwin*)
30     pic_options='-fno-common'
31     ;;
33     dolt_supported=no
34     ;;
35 esac
36 if test x$dolt_supported = xno ; then
37     AC_MSG_RESULT([no, falling back to libtool])
38     LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
39     LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
40 else
41     AC_MSG_RESULT([yes, replacing libtool])
43 dnl Start writing out doltcompile.
44     cat <<__DOLTCOMPILE__EOF__ >doltcompile
45 #!$DOLT_BASH
46 __DOLTCOMPILE__EOF__
47     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
48 args=("$[]@")
49 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
50     if test x"${args@<:@$arg@:>@}" = x-o ; then
51         objarg=$((arg+1))
52         break
53     fi
54 done
55 if test x$objarg = x ; then
56     echo 'Error: no -o on compiler command line' 1>&2
57     exit 1
59 lo="${args@<:@$objarg@:>@}"
60 obj="${lo%.lo}"
61 if test x"$lo" = x"$obj" ; then
62     echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
63     exit 1
65 objbase="${obj##*/}"
66 __DOLTCOMPILE__EOF__
68 dnl Write out shared compilation code.
69     if test x$enable_shared = xyes; then
70         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
71 libobjdir="${obj%$objbase}.libs"
72 if test ! -d "$libobjdir" ; then
73     mkdir_out="$(mkdir "$libobjdir" 2>&1)"
74     mkdir_ret=$?
75     if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
76         echo "$mkdir_out" 1>&2
77         exit $mkdir_ret
78     fi
80 pic_object="$libobjdir/$objbase.o"
81 args@<:@$objarg@:>@="$pic_object"
82 __DOLTCOMPILE__EOF__
83     cat <<__DOLTCOMPILE__EOF__ >>doltcompile
84 "\${args@<:@@@:>@}" $pic_options -DPIC || exit \$?
85 __DOLTCOMPILE__EOF__
86     fi
88 dnl Write out static compilation code.
89 dnl Avoid duplicate compiler output if also building shared objects.
90     if test x$enable_static = xyes; then
91         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
92 non_pic_object="$obj.o"
93 args@<:@$objarg@:>@="$non_pic_object"
94 __DOLTCOMPILE__EOF__
95         if test x$enable_shared = xyes; then
96             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
97 "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
98 __DOLTCOMPILE__EOF__
99         else
100             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
101 "${args@<:@@@:>@}" || exit $?
102 __DOLTCOMPILE__EOF__
103         fi
104     fi
106 dnl Write out the code to write the .lo file.
107 dnl The second line of the .lo file must match "^# Generated by .*libtool"
108     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
110 echo "# $lo - a libtool object file"
111 echo "# Generated by doltcompile, not libtool"
112 __DOLTCOMPILE__EOF__
114     if test x$enable_shared = xyes; then
115         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
116 echo "pic_object='.libs/${objbase}.o'"
117 __DOLTCOMPILE__EOF__
118     else
119         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
120 echo pic_object=none
121 __DOLTCOMPILE__EOF__
122     fi
124     if test x$enable_static = xyes; then
125         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
126 echo "non_pic_object='${objbase}.o'"
127 __DOLTCOMPILE__EOF__
128     else
129         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
130 echo non_pic_object=none
131 __DOLTCOMPILE__EOF__
132     fi
134     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
135 } > "$lo"
136 __DOLTCOMPILE__EOF__
138 dnl Done writing out doltcompile; substitute it for libtool compilation.
139     chmod +x doltcompile
140     LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
141     LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
143 dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
144 dnl a target, so write out a libtool wrapper to handle that case.
145 dnl Note that doltlibtool does not handle inferred tags or option arguments
146 dnl without '=', because automake does not use them.
147     cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
148 #!$DOLT_BASH
149 __DOLTLIBTOOL__EOF__
150     cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
151 top_builddir_slash="${0%%doltlibtool}"
152 : ${top_builddir_slash:=./}
153 args=()
154 modeok=false
155 tagok=false
156 for arg in "$[]@"; do
157     case "$arg" in
158         --mode=compile) modeok=true ;;
159         --tag=CC|--tag=CXX) tagok=true ;;
160         *) args+=("$arg")
161     esac
162 done
163 if $modeok && $tagok ; then
164     . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
165 else
166     exec ${top_builddir_slash}libtool "$[]@"
168 __DOLTLIBTOOL__EOF__
170 dnl Done writing out doltlibtool; substitute it for libtool.
171     chmod +x doltlibtool
172     LIBTOOL='$(top_builddir)/doltlibtool'
174 AC_SUBST(LTCOMPILE)
175 AC_SUBST(LTCXXCOMPILE)
176 # end dolt
179 # ===========================================================================
180 #           http://autoconf-archive.cryp.to/ax_compare_version.html
181 # ===========================================================================
183 # SYNOPSIS
185 #   AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
187 # DESCRIPTION
189 #   This macro compares two version strings. Due to the various number of
190 #   minor-version numbers that can exist, and the fact that string
191 #   comparisons are not compatible with numeric comparisons, this is not
192 #   necessarily trivial to do in a autoconf script. This macro makes doing
193 #   these comparisons easy.
195 #   The six basic comparisons are available, as well as checking equality
196 #   limited to a certain number of minor-version levels.
198 #   The operator OP determines what type of comparison to do, and can be one
199 #   of:
201 #    eq  - equal (test A == B)
202 #    ne  - not equal (test A != B)
203 #    le  - less than or equal (test A <= B)
204 #    ge  - greater than or equal (test A >= B)
205 #    lt  - less than (test A < B)
206 #    gt  - greater than (test A > B)
208 #   Additionally, the eq and ne operator can have a number after it to limit
209 #   the test to that number of minor versions.
211 #    eq0 - equal up to the length of the shorter version
212 #    ne0 - not equal up to the length of the shorter version
213 #    eqN - equal up to N sub-version levels
214 #    neN - not equal up to N sub-version levels
216 #   When the condition is true, shell commands ACTION-IF-TRUE are run,
217 #   otherwise shell commands ACTION-IF-FALSE are run. The environment
218 #   variable 'ax_compare_version' is always set to either 'true' or 'false'
219 #   as well.
221 #   Examples:
223 #     AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8])
224 #     AX_COMPARE_VERSION([3.15],[lt],[3.15.8])
226 #   would both be true.
228 #     AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8])
229 #     AX_COMPARE_VERSION([3.15],[gt],[3.15.8])
231 #   would both be false.
233 #     AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8])
235 #   would be true because it is only comparing two minor versions.
237 #     AX_COMPARE_VERSION([3.15.7],[eq0],[3.15])
239 #   would be true because it is only comparing the lesser number of minor
240 #   versions of the two values.
242 #   Note: The characters that separate the version numbers do not matter. An
243 #   empty string is the same as version 0. OP is evaluated by autoconf, not
244 #   configure, so must be a string, not a variable.
246 #   The author would like to acknowledge Guido Draheim whose advice about
247 #   the m4_case and m4_ifvaln functions make this macro only include the
248 #   portions necessary to perform the specific comparison specified by the
249 #   OP argument in the final configure script.
251 # LAST MODIFICATION
253 #   2008-04-12
255 # COPYLEFT
257 #   Copyright (c) 2008 Tim Toolan <toolan@ele.uri.edu>
259 #   Copying and distribution of this file, with or without modification, are
260 #   permitted in any medium without royalty provided the copyright notice
261 #   and this notice are preserved.
263 dnl #########################################################################
264 AC_DEFUN([AX_COMPARE_VERSION], [
265   AC_PROG_AWK
267   # Used to indicate true or false condition
268   ax_compare_version=false
270   # Convert the two version strings to be compared into a format that
271   # allows a simple string comparison.  The end result is that a version
272   # string of the form 1.12.5-r617 will be converted to the form
273   # 0001001200050617.  In other words, each number is zero padded to four
274   # digits, and non digits are removed.
275   AS_VAR_PUSHDEF([A],[ax_compare_version_A])
276   A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
277                      -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
278                      -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
279                      -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
280                      -e 's/[[^0-9]]//g'`
282   AS_VAR_PUSHDEF([B],[ax_compare_version_B])
283   B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
284                      -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
285                      -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
286                      -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
287                      -e 's/[[^0-9]]//g'`
289   dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
290   dnl # then the first line is used to determine if the condition is true.
291   dnl # The sed right after the echo is to remove any indented white space.
292   m4_case(m4_tolower($2),
293   [lt],[
294     ax_compare_version=`echo "x$A
295 x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
296   ],
297   [gt],[
298     ax_compare_version=`echo "x$A
299 x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
300   ],
301   [le],[
302     ax_compare_version=`echo "x$A
303 x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
304   ],
305   [ge],[
306     ax_compare_version=`echo "x$A
307 x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
308   ],[
309     dnl Split the operator from the subversion count if present.
310     m4_bmatch(m4_substr($2,2),
311     [0],[
312       # A count of zero means use the length of the shorter version.
313       # Determine the number of characters in A and B.
314       ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'`
315       ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'`
317       # Set A to no more than B's length and B to no more than A's length.
318       A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
319       B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
320     ],
321     [[0-9]+],[
322       # A count greater than zero means use only that many subversions
323       A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
324       B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
325     ],
326     [.+],[
327       AC_WARNING(
328         [illegal OP numeric parameter: $2])
329     ],[])
331     # Pad zeros at end of numbers to make same length.
332     ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
333     B="$B`echo $A | sed 's/./0/g'`"
334     A="$ax_compare_version_tmp_A"
336     # Check for equality or inequality as necessary.
337     m4_case(m4_tolower(m4_substr($2,0,2)),
338     [eq],[
339       test "x$A" = "x$B" && ax_compare_version=true
340     ],
341     [ne],[
342       test "x$A" != "x$B" && ax_compare_version=true
343     ],[
344       AC_WARNING([illegal OP parameter: $2])
345     ])
346   ])
348   AS_VAR_POPDEF([A])dnl
349   AS_VAR_POPDEF([B])dnl
351   dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
352   if test "$ax_compare_version" = "true" ; then
353     m4_ifvaln([$4],[$4],[:])dnl
354     m4_ifvaln([$5],[else $5])dnl
355   fi
356 ]) dnl AX_COMPARE_VERSION