ax_check_java.m4 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. dnl Usage:
  2. dnl AX_CHECK_JAVA
  3. dnl Test for java, and defines
  4. dnl - JAVA_CFLAGS (compiler flags)
  5. dnl - LIB_JAVA (linker flags, stripping and path)
  6. dnl prerequisites:
  7. AC_DEFUN([AX_CHECK_JAVA],
  8. [
  9. AC_ARG_WITH([java],
  10. [AC_HELP_STRING([--with-java=PFX], [prefix where 'java' is installed.])],
  11. [with_java_prefix="$withval"],
  12. [with_java_prefix="${JAVA_INSTALL_PATH:-/usr/java/j2sdk1.4.1_01}"])
  13. have_java='no'
  14. LIB_JAVA=''
  15. JAVA_FLAGS=''
  16. JAVA_HOME=''
  17. if test "x$with_java" != 'xno'
  18. then
  19. AC_MSG_CHECKING([for JAVA installation at ${with_java}])
  20. AC_MSG_RESULT()
  21. dnl these two lines should let u find most java installations
  22. java_dirs="/usr /usr/local /usr/lib/j2sdk1.4-sun /usr/lib/jvm/java /usr/lib/jvm/default-java /System/Library/Frameworks/JavaVM.framework/Versions/Current /opt /mingw"
  23. java_inc_dirs="include include/libgcj Headers"
  24. if test "x$with_java" != 'x'
  25. then
  26. if test -d "$with_java"
  27. then
  28. JAVA_HOME="$with_java"
  29. for j in $java_inc_dirs
  30. do
  31. echo "configure: __oline__: checking $JAVA_HOME/$j" >&AC_FD_CC
  32. if test -r "$JAVA_HOME/$j/jni.h"; then
  33. echo "taking that" >&AC_FD_CC
  34. java_inc_dir="$j"
  35. break 2
  36. fi
  37. done
  38. else
  39. AC_MSG_WARN([Sorry, $with_java does not exist, checking usual places])
  40. with_java=''
  41. fi
  42. fi
  43. dnl now find the java dirs
  44. if test "x$JAVA_HOME" = 'x'
  45. then
  46. for i in $java_dirs;
  47. do
  48. for j in $java_inc_dirs
  49. do
  50. echo "configure: __oline__: checking $i/$j" >&AC_FD_CC
  51. if test -r "$i/$j/jni.h"; then
  52. echo "taking that" >&AC_FD_CC
  53. JAVA_HOME="$i"
  54. java_inc_dir="$j"
  55. break
  56. fi
  57. done
  58. done
  59. if test "x$JAVA_HOME" != 'x'
  60. then
  61. AC_MSG_NOTICE([java home set to $JAVA_HOME])
  62. else
  63. AC_MSG_NOTICE([cannot find the java directory, assuming it is specified in CFLAGS])
  64. fi
  65. fi
  66. failed=0;
  67. passed=0;
  68. JAVA_OLD_CPPFLAGS=$CPPFLAGS
  69. case "${host_os}" in
  70. linux*)
  71. java_extra_inc=linux
  72. ;;
  73. darwin*)
  74. java_extra_inc=darwin
  75. ;;
  76. *mingw32*)
  77. java_extra_inc=win32
  78. ;;
  79. *cygwin*)
  80. java_extra_inc=win32
  81. ;;
  82. esac
  83. dnl Check if extra inc is required
  84. CPPFLAGS="$CPPFLAGS -I$JAVA_HOME/$java_inc_dir"
  85. AC_LANG_SAVE
  86. AC_LANG_C
  87. AC_COMPILE_IFELSE([
  88. AC_LANG_SOURCE(
  89. [[#include <jni.h>]]
  90. )],
  91. passed=`expr $passed + 1`,failed=`expr $failed + 1`
  92. )
  93. AC_LANG_RESTORE
  94. CPPFLAGS="$JAVA_OLD_CPPFLAGS"
  95. JAVA_FLAGS="-I$JAVA_HOME/$java_inc_dir -DHasJava"
  96. if test $failed -gt 0
  97. then
  98. echo "configure: __oline__: checking if extra_inc required" >&AC_FD_CC
  99. failed=0;
  100. CPPFLAGS="$CPPFLAGS -I$JAVA_HOME/$java_inc_dir -I$JAVA_HOME/$java_inc_dir/$java_extra_inc"
  101. AC_LANG_SAVE
  102. AC_LANG_C
  103. AC_COMPILE_IFELSE([
  104. AC_LANG_SOURCE(
  105. [[#include <jni.h>]]
  106. )],
  107. passed=`expr $passed + 1`,failed=`expr $failed + 1`
  108. )
  109. AC_LANG_RESTORE
  110. CPPFLAGS="$JAVA_OLD_CPPFLAGS"
  111. JAVA_FLAGS="-I$JAVA_HOME/$java_inc_dir -I$JAVA_HOME/$java_inc_dir/$java_extra_inc -DHasJava"
  112. fi
  113. AC_MSG_CHECKING(if JAVA package is complete)
  114. if test $passed -gt 0
  115. then
  116. if test $failed -gt 0
  117. then
  118. AC_MSG_RESULT(no -- some components failed test)
  119. have_java='no (failed tests)'
  120. JAVA_FLAGS=
  121. else
  122. if test "x$JAVA_HOME" = 'x'
  123. then
  124. JAVA_FLAGS=
  125. else
  126. LIB_JAVA="-L$JAVA_HOME/lib"
  127. fi
  128. AC_DEFINE(HasJava,1,Define if you have Java)
  129. AC_MSG_RESULT(yes)
  130. have_java='yes'
  131. fi
  132. else
  133. JAVA_FLAGS=
  134. AC_MSG_RESULT(no)
  135. fi
  136. fi
  137. AM_CONDITIONAL(HasJava, test "x$have_java" = 'xyes')
  138. AC_SUBST(LIB_JAVA)
  139. AC_SUBST(JAVA_FLAGS)
  140. AC_SUBST(JAVA_HOME)
  141. ])