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.
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.
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])
18 if test x$DOLT_BASH = x; then
21 if test x$GCC != xyes; then
25 i?86-*-linux*|x86_64-*-linux*|powerpc-*-linux* \
26 |amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*)
30 pic_options='-fno-common'
33 pic_options='-DDLL_EXPORT'
39 if test x$dolt_supported = xno ; then
40 AC_MSG_RESULT([no, falling back to libtool])
41 LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
42 LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
44 AC_MSG_RESULT([yes, replacing libtool])
46 dnl Start writing out doltcompile.
47 cat <<__DOLTCOMPILE__EOF__ >doltcompile
50 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
52 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
53 if test x"${args@<:@$arg@:>@}" = x-o ; then
58 if test x$objarg = x ; then
59 echo 'Error: no -o on compiler command line' 1>&2
62 lo="${args@<:@$objarg@:>@}"
64 if test x"$lo" = x"$obj" ; then
65 echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
71 dnl Write out shared compilation code.
72 if test x$enable_shared = xyes; then
73 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
74 libobjdir="${obj%$objbase}.libs"
75 if test ! -d "$libobjdir" ; then
76 mkdir_out="$(mkdir "$libobjdir" 2>&1)"
78 if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
79 echo "$mkdir_out" 1>&2
83 pic_object="$libobjdir/$objbase.o"
84 args@<:@$objarg@:>@="$pic_object"
86 cat <<__DOLTCOMPILE__EOF__ >>doltcompile
87 "\${args@<:@@@:>@}" $pic_options -DPIC || exit \$?
91 dnl Write out static compilation code.
92 dnl Avoid duplicate compiler output if also building shared objects.
93 if test x$enable_static = xyes; then
94 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
95 non_pic_object="$obj.o"
96 args@<:@$objarg@:>@="$non_pic_object"
98 if test x$enable_shared = xyes; then
99 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
100 "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
103 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
104 "${args@<:@@@:>@}" || exit $?
109 dnl Write out the code to write the .lo file.
110 dnl The second line of the .lo file must match "^# Generated by .*libtool"
111 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
113 echo "# $lo - a libtool object file"
114 echo "# Generated by doltcompile, not libtool"
117 if test x$enable_shared = xyes; then
118 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
119 echo "pic_object='.libs/${objbase}.o'"
122 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
127 if test x$enable_static = xyes; then
128 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
129 echo "non_pic_object='${objbase}.o'"
132 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
133 echo non_pic_object=none
137 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
141 dnl Done writing out doltcompile; substitute it for libtool compilation.
143 LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
144 LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
146 dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
147 dnl a target, so write out a libtool wrapper to handle that case.
148 dnl Note that doltlibtool does not handle inferred tags or option arguments
149 dnl without '=', because automake does not use them.
150 cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
153 cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
154 top_builddir_slash="${0%%doltlibtool}"
155 : ${top_builddir_slash:=./}
159 for arg in "$[]@"; do
161 --mode=compile) modeok=true ;;
162 --tag=CC|--tag=CXX) tagok=true ;;
163 *) args@<:@${#args[@]}@:>@="$arg" ;;
166 if $modeok && $tagok ; then
167 . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
169 exec ${top_builddir_slash}libtool "$[]@"
173 dnl Done writing out doltlibtool; substitute it for libtool.
175 LIBTOOL='$(top_builddir)/doltlibtool'
178 AC_SUBST(LTCXXCOMPILE)
182 # ===========================================================================
183 # http://autoconf-archive.cryp.to/ax_compare_version.html
184 # ===========================================================================
188 # AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
192 # This macro compares two version strings. Due to the various number of
193 # minor-version numbers that can exist, and the fact that string
194 # comparisons are not compatible with numeric comparisons, this is not
195 # necessarily trivial to do in a autoconf script. This macro makes doing
196 # these comparisons easy.
198 # The six basic comparisons are available, as well as checking equality
199 # limited to a certain number of minor-version levels.
201 # The operator OP determines what type of comparison to do, and can be one
204 # eq - equal (test A == B)
205 # ne - not equal (test A != B)
206 # le - less than or equal (test A <= B)
207 # ge - greater than or equal (test A >= B)
208 # lt - less than (test A < B)
209 # gt - greater than (test A > B)
211 # Additionally, the eq and ne operator can have a number after it to limit
212 # the test to that number of minor versions.
214 # eq0 - equal up to the length of the shorter version
215 # ne0 - not equal up to the length of the shorter version
216 # eqN - equal up to N sub-version levels
217 # neN - not equal up to N sub-version levels
219 # When the condition is true, shell commands ACTION-IF-TRUE are run,
220 # otherwise shell commands ACTION-IF-FALSE are run. The environment
221 # variable 'ax_compare_version' is always set to either 'true' or 'false'
226 # AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8])
227 # AX_COMPARE_VERSION([3.15],[lt],[3.15.8])
229 # would both be true.
231 # AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8])
232 # AX_COMPARE_VERSION([3.15],[gt],[3.15.8])
234 # would both be false.
236 # AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8])
238 # would be true because it is only comparing two minor versions.
240 # AX_COMPARE_VERSION([3.15.7],[eq0],[3.15])
242 # would be true because it is only comparing the lesser number of minor
243 # versions of the two values.
245 # Note: The characters that separate the version numbers do not matter. An
246 # empty string is the same as version 0. OP is evaluated by autoconf, not
247 # configure, so must be a string, not a variable.
249 # The author would like to acknowledge Guido Draheim whose advice about
250 # the m4_case and m4_ifvaln functions make this macro only include the
251 # portions necessary to perform the specific comparison specified by the
252 # OP argument in the final configure script.
260 # Copyright (c) 2008 Tim Toolan <toolan@ele.uri.edu>
262 # Copying and distribution of this file, with or without modification, are
263 # permitted in any medium without royalty provided the copyright notice
264 # and this notice are preserved.
266 dnl #########################################################################
267 AC_DEFUN([AX_COMPARE_VERSION], [
270 # Used to indicate true or false condition
271 ax_compare_version=false
273 # Convert the two version strings to be compared into a format that
274 # allows a simple string comparison. The end result is that a version
275 # string of the form 1.12.5-r617 will be converted to the form
276 # 0001001200050617. In other words, each number is zero padded to four
277 # digits, and non digits are removed.
278 AS_VAR_PUSHDEF([A],[ax_compare_version_A])
279 A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
280 -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
281 -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
282 -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
285 AS_VAR_PUSHDEF([B],[ax_compare_version_B])
286 B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
287 -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
288 -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
289 -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
292 dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
293 dnl # then the first line is used to determine if the condition is true.
294 dnl # The sed right after the echo is to remove any indented white space.
295 m4_case(m4_tolower($2),
297 ax_compare_version=`echo "x$A
298 x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
301 ax_compare_version=`echo "x$A
302 x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
305 ax_compare_version=`echo "x$A
306 x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
309 ax_compare_version=`echo "x$A
310 x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
312 dnl Split the operator from the subversion count if present.
313 m4_bmatch(m4_substr($2,2),
315 # A count of zero means use the length of the shorter version.
316 # Determine the number of characters in A and B.
317 ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'`
318 ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'`
320 # Set A to no more than B's length and B to no more than A's length.
321 A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
322 B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
325 # A count greater than zero means use only that many subversions
326 A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
327 B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
331 [illegal OP numeric parameter: $2])
334 # Pad zeros at end of numbers to make same length.
335 ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
336 B="$B`echo $A | sed 's/./0/g'`"
337 A="$ax_compare_version_tmp_A"
339 # Check for equality or inequality as necessary.
340 m4_case(m4_tolower(m4_substr($2,0,2)),
342 test "x$A" = "x$B" && ax_compare_version=true
345 test "x$A" != "x$B" && ax_compare_version=true
347 AC_WARNING([illegal OP parameter: $2])
351 AS_VAR_POPDEF([A])dnl
352 AS_VAR_POPDEF([B])dnl
354 dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
355 if test "$ax_compare_version" = "true" ; then
356 m4_ifvaln([$4],[$4],[:])dnl
357 m4_ifvaln([$5],[else $5])dnl
359 ]) dnl AX_COMPARE_VERSION