The R Project SVN R

Rev

Rev 62851 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 62851 Rev 63241
1
if test -z "${R_HOME}"; then
1
if test -z "${R_HOME}"; then
2
    echo "This command can be only executed via R CMD!"
2
    echo "This command can be only executed via R CMD!"
3
    exit 1
3
    exit 1
4
fi
4
fi
5
 
5
 
6
## pick up configure-time settings
6
## pick up configure-time settings
7
. "${R_HOME}/etc${R_ARCH}/javaconf"
7
. "${R_HOME}/etc${R_ARCH}/javaconf"
8
 
8
 
9
DYLIB_EXT=`${R_HOME}/bin/R CMD config DYLIB_EXT`
9
DYLIB_EXT=`${R_HOME}/bin/R CMD config DYLIB_EXT`
10
tools_classpath=${R_SHARE_DIR}/java
10
tools_classpath=${R_SHARE_DIR}/java
11
 
11
 
12
revision='$Rev: 62851 $'
12
revision='$Rev: 63241 $'
13
version=`set - ${revision}; echo ${2}`
13
version=`set - ${revision}; echo ${2}`
14
version="R Java configurator: ${R_VERSION} (r${version})
14
version="R Java configurator: ${R_VERSION} (r${version})
15
 
15
 
16
Copyright (C) 2002-13 The R Core Team.
16
Copyright (C) 2002-13 The R Core Team.
17
This is free software; see the GNU General Public License version 2
17
This is free software; see the GNU General Public License version 2
18
or later for copying conditions.  There is NO warranty."
18
or later for copying conditions.  There is NO warranty."
19
 
19
 
20
usage="
20
usage="
21
Usage: R CMD javareconf [options]
21
Usage: R CMD javareconf [options]
22
 
22
 
23
Detect current Java setup and update the corresponding configuration in R.
23
Detect current Java setup and update the corresponding configuration in R.
24
 
24
 
25
Options:
25
Options:
26
  -h, --help     print this help message and exit
26
  -h, --help     print this help message and exit
27
  -v, --version  print version info and exit
27
  -v, --version  print version info and exit
28
  -n, --dry-run  perform Java detection, but don't touch any
28
  -n, --dry-run  perform Java detection, but don't touch any
29
                 configuration files
29
                 configuration files
30
  -e <prog>      same as -n but exports all detected variables
30
  -e <prog>      same as -n but exports all detected variables
31
                 and runs <prog>. If -e is the last argument
31
                 and runs <prog>. If -e is the last argument
32
                 or <prog> is '' then a shell is used instead
32
                 or <prog> is '' then a shell is used instead
33
  xxx=yyy        evaluate the corresponding expression
33
  xxx=yyy        evaluate the corresponding expression
34
                 (e.g. JAVA_HOME=/usr/lib/java)
34
                 (e.g. JAVA_HOME=/usr/lib/java)
35
 
35
 
36
Environment variables that can be used to influence the detection:
36
Environment variables that can be used to influence the detection:
37
  JAVA           path to a Java interpreter executable
37
  JAVA           path to a Java interpreter executable
38
                 By default first 'java' command found on the PATH
38
                 By default first 'java' command found on the PATH
39
                 is taken (unless JAVA_HOME is also specified).
39
                 is taken (unless JAVA_HOME is also specified).
40
  JAVA_HOME      home of the Java environment. If not specified,
40
  JAVA_HOME      home of the Java environment. If not specified,
41
                 it will be detected automatically from the Java
41
                 it will be detected automatically from the Java
42
                 interpreter.
42
                 interpreter.
43
  JAVAC          path to a Java compiler
43
  JAVAC          path to a Java compiler
44
  JAVAH          path to a Java header/stub generator
44
  JAVAH          path to a Java header/stub generator
45
  JAR            path to a Java archive tool
45
  JAR            path to a Java archive tool
46
 
46
 
47
The following variables should be used with extreme caution. They
47
The following variables should be used with extreme caution. They
48
must all match, so use only if you have a very special setup that
48
must all match, so use only if you have a very special setup that
49
javareconf cannot detect automatically:
49
javareconf cannot detect automatically:
50
  JAVA_LD_LIBRARY_PATH library path necessary at run-time
50
  JAVA_LD_LIBRARY_PATH library path necessary at run-time
51
  JAVA_CPPFLAGS  C preprocessor flags necessary to compile JNI programs
51
  JAVA_CPPFLAGS  C preprocessor flags necessary to compile JNI programs
52
  JAVA_LIBS      libraries (as linker flags) necessary to compile
52
  JAVA_LIBS      libraries (as linker flags) necessary to compile
53
                 JNI programs
53
                 JNI programs
54
 
54
 
55
Report bugs at bugs.r-project.org ."
55
Report bugs at bugs.r-project.org ."
56
 
56
 
57
 
57
 
58
dry_run=no
58
dry_run=no
59
export_vars=no
59
export_vars=no
60
while test -n "${1}"; do
60
while test -n "${1}"; do
61
    case ${1} in
61
    case ${1} in
62
	-help | --help | -h) echo "${usage}"; exit 0 ;;
62
	-help | --help | -h) echo "${usage}"; exit 0 ;;
63
	-v | --version) echo "${version}"; exit 0 ;;
63
	-v | --version) echo "${version}"; exit 0 ;;
64
	-n | --dry-run) dry_run=yes ;;
64
	-n | --dry-run) dry_run=yes ;;
65
	-e) dry_run=yes; export_vars=yes; run_prog="${2}"; if test "$#" != 1; then shift; fi ;;
65
	-e) dry_run=yes; export_vars=yes; run_prog="${2}"; if test "$#" != 1; then shift; fi ;;
66
	*=*) eval ${1} ;;
66
	*=*) eval ${1} ;;
67
    esac
67
    esac
68
    shift
68
    shift
69
done
69
done
70
 
70
 
71
## find java compiler binaries
71
## find java compiler binaries
72
if test -z "${JAVA_HOME}" ; then
72
if test -z "${JAVA_HOME}" ; then
73
    JAVA_PATH=${PATH}
73
    JAVA_PATH=${PATH}
74
else
74
else
75
    if test ! -d "${JAVA_HOME}"; then
75
    if test ! -d "${JAVA_HOME}"; then
76
	echo "*** JAVA_HOME is not a valid path, ignoring"
76
	echo "*** JAVA_HOME is not a valid path, ignoring"
77
	JAVA_HOME=
77
	JAVA_HOME=
78
	JAVA_PATH=${PATH}
78
	JAVA_PATH=${PATH}
79
    else
79
    else
80
	## try jre/bin first just in case we don't have full JDK
80
	## try jre/bin first just in case we don't have full JDK
81
	JAVA_PATH=${JAVA_HOME}:${JAVA_HOME}/jre/bin:${JAVA_HOME}/bin:${JAVA_HOME}/../bin:${PATH}
81
	JAVA_PATH=${JAVA_HOME}:${JAVA_HOME}/jre/bin:${JAVA_HOME}/bin:${JAVA_HOME}/../bin:${PATH}
82
    fi
82
    fi
83
fi
83
fi
84
## if 'java' is not on the PATH or JAVA_HOME, add some guesses as of
84
## if 'java' is not on the PATH or JAVA_HOME, add some guesses as of
85
## where java could live
85
## where java could live
86
JAVA_PATH=${JAVA_PATH}:/usr/java/bin:/usr/jdk/bin:/usr/lib/java/bin:/usr/lib/jdk/bin:/usr/local/java/bin:/usr/local/jdk/bin:/usr/local/lib/java/bin:/usr/local/lib/jdk/bin
86
JAVA_PATH=${JAVA_PATH}:/usr/java/bin:/usr/jdk/bin:/usr/lib/java/bin:/usr/lib/jdk/bin:/usr/local/java/bin:/usr/local/jdk/bin:/usr/local/lib/java/bin:/usr/local/lib/jdk/bin
87
 
87
 
88
if test -z "$JAVA"; then
88
if test -z "$JAVA"; then
89
    save_IFS=$IFS; IFS=:
89
    save_IFS=$IFS; IFS=:
90
    for dir in ${JAVA_PATH}; do
90
    for dir in ${JAVA_PATH}; do
91
	if test -f "$dir/java"; then
91
	if test -f "$dir/java"; then
92
	    JAVA="$dir/java"
92
	    JAVA="$dir/java"
93
	    break
93
	    break
94
	fi
94
	fi
95
    done
95
    done
96
    IFS=${save_IFS}
96
    IFS=${save_IFS}
97
fi
97
fi
98
 
98
 
99
if test -z "$JAVA"; then
99
if test -z "$JAVA"; then
100
    echo "~*** Cannot find any Java interpreter~*** Please make sure 'java' is on your PATH or set JAVA_HOME correspondingly"|${SED-sed} -e 'y/~/\n/' >&2
100
    echo "~*** Cannot find any Java interpreter~*** Please make sure 'java' is on your PATH or set JAVA_HOME correspondingly"|${SED-sed} -e 'y/~/\n/' >&2
101
    exit 1
101
    exit 1
102
fi
102
fi
103
 
103
 
104
echo "Java interpreter : $JAVA"
104
echo "Java interpreter : $JAVA"
105
jires=`$JAVA -classpath ${tools_classpath} getsp -test`
105
jires=`$JAVA -classpath ${tools_classpath} getsp -test`
106
if test "$jires" != "Test1234OK"; then
106
if test "$jires" != "Test1234OK"; then
107
    echo "$jires"
107
    echo "$jires"
108
    echo "~*** Java interpreter doesn't work properly.~"|${SED-sed} -e 'y/~/\n/' >&2
108
    echo "~*** Java interpreter doesn't work properly.~"|${SED-sed} -e 'y/~/\n/' >&2
109
    exit 1
109
    exit 1
110
fi
110
fi
111
 
111
 
112
if test -z "${JAVA_HOME}"; then
112
if test -z "${JAVA_HOME}"; then
113
    JAVA_HOME=`$JAVA -classpath ${tools_classpath} getsp java.home`
113
    JAVA_HOME=`$JAVA -classpath ${tools_classpath} getsp java.home`
114
fi
114
fi
115
 
115
 
116
if test -z "${JAVA_HOME}"; then
116
if test -z "${JAVA_HOME}"; then
117
    echo "~*** Cannot find Java environemnt.~*** Please set JAVA_HOME correspondingly.~"|${SED-sed} -e 'y/~/\n/' >&2
117
    echo "~*** Cannot find Java environemnt.~*** Please set JAVA_HOME correspondingly.~"|${SED-sed} -e 'y/~/\n/' >&2
118
    exit 1
118
    exit 1
119
fi
119
fi
120
 
120
 
121
echo "Java version     : `$JAVA -classpath ${tools_classpath} getsp java.version 2>/dev/null`"
121
echo "Java version     : `$JAVA -classpath ${tools_classpath} getsp java.version 2>/dev/null`"
122
echo "Java home path   : ${JAVA_HOME}"
122
echo "Java home path   : ${JAVA_HOME}"
123
 
123
 
124
# optional parts - compiler, javah and jar
124
# optional parts - compiler, javah and jar
125
if test -z "$JAVAC"; then
125
if test -z "$JAVAC"; then
126
    save_IFS=$IFS; IFS=:
126
    save_IFS=$IFS; IFS=:
127
    for dir in ${JAVA_PATH}; do
127
    for dir in ${JAVA_PATH}; do
128
	if test -f "$dir/javac"; then
128
	if test -f "$dir/javac"; then
129
	    JAVAC="$dir/javac"
129
	    JAVAC="$dir/javac"
130
	    break
130
	    break
131
	fi
131
	fi
132
    done
132
    done
133
    IFS=${save_IFS}
133
    IFS=${save_IFS}
134
fi
134
fi
135
 
135
 
136
: ${TMPDIR=/tmp}
136
: ${TMPDIR=/tmp}
137
{ tempdir=`(mktemp -d -q "${TMPDIR}/Rjavareconf.XXXXXX") 2>/dev/null` \
137
{ tempdir=`(mktemp -d -q "${TMPDIR}/Rjavareconf.XXXXXX") 2>/dev/null` \
138
	&& test -n "${tempdir}" && test -d "${tempdir}" ; } ||
138
	&& test -n "${tempdir}" && test -d "${tempdir}" ; } ||
139
{ test -n "${RANDOM}" && tempdir=${TMPDIR}/Rjavareconf.$$-${RANDOM} \
139
{ test -n "${RANDOM}" && tempdir=${TMPDIR}/Rjavareconf.$$-${RANDOM} \
140
	&& (mkdir "${tempdir}") ; } ||
140
	&& (mkdir "${tempdir}") ; } ||
141
{ tempdir=${TMPDIR}/Rjavareconf.$$-`date +%m%d%H%M%S` \
141
{ tempdir=${TMPDIR}/Rjavareconf.$$-`date +%m%d%H%M%S` \
142
	&& (mkdir "${tempdir}"); } ||
142
	&& (mkdir "${tempdir}"); } ||
143
{ tempdir=${TMPDIR}/Rjavareconf.$$ && (mkdir "${tempdir}") ; } ||
143
{ tempdir=${TMPDIR}/Rjavareconf.$$ && (mkdir "${tempdir}") ; } ||
144
    (error "cannot create temporary directory" && exit 1)
144
    (error "cannot create temporary directory" && exit 1)
145
 
145
 
146
# test functionality of the compiler
146
# test functionality of the compiler
147
javac_works='not present'
147
javac_works='not present'
148
if test -n "$JAVAC"; then
148
if test -n "$JAVAC"; then
149
    javac_works='not functional'
149
    javac_works='not functional'
150
    echo "public class A { }" > ${tempdir}/A.java
150
    echo "public class A { }" > ${tempdir}/A.java
151
    if test -f ${tempdir}/A.java; then
151
    if test -f ${tempdir}/A.java; then
152
	if "${JAVAC}" ${tempdir}/A.java >/dev/null; then
152
	if "${JAVAC}" ${tempdir}/A.java >/dev/null; then
153
           if test -f ${tempdir}/A.class; then
153
           if test -f ${tempdir}/A.class; then
154
		javac_works=yes
154
		javac_works=yes
155
	    fi
155
	    fi
156
	fi
156
	fi
157
    fi
157
    fi
158
fi
158
fi
159
if test "${javac_works}" = yes; then
159
if test "${javac_works}" = yes; then
160
    echo "Java compiler    : ${JAVAC}"
160
    echo "Java compiler    : ${JAVAC}"
161
else
161
else
162
    echo "Java compiler    : ${javac_works}"
162
    echo "Java compiler    : ${javac_works}"
163
fi
163
fi
164
 
164
 
165
if test -z "$JAVAH"; then
165
if test -z "$JAVAH"; then
166
    save_IFS=$IFS; IFS=:
166
    save_IFS=$IFS; IFS=:
167
    for dir in ${JAVA_PATH}; do
167
    for dir in ${JAVA_PATH}; do
168
	if test -f "$dir/javah"; then
168
	if test -f "$dir/javah"; then
169
	    JAVAH="$dir/javah"
169
	    JAVAH="$dir/javah"
170
	    break
170
	    break
171
	fi
171
	fi
172
    done
172
    done
173
    IFS=${save_IFS}
173
    IFS=${save_IFS}
174
fi
174
fi
175
echo "Java headers gen.: ${JAVAH}"
175
echo "Java headers gen.: ${JAVAH}"
176
 
176
 
177
if test -z "$JAR"; then
177
if test -z "$JAR"; then
178
    save_IFS=$IFS; IFS=:
178
    save_IFS=$IFS; IFS=:
179
    for dir in ${JAVA_PATH}; do
179
    for dir in ${JAVA_PATH}; do
180
	if test -f "$dir/jar"; then
180
	if test -f "$dir/jar"; then
181
	    JAR="$dir/jar"
181
	    JAR="$dir/jar"
182
	    break
182
	    break
183
	fi
183
	fi
184
    done
184
    done
185
    IFS=${save_IFS}
185
    IFS=${save_IFS}
186
fi
186
fi
187
echo "Java archive tool: ${JAR}"
187
echo "Java archive tool: ${JAR}"
188
 
188
 
189
: ${JAVA_LIBS=~autodetect~}
189
: ${JAVA_LIBS=~autodetect~}
190
: ${JAVA_CPPFLAGS=~autodetect~}
190
: ${JAVA_CPPFLAGS=~autodetect~}
191
: ${JAVA_LD_LIBRARY_PATH=~autodetect~}
191
: ${JAVA_LD_LIBRARY_PATH=~autodetect~}
192
custom_JAVA_LIBS="${JAVA_LIBS}"
192
custom_JAVA_LIBS="${JAVA_LIBS}"
193
custom_JAVA_CPPFLAGS="${JAVA_CPPFLAGS}"
193
custom_JAVA_CPPFLAGS="${JAVA_CPPFLAGS}"
194
custom_JAVA_LD_LIBRARY_PATH="${JAVA_LD_LIBRARY_PATH}"
194
custom_JAVA_LD_LIBRARY_PATH="${JAVA_LD_LIBRARY_PATH}"
195
 
195
 
196
 
196
 
197
# sys-dependent tweaks to JNI flags
197
# sys-dependent tweaks to JNI flags
198
hostos=`uname 2>/dev/null`
198
hostos=`uname 2>/dev/null`
199
if test "${hostos}" = "Darwin"; then
199
if test "${hostos}" = "Darwin"; then
200
     pref=`echo "${JAVA_HOME}" | grep "/Home$"`
200
     pref=`echo "${JAVA_HOME}" | grep "/Home$"`
201
     if test "${pref}" = "${JAVA_HOME}"; then 
201
     if test "${pref}" = "${JAVA_HOME}"; then 
202
       echo "System Java on OS X"
202
       echo "System Java on OS X"
203
       JAVA_CPPFLAGS="-I/System/Library/Frameworks/JavaVM.framework/Headers"
203
       JAVA_CPPFLAGS="-I/System/Library/Frameworks/JavaVM.framework/Headers"
204
       JAVA_LIBS="-framework JavaVM"
204
       JAVA_LIBS="-framework JavaVM"
205
       JAVA_LD_LIBRARY_PATH=
205
       JAVA_LD_LIBRARY_PATH=
206
	has_libjvm=unknown
206
	has_libjvm=unknown
207
    else
207
    else
208
       echo "Non-system Java on OS X"
208
       echo "Non-system Java on OS X"
209
    fi
209
    fi
210
fi
210
fi
211
## we now look for a path to put in R_LD_LIBRARY_PATH which will
211
## we now look for a path to put in R_LD_LIBRARY_PATH which will
212
## enable libjvm to be found at run time.  This should not be needed,
212
## enable libjvm to be found at run time.  This should not be needed,
213
## but it seems that libjvm is often not in the ld.so cache.
213
## but it seems that libjvm is often not in the ld.so cache.
214
if test "${JAVA_LIBS}" = "~autodetect~"; then
214
if test "${JAVA_LIBS}" = "~autodetect~"; then
215
	## we need to reset LD_LIBRARY_PATH, because Java automatically
215
	## we need to reset LD_LIBRARY_PATH, because Java automatically
216
	## adds all LD_LIBRARY_PATH to Java path
216
	## adds all LD_LIBRARY_PATH to Java path
217
	save_LDLP=${LD_LIBRARY_PATH}
217
	save_LDLP=${LD_LIBRARY_PATH}
218
	LD_LIBRARY_PATH=
218
	LD_LIBRARY_PATH=
219
	export LD_LIBRARY_PATH
219
	export LD_LIBRARY_PATH
220
	# remove trailing/leading : (if any)
220
	# remove trailing/leading : (if any)
221
	java_library_path=`"$JAVA" -classpath "${tools_classpath}" getsp java.library.path| ${SED-sed} -e 's/:$//' -e 's/^://'`
221
	java_library_path=`"$JAVA" -classpath "${tools_classpath}" getsp java.library.path| ${SED-sed} -e 's/:$//' -e 's/^://'`
222
	## see if libjvm is on this path: it is not for recent Oracle Java
222
	## see if libjvm is on this path: it is not for recent Oracle Java
223
	has_libjvm=no
223
	has_libjvm=no
224
	save_IFS=$IFS; IFS=:
224
	save_IFS=$IFS; IFS=:
225
	for dir in ${java_library_path}; do
225
	for dir in ${java_library_path}; do
226
	    if test -f "$dir/libjvm${DYLIB_EXT}"; then
226
	    if test -f "$dir/libjvm${DYLIB_EXT}"; then
227
		has_libjvm=yes
227
		has_libjvm=yes
228
		java_library_path="${dir}"
228
		java_library_path="${dir}"
229
		break
229
		break
230
	    fi
230
	    fi
231
	done
231
	done
232
	# Then try some heuristics using sun.boot.library.path
232
	# Then try some heuristics using sun.boot.library.path
233
	if test ${has_libjvm} = no; then
233
	if test ${has_libjvm} = no; then
234
	    boot_path=`"$JAVA" -classpath "${tools_classpath}" getsp sun.boot.library.path| ${SED-sed} -e 's/:$//' -e 's/^://'`
234
	    boot_path=`"$JAVA" -classpath "${tools_classpath}" getsp sun.boot.library.path| ${SED-sed} -e 's/:$//' -e 's/^://'`
235
	    if test -n "${boot_path}"; then
235
	    if test -n "${boot_path}"; then
236
		for dir in "${boot_path}" "${boot_path}/client" "${boot_path}/server"; do
236
		for dir in "${boot_path}" "${boot_path}/client" "${boot_path}/server"; do
237
		    if test -f "$dir/libjvm${DYLIB_EXT}"; then
237
		    if test -f "$dir/libjvm${DYLIB_EXT}"; then
238
			has_libjvm=yes
238
			has_libjvm=yes
239
			java_library_path="${dir}"
239
			java_library_path="${dir}"
240
			break
240
			break
241
		    fi
241
		    fi
242
		done
242
		done
243
	    fi
243
	    fi
244
	fi	
244
	fi	
245
	IFS=${save_IFS}
245
	IFS=${save_IFS}
246
	# replace occurrences of JAVA_HOME with $(JAVA_HOME)
246
	# replace occurrences of JAVA_HOME with $(JAVA_HOME)
247
	JAVA_LD_LIBRARY_PATH=`echo "${java_library_path}" | ${SED-sed} -e" s:${JAVA_HOME}:\$\(JAVA_HOME\):g"`
247
	JAVA_LD_LIBRARY_PATH=`echo "${java_library_path}" | ${SED-sed} -e" s:${JAVA_HOME}:\$\(JAVA_HOME\):g"`
248
	
248
	
249
	LD_LIBRARY_PATH=${save_LDLP}
249
	LD_LIBRARY_PATH=${save_LDLP}
250
	export LD_LIBRARY_PATH
250
	export LD_LIBRARY_PATH
251
	# build JAVA_LIBS from the detected path
251
	# build JAVA_LIBS from the detected path
252
	JAVA_LIBS=`echo ${JAVA_LD_LIBRARY_PATH}|${SED-sed} -e 's|:| -L|g'`
252
	JAVA_LIBS=`echo ${JAVA_LD_LIBRARY_PATH}|${SED-sed} -e 's|:| -L|g'`
253
	if test -n "${JAVA_LIBS}"; then JAVA_LIBS="-L${JAVA_LIBS}"; fi
253
	if test -n "${JAVA_LIBS}"; then JAVA_LIBS="-L${JAVA_LIBS}"; fi
254
	JAVA_LIBS="${JAVA_LIBS} -ljvm"
254
	JAVA_LIBS="${JAVA_LIBS} -ljvm"
255
	# create shell-version to be used in scripts
255
	# create shell-version to be used in scripts
256
	JAVA_LD_LIBRARY_PATH_SH=`echo ${JAVA_LD_LIBRARY_PATH}|${SED-sed} -e 's:$(JAVA_HOME):\$\{JAVA_HOME\}:g'`
256
	JAVA_LD_LIBRARY_PATH_SH=`echo ${JAVA_LD_LIBRARY_PATH}|${SED-sed} -e 's:$(JAVA_HOME):\$\{JAVA_HOME\}:g'`
257
 
257
 
258
        ## includes consist of two parts - jni.h and machine-dependent jni_md.h
258
        ## includes consist of two parts - jni.h and machine-dependent jni_md.h
259
        jinc=''
259
        jinc=''
260
	JAVA_CPPFLAGS=''
260
	JAVA_CPPFLAGS=''
261
        for pinc in include ../include jre/include; do
261
        for pinc in include ../include jre/include; do
262
          if test -f "${JAVA_HOME}/${pinc}/jni.h"; then jinc="${JAVA_HOME}/${pinc}"; break; fi
262
          if test -f "${JAVA_HOME}/${pinc}/jni.h"; then jinc="${JAVA_HOME}/${pinc}"; break; fi
263
        done
263
        done
264
        ## only if we get jni.h we can try to find jni_md.h
264
        ## only if we get jni.h we can try to find jni_md.h
265
        if test -n "${jinc}"; then
265
        if test -n "${jinc}"; then
266
           JAVA_CPPFLAGS="-I${jinc}"
266
           JAVA_CPPFLAGS="-I${jinc}"
267
           jmdinc=''
267
           jmdinc=''
268
           jmdirs=''
268
           jmdirs=''
269
	   ## we are not in configure, so we need to find the OS from R
269
	   ## we are not in configure, so we need to find the OS from R
270
	   host_os=`echo 'cat(R.version$os)'|${R_HOME}/bin/R --vanilla --slave 2>/dev/null`
270
	   host_os=`echo 'cat(R.version$os)'|${R_HOME}/bin/R --vanilla --slave 2>/dev/null`
271
           ## put the most probable locations for each system in the first place
271
           ## put the most probable locations for each system in the first place
272
           case "${host_os}" in
272
           case "${host_os}" in
273
             darwin*)  jmdirs=darwin;;
273
             darwin*)  jmdirs=darwin;;
274
             linux*)   jmdirs=linux;;
274
             linux*)   jmdirs=linux;;
275
             bsdi*)    jmdirs=bsdos;;
275
             bsdi*)    jmdirs=bsdos;;
276
             osf*)     jmdirs=alpha;;
276
             osf*)     jmdirs=alpha;;
277
             solaris*) jmdirs=solaris;;
277
             solaris*) jmdirs=solaris;;
278
             freebsd*) jmdirs=freebsd; add_java_libs='-lpthread';;
278
             freebsd*) jmdirs=freebsd; add_java_libs='-lpthread';;
279
           esac
279
           esac
280
	   ## in case host_os detection failed, add all candidates
280
	   ## in case host_os detection failed, add all candidates
281
	   if test -z "${jmdirs}"; then jmdirs='linux solaris freebsd alpha bsdos'; fi
281
	   if test -z "${jmdirs}"; then jmdirs='linux solaris freebsd alpha bsdos'; fi
282
           ## prepend . and append less-likely ones
282
           ## prepend . and append less-likely ones
283
           jmdirs=". ${jmdirs} genunix ppc x86 iris hp-ux aix win32 cygwin openbsd"
283
           jmdirs=". ${jmdirs} genunix ppc x86 iris hp-ux aix win32 cygwin openbsd"
284
           for pimd in ${jmdirs}; do
284
           for pimd in ${jmdirs}; do
285
             if test -f "${jinc}/${pimd}/jni_md.h"; then jmdinc="${jinc}/${pimd}"; break; fi
285
             if test -f "${jinc}/${pimd}/jni_md.h"; then jmdinc="${jinc}/${pimd}"; break; fi
286
           done
286
           done
287
           if test -z "${jmdinc}"; then
287
           if test -z "${jmdinc}"; then
288
             # ultima-ratio: use find and pray that it works
288
             # ultima-ratio: use find and pray that it works
289
             jmdinc=`find "${jinc}/" -name jni_md.h 2> /dev/null |head -n 1 2>/dev/null`
289
             jmdinc=`find "${jinc}/" -name jni_md.h 2> /dev/null |head -n 1 2>/dev/null`
290
             if test -n "${jmdinc}"; then jmdinc=`dirname "${jmdinc}"`; fi
290
             if test -n "${jmdinc}"; then jmdinc=`dirname "${jmdinc}"`; fi
291
           fi
291
           fi
292
           if test -n "${jmdinc}"; then
292
           if test -n "${jmdinc}"; then
293
             if test "${jmdinc}" != "${jinc}/."; then
293
             if test "${jmdinc}" != "${jinc}/."; then
294
               JAVA_CPPFLAGS="${JAVA_CPPFLAGS} -I${jmdinc}"
294
               JAVA_CPPFLAGS="${JAVA_CPPFLAGS} -I${jmdinc}"
295
             fi
295
             fi
296
           fi
296
           fi
297
	   JAVA_CPPFLAGS=`echo ${JAVA_CPPFLAGS} | ${SED-sed} -e s:${JAVA_HOME}:\$\(JAVA_HOME\):g`
297
	   JAVA_CPPFLAGS=`echo ${JAVA_CPPFLAGS} | ${SED-sed} -e s:${JAVA_HOME}:\$\(JAVA_HOME\):g`
298
        fi
298
        fi
299
fi
299
fi
300
 
300
 
301
if test -n "${add_java_libs}"; then JAVA_LIBS="${JAVA_LIBS} ${add_java_libs}"; fi
301
if test -n "${add_java_libs}"; then JAVA_LIBS="${JAVA_LIBS} ${add_java_libs}"; fi
302
 
302
 
303
## honor user overrides
303
## honor user overrides
304
acx_custom_java_libs=no
304
acx_custom_java_libs=no
305
if test "${custom_JAVA_LIBS}" != '~autodetect~'; then
305
if test "${custom_JAVA_LIBS}" != '~autodetect~'; then
306
  JAVA_LIBS="${custom_JAVA_LIBS}"
306
  JAVA_LIBS="${custom_JAVA_LIBS}"
307
  JAVA_LIBS0=`echo ${JAVA_LIBS} | ${SED-sed} -e s:${JAVA_HOME}:\$\(JAVA_HOME\):g`
307
  JAVA_LIBS0=`echo ${JAVA_LIBS} | ${SED-sed} -e s:${JAVA_HOME}:\$\(JAVA_HOME\):g`
308
  acx_custom_java_libs=yes
308
  acx_custom_java_libs=yes
309
fi
309
fi
310
if test "${custom_JAVA_CPPFLAGS}" != '~autodetect~'; then
310
if test "${custom_JAVA_CPPFLAGS}" != '~autodetect~'; then
311
  JAVA_CPPFLAGS="${custom_JAVA_CPPFLAGS}"
311
  JAVA_CPPFLAGS="${custom_JAVA_CPPFLAGS}"
312
fi
312
fi
313
if test "${custom_JAVA_LD_LIBRARY_PATH}" != '~autodetect~'; then
313
if test "${custom_JAVA_LD_LIBRARY_PATH}" != '~autodetect~'; then
314
  JAVA_LD_LIBRARY_PATH="${custom_JAVA_LD_LIBRARY_PATH}"
314
  JAVA_LD_LIBRARY_PATH="${custom_JAVA_LD_LIBRARY_PATH}"
315
  JAVA_LD_LIBRARY_PATH_SH=`echo ${JAVA_LD_LIBRARY_PATH}|${SED-sed} -e 's:$(JAVA_HOME):\$\{JAVA_HOME\}:g'`
315
  JAVA_LD_LIBRARY_PATH_SH=`echo ${JAVA_LD_LIBRARY_PATH}|${SED-sed} -e 's:$(JAVA_HOME):\$\{JAVA_HOME\}:g'`
316
fi
316
fi
317
 
317
 
318
## Do cpmpile test in the temporary dir
318
## Do cpmpile test in the temporary dir
319
wd=${PWD}
319
wd=${PWD}
320
cd ${tempdir}
320
cd ${tempdir}
321
 
321
 
322
echo
322
echo
323
echo "trying to compile and link a JNI progam "
323
echo "trying to compile and link a JNI progam "
324
echo "detected JNI cpp flags    : ${JAVA_CPPFLAGS}"
324
echo "detected JNI cpp flags    : ${JAVA_CPPFLAGS}"
325
echo "detected JNI linker flags : ${JAVA_LIBS}"
325
echo "detected JNI linker flags : ${JAVA_LIBS}"
326
 
326
 
327
cat <<_ACEOF >conftest.c
327
cat <<_ACEOF >conftest.c
328
#include <jni.h>
328
#include <jni.h>
329
 
329
 
330
int main(void) {
330
int main(void) {
331
    JNI_CreateJavaVM(0, 0, 0);
331
    JNI_CreateJavaVM(0, 0, 0);
332
    return 0;
332
    return 0;
333
}
333
}
334
_ACEOF
334
_ACEOF
335
 
335
 
336
JAVA_CPPFLAGS1=`echo ${JAVA_CPPFLAGS}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
336
JAVA_CPPFLAGS1=`echo ${JAVA_CPPFLAGS}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
337
JAVA_LIBS1=`echo ${JAVA_LIBS}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
337
JAVA_LIBS1=`echo ${JAVA_LIBS}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
338
cat <<_ACEOF >Makevars
338
cat <<_ACEOF >Makevars
339
PKG_CPPFLAGS = ${JAVA_CPPFLAGS1}
339
PKG_CPPFLAGS = ${JAVA_CPPFLAGS1}
340
PKG_LIBS = ${JAVA_LIBS1}
340
PKG_LIBS = ${JAVA_LIBS1}
341
_ACEOF
341
_ACEOF
342
 
342
 
343
## in case e.g. -k was passed in the environment
343
## in case e.g. -k was passed in the environment
344
export MAKEFLAGS=
344
export MAKEFLAGS=
345
${R_HOME}/bin/R CMD SHLIB conftest.c
345
${R_HOME}/bin/R CMD SHLIB conftest.c
346
ac_status=$?
346
ac_status=$?
347
 
347
 
348
if test $ac_status != 0; then
348
if test $ac_status != 0; then
349
  echo "Unable to compile a JNI program"
349
  echo "Unable to compile a JNI program"
350
  JAVA_LD_LIBRARY_PATH=
350
  JAVA_LD_LIBRARY_PATH=
351
  JAVA_LIBS=
351
  JAVA_LIBS=
352
  JAVA_CPPFLAGS=
352
  JAVA_CPPFLAGS=
353
fi
353
fi
354
 
354
 
355
rm -f conftest.c conftest.o conftest.so Makevars
355
rm -f conftest.c conftest.o conftest.so Makevars
356
cd ${wd}
356
cd ${wd}
357
rm -rf ${tempdir}
357
rm -rf ${tempdir}
358
 
358
 
359
 
359
 
360
echo ""
360
echo ""
361
 
361
 
362
if test "${export_vars}" = yes; then
362
if test "${export_vars}" = yes; then
363
    ## we have to re-substitute $(JAVA_HOME), otherwise it will be replaced by R's
363
    ## we have to re-substitute $(JAVA_HOME), otherwise it will be replaced by R's
364
    ## Makeconf setting which is highly likely different and thus not intended
364
    ## Makeconf setting which is highly likely different and thus not intended
365
    JAVA_LD_LIBRARY_PATH=`echo ${JAVA_LD_LIBRARY_PATH}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
365
    JAVA_LD_LIBRARY_PATH=`echo ${JAVA_LD_LIBRARY_PATH}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
366
    JAVA_CPPFLAGS=`echo ${JAVA_CPPFLAGS}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
366
    JAVA_CPPFLAGS=`echo ${JAVA_CPPFLAGS}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
367
    JAVA_LIBS=`echo ${JAVA_LIBS}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
367
    JAVA_LIBS=`echo ${JAVA_LIBS}|${SED-sed} -e 's:$(JAVA_HOME):'"${JAVA_HOME}:g"`
368
 
368
 
369
    export JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH
369
    export JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH
370
    echo "The following Java variables have been exported:"
370
    echo "The following Java variables have been exported:"
371
    echo "JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH"
371
    echo "JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH"
372
    test -z "${run_prog}" && test -n "${SHELL}" && run_prog="${SHELL}"
372
    test -z "${run_prog}" && test -n "${SHELL}" && run_prog="${SHELL}"
373
    test -z "${run_prog}" && run_prog=/bin/sh
373
    test -z "${run_prog}" && run_prog=/bin/sh
374
    echo "Running: ${run_prog}"
374
    echo "Running: ${run_prog}"
375
    ${run_prog}
375
    ${run_prog}
376
    exit 0
376
    exit 0
377
fi
377
fi
378
 
378
 
379
echo ""
379
echo ""
380
echo "Java library path: ${JAVA_LD_LIBRARY_PATH}"
380
echo "Java library path: ${JAVA_LD_LIBRARY_PATH}"
381
echo "JNI cpp flags    : ${JAVA_CPPFLAGS}"
381
echo "JNI cpp flags    : ${JAVA_CPPFLAGS}"
382
echo "JNI linker flags : ${JAVA_LIBS}"
382
echo "JNI linker flags : ${JAVA_LIBS}"
383
 
383
 
384
test "${dry_run}" = yes && exit 0
384
test "${dry_run}" = yes && exit 0
385
 
385
 
386
echo "Updating Java configuration in ${R_HOME}"
386
echo "Updating Java configuration in ${R_HOME}"
387
 
387
 
388
## We update both the base and arch-specific versions as etc/Makefile
388
## We update both the base and arch-specific versions as etc/Makefile
389
## copies the first to the second (only the second is used).
389
## copies the first to the second (only the second is used).
390
if test -n "${R_ARCH}"; then
390
if test -n "${R_ARCH}"; then
391
  files="${R_HOME}/etc/Makeconf ${R_HOME}/etc/ldpaths ${R_HOME}/etc${R_ARCH}/Makeconf ${R_HOME}/etc${R_ARCH}/ldpaths"
391
  files="${R_HOME}/etc/Makeconf ${R_HOME}/etc/ldpaths ${R_HOME}/etc${R_ARCH}/Makeconf ${R_HOME}/etc${R_ARCH}/ldpaths"
392
else
392
else
393
  files="${R_HOME}/etc/Makeconf ${R_HOME}/etc/ldpaths"
393
  files="${R_HOME}/etc/Makeconf ${R_HOME}/etc/ldpaths"
394
fi
394
fi
395
for file in $files; do
395
for file in $files; do
396
    ${SED-sed} -e "s|JAVA =.\{0,\}|JAVA = $JAVA|" -e "s|JAVA_HOME =.\{0,\}|JAVA_HOME = ${JAVA_HOME}|" -e "s|: \${JAVA_HOME=.\{1,\}|: \${JAVA_HOME=${JAVA_HOME}}|" -e "s|: \${R_JAVA_LD_LIBRARY_PATH=.\{1,\}|: \${R_JAVA_LD_LIBRARY_PATH=${JAVA_LD_LIBRARY_PATH_SH}}|" -e "s|JAVA_LIBS =.\{0,\}|JAVA_LIBS = ${JAVA_LIBS}|g" -e "s|JAVA_LD_LIBRARY_PATH =.\{0,\}|JAVA_LD_LIBRARY_PATH = ${JAVA_LD_LIBRARY_PATH}|" -e "s|JAVAC =.\{0,\}|JAVAC = $JAVAC|" -e "s|JAVAH =.\{0,\}|JAVAH = $JAVAH|" -e "s|JAR =.\{0,\}|JAR = $JAR|" -e "s|JAVA_CPPFLAGS =.\{0,\}|JAVA_CPPFLAGS = ${JAVA_CPPFLAGS}|g"  "${file}" > "${file}.new"
396
    ${SED-sed} -e "s|JAVA =.\{0,\}|JAVA = $JAVA|" -e "s|JAVA_HOME =.\{0,\}|JAVA_HOME = ${JAVA_HOME}|" -e "s|: \${JAVA_HOME=.\{1,\}|: \${JAVA_HOME=${JAVA_HOME}}|" -e "s|: \${R_JAVA_LD_LIBRARY_PATH=.\{1,\}|: \${R_JAVA_LD_LIBRARY_PATH=${JAVA_LD_LIBRARY_PATH_SH}}|" -e "s|JAVA_LIBS =.\{0,\}|JAVA_LIBS = ${JAVA_LIBS}|g" -e "s|JAVA_LD_LIBRARY_PATH =.\{0,\}|JAVA_LD_LIBRARY_PATH = ${JAVA_LD_LIBRARY_PATH}|" -e "s|JAVAC =.\{0,\}|JAVAC = $JAVAC|" -e "s|JAVAH =.\{0,\}|JAVAH = $JAVAH|" -e "s|JAR =.\{0,\}|JAR = $JAR|" -e "s|JAVA_CPPFLAGS =.\{0,\}|JAVA_CPPFLAGS = ${JAVA_CPPFLAGS}|g"  "${file}" > "${file}.new"
397
    if test -f "${file}.new"; then
397
    if test -f "${file}.new"; then
398
	mv "${file}" "${file}.old"
398
	mv "${file}" "${file}.old"
399
	mv "${file}.new" "${file}"
399
	mv "${file}.new" "${file}"
400
    else
400
    else
401
	echo "*** cannot create ${file}.new~*** Please run as root if required.~" | ${SED-sed} -e 'y/~/\n/' >&2
401
	echo "*** cannot create ${file}.new~*** Please run as root if required.~" | ${SED-sed} -e 'y/~/\n/' >&2
402
	exit 1
402
	exit 1
403
    fi
403
    fi
404
done
404
done
405
 
405
 
406
echo "Done."
406
echo "Done."
407
echo ''
407
echo ''
-
 
408
 
-
 
409
### Local Variables: ***
-
 
410
### mode: sh ***
-
 
411
### sh-indentation: 2 ***
-
 
412
### End: ***