| 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. |
|---|
| 10 | |
|---|
| 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 |
|---|
| 20 | fi |
|---|
| 21 | if test x$GCC != xyes; then |
|---|
| 22 | dolt_supported=no |
|---|
| 23 | fi |
|---|
| 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 | ;; |
|---|
| 32 | *mingw32*) |
|---|
| 33 | pic_options='-DDLL_EXPORT' |
|---|
| 34 | ;; |
|---|
| 35 | *) |
|---|
| 36 | dolt_supported=no |
|---|
| 37 | ;; |
|---|
| 38 | esac |
|---|
| 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)' |
|---|
| 43 | else |
|---|
| 44 | AC_MSG_RESULT([yes, replacing libtool]) |
|---|
| 45 | |
|---|
| 46 | dnl Start writing out doltcompile. |
|---|
| 47 | cat <<__DOLTCOMPILE__EOF__ >doltcompile |
|---|
| 48 | #!$DOLT_BASH |
|---|
| 49 | __DOLTCOMPILE__EOF__ |
|---|
| 50 | cat <<'__DOLTCOMPILE__EOF__' >>doltcompile |
|---|
| 51 | args=("$[]@") |
|---|
| 52 | for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do |
|---|
| 53 | if test x"${args@<:@$arg@:>@}" = x-o ; then |
|---|
| 54 | objarg=$((arg+1)) |
|---|
| 55 | break |
|---|
| 56 | fi |
|---|
| 57 | done |
|---|
| 58 | if test x$objarg = x ; then |
|---|
| 59 | echo 'Error: no -o on compiler command line' 1>&2 |
|---|
| 60 | exit 1 |
|---|
| 61 | fi |
|---|
| 62 | lo="${args@<:@$objarg@:>@}" |
|---|
| 63 | obj="${lo%.lo}" |
|---|
| 64 | if test x"$lo" = x"$obj" ; then |
|---|
| 65 | echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2 |
|---|
| 66 | exit 1 |
|---|
| 67 | fi |
|---|
| 68 | objbase="${obj##*/}" |
|---|
| 69 | __DOLTCOMPILE__EOF__ |
|---|
| 70 | |
|---|
| 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)" |
|---|
| 77 | mkdir_ret=$? |
|---|
| 78 | if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then |
|---|
| 79 | echo "$mkdir_out" 1>&2 |
|---|
| 80 | exit $mkdir_ret |
|---|
| 81 | fi |
|---|
| 82 | fi |
|---|
| 83 | pic_object="$libobjdir/$objbase.o" |
|---|
| 84 | args@<:@$objarg@:>@="$pic_object" |
|---|
| 85 | __DOLTCOMPILE__EOF__ |
|---|
| 86 | cat <<__DOLTCOMPILE__EOF__ >>doltcompile |
|---|
| 87 | "\${args@<:@@@:>@}" $pic_options -DPIC || exit \$? |
|---|
| 88 | __DOLTCOMPILE__EOF__ |
|---|
| 89 | fi |
|---|
| 90 | |
|---|
| 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" |
|---|
| 97 | __DOLTCOMPILE__EOF__ |
|---|
| 98 | if test x$enable_shared = xyes; then |
|---|
| 99 | cat <<'__DOLTCOMPILE__EOF__' >>doltcompile |
|---|
| 100 | "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $? |
|---|
| 101 | __DOLTCOMPILE__EOF__ |
|---|
| 102 | else |
|---|
| 103 | cat <<'__DOLTCOMPILE__EOF__' >>doltcompile |
|---|
| 104 | "${args@<:@@@:>@}" || exit $? |
|---|
| 105 | __DOLTCOMPILE__EOF__ |
|---|
| 106 | fi |
|---|
| 107 | fi |
|---|
| 108 | |
|---|
| 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 |
|---|
| 112 | { |
|---|
| 113 | echo "# $lo - a libtool object file" |
|---|
| 114 | echo "# Generated by doltcompile, not libtool" |
|---|
| 115 | __DOLTCOMPILE__EOF__ |
|---|
| 116 | |
|---|
| 117 | if test x$enable_shared = xyes; then |
|---|
| 118 | cat <<'__DOLTCOMPILE__EOF__' >>doltcompile |
|---|
| 119 | echo "pic_object='.libs/${objbase}.o'" |
|---|
| 120 | __DOLTCOMPILE__EOF__ |
|---|
| 121 | else |
|---|
| 122 | cat <<'__DOLTCOMPILE__EOF__' >>doltcompile |
|---|
| 123 | echo pic_object=none |
|---|
| 124 | __DOLTCOMPILE__EOF__ |
|---|
| 125 | fi |
|---|
| 126 | |
|---|
| 127 | if test x$enable_static = xyes; then |
|---|
| 128 | cat <<'__DOLTCOMPILE__EOF__' >>doltcompile |
|---|
| 129 | echo "non_pic_object='${objbase}.o'" |
|---|
| 130 | __DOLTCOMPILE__EOF__ |
|---|
| 131 | else |
|---|
| 132 | cat <<'__DOLTCOMPILE__EOF__' >>doltcompile |
|---|
| 133 | echo non_pic_object=none |
|---|
| 134 | __DOLTCOMPILE__EOF__ |
|---|
| 135 | fi |
|---|
| 136 | |
|---|
| 137 | cat <<'__DOLTCOMPILE__EOF__' >>doltcompile |
|---|
| 138 | } > "$lo" |
|---|
| 139 | __DOLTCOMPILE__EOF__ |
|---|
| 140 | |
|---|
| 141 | dnl Done writing out doltcompile; substitute it for libtool compilation. |
|---|
| 142 | chmod +x doltcompile |
|---|
| 143 | LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)' |
|---|
| 144 | LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)' |
|---|
| 145 | |
|---|
| 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 |
|---|
| 151 | #!$DOLT_BASH |
|---|
| 152 | __DOLTLIBTOOL__EOF__ |
|---|
| 153 | cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool |
|---|
| 154 | top_builddir_slash="${0%%doltlibtool}" |
|---|
| 155 | : ${top_builddir_slash:=./} |
|---|
| 156 | args=() |
|---|
| 157 | modeok=false |
|---|
| 158 | tagok=false |
|---|
| 159 | for arg in "$[]@"; do |
|---|
| 160 | case "$arg" in |
|---|
| 161 | --mode=compile) modeok=true ;; |
|---|
| 162 | --tag=CC|--tag=CXX) tagok=true ;; |
|---|
| 163 | *) args@<:@${#args[@]}@:>@="$arg" ;; |
|---|
| 164 | esac |
|---|
| 165 | done |
|---|
| 166 | if $modeok && $tagok ; then |
|---|
| 167 | . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}" |
|---|
| 168 | else |
|---|
| 169 | exec ${top_builddir_slash}libtool "$[]@" |
|---|
| 170 | fi |
|---|
| 171 | __DOLTLIBTOOL__EOF__ |
|---|
| 172 | |
|---|
| 173 | dnl Done writing out doltlibtool; substitute it for libtool. |
|---|
| 174 | chmod +x doltlibtool |
|---|
| 175 | LIBTOOL='$(top_builddir)/doltlibtool' |
|---|
| 176 | fi |
|---|
| 177 | AC_SUBST(LTCOMPILE) |
|---|
| 178 | AC_SUBST(LTCXXCOMPILE) |
|---|
| 179 | # end dolt |
|---|
| 180 | ]) |
|---|
| 181 | |
|---|
| 182 | # =========================================================================== |
|---|
| 183 | # http://autoconf-archive.cryp.to/ax_compare_version.html |
|---|
| 184 | # =========================================================================== |
|---|
| 185 | # |
|---|
| 186 | # SYNOPSIS |
|---|
| 187 | # |
|---|
| 188 | # AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) |
|---|
| 189 | # |
|---|
| 190 | # DESCRIPTION |
|---|
| 191 | # |
|---|
| 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. |
|---|
| 197 | # |
|---|
| 198 | # The six basic comparisons are available, as well as checking equality |
|---|
| 199 | # limited to a certain number of minor-version levels. |
|---|
| 200 | # |
|---|
| 201 | # The operator OP determines what type of comparison to do, and can be one |
|---|
| 202 | # of: |
|---|
| 203 | # |
|---|
| 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) |
|---|
| 210 | # |
|---|
| 211 | # Additionally, the eq and ne operator can have a number after it to limit |
|---|
| 212 | # the test to that number of minor versions. |
|---|
| 213 | # |
|---|
| 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 |
|---|
| 218 | # |
|---|
| 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' |
|---|
| 222 | # as well. |
|---|
| 223 | # |
|---|
| 224 | # Examples: |
|---|
| 225 | # |
|---|
| 226 | # AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) |
|---|
| 227 | # AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) |
|---|
| 228 | # |
|---|
| 229 | # would both be true. |
|---|
| 230 | # |
|---|
| 231 | # AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) |
|---|
| 232 | # AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) |
|---|
| 233 | # |
|---|
| 234 | # would both be false. |
|---|
| 235 | # |
|---|
| 236 | # AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) |
|---|
| 237 | # |
|---|
| 238 | # would be true because it is only comparing two minor versions. |
|---|
| 239 | # |
|---|
| 240 | # AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) |
|---|
| 241 | # |
|---|
| 242 | # would be true because it is only comparing the lesser number of minor |
|---|
| 243 | # versions of the two values. |
|---|
| 244 | # |
|---|
| 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. |
|---|
| 248 | # |
|---|
| 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. |
|---|
| 253 | # |
|---|
| 254 | # LAST MODIFICATION |
|---|
| 255 | # |
|---|
| 256 | # 2008-04-12 |
|---|
| 257 | # |
|---|
| 258 | # COPYLEFT |
|---|
| 259 | # |
|---|
| 260 | # Copyright (c) 2008 Tim Toolan <toolan@ele.uri.edu> |
|---|
| 261 | # |
|---|
| 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. |
|---|
| 265 | |
|---|
| 266 | dnl ######################################################################### |
|---|
| 267 | AC_DEFUN([AX_COMPARE_VERSION], [ |
|---|
| 268 | AC_PROG_AWK |
|---|
| 269 | |
|---|
| 270 | # Used to indicate true or false condition |
|---|
| 271 | ax_compare_version=false |
|---|
| 272 | |
|---|
| 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' \ |
|---|
| 283 | -e 's/[[^0-9]]//g'` |
|---|
| 284 | |
|---|
| 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' \ |
|---|
| 290 | -e 's/[[^0-9]]//g'` |
|---|
| 291 | |
|---|
| 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), |
|---|
| 296 | [lt],[ |
|---|
| 297 | ax_compare_version=`echo "x$A |
|---|
| 298 | x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` |
|---|
| 299 | ], |
|---|
| 300 | [gt],[ |
|---|
| 301 | ax_compare_version=`echo "x$A |
|---|
| 302 | x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` |
|---|
| 303 | ], |
|---|
| 304 | [le],[ |
|---|
| 305 | ax_compare_version=`echo "x$A |
|---|
| 306 | x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` |
|---|
| 307 | ], |
|---|
| 308 | [ge],[ |
|---|
| 309 | ax_compare_version=`echo "x$A |
|---|
| 310 | x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` |
|---|
| 311 | ],[ |
|---|
| 312 | dnl Split the operator from the subversion count if present. |
|---|
| 313 | m4_bmatch(m4_substr($2,2), |
|---|
| 314 | [0],[ |
|---|
| 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)}'` |
|---|
| 319 | |
|---|
| 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/"` |
|---|
| 323 | ], |
|---|
| 324 | [[0-9]+],[ |
|---|
| 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/"` |
|---|
| 328 | ], |
|---|
| 329 | [.+],[ |
|---|
| 330 | AC_WARNING( |
|---|
| 331 | [illegal OP numeric parameter: $2]) |
|---|
| 332 | ],[]) |
|---|
| 333 | |
|---|
| 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" |
|---|
| 338 | |
|---|
| 339 | # Check for equality or inequality as necessary. |
|---|
| 340 | m4_case(m4_tolower(m4_substr($2,0,2)), |
|---|
| 341 | [eq],[ |
|---|
| 342 | test "x$A" = "x$B" && ax_compare_version=true |
|---|
| 343 | ], |
|---|
| 344 | [ne],[ |
|---|
| 345 | test "x$A" != "x$B" && ax_compare_version=true |
|---|
| 346 | ],[ |
|---|
| 347 | AC_WARNING([illegal OP parameter: $2]) |
|---|
| 348 | ]) |
|---|
| 349 | ]) |
|---|
| 350 | |
|---|
| 351 | AS_VAR_POPDEF([A])dnl |
|---|
| 352 | AS_VAR_POPDEF([B])dnl |
|---|
| 353 | |
|---|
| 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 |
|---|
| 358 | fi |
|---|
| 359 | ]) dnl AX_COMPARE_VERSION |
|---|