tools.m4 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # tl_CHECK_TOOL_PREFIX will work _BEFORE_ AC_CANONICAL_HOST, etc., has been
  2. # called. It should be called again after these have been called.
  3. #
  4. # Basically we want to check if the host alias specified by the user is
  5. # different from the build alias. The rules work like this:-
  6. #
  7. # If host is not specified, it defaults to NONOPT
  8. # If build is not specified, it defaults to NONOPT
  9. # If nonopt is not specified, we guess all other values
  10. dnl Replace AC_CHECK_TOOL_PREFIX
  11. undefine([AC_CHECK_TOOL_PREFIX])
  12. define([AC_CHECK_TOOL_PREFIX], [tl_CHECK_TOOL_PREFIX])
  13. AC_DEFUN(tl_CHECK_TOOL_PREFIX,
  14. [AC_PROVIDE([AC_CHECK_TOOL_PREFIX])
  15. AC_BEFORE([AC_CANONICAL_HOST])
  16. AC_BEFORE([AC_CANONICAL_BUILD])
  17. dnl Quick check
  18. if test "$host_alias" = ""; then
  19. if test $host = NONE; then
  20. thost=$nonopt
  21. else
  22. thost=$host
  23. fi
  24. if test $thost != $build -a $thost != NONE; then
  25. ac_tool_prefix=${thost}-
  26. ac_tool_dir=${thost}
  27. else
  28. ac_tool_prefix=
  29. ac_tool_dir=
  30. fi
  31. else
  32. if test $host != $build; then
  33. ac_tool_prefix=${host_alias}-
  34. ac_tool_dir=${host_alias}
  35. else
  36. ac_tool_prefix=
  37. ac_tool_dir=
  38. fi
  39. fi
  40. ])
  41. dnl replacement for AC_CHECK_TOOL
  42. undefine([AC_CHECK_TOOL])
  43. define([AC_CHECK_TOOL], [tl_CHECK_TOOL($1, $2, $3, $4)])
  44. dnl tl_CHECK_TOOL - AC_CHECK_TOOL, with a couple of extra checks
  45. dnl tl_CHECK_TOOL(VARIABLE, PROG-TO-CHECK-FOR[, VALUE-IF-NOT-FOUND [, PATH
  46. dnl [, REJECT]])
  47. AC_DEFUN(tl_CHECK_TOOL,
  48. [AC_REQUIRE([AC_CHECK_TOOL_PREFIX])
  49. AC_CHECK_PROG($1, ${ac_tool_prefix}$2, ${ac_tool_prefix}$2,
  50. ifelse([$3], , [$2], ), $4, $5)
  51. if test -z "$ac_cv_prog_$1_dir";then ac_cv_prog_$1_dir=""; fi
  52. if test "$ac_tool_dir" != ""; then
  53. if test -z "$ac_cv_prog_$1" -a "$5" != "/usr/${ac_tool_dir}/bin/$2" -a \
  54. "$5" != "/usr/local/${ac_tool_dir}/bin/$2"; then
  55. if test -f /usr/${ac_tool_dir}/bin/$2; then $1="/usr/${ac_tool_dir}/bin/$2"; ac_cv_prog_$1_dir=/usr/${ac_tool_dir}
  56. elif test -f /usr/local/${ac_tool_dir}/bin/$2; then $1="/usr/local/${ac_tool_dir}/bin/$2"; ac_cv_prog_$1_dir=/usr/local/${ac_tool_dir}
  57. fi
  58. fi
  59. fi
  60. ifelse([$3], , , [
  61. if test -z "$ac_cv_prog_$1"; then
  62. if test -n "$ac_tool_prefix"; then
  63. AC_CHECK_PROG($1, $2, $2, $3, $4, $5)
  64. else
  65. $1="$3"
  66. fi
  67. fi])
  68. ])
  69. dnl tl_CHECK_TOOLS -
  70. dnl do a tl_CHECK_TOOL for multiple tools (like AC_CHECK_PROGS)
  71. dnl tl_CHECK_TOOLS(VARIABLE, PROGS-TO-CHECK-FOR [, VALUE-IF-NOT-FOUND
  72. dnl [, PATH]])
  73. AC_DEFUN(tl_CHECK_TOOLS,
  74. [for ac_tool in $2
  75. do
  76. tl_CHECK_TOOL($1, [$]ac_tool, [$]ac_tool, , $4)
  77. test -n "[$]$1" && break
  78. done
  79. ifelse([$3], , , [test -n "[$]$1" || $1="$3"
  80. ])])
  81. dnl replace AC_PROG_CC and AC_PROG_CXX
  82. undefine([AC_PROG_CC])
  83. define([AC_PROG_CC], [tl_PROG_CC])
  84. undefine([AC_PROG_CXX])
  85. define([AC_PROG_CXX], [tl_PROG_CXX])
  86. dnl tl_PROG_CC, tl_PROG_CXX - same as old AC_PROG_CC and AC_PROG_CXX, but
  87. dnl use AC_CHECK_TOOL/tl_CHECK_TOOLS instead of AC_CHECK_PROG, etc.
  88. AC_DEFUN(tl_PROG_CC,
  89. [AC_BEFORE([$0], [AC_PROG_CPP])dnl
  90. AC_PROVIDE([AC_PROG_CC])dnl
  91. tl_CHECK_TOOL(CC, gcc, gcc)
  92. if test -z "$CC"; then
  93. AC_CHECK_TOOL(CC, cc, cc, , , /usr/ucb/cc)
  94. test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
  95. fi
  96. if test -n "$ac_tool_prefix" -a "`echo $CC | grep '$ac_tool_prefix'`" = "" \
  97. -a "`echo $CC | grep -- '-b'`" = ""; then
  98. if test -z "$ac_cv_prog_CC_dir" && $CC -v 2>&1 | grep -q gcc; then
  99. AC_CACHE_CHECK([if $CC -b${ac_tool_dir} works], tl_cv_prog_cc_bhost,[
  100. old_cc="${CC}"
  101. CC="${CC} -b${ac_tool_dir}"
  102. AC_LANG_SAVE
  103. AC_LANG_C
  104. AC_TRY_COMPILER([main(){return(0);}], tl_cv_prog_cc_bhost, ac_cv_prog_cc_cross)
  105. AC_LANG_RESTORE])
  106. if test $tl_cv_prog_cc_bhost = "yes"; then
  107. ac_cv_prog_cc_works=yes
  108. cctest=yes
  109. else
  110. CC="${old_cc}"
  111. fi
  112. fi
  113. fi
  114. if test "$cctest" != "yes"; then
  115. tl_PROG_CC_WORKS
  116. fi
  117. AC_PROG_CC_GNU
  118. if test $ac_cv_prog_gcc = yes; then
  119. GCC=yes
  120. dnl Check whether -g works, even if CFLAGS is set, in case the package
  121. dnl plays around with CFLAGS (such as to build both debugging and
  122. dnl normal versions of a library), tasteless as that idea is.
  123. ac_test_CFLAGS="${CFLAGS+set}"
  124. ac_save_CFLAGS="$CFLAGS"
  125. CFLAGS=
  126. AC_PROG_CC_G
  127. if test "$ac_test_CFLAGS" = set; then
  128. CFLAGS="$ac_save_CFLAGS"
  129. elif test $ac_cv_prog_cc_g = yes; then
  130. CFLAGS="-g -O2"
  131. else
  132. CFLAGS="-O2"
  133. fi
  134. else
  135. GCC=
  136. test "${CFLAGS+set}" = set || CFLAGS="-g"
  137. fi
  138. ])
  139. AC_DEFUN(tl_PROG_CXX,
  140. [AC_BEFORE([$0], [AC_PROG_CXXCPP])dnl
  141. AC_PROVIDE([AC_PROG_CXX])dnl
  142. tl_CHECK_TOOLS(CXX, $CCC c++ g++ gcc CC cxx cc++, gcc)
  143. if test -n "$CXX"; then
  144. if test -n "$ac_tool_prefix" -a "`echo $CXX | grep '$ac_tool_prefix'`" = "" \
  145. -a "`echo $CXX | grep -- '-b'`" = ""; then
  146. if test -z "$ac_cv_prog_CXX_dir" && $CXX -v 2>&1 | grep -q gcc; then
  147. AC_CACHE_CHECK([if $CXX -b${ac_tool_dir} works], tl_cv_prog_cxx_bhost,[
  148. old_cxx="${CXX}"
  149. CXX="${CXX} -b${ac_tool_dir}"
  150. AC_LANG_SAVE
  151. AC_LANG_CPLUSPLUS
  152. AC_TRY_COMPILER([main(){return(0);}], tl_cv_prog_cxx_bhost, ac_cv_prog_cxx_cross)
  153. AC_LANG_RESTORE])
  154. if test $tl_cv_prog_cxx_bhost = "yes"; then
  155. ac_cv_prog_cxx_works=yes
  156. cxxtest=yes
  157. else
  158. CXX="${old_cxx}"
  159. fi
  160. fi
  161. fi
  162. if test "$cxxtest" != "yes"; then
  163. tl_PROG_CXX_WORKS
  164. fi
  165. AC_PROG_CXX_GNU
  166. if test $ac_cv_prog_gxx = yes; then
  167. GXX=yes
  168. dnl Check whether -g works, even if CXXFLAGS is set, in case the package
  169. dnl plays around with CXXFLAGS (such as to build both debugging and
  170. dnl normal versions of a library), tasteless as that idea is.
  171. ac_test_CXXFLAGS="${CXXFLAGS+set}"
  172. ac_save_CXXFLAGS="$CXXFLAGS"
  173. CXXFLAGS=
  174. AC_PROG_CXX_G
  175. if test "$ac_test_CXXFLAGS" = set; then
  176. CXXFLAGS="$ac_save_CXXFLAGS"
  177. elif test $ac_cv_prog_cxx_g = yes; then
  178. CXXFLAGS="-g -O2"
  179. else
  180. CXXFLAGS="-O2"
  181. fi
  182. else
  183. GXX=
  184. test "${CXXFLAGS+set}" = set || CXXFLAGS="-g"
  185. fi
  186. fi
  187. ])
  188. AC_DEFUN(tl_PROG_CC_WORKS,
  189. [AC_PROVIDE(AC_PROG_CC_WORKS)
  190. AC_CACHE_CHECK([whether the C compiler ($CC $CFLAGS $LDFLAGS) works],
  191. ac_cv_prog_cc_works, [
  192. AC_LANG_SAVE
  193. AC_LANG_C
  194. AC_TRY_COMPILER([main(){return(0);}], ac_cv_prog_cc_works, ac_cv_prog_cc_cross)
  195. AC_LANG_RESTORE
  196. if test $ac_cv_prog_cc_works = no; then
  197. AC_MSG_ERROR([installation or configuration problem: C compiler cannot create executables.])
  198. fi])
  199. AC_MSG_CHECKING([whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler])
  200. AC_MSG_RESULT($ac_cv_prog_cc_cross)
  201. cross_compiling=$ac_cv_prog_cc_cross
  202. ])
  203. AC_DEFUN(tl_PROG_CXX_WORKS,
  204. [AC_PROVIDE(AC_PROG_CXX_WORKS)
  205. AC_CACHE_CHECK([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works],
  206. ac_cv_prog_cxx_works, [
  207. AC_LANG_SAVE
  208. AC_LANG_CPLUSPLUS
  209. AC_TRY_COMPILER([main(){return(0);}], ac_cv_prog_cxx_works, ac_cv_prog_cxx_cross)
  210. AC_LANG_RESTORE
  211. if test $ac_cv_prog_cxx_works = no; then
  212. AC_MSG_ERROR([installation or configuration problem: C++ compiler cannot create executables.])
  213. fi])
  214. AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler])
  215. AC_MSG_RESULT($ac_cv_prog_cxx_cross)
  216. cross_compiling=$ac_cv_prog_cxx_cross
  217. ])