@@ -13,92 +13,237 @@ dnl All rights reserved.
1313dnl Copyright (c) 2006-2012 Los Alamos National Security, LLC. All rights
1414dnl reserved.
1515dnl Copyright (c) 2007-2012 Oracle and/or its affiliates. All rights reserved.
16- dnl Copyright (c) 2008-2012 Cisco Systems, Inc. All rights reserved.
17- dnl Copyright (c) 2015 Research Organization for Information Science
16+ dnl Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved
17+ dnl Copyright (c) 2013 Intel, Inc. All rights reserved.
18+ dnl Copyright (c) 2015-2018 Research Organization for Information Science
1819dnl and Technology (RIST). All rights reserved.
20+ dnl Copyright (c) 2017 FUJITSU LIMITED. All rights reserved.
1921dnl $COPYRIGHT $
2022dnl
2123dnl Additional copyrights may follow
2224dnl
2325dnl $HEADER $
2426dnl
2527
26- # This macro is necessary to get the title to be displayed first. :-)
27- AC_DEFUN([OMPI_SETUP_JAVA_BINDINGS_BANNER],[
28- opal_show_subtitle " Java MPI bindings"
29- ])
28+ dnl _OMPI_SETUP_JAVA ()
29+ dnl ----------------
30+ dnl Invoked by OMPI_SETUP_JAVA only if --enable-mpi-java was specified.
31+ AC_DEFUN([_OMPI_SETUP_JAVA],[
32+ OPAL_VAR_SCOPE_PUSH([ompi_java_bad ompi_java_found ompi_java_dir ompi_java_jnih ompi_java_PATH_save ompi_java_CPPFLAGS_save])
3033
31- # OMPI_SETUP_JAVA_BINDINGS()
32- # ----------------
33- # Do everything required to setup the Java MPI bindings. Safe to AC_REQUIRE
34- # this macro.
35- AC_DEFUN([OMPI_SETUP_JAVA_BINDINGS],[
36- # must have Java setup
37- AC_REQUIRE([OPAL_SETUP_JAVA])
38-
39- AC_REQUIRE([OMPI_SETUP_JAVA_BINDINGS_BANNER])
40-
41- AC_MSG_CHECKING([if want Java bindings])
42- AC_ARG_ENABLE(mpi-java,
43- AC_HELP_STRING([--enable-mpi-java],
44- [enable Java MPI bindings (default: disabled)]))
45-
46- # check for required support
47- if test " $opal_java_happy " = " no" && test " $enable_mpi_java " = " yes" ; then
48- AC_MSG_RESULT([yes])
49- AC_MSG_WARN([Java bindings requested but no Java support found])
50- AC_MSG_ERROR([cannot continue])
51- fi
34+ # Check for bozo case: ensure a directory was specified
35+ AS_IF([test " $with_jdk_dir " = " yes" || test " $with_jdk_dir " = " no" ],
36+ [AC_MSG_WARN([Must specify a directory name for --with-jdk-dir])
37+ AC_MSG_ERROR([Cannot continue])])
38+ AS_IF([test " $with_jdk_bindir " = " yes" || test " $with_jdk_bindir " = " no" ],
39+ [AC_MSG_WARN([Must specify a directory name for --with-jdk-bindir])
40+ AC_MSG_ERROR([Cannot continue])])
41+ AS_IF([test " $with_jdk_headers " = " yes" || test " $with_jdk_headers " = " no" ],
42+ [AC_MSG_WARN([Must specify a directory name for --with-jdk-headers])
43+ AC_MSG_ERROR([Cannot continue])])
44+
45+ # Check for bozo case: either specify --with-jdk-dir or
46+ # (--with-jdk-bindir, --with-jdk-headers) -- not both.
47+ ompi_java_bad= 0
48+ AS_IF([test -n " $with_jdk_dir " && \
49+ (test -n " $with_jdk_bindir " || test -n " $with_jdk_headers " )],
50+ [ompi_java_bad= 1])
51+ AS_IF([(test -z " $with_jdk_bindir " && test -n " $with_jdk_headers " ) || \
52+ (test -n " $with_jdk_bindir " && test -z " $with_jdk_headers " )],
53+ [ompi_java_bad= 1])
54+ AS_IF([test $ompi_java_bad -eq 1],
55+ [AC_MSG_WARN([Either specify --with-jdk-dir or both of (--with-jdk_bindir, --with-jdk-headers) -- not both.])
56+ AC_MSG_ERROR([Cannot continue])])
57+
58+ AS_IF([test -n " $with_jdk_dir " ],
59+ [with_jdk_bindir= $with_jdk_dir /bin
60+ with_jdk_headers= $with_jdk_dir /include])
61+
62+ # #################################################################
63+ # with_jdk_dir can now be ignored; with_jdk_bindir and
64+ # with_jdk_headers will be either empty or have valid values.
65+ # #################################################################
66+
67+ # Some java installations are in obscure places. So let's
68+ # hard-code a few of the common ones so that users don't have to
69+ # specify --with-java-<foo>=LONG_ANNOYING_DIRECTORY.
70+ AS_IF([test -z " $with_jdk_bindir " ],
71+ [ # OS X/macOS
72+ ompi_java_found= 0
73+ # The following logic was deliberately decided upon in
74+ # https://github.com/open-mpi/ompi/pull/5015 specifically
75+ # to prevent this script and the rest of Open MPI's build
76+ # system from getting confused by the somewhat unorthodox
77+ # Java toolchain layout present on OS X/macOS systems,
78+ # described in depth by
79+ # https://github.com/open-mpi/ompi/pull/5015#issuecomment-379324639,
80+ # and mishandling OS X/macOS Java toolchain path detection
81+ # as a result.
82+ AS_IF([test -x /usr/libexec/java_home],
83+ [ompi_java_dir= ` /usr/libexec/java_home` ],
84+ [ompi_java_dir= /System/Library/Frameworks/JavaVM.framework/Versions/Current])
85+ AC_MSG_CHECKING([for Java in OS X/macOS locations])
86+ AS_IF([test -d $ompi_java_dir ],
87+ [AC_MSG_RESULT([found ($ompi_java_dir )])
88+ ompi_java_found= 1
89+ if test -d " $ompi_java_dir /Headers" && test -d " $ompi_java_dir /Commands" ; then
90+ with_jdk_headers=$ompi_java_dir /Headers
91+ with_jdk_bindir=$ompi_java_dir /Commands
92+ elif test -d " $ompi_java_dir /include" && test -d " $ompi_java_dir /bin" ; then
93+ with_jdk_headers=$ompi_java_dir /include
94+ with_jdk_bindir=$ompi_java_dir /bin
95+ else
96+ AC_MSG_WARN([No recognized OS X/macOS JDK directory structure found under $ompi_java_dir ])
97+ ompi_java_found=0
98+ fi],
99+ [AC_MSG_RESULT([not found])])
100+
101+ if test " $ompi_java_found " = " 0" ; then
102+ # Various Linux
103+ if test -z " $JAVA_HOME " ; then
104+ ompi_java_dir=' /usr/lib/jvm/java-*-openjdk-*/include/'
105+ else
106+ ompi_java_dir=$JAVA_HOME /include
107+ fi
108+ ompi_java_jnih=` ls $ompi_java_dir /jni.h 2> /dev/null | head -n 1`
109+ AC_MSG_CHECKING([for Java in Linux locations])
110+ AS_IF([test -r " $ompi_java_jnih " ],
111+ [with_jdk_headers= ` dirname $ompi_java_jnih `
112+ OPAL_WHICH([javac], [with_jdk_bindir])
113+ AS_IF([test -n " $with_jdk_bindir " ],
114+ [AC_MSG_RESULT([found ($with_jdk_headers )])
115+ ompi_java_found= 1
116+ with_jdk_bindir= ` dirname $with_jdk_bindir ` ],
117+ [with_jdk_headers= ])],
118+ [ompi_java_dir= ' /usr/lib/jvm/default-java/include/'
119+ ompi_java_jnih= ` ls $ompi_java_dir /jni.h 2> /dev/null | head -n 1`
120+ AS_IF([test -r " $ompi_java_jnih " ],
121+ [with_jdk_headers= ` dirname $ompi_java_jnih `
122+ OPAL_WHICH([javac], [with_jdk_bindir])
123+ AS_IF([test -n " $with_jdk_bindir " ],
124+ [AC_MSG_RESULT([found ($with_jdk_headers )])
125+ ompi_java_found= 1
126+ with_jdk_bindir= ` dirname $with_jdk_bindir ` ],
127+ [with_jdk_headers= ])],
128+ [AC_MSG_RESULT([not found])])])
129+ fi
130+
131+ if test " $ompi_java_found " = " 0" ; then
132+ # Solaris
133+ ompi_java_dir=/usr/java
134+ AC_MSG_CHECKING([for Java in Solaris locations])
135+ AS_IF([test -d $ompi_java_dir && test -r " $ompi_java_dir /include/jni.h" ],
136+ [AC_MSG_RESULT([found ($ompi_java_dir )])
137+ with_jdk_headers= $ompi_java_dir /include
138+ with_jdk_bindir= $ompi_java_dir /bin
139+ ompi_java_found= 1],
140+ [AC_MSG_RESULT([not found])])
141+ fi
142+ ],
143+ [ompi_java_found= 1])
144+
145+ if test " $ompi_java_found " = " 1" ; then
146+ OPAL_CHECK_WITHDIR([jdk-bindir], [$with_jdk_bindir ], [javac])
147+ OPAL_CHECK_WITHDIR([jdk-headers], [$with_jdk_headers ], [jni.h])
148+
149+ # Look for various Java-related programs
150+ ompi_java_happy=no
151+ ompi_java_PATH_save=$PATH
152+ AS_IF([test -n " $with_jdk_bindir " && test " $with_jdk_bindir " != " yes" && test " $with_jdk_bindir " != " no" ],
153+ [PATH= " $with_jdk_bindir :$PATH " ])
154+ AC_PATH_PROG(JAVAC, javac)
155+ AC_PATH_PROG(JAR, jar)
156+ AC_PATH_PROG(JAVADOC, javadoc)
157+ AC_PATH_PROG(JAVAH, javah)
158+ PATH=$ompi_java_PATH_save
159+
160+ # Check to see if we have all 3 programs.
161+ AS_IF([test -z " $JAVAC " || test -z " $JAR " || test -z " $JAVADOC " ],
162+ [ompi_java_happy= no],
163+ [ompi_java_happy= yes])
52164
53- # Only build the Java bindings if requested
54- if test " $opal_java_happy " = " yes" && test " $enable_mpi_java " = " yes" ; then
55- AC_MSG_RESULT([yes])
56- WANT_MPI_JAVA_SUPPORT=1
57- AC_MSG_CHECKING([if shared libraries are enabled])
58- AS_IF([test " $enable_shared " != " yes" ],
59- [AC_MSG_RESULT([no])
60- AC_MSG_WARN([Java bindings cannot be built without shared libraries])
61- AC_MSG_WARN([Please reconfigure with --enable-shared])
62- AC_MSG_ERROR([Cannot continue])],
63- [AC_MSG_RESULT([yes])])
64- # must have Java support
65- AC_MSG_CHECKING([if Java support was found])
66- AS_IF([test " $opal_java_happy " = " yes" ],
67- [AC_MSG_RESULT([yes])],
68- [AC_MSG_WARN([Java MPI bindings requested, but Java support was not found])
69- AC_MSG_WARN([Please reconfigure the --with-jdk options to where Java])
70- AC_MSG_WARN([support can be found])
71- AC_MSG_ERROR([Cannot continue])])
72-
73- # Mac Java requires this file (i.e., some other Java-related
74- # header file needs this file, so we need to check for
75- # it/include it in our sources when compiling on Mac).
76- AC_CHECK_HEADERS([TargetConditionals.h])
77-
78- # dladdr and Dl_info are required to build the full path to libmpi on OS X 10.11 aka El Capitan
79- AC_CHECK_TYPES([Dl_info], [], [], [[# include <dlfcn.h>]])
165+ # Look for jni.h
166+ AS_IF([test " $ompi_java_happy " = " yes" ],
167+ [ompi_java_CPPFLAGS_save= $CPPFLAGS
168+ # silence a stupid Mac warning
169+ CPPFLAGS= " $CPPFLAGS -DTARGET_RT_MAC_CFM=0"
170+ AC_MSG_CHECKING([javac -h ])
171+ cat > Conftest.java << EOF
172+ public final class Conftest {
173+ public native void conftest ();
174+ }
175+ EOF
176+ AS_IF([$JAVAC -d . -h . Conftest.java > /dev/null 2>&1 ],
177+ [AC_MSG_RESULT([yes])],
178+ [AC_MSG_RESULT([no])
179+ AS_IF([test -n " $JAVAH " ],
180+ [ompi_javah_happy= yes],
181+ [ompi_java_happy= no])])
182+ rm -f Conftest.java Conftest.class Conftest.h
183+
184+ AS_IF([test -n " $with_jdk_headers " && test " $with_jdk_headers " != " yes" && test " $with_jdk_headers " != " no" ],
185+ [OMPI_JDK_CPPFLAGS= " -I$with_jdk_headers "
186+ # Some flavors of JDK also require -I<blah>/linux.
187+ # See if that's there, and if so, add a -I for that,
188+ # too. Ugh.
189+ AS_IF([test -d " $with_jdk_headers /linux" ],
190+ [OMPI_JDK_CPPFLAGS= " $OMPI_JDK_CPPFLAGS -I$with_jdk_headers /linux" ])
191+ # Solaris JDK also require -I<blah>/solaris.
192+ # See if that's there, and if so, add a -I for that,
193+ # too. Ugh.
194+ AS_IF([test -d " $with_jdk_headers /solaris" ],
195+ [OMPI_JDK_CPPFLAGS= " $OMPI_JDK_CPPFLAGS -I$with_jdk_headers /solaris" ])
196+ # Darwin JDK also require -I<blah>/darwin.
197+ # See if that's there, and if so, add a -I for that,
198+ # too. Ugh.
199+ AS_IF([test -d " $with_jdk_headers /darwin" ],
200+ [OMPI_JDK_CPPFLAGS= " $OMPI_JDK_CPPFLAGS -I$with_jdk_headers /darwin" ])
201+
202+ CPPFLAGS= " $CPPFLAGS $OMPI_JDK_CPPFLAGS " ])
203+ AC_CHECK_HEADER([jni.h], [],
204+ [ompi_java_happy= no])
205+ CPPFLAGS= $ompi_java_CPPFLAGS_save
206+ ])
80207 else
81- AC_MSG_RESULT([no])
82- WANT_MPI_JAVA_SUPPORT= 0
208+ ompi_java_happy=no
83209 fi
84- AC_DEFINE_UNQUOTED([OMPI_WANT_JAVA_BINDINGS], [$WANT_MPI_JAVA_SUPPORT ],
85- [do we want java mpi bindings])
86- AM_CONDITIONAL(OMPI_WANT_JAVA_BINDINGS, test " $WANT_MPI_JAVA_SUPPORT " = " 1" )
87-
88- # Are we happy?
89- AS_IF([test " $WANT_MPI_JAVA_SUPPORT " = " 1" ],
90- [AC_MSG_WARN([****************************************************** ])
91- AC_MSG_WARN([*** Java MPI bindings are provided on a provisional])
92- AC_MSG_WARN([*** basis. They are NOT part of the current or])
93- AC_MSG_WARN([*** proposed MPI standard. Continued inclusion of])
94- AC_MSG_WARN([*** the Java MPI bindings in Open MPI is contingent])
95- AC_MSG_WARN([*** upon user interest and developer support.])
96- AC_MSG_WARN([****************************************************** ])
97- ])
98-
99- AC_CONFIG_FILES([
100- ompi/mpi/java/Makefile
101- ompi/mpi/java/java/Makefile
102- ompi/mpi/java/c/Makefile
103- ])
210+ AC_SUBST(OMPI_JDK_CPPFLAGS)
211+
212+ # Are we happy?
213+ AC_MSG_CHECKING([if Java support available])
214+ AS_IF([test " $ompi_java_happy " = " yes" ],
215+ [AC_MSG_RESULT([yes])],
216+ [AC_MSG_RESULT([no])
217+ AC_MSG_WARN([Java support requested but not found.])
218+ AC_MSG_ERROR([Cannot continue])])
219+
220+ OPAL_VAR_SCOPE_POP
221+ ])
222+
223+ dnl OMPI_SETUP_JAVA ()
224+ dnl ----------------
225+ dnl Do everything required to setup the Java compiler.
226+ AC_DEFUN([OMPI_SETUP_JAVA],[
227+ OPAL_VAR_SCOPE_PUSH([ompi_java_happy ompi_javah_happy])
228+
229+ ompi_java_happy= no
230+ ompi_javah_happy= no
231+
232+ AC_ARG_WITH(jdk-dir,
233+ AC_HELP_STRING([--with-jdk-dir(=DIR)],
234+ [Location of the JDK header directory. If you use this option, do not specify --with-jdk-bindir or --with-jdk-headers.]))
235+ AC_ARG_WITH(jdk-bindir,
236+ AC_HELP_STRING([--with-jdk-bindir(=DIR)],
237+ [Location of the JDK bin directory. If you use this option, you must also use --with-jdk-headers (and you must NOT use --with-jdk-dir)]))
238+ AC_ARG_WITH(jdk-headers,
239+ AC_HELP_STRING([--with-jdk-headers(=DIR)],
240+ [Location of the JDK header directory. If you use this option, you must also use --with-jdk-bindir (and you must NOT use --with-jdk-dir)]))
241+
242+ # Only setup the compiler if we were requested to
243+ AS_IF([test " $1 " = " yes" ],
244+ [_OMPI_SETUP_JAVA])
245+
246+ AM_CONDITIONAL(OMPI_HAVE_JAVAH_SUPPORT, test " $ompi_javah_happy " = " yes" )
247+
248+ OPAL_VAR_SCOPE_POP
104249])
0 commit comments