ax_jni_include_dir.m4 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_jni_include_dir.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_JNI_INCLUDE_DIR
  8. #
  9. # DESCRIPTION
  10. #
  11. # AX_JNI_INCLUDE_DIR finds include directories needed for compiling
  12. # programs using the JNI interface.
  13. #
  14. # JNI include directories are usually in the Java distribution. This is
  15. # deduced from the value of $JAVA_HOME, $JAVAC, or the path to "javac", in
  16. # that order. When this macro completes, a list of directories is left in
  17. # the variable JNI_INCLUDE_DIRS.
  18. #
  19. # Example usage follows:
  20. #
  21. # AX_JNI_INCLUDE_DIR
  22. #
  23. # for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS
  24. # do
  25. # CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR"
  26. # done
  27. #
  28. # If you want to force a specific compiler:
  29. #
  30. # - at the configure.in level, set JAVAC=yourcompiler before calling
  31. # AX_JNI_INCLUDE_DIR
  32. #
  33. # - at the configure level, setenv JAVAC
  34. #
  35. # This macro depends on AC_CANONICAL_HOST which requires that config.guess
  36. # and config.sub be distributed along with the source code. See autoconf
  37. # manual for details.
  38. #
  39. # Note: This macro can work with the autoconf M4 macros for Java programs.
  40. # This particular macro is not part of the original set of macros.
  41. #
  42. # LICENSE
  43. #
  44. # Copyright (c) 2008 Don Anderson <dda@sleepycat.com>
  45. #
  46. # Copying and distribution of this file, with or without modification, are
  47. # permitted in any medium without royalty provided the copyright notice
  48. # and this notice are preserved. This file is offered as-is, without any
  49. # warranty.
  50. #serial 15
  51. AU_ALIAS([AC_JNI_INCLUDE_DIR], [AX_JNI_INCLUDE_DIR])
  52. AC_DEFUN([AX_JNI_INCLUDE_DIR],[
  53. AC_REQUIRE([AC_CANONICAL_HOST])
  54. JNI_INCLUDE_DIRS=""
  55. if test "x$JAVA_HOME" != x; then
  56. _JTOPDIR="$JAVA_HOME"
  57. else
  58. if test "x$JAVAC" = x; then
  59. JAVAC=javac
  60. fi
  61. AC_PATH_PROG([_ACJNI_JAVAC], [$JAVAC], [no])
  62. if test "x$_ACJNI_JAVAC" = xno; then
  63. AC_MSG_ERROR([cannot find JDK; try setting \$JAVAC or \$JAVA_HOME])
  64. fi
  65. _ACJNI_FOLLOW_SYMLINKS("$_ACJNI_JAVAC")
  66. _JTOPDIR=`echo "$_ACJNI_FOLLOWED" | sed -e 's://*:/:g' -e 's:/[[^/]]*$::'`
  67. fi
  68. case "$host_os" in
  69. darwin*) # Apple Java headers are inside the Xcode bundle.
  70. macos_version=$(sw_vers -productVersion | sed -n -e 's/^@<:@0-9@:>@*.\(@<:@0-9@:>@*\).@<:@0-9@:>@*/\1/p')
  71. if @<:@ "$macos_version" -gt "7" @:>@; then
  72. _JTOPDIR="$(xcrun --show-sdk-path)/System/Library/Frameworks/JavaVM.framework"
  73. _JINC="$_JTOPDIR/Headers"
  74. else
  75. _JTOPDIR="/System/Library/Frameworks/JavaVM.framework"
  76. _JINC="$_JTOPDIR/Headers"
  77. fi
  78. ;;
  79. *) _JINC="$_JTOPDIR/include";;
  80. esac
  81. _AS_ECHO_LOG([_JTOPDIR=$_JTOPDIR])
  82. _AS_ECHO_LOG([_JINC=$_JINC])
  83. # On Mac OS X 10.6.4, jni.h is a symlink:
  84. # /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/jni.h
  85. # -> ../../CurrentJDK/Headers/jni.h.
  86. AC_CACHE_CHECK(jni headers, ac_cv_jni_header_path,
  87. [
  88. if test -f "$_JINC/jni.h"; then
  89. ac_cv_jni_header_path="$_JINC"
  90. JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path"
  91. else
  92. _JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'`
  93. if test -f "$_JTOPDIR/include/jni.h"; then
  94. ac_cv_jni_header_path="$_JTOPDIR/include"
  95. JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path"
  96. else
  97. ac_cv_jni_header_path=none
  98. fi
  99. fi
  100. ])
  101. # get the likely subdirectories for system specific java includes
  102. case "$host_os" in
  103. bsdi*) _JNI_INC_SUBDIRS="bsdos";;
  104. freebsd*) _JNI_INC_SUBDIRS="freebsd";;
  105. darwin*) _JNI_INC_SUBDIRS="darwin";;
  106. linux*) _JNI_INC_SUBDIRS="linux genunix";;
  107. osf*) _JNI_INC_SUBDIRS="alpha";;
  108. solaris*) _JNI_INC_SUBDIRS="solaris";;
  109. mingw*) _JNI_INC_SUBDIRS="win32";;
  110. cygwin*) _JNI_INC_SUBDIRS="win32";;
  111. *) _JNI_INC_SUBDIRS="genunix";;
  112. esac
  113. if test "x$ac_cv_jni_header_path" != "xnone"; then
  114. # add any subdirectories that are present
  115. for JINCSUBDIR in $_JNI_INC_SUBDIRS
  116. do
  117. if test -d "$_JTOPDIR/include/$JINCSUBDIR"; then
  118. JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include/$JINCSUBDIR"
  119. fi
  120. done
  121. fi
  122. ])
  123. # _ACJNI_FOLLOW_SYMLINKS <path>
  124. # Follows symbolic links on <path>,
  125. # finally setting variable _ACJNI_FOLLOWED
  126. # ----------------------------------------
  127. AC_DEFUN([_ACJNI_FOLLOW_SYMLINKS],[
  128. # find the include directory relative to the javac executable
  129. _cur="$1"
  130. while ls -ld "$_cur" 2>/dev/null | grep " -> " >/dev/null; do
  131. AC_MSG_CHECKING([symlink for $_cur])
  132. _slink=`ls -ld "$_cur" | sed 's/.* -> //'`
  133. case "$_slink" in
  134. /*) _cur="$_slink";;
  135. # 'X' avoids triggering unwanted echo options.
  136. *) _cur=`echo "X$_cur" | sed -e 's/^X//' -e 's:[[^/]]*$::'`"$_slink";;
  137. esac
  138. AC_MSG_RESULT([$_cur])
  139. done
  140. _ACJNI_FOLLOWED="$_cur"
  141. ])# _ACJNI