dolt.m4 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. dnl dolt, a replacement for libtool
  2. dnl Copyright © 2007-2010 Josh Triplett <josh@joshtriplett.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. AC_DEFUN([DOLT], [
  11. AC_REQUIRE([AC_CANONICAL_HOST])
  12. # dolt, a replacement for libtool
  13. # Josh Triplett <josh@freedesktop.org>
  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. *-*-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. *mingw*)
  32. pic_options=''
  33. ;;
  34. *)
  35. dolt_supported=no
  36. ;;
  37. esac
  38. if test x$dolt_supported = xno ; then
  39. AC_MSG_RESULT([no, falling back to libtool])
  40. LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
  41. LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
  42. else
  43. AC_MSG_RESULT([yes, replacing libtool])
  44. dnl Start writing out doltcompile.
  45. cat <<__DOLTCOMPILE__EOF__ >doltcompile
  46. #!$DOLT_BASH
  47. __DOLTCOMPILE__EOF__
  48. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  49. args=("$[]@")
  50. for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
  51. if test x"${args@<:@$arg@:>@}" = x-o ; then
  52. objarg=$((arg+1))
  53. break
  54. fi
  55. done
  56. if test x$objarg = x ; then
  57. echo 'Error: no -o on compiler command line' 1>&2
  58. exit 1
  59. fi
  60. lo="${args@<:@$objarg@:>@}"
  61. obj="${lo%.lo}"
  62. if test x"$lo" = x"$obj" ; then
  63. echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
  64. exit 1
  65. fi
  66. objbase="${obj##*/}"
  67. __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
  79. 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
  87. dnl Write out static compilation code.
  88. dnl Avoid duplicate compiler output if also building shared objects.
  89. if test x$enable_static = xyes; then
  90. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  91. non_pic_object="$obj.o"
  92. args@<:@$objarg@:>@="$non_pic_object"
  93. __DOLTCOMPILE__EOF__
  94. if test x$enable_shared = xyes; then
  95. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  96. "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
  97. __DOLTCOMPILE__EOF__
  98. else
  99. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  100. "${args@<:@@@:>@}" || exit $?
  101. __DOLTCOMPILE__EOF__
  102. fi
  103. fi
  104. dnl Write out the code to write the .lo file.
  105. dnl The second line of the .lo file must match "^# Generated by .*libtool"
  106. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  107. {
  108. echo "# $lo - a libtool object file"
  109. echo "# Generated by doltcompile, not libtool"
  110. __DOLTCOMPILE__EOF__
  111. if test x$enable_shared = xyes; then
  112. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  113. echo "pic_object='.libs/${objbase}.o'"
  114. __DOLTCOMPILE__EOF__
  115. else
  116. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  117. echo pic_object=none
  118. __DOLTCOMPILE__EOF__
  119. fi
  120. if test x$enable_static = xyes; then
  121. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  122. echo "non_pic_object='${objbase}.o'"
  123. __DOLTCOMPILE__EOF__
  124. else
  125. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  126. echo non_pic_object=none
  127. __DOLTCOMPILE__EOF__
  128. fi
  129. cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
  130. } > "$lo"
  131. __DOLTCOMPILE__EOF__
  132. dnl Done writing out doltcompile; substitute it for libtool compilation.
  133. chmod +x doltcompile
  134. LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
  135. LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
  136. dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
  137. dnl a target, so write out a libtool wrapper to handle that case.
  138. dnl Note that doltlibtool does not handle inferred tags or option arguments
  139. dnl without '=', because automake does not use them.
  140. cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
  141. #!$DOLT_BASH
  142. __DOLTLIBTOOL__EOF__
  143. cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
  144. top_builddir_slash="${0%%doltlibtool}"
  145. : ${top_builddir_slash:=./}
  146. args=()
  147. modeok=false
  148. tagok=false
  149. for arg in "$[]@"; do
  150. case "$arg" in
  151. --mode=compile) modeok=true ;;
  152. --tag=CC|--tag=CXX) tagok=true ;;
  153. --silent|--quiet) ;;
  154. *) args@<:@${#args[@]}@:>@="$arg" ;;
  155. esac
  156. done
  157. if $modeok && $tagok ; then
  158. . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
  159. else
  160. exec ${top_builddir_slash}libtool "$[]@"
  161. fi
  162. __DOLTLIBTOOL__EOF__
  163. dnl Done writing out doltlibtool; substitute it for libtool.
  164. chmod +x doltlibtool
  165. LIBTOOL='$(top_builddir)/doltlibtool'
  166. fi
  167. AC_SUBST(LTCOMPILE)
  168. AC_SUBST(LTCXXCOMPILE)
  169. # end dolt
  170. ])