The R Project SVN R

Rev

Rev 41169 | Rev 41594 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 41169 Rev 41576
Line 1... Line 1...
1
### java.m4 -- macros for Java environment detection    -*- Autoconf -*-
1
### java.m4 -- macros for Java environment detection    -*- Autoconf -*-
2
###
2
###
3
### Copyright (C) 2005 R Core Team
3
### Copyright (C) 2005-7 R Core Team
4
###
4
###
5
### This file is part of R.
5
### This file is part of R.
6
###
6
###
7
### R is free software; you can redistribute it and/or modify it under
7
### R is free software; you can redistribute it and/or modify it under
8
### the terms of the GNU General Public License as published by the Free
8
### the terms of the GNU General Public License as published by the Free
Line 77... Line 77...
77
AC_PATH_PROGS(JAVAC,javac,,${JAVA_PATH})
77
AC_PATH_PROGS(JAVAC,javac,,${JAVA_PATH})
78
AC_PATH_PROGS(JAVAH,javah,,${JAVA_PATH})
78
AC_PATH_PROGS(JAVAH,javah,,${JAVA_PATH})
79
AC_PATH_PROGS(JAR,jar,,${JAVA_PATH})
79
AC_PATH_PROGS(JAR,jar,,${JAVA_PATH})
80
 
80
 
81
## we don't require a compiler, but it would be useful
81
## we don't require a compiler, but it would be useful
82
AC_MSG_CHECKING([whether Java compiler works])
82
AC_CACHE_CHECK([whether Java compiler works], [r_cv_javac_works],
83
acx_javac_works=no
83
[r_cv_javac_works=no
84
if test -n "${JAVAC}"; then
84
if test -n "${JAVAC}"; then
85
  rm -f A.java A.class
85
  rm -f A.java A.class
86
  echo "public class A { }" > A.java
86
  echo "public class A { }" > A.java
87
  if "${JAVAC}" A.java 2>&AS_MESSAGE_LOG_FD; then
87
  if "${JAVAC}" A.java 2>&AS_MESSAGE_LOG_FD; then
88
    if test -e A.class; then
88
    if test -e A.class; then
89
      acx_javac_works=yes
89
      r_cv_javac_works=yes
90
    fi
90
    fi
91
  fi
91
  fi
92
  rm -rf A.java A.class
92
  rm -rf A.java A.class
93
fi
93
fi])
94
if test "${acx_javac_works}" = yes; then
-
 
95
  AC_MSG_RESULT([yes])
-
 
96
else
-
 
97
  JAVAC=
-
 
98
  AC_MSG_RESULT([no])
-
 
99
fi
-
 
100
 
94
 
101
## this is where our test-class lives (in tools directory)
95
## this is where our test-class lives (in tools directory)
102
getsp_cp=${ac_aux_dir}
96
getsp_cp=${ac_aux_dir}
103
 
97
 
104
AC_MSG_CHECKING([whether Java interpreter works])
98
AC_CACHE_CHECK([whether Java interpreter works], [r_cv_java_works],
105
acx_java_works=no
99
[r_cv_java_works=no
106
if test -n "${JAVA}" ; then
100
if test -n "${JAVA}" ; then
107
  R_RUN_JAVA(acx_jc_result,[-classpath ${getsp_cp} getsp -test])
101
  R_RUN_JAVA(acx_jc_result,[-classpath ${getsp_cp} getsp -test])
108
  if test "${acx_jc_result}" = "Test1234OK"; then
102
  if test "${acx_jc_result}" = "Test1234OK"; then
109
    acx_java_works=yes
103
    r_cv_java_works=yes
110
  fi
104
  fi
111
  acx_jc_result=
105
  acx_jc_result=
112
fi
106
fi])
113
 
107
 
114
if test ${acx_java_works} = yes; then
108
if test ${r_cv_java_works} = yes; then
115
  AC_MSG_RESULT([yes])
-
 
116
 
109
 
-
 
110
  ## we cannot cache this part without caching JAVA_HOME
117
  AC_MSG_CHECKING([for Java environment])
111
  AC_MSG_CHECKING([for Java environment])
118
 
-
 
-
 
112
  r_cv_java_env="not found"
119
  ## find JAVA_HOME from Java itself unless specified
113
  ## find JAVA_HOME from Java itself unless specified
120
  if test -z "${JAVA_HOME}" ; then
114
  if test -z "${JAVA_HOME}" ; then
121
    R_RUN_JAVA(JAVA_HOME,[-classpath ${getsp_cp} getsp java.home])
115
    R_RUN_JAVA(JAVA_HOME,[-classpath ${getsp_cp} getsp java.home])
122
  fi
116
  fi
123
 
117
 
124
  ## the availability of JAVA_HOME will tell us whether it's supported
118
  ## the availability of JAVA_HOME will tell us whether it's supported
125
  if test -z "${JAVA_HOME}" ; then
119
  if test -n "${JAVA_HOME}" ; then
126
    if test x$acx_java_env_msg != xyes; then
120
    r_cv_java_env="in ${JAVA_HOME}"
127
      AC_MSG_RESULT([not found])
-
 
128
    fi
121
  fi
129
  else
-
 
130
    AC_MSG_RESULT([in ${JAVA_HOME}])
122
  AC_MSG_RESULT([$r_cv_java_env])
131
 
123
 
-
 
124
  if test "$r_cv_java_env" != "not found"; then 
132
    : ${JAVA_LIBS=~autodetect~}
125
    : ${JAVA_LIBS=~autodetect~}
133
    : ${JAVA_CPPFLAGS=~autodetect~}
126
    : ${JAVA_CPPFLAGS=~autodetect~}
134
    : ${JAVA_LD_LIBRARY_PATH=~autodetect~}
127
    : ${JAVA_LD_LIBRARY_PATH=~autodetect~}
135
    custom_JAVA_LIBS="${JAVA_LIBS}"
128
    custom_JAVA_LIBS="${JAVA_LIBS}"
136
    custom_JAVA_CPPFLAGS="${JAVA_CPPFLAGS}"
129
    custom_JAVA_CPPFLAGS="${JAVA_CPPFLAGS}"
Line 205... Line 198...
205
    if test "${custom_JAVA_LD_LIBRARY_PATH}" != '~autodetect~'; then
198
    if test "${custom_JAVA_LD_LIBRARY_PATH}" != '~autodetect~'; then
206
      JAVA_LD_LIBRARY_PATH="${custom_JAVA_LD_LIBRARY_PATH}"
199
      JAVA_LD_LIBRARY_PATH="${custom_JAVA_LD_LIBRARY_PATH}"
207
    fi
200
    fi
208
 
201
 
209
    ## try to link a simple JNI program
202
    ## try to link a simple JNI program
210
    AC_MSG_CHECKING([whether JNI programs can be compiled])
203
    AC_CACHE_CHECK([whether JNI programs can be compiled], [r_cv_jni],
-
 
204
    [r_cv_jni=
211
    j_save_LIBS="${LIBS}"
205
    j_save_LIBS="${LIBS}"
212
    j_save_CPPF="${CPPFLAGS}"
206
    j_save_CPPF="${CPPFLAGS}"
213
    LIBS="${JAVA_LIBS}"
207
    LIBS="${JAVA_LIBS}"
214
    CPPFLAGS="${JAVA_CPPFLAGS}"
208
    CPPFLAGS="${JAVA_CPPFLAGS}"
215
    AC_LINK_IFELSE([
209
    AC_LINK_IFELSE([
216
#include <jni.h>
210
#include <jni.h>
217
int main(void) {
211
int main(void) {
218
    JNI_CreateJavaVM(0, 0, 0);
212
    JNI_CreateJavaVM(0, 0, 0);
219
    return 0;
213
    return 0;
220
}
214
}
221
],[AC_MSG_RESULT(yes)
215
],[r_cv_jni="yes"],[
222
    LIBS="${j_save_LIBS}"
-
 
223
    CPPFLAGS="${j_save_CPPF}"
-
 
224
],[
-
 
225
    if test "${acx_java_uses_custom_flags}" = yes; then
216
    if test "${acx_java_uses_custom_flags}" = yes; then
226
      AC_MSG_RESULT(no)
217
      r_cv_jni=no
227
      AC_MSG_ERROR([Failed to compile a JNI program with custom JAVA_LIBS/JAVA_CPPFLAGS.
218
      AC_MSG_ERROR([Failed to compile a JNI program with custom JAVA_LIBS/JAVA_CPPFLAGS.
228
See config.log for details.
219
See config.log for details.
229
Do NOT set JAVA_LIBS/JAVA_CPPFLAGS unless you are sure they are correct!
220
Do NOT set JAVA_LIBS/JAVA_CPPFLAGS unless you are sure they are correct!
230
Java/JNI support is optional unless you set either JAVA_LIBS or JAVA_CPPFLAGS.])
221
Java/JNI support is optional unless you set either JAVA_LIBS or JAVA_CPPFLAGS.])
231
    fi
222
    fi
Line 235... Line 226...
235
#include <jni.h>
226
#include <jni.h>
236
int main(void) {
227
int main(void) {
237
    JNI_CreateJavaVM(0, 0, 0);
228
    JNI_CreateJavaVM(0, 0, 0);
238
    return 0;
229
    return 0;
239
}
230
}
240
],[AC_MSG_RESULT([yes (with pthreads)])
231
],[r_cv_jni="yes (with pthreads)"],[r_cv_jni="no"])])
241
    JAVA_LIBS0="${JAVA_LIBS0} -lpthread"
-
 
242
],[AC_MSG_RESULT(no)])
-
 
243
    LIBS="${j_save_LIBS}"
232
    LIBS="${j_save_LIBS}"
244
    CPPFLAGS="${j_save_CPPF}"
233
    CPPFLAGS="${j_save_CPPF}"
245
])
234
])
-
 
235
    ##AC_MSG_RESULT([$r_cv_jni])
-
 
236
    if test "$r_cv_jni"="yes (with pthreads)"; then
-
 
237
      JAVA_LIBS0="${JAVA_LIBS0} -lpthread"
246
 
238
    fi
247
    have_java=yes
239
    have_java=yes
248
  fi
240
  fi
249
else
-
 
250
  AC_MSG_RESULT([no])
241
else  ## not r_cv_java_works
251
  JAVA=
242
  JAVA=
252
  JAVA_HOME=
243
  JAVA_HOME=
253
fi
244
fi
254
 
245
 
255
AC_SUBST(JAVA_HOME)
246
AC_SUBST(JAVA_HOME)