dolt.m4 5.4 KB

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