tools.m4 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 && test $build != NONE; then
  20. thost=$nonopt
  21. else
  22. thost=$host
  23. fi
  24. if test $thost != $build && test $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 "$ac_tool_dir" != ""; then
  52. if test -z "$ac_cv_prog_$1" && test "$5" != "/usr/${ac_tool_dir}/bin/$2" &&
  53. test "$5" != "/usr/local/${ac_tool_dir}/bin/$2"; then
  54. if test -f /usr/${ac_tool_dir}/bin/$2; then $1="/usr/${ac_tool_dir}/bin/$2"
  55. elif test -f /usr/local/${ac_tool_dir}/bin/$2; then $1="/usr/local/${ac_tool_dir}/bin/$2"
  56. fi
  57. fi
  58. fi
  59. ifelse([$3], , , [
  60. if test -z "$ac_cv_prog_$1"; then
  61. if test -n "$ac_tool_prefix"; then
  62. AC_CHECK_PROG($1, $2, $2, $3, $4, $5)
  63. else
  64. $1="$3"
  65. fi
  66. fi])
  67. ])
  68. dnl tl_CHECK_TOOLS -
  69. dnl do a tl_CHECK_TOOL for multiple tools (like AC_CHECK_PROGS)
  70. dnl tl_CHECK_TOOLS(VARIABLE, PROGS-TO-CHECK-FOR [, VALUE-IF-NOT-FOUND
  71. dnl [, PATH]])
  72. AC_DEFUN(tl_CHECK_TOOLS,
  73. [for ac_tool in $2
  74. do
  75. tl_CHECK_TOOL($1, [$]ac_tool, [$]ac_tool, , $4)
  76. test -n "[$]$1" && break
  77. done
  78. ifelse([$3], , , [test -n "[$]$1" || $1="$3"
  79. ])])
  80. dnl replace AC_PROG_CC and AC_PROG_CXX
  81. undefine([AC_PROG_CC])
  82. define([AC_PROG_CC], [tl_PROG_CC])
  83. undefine([AC_PROG_CXX])
  84. define([AC_PROG_CXX], [tl_PROG_CXX])
  85. dnl tl_PROG_CC, tl_PROG_CXX - same as old AC_PROG_CC and AC_PROG_CXX, but
  86. dnl use AC_CHECK_TOOL/tl_CHECK_TOOLS instead of AC_CHECK_PROG, etc.
  87. AC_DEFUN(tl_PROG_CC,
  88. [AC_BEFORE([$0], [AC_PROG_CPP])dnl
  89. AC_PROVIDE([AC_PROG_CC])dnl
  90. tl_CHECK_TOOL(CC, gcc, gcc)
  91. if test -z "$CC"; then
  92. AC_CHECK_TOOL(CC, cc, cc, , , /usr/ucb/cc)
  93. test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
  94. fi
  95. if test -n "$ac_tool_prefix" &&
  96. test "`echo $CC | grep '$ac_tool_prefix'`" = "" &&
  97. test "`echo $CC | grep -- '-b'`" = ""; then
  98. if $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" &&
  145. test "`echo $CXX | grep '$ac_tool_prefix'`" = "" &&
  146. test "`echo $CXX | grep -- '-b'`" = ""; then
  147. if $CXX -v 2>&1 | grep -q gcc; then
  148. AC_CACHE_CHECK([if $CXX -b${ac_tool_dir} works], tl_cv_prog_cxx_bhost,[
  149. old_cxx="${CXX}"
  150. CXX="${CXX} -b${ac_tool_dir}"
  151. AC_LANG_SAVE
  152. AC_LANG_CPLUSPLUS
  153. AC_TRY_COMPILER([main(){return(0);}], tl_cv_prog_cxx_bhost, ac_cv_prog_cxx_cross)
  154. AC_LANG_RESTORE])
  155. if test $tl_cv_prog_cxx_bhost = "yes"; then
  156. ac_cv_prog_cxx_works=yes
  157. cxxtest=yes
  158. else
  159. CXX="${old_cxx}"
  160. fi
  161. fi
  162. fi
  163. if test "$cxxtest" != "yes"; then
  164. tl_PROG_CXX_WORKS
  165. fi
  166. AC_PROG_CXX_GNU
  167. if test $ac_cv_prog_gxx = yes; then
  168. GXX=yes
  169. dnl Check whether -g works, even if CXXFLAGS is set, in case the package
  170. dnl plays around with CXXFLAGS (such as to build both debugging and
  171. dnl normal versions of a library), tasteless as that idea is.
  172. ac_test_CXXFLAGS="${CXXFLAGS+set}"
  173. ac_save_CXXFLAGS="$CXXFLAGS"
  174. CXXFLAGS=
  175. AC_PROG_CXX_G
  176. if test "$ac_test_CXXFLAGS" = set; then
  177. CXXFLAGS="$ac_save_CXXFLAGS"
  178. elif test $ac_cv_prog_cxx_g = yes; then
  179. CXXFLAGS="-g -O2"
  180. else
  181. CXXFLAGS="-O2"
  182. fi
  183. else
  184. GXX=
  185. test "${CXXFLAGS+set}" = set || CXXFLAGS="-g"
  186. fi
  187. fi
  188. ])
  189. AC_DEFUN(tl_PROG_CC_WORKS,
  190. [AC_PROVIDE(AC_PROG_CC_WORKS)
  191. AC_CACHE_CHECK([whether the C compiler ($CC $CFLAGS $LDFLAGS) works],
  192. ac_cv_prog_cc_works, [
  193. AC_LANG_SAVE
  194. AC_LANG_C
  195. AC_TRY_COMPILER([main(){return(0);}], ac_cv_prog_cc_works, ac_cv_prog_cc_cross)
  196. AC_LANG_RESTORE
  197. if test $ac_cv_prog_cc_works = no; then
  198. AC_MSG_ERROR([installation or configuration problem: C compiler cannot create executables.])
  199. fi])
  200. AC_MSG_CHECKING([whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler])
  201. AC_MSG_RESULT($ac_cv_prog_cc_cross)
  202. cross_compiling=$ac_cv_prog_cc_cross
  203. ])
  204. AC_DEFUN(tl_PROG_CXX_WORKS,
  205. [AC_PROVIDE(AC_PROG_CXX_WORKS)
  206. AC_CACHE_CHECK([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works],
  207. ac_cv_prog_cxx_works, [
  208. AC_LANG_SAVE
  209. AC_LANG_CPLUSPLUS
  210. AC_TRY_COMPILER([main(){return(0);}], ac_cv_prog_cxx_works, ac_cv_prog_cxx_cross)
  211. AC_LANG_RESTORE
  212. if test $ac_cv_prog_cxx_works = no; then
  213. AC_MSG_ERROR([installation or configuration problem: C++ compiler cannot create executables.])
  214. fi])
  215. AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler])
  216. AC_MSG_RESULT($ac_cv_prog_cxx_cross)
  217. cross_compiling=$ac_cv_prog_cxx_cross
  218. ])