acinclude.m4 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. dnl dolt, a replacement for libtool
  2. dnl Copyright © 2007-2008 Josh Triplett <[email protected]>
  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. AC_DEFUN([DOLT], [
  11. AC_REQUIRE([AC_CANONICAL_HOST])
  12. # dolt, a replacement for libtool
  13. # Josh Triplett <[email protected]>
  14. AC_PATH_PROG(DOLT_BASH, bash)
  15. AC_MSG_CHECKING([if dolt supports this host])
  16. dolt_supported=yes
  17. if test x$DOLT_BASH = x; then
  18. dolt_supported=no
  19. fi
  20. if test x$GCC != xyes; then
  21. dolt_supported=no
  22. fi
  23. case $host in
  24. i?86-*-linux*|x86_64-*-linux*|powerpc-*-linux* \
  25. |amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*)
  26. pic_options='-fPIC'
  27. ;;
  28. i?86-apple-darwin*)
  29. pic_options='-fno-common'
  30. ;;
  31. *)
  32. dolt_supported=no
  33. ;;
  34. esac
  35. if test x$dolt_supported = xno ; then
  36. AC_MSG_RESULT([no, falling back to libtool])
  37. LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
  38. LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
  39. else
  40. AC_MSG_RESULT([yes, replacing libtool])
  41. dnl Start writing out doltcompile.
  42. cat <<__DOLTCOMPILE__EOF__ >doltcompile
  43. #!$DOLT_BASH
  44. __DOLTCOMPILE__EOF__
  45. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  46. args=("$[]@")
  47. for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
  48. if test x"${args@<:@$arg@:>@}" = x-o ; then
  49. objarg=$((arg+1))
  50. break
  51. fi
  52. done
  53. if test x$objarg = x ; then
  54. echo 'Error: no -o on compiler command line' 1>&2
  55. exit 1
  56. fi
  57. lo="${args@<:@$objarg@:>@}"
  58. obj="${lo%.lo}"
  59. if test x"$lo" = x"$obj" ; then
  60. echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
  61. exit 1
  62. fi
  63. objbase="${obj##*/}"
  64. __DOLTCOMPILE__EOF__
  65. dnl Write out shared compilation code.
  66. if test x$enable_shared = xyes; then
  67. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  68. libobjdir="${obj%$objbase}.libs"
  69. if test ! -d "$libobjdir" ; then
  70. mkdir_out="$(mkdir "$libobjdir" 2>&1)"
  71. mkdir_ret=$?
  72. if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
  73. echo "$mkdir_out" 1>&2
  74. exit $mkdir_ret
  75. fi
  76. fi
  77. pic_object="$libobjdir/$objbase.o"
  78. args@<:@$objarg@:>@="$pic_object"
  79. __DOLTCOMPILE__EOF__
  80. cat <<__DOLTCOMPILE__EOF__ >>doltcompile
  81. "\${args@<:@@@:>@}" $pic_options -DPIC || exit \$?
  82. __DOLTCOMPILE__EOF__
  83. fi
  84. dnl Write out static compilation code.
  85. dnl Avoid duplicate compiler output if also building shared objects.
  86. if test x$enable_static = xyes; then
  87. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  88. non_pic_object="$obj.o"
  89. args@<:@$objarg@:>@="$non_pic_object"
  90. __DOLTCOMPILE__EOF__
  91. if test x$enable_shared = xyes; then
  92. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  93. "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
  94. __DOLTCOMPILE__EOF__
  95. else
  96. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  97. "${args@<:@@@:>@}" || exit $?
  98. __DOLTCOMPILE__EOF__
  99. fi
  100. fi
  101. dnl Write out the code to write the .lo file.
  102. dnl The second line of the .lo file must match "^# Generated by .*libtool"
  103. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  104. {
  105. echo "# $lo - a libtool object file"
  106. echo "# Generated by doltcompile, not libtool"
  107. __DOLTCOMPILE__EOF__
  108. if test x$enable_shared = xyes; then
  109. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  110. echo "pic_object='.libs/${objbase}.o'"
  111. __DOLTCOMPILE__EOF__
  112. else
  113. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  114. echo pic_object=none
  115. __DOLTCOMPILE__EOF__
  116. fi
  117. if test x$enable_static = xyes; then
  118. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  119. echo "non_pic_object='${objbase}.o'"
  120. __DOLTCOMPILE__EOF__
  121. else
  122. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  123. echo non_pic_object=none
  124. __DOLTCOMPILE__EOF__
  125. fi
  126. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  127. } > "$lo"
  128. __DOLTCOMPILE__EOF__
  129. dnl Done writing out doltcompile; substitute it for libtool compilation.
  130. chmod +x doltcompile
  131. LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
  132. LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
  133. dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
  134. dnl a target, so write out a libtool wrapper to handle that case.
  135. dnl Note that doltlibtool does not handle inferred tags or option arguments
  136. dnl without '=', because automake does not use them.
  137. cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
  138. #!$DOLT_BASH
  139. __DOLTLIBTOOL__EOF__
  140. cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
  141. top_builddir_slash="${0%%doltlibtool}"
  142. : ${top_builddir_slash:=./}
  143. args=()
  144. modeok=false
  145. tagok=false
  146. for arg in "$[]@"; do
  147. case "$arg" in
  148. --mode=compile) modeok=true ;;
  149. --tag=CC|--tag=CXX) tagok=true ;;
  150. --quiet) ;;
  151. *) args@<:@${#args[@]}@:>@="$arg" ;;
  152. esac
  153. done
  154. if $modeok && $tagok ; then
  155. . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
  156. else
  157. exec ${top_builddir_slash}libtool "$[]@"
  158. fi
  159. __DOLTLIBTOOL__EOF__
  160. dnl Done writing out doltlibtool; substitute it for libtool.
  161. chmod +x doltlibtool
  162. LIBTOOL='$(top_builddir)/doltlibtool'
  163. fi
  164. AC_SUBST(LTCOMPILE)
  165. AC_SUBST(LTCXXCOMPILE)
  166. # end dolt
  167. ])