4 # bsd.java.mk - Support for Java-based ports.
6 # Created by: Ernst de Haan <znerd@FreeBSD.org>
8 # For FreeBSD committers:
9 # Please send all suggested changes to the maintainer instead of committing
10 # them to svn yourself.
15 .if !defined(Java_Include)
17 Java_Include= bsd.java.mk
18 Java_Include_MAINTAINER= java@FreeBSD.org
20 #-------------------------------------------------------------------------------
21 # Variables that each port can define:
23 # USE_JAVA Should be defined to the remaining variables to have any
26 # JAVA_VERSION List of space-separated suitable java versions for the
27 # port. An optional "+" allows you to specify a range of
28 # versions. (allowed values: 1.6[+] 1.7[+] 1.8[+])
30 # JAVA_OS List of space-separated suitable JDK port operating systems
31 # for the port. (allowed values: native linux)
33 # JAVA_VENDOR List of space-separated suitable JDK port vendors for the
34 # port. (allowed values: openjdk oracle sun)
36 # JAVA_BUILD When set, it means that the selected JDK port should be
37 # added to build dependencies for the port.
39 # JAVA_EXTRACT This variable works exactly the same as JAVA_BUILD but
40 # regarding extract dependencies.
42 # JAVA_RUN This variable works exactly the same as JAVA_BUILD but
43 # regarding run dependencies.
45 # USE_ANT Should be defined when the port uses Apache Ant. Ant is thus
46 # considered to be the sub-make command. When no 'do-build'
47 # target is defined by the port, a default one will be set
48 # that simply runs Ant according to MAKE_ENV, MAKE_ARGS and
49 # ALL_TARGET. Read the documentation in bsd.port.mk for more
52 #-------------------------------------------------------------------------------
53 # Variables defined for the port:
55 # JAVA_PORT The name of the JDK port. (e.g. 'java/openjdk6')
57 # JAVA_PORT_VERSION The version of the JDK port. (e.g. '1.6')
59 # JAVA_PORT_OS The operating system used by the JDK port. (e.g. 'linux')
61 # JAVA_PORT_VENDOR The vendor of the JDK port. (e.g. 'sun')
63 # JAVA_PORT_OS_DESCRIPTION Description of the operating system used by the
64 # JDK port. (e.g. 'Linux')
66 # JAVA_PORT_VENDOR_DESCRIPTION Description of the vendor of the JDK port.
67 # (e.g. 'OpenJDK BSD Porting Team')
69 # JAVA_HOME Path to the installation directory of the JDK. (e.g.
70 # '/usr/local/openjdk6')
72 # JAVAC Path to the Java compiler to use. (e.g.
73 # '/usr/local/openjdk6/bin/javac' or '/usr/local/bin/javac')
75 # JAR Path to the JAR tool to use. (e.g.
76 # '/usr/local/openjdk6/bin/jar' or '/usr/local/bin/fastjar')
78 # APPLETVIEWER Path to the appletviewer utility. (e.g.
79 # '/usr/local/linux-jdk1.7.0/bin/appletviewer')
81 # JAVA Path to the java executable. Use this for executing Java
82 # programs. (e.g. '/usr/local/openjdk6/bin/java')
84 # JAVADOC Path to the javadoc utility program.
86 # JAVAH Path to the javah program.
88 # JAVAP Path to the javap program.
90 # JAVA_KEYTOOL Path to the keytool utility program.
92 # JAVA_N2A Path to the native2ascii tool.
94 # JAVA_POLICYTOOL Path to the policytool program.
96 # JAVA_SERIALVER Path to the serialver utility program.
98 # RMIC Path to the RMI stub/skeleton generator, rmic.
100 # RMIREGISTRY Path to the RMI registry program, rmiregistry.
102 # RMID Path to the RMI daemon program.
104 # JAVA_CLASSES Path to the archive that contains the JDK class files. On
105 # most JDKs, this is ${JAVA_HOME}/jre/lib/rt.jar.
107 # JAVASHAREDIR The base directory for all shared Java resources.
109 # JAVAJARDIR The directory where a port should install JAR files.
111 # JAVALIBDIR The directory where JAR files installed by other ports
114 #-------------------------------------------------------------------------------
117 # To retrieve the Major version number from JAVA_PORT_VERSION (e.g. "1.6"):
118 # -> ${JAVA_PORT_VERSION:C/^([0-9])\.([0-9])(.*)$/\1.\2/}
120 #-------------------------------------------------------------------------------
121 # There are the following stages:
123 # Stage 1: Define constants
124 # Stage 2: Determine which JDK ports are installed and which JDK ports are
126 # Stage 3: Decide the exact JDK to use (or install)
127 # Stage 4: Add any dependencies if necessary
128 # Stage 5: Define all settings for the port to use
131 . if defined(USE_JAVA)
134 #-------------------------------------------------------------------------------
135 # Stage 1: Define constants
138 # System-global directories
139 # NB: If the value of JAVALIBDIR is altered here it must also be altered
140 # in java/javavmwrapper/Makefile.
141 JAVASHAREDIR?= ${PREFIX}/share/java
142 JAVAJARDIR?= ${JAVASHAREDIR}/classes
143 JAVALIBDIR?= ${LOCALBASE}/share/java/classes
145 # Add appropriate substitutions to PLIST_SUB and LIST_SUB
146 PLIST_SUB+= JAVASHAREDIR="${JAVASHAREDIR:S,^${PREFIX}/,,}" \
147 JAVAJARDIR="${JAVAJARDIR:S,^${PREFIX}/,,}"
148 SUB_LIST+= JAVASHAREDIR="${JAVASHAREDIR}" \
149 JAVAJARDIR="${JAVAJARDIR}" \
150 JAVALIBDIR="${JAVALIBDIR}"
151 . if defined(JAVA_VERSION)
152 SUB_LIST+= JAVA_VERSION="${JAVA_VERSION}"
154 . if defined(JAVA_VENDOR)
155 SUB_LIST+= JAVA_VENDOR="${JAVA_VENDOR}"
157 . if defined(JAVA_OS)
158 SUB_LIST+= JAVA_OS="${JAVA_OS}"
161 # The complete list of Java versions, os and vendors supported.
162 __JAVA_VERSION_LIST= 1.6 1.7 1.8
163 _JAVA_VERSION_LIST= ${__JAVA_VERSION_LIST} ${__JAVA_VERSION_LIST:S/$/+/}
164 _JAVA_OS_LIST= native linux
165 _JAVA_VENDOR_LIST= openjdk oracle sun
167 # Set all meta-information about JDK ports:
168 # port location, corresponding JAVA_HOME, JDK version, OS, vendor
169 _JAVA_PORT_NATIVE_OPENJDK_JDK_1_6_INFO= PORT=java/openjdk6 HOME=${LOCALBASE}/openjdk6 \
170 VERSION=1.6.0 OS=native VENDOR=openjdk
171 _JAVA_PORT_NATIVE_OPENJDK_JDK_1_7_INFO= PORT=java/openjdk7 HOME=${LOCALBASE}/openjdk7 \
172 VERSION=1.7.0 OS=native VENDOR=openjdk
173 _JAVA_PORT_NATIVE_OPENJDK_JDK_1_8_INFO= PORT=java/openjdk8 HOME=${LOCALBASE}/openjdk8 \
174 VERSION=1.8.0 OS=native VENDOR=openjdk
175 _JAVA_PORT_LINUX_ORACLE_JDK_1_8_INFO= PORT=java/linux-oracle-jdk18 HOME=${LOCALBASE}/linux-oracle-jdk1.8.0 \
176 VERSION=1.8.0 OS=linux VENDOR=oracle
178 # Verbose description for each VENDOR
179 _JAVA_VENDOR_openjdk= "OpenJDK BSD Porting Team"
180 _JAVA_VENDOR_oracle= Oracle
181 _JAVA_VENDOR_sun= Sun
183 # Verbose description for each OS
184 _JAVA_OS_native= Native
185 _JAVA_OS_linux= Linux
187 # List all JDK ports in order of preference
188 __JAVA_PORTS_ALL= JAVA_PORT_NATIVE_OPENJDK_JDK_1_8 \
189 JAVA_PORT_NATIVE_OPENJDK_JDK_1_7 \
190 JAVA_PORT_NATIVE_OPENJDK_JDK_1_6 \
191 JAVA_PORT_LINUX_ORACLE_JDK_1_8
192 _JAVA_PORTS_ALL= ${JAVA_PREFERRED_PORTS} \
195 # Set the name of the file that indicates that a JDK is indeed installed, as a
196 # relative path within the JAVA_HOME directory.
199 #-------------------------------------------------------------------------------
200 # Stage 2: Determine which JDK ports are suitable and which JDK ports are
204 # From here, the port is using bsd.java.mk v2.0
206 # Error checking: defined JAVA_{HOME,PORT,PORT_VERSION,PORT_VENDOR,PORT_OS}
207 . for variable in JAVA_HOME JAVA_PORT JAVA_PORT_VERSION JAVA_PORT_VENDOR JAVA_PORT_OS
208 . if defined(${variable})
210 @${ECHO_CMD} "${PKGNAME}: Environment error: \"${variable}\" should not be defined -- clearing."
215 # Error checking: JAVA_VERSION
216 .if !defined(_JAVA_VERSION_LIST_REGEXP)
217 _JAVA_VERSION_LIST_REGEXP= ${_JAVA_VERSION_LIST:C/\+/\\+/:ts|}
221 @test ! -z "${JAVA_VERSION}" && ( ${ECHO_CMD} "${JAVA_VERSION}" | ${TR} " " "\n" | ${GREP} -Eq "${_JAVA_VERSION_LIST_REGEXP}" || \
222 (${ECHO_CMD} "${PKGNAME}: Makefile error: \"${JAVA_VERSION}\" is not a valid value for JAVA_VERSION. It should be one or more of: ${__JAVA_VERSION_LIST} (with an optional \"+\" suffix.)"; ${FALSE})) || true
224 # Error checking: JAVA_VENDOR
225 .if !defined(_JAVA_VENDOR_LIST_REGEXP)
226 _JAVA_VENDOR_LIST_REGEXP= ${_JAVA_VENDOR_LIST:ts|}
230 @test ! -z "${JAVA_VENDOR}" && ( ${ECHO_CMD} "${JAVA_VENDOR}" | ${TR} " " "\n" | ${GREP} -Eq "${_JAVA_VENDOR_LIST_REGEXP}" || \
231 (${ECHO_CMD} "${PKGNAME}: Makefile error: \"${JAVA_VENDOR}\" is not a valid value for JAVA_VENDOR. It should be one or more of: ${_JAVA_VENDOR_LIST}"; \
234 # Error checking: JAVA_OS
235 .if !defined(_JAVA_OS_LIST_REGEXP)
236 _JAVA_OS_LIST_REGEXP= ${_JAVA_OS_LIST:ts|}
240 @test ! -z "${JAVA_OS}" && ( ${ECHO_CMD} "${JAVA_OS}" | ${TR} " " "\n" | ${GREP} -Eq "${_JAVA_OS_LIST_REGEXP}" || \
241 (${ECHO_CMD} "${PKGNAME}: Makefile error: \"${JAVA_OS}\" is not a valid value for JAVA_OS. It should be one or more of: ${_JAVA_OS_LIST}"; \
244 # Set default values for JAVA_BUILD and JAVA_RUN
245 # When nothing is set, assume JAVA_BUILD=jdk and JAVA_RUN=jre
246 # (unless NO_BUILD is set)
247 . if !defined(JAVA_EXTRACT) && !defined(JAVA_BUILD) && !defined(JAVA_RUN)
248 . if !defined(NO_BUILD)
254 # JDK dependency setting
255 . undef _JAVA_PORTS_INSTALLED
256 . undef _JAVA_PORTS_POSSIBLE
257 . if defined(JAVA_VERSION)
258 _JAVA_VERSION= ${JAVA_VERSION:S/1.6+/1.6 1.7+/:S/1.7+/1.7 1.8+/:S/1.8+/1.8/}
260 _JAVA_VERSION= ${__JAVA_VERSION_LIST}
262 . if defined(JAVA_OS)
265 _JAVA_OS= ${_JAVA_OS_LIST}
267 . if defined(JAVA_VENDOR)
268 _JAVA_VENDOR= ${JAVA_VENDOR}
270 _JAVA_VENDOR= ${_JAVA_VENDOR_LIST}
273 . for A_JAVA_PORT in ${_JAVA_PORTS_ALL}
274 A_JAVA_PORT_INFO:= ${A_JAVA_PORT:S/^/\${_/:S/$/_INFO}/}
275 A_JAVA_PORT_HOME= ${A_JAVA_PORT_INFO:MHOME=*:S,HOME=,,}
276 A_JAVA_PORT_VERSION= ${A_JAVA_PORT_INFO:MVERSION=*:C/VERSION=([0-9])\.([0-9])(.*)/\1.\2/}
277 A_JAVA_PORT_OS= ${A_JAVA_PORT_INFO:MOS=*:S,OS=,,}
278 A_JAVA_PORT_VENDOR= ${A_JAVA_PORT_INFO:MVENDOR=*:S,VENDOR=,,}
279 .if !defined(_JAVA_PORTS_INSTALLED) && exists(${A_JAVA_PORT_HOME}/${_JDK_FILE})
280 __JAVA_PORTS_INSTALLED+= ${A_JAVA_PORT}
283 # Because variables inside for loops are special (directly replaced as strings),
284 # we are allowed to use them inside modifiers, where normally ${FOO:M${BAR}} is
287 .for ver in ${A_JAVA_PORT_VERSION}
288 .for os in ${A_JAVA_PORT_OS}
289 .for vendor in ${A_JAVA_PORT_VENDOR}
290 .if ${_JAVA_VERSION:M${ver}} && ${_JAVA_OS:M${os}} && ${_JAVA_VENDOR:M${vendor}}
291 __JAVA_PORTS_POSSIBLE+= ${A_JAVA_PORT}
298 .if !defined(_JAVA_PORTS_INSTALLED)
299 _JAVA_PORTS_INSTALLED= ${__JAVA_PORTS_INSTALLED:C/ [ ]+/ /g}
301 _JAVA_PORTS_POSSIBLE= ${__JAVA_PORTS_POSSIBLE:C/ [ ]+/ /g}
304 #-------------------------------------------------------------------------------
305 # Stage 3: Decide the exact JDK to use (or install)
308 # Find an installed JDK port that matches the requirements of the port
310 . undef _JAVA_PORTS_INSTALLED_POSSIBLE
312 . for A_JAVA_PORT in ${_JAVA_PORTS_POSSIBLE}
313 __JAVA_PORTS_INSTALLED_POSSIBLE+= ${_JAVA_PORTS_INSTALLED:M${A_JAVA_PORT}}
315 _JAVA_PORTS_INSTALLED_POSSIBLE= ${__JAVA_PORTS_INSTALLED_POSSIBLE:C/[ ]+//g}
317 . if ${_JAVA_PORTS_INSTALLED_POSSIBLE} != ""
318 . for i in ${_JAVA_PORTS_INSTALLED_POSSIBLE}
319 . if !defined(_JAVA_PORTS_INSTALLED_POSSIBLE_shortcircuit)
321 _JAVA_PORTS_INSTALLED_POSSIBLE_shortcircuit= 1
324 # If no installed JDK port fits, then pick one from the list of possible ones
326 . for i in ${_JAVA_PORTS_POSSIBLE}
327 . if !defined(_JAVA_PORTS_POSSIBLE_shortcircuit)
329 _JAVA_PORTS_POSSIBLE_shortcircuit= 1
334 _JAVA_PORT_INFO:= ${_JAVA_PORT:S/^/\${_/:S/$/_INFO}/}
335 JAVA_PORT= ${_JAVA_PORT_INFO:MPORT=*:S,PORT=,,}
336 JAVA_HOME= ${_JAVA_PORT_INFO:MHOME=*:S,HOME=,,}
337 JAVA_PORT_VERSION= ${_JAVA_PORT_INFO:MVERSION=*:S,VERSION=,,}
338 JAVA_PORT_OS= ${_JAVA_PORT_INFO:MOS=*:S,OS=,,}
339 JAVA_PORT_VENDOR= ${_JAVA_PORT_INFO:MVENDOR=*:S,VENDOR=,,}
341 JAVA_PORT_VENDOR_DESCRIPTION:= ${JAVA_PORT_VENDOR:S/^/\${_JAVA_VENDOR_/:S/$/}/}
342 JAVA_PORT_OS_DESCRIPTION:= ${JAVA_PORT_OS:S/^/\${_JAVA_OS_/:S/$/}/}
344 #-------------------------------------------------------------------------------
345 # Stage 4: Add any dependencies if necessary
348 # Ant Support: USE_ANT --> JAVA_BUILD=jdk
349 . if defined(USE_ANT)
353 # Add the JDK port to the dependencies
354 DEPEND_JAVA= ${JAVA}:${JAVA_PORT}
355 . if defined(JAVA_EXTRACT)
356 EXTRACT_DEPENDS+= ${DEPEND_JAVA}
358 . if defined(JAVA_BUILD)
359 . if defined(NO_BUILD)
361 @${ECHO_CMD} "${PKGNAME}: Makefile error: JAVA_BUILD and NO_BUILD cannot be set at the same time.";
364 BUILD_DEPENDS+= ${DEPEND_JAVA}
366 . if defined(JAVA_RUN)
367 RUN_DEPENDS+= ${DEPEND_JAVA}
370 # Ant support: default do-build target
371 . if defined(USE_ANT)
372 DESTDIRNAME?= -Dfreebsd.ports.destdir
373 ANT?= ${LOCALBASE}/bin/ant
374 MAKE_ENV+= JAVA_HOME=${JAVA_HOME}
375 BUILD_DEPENDS+= ${ANT}:devel/apache-ant
377 . if !target(do-build)
379 @(cd ${BUILD_WRKSRC}; \
380 ${SETENV} ${MAKE_ENV} ${ANT} ${MAKE_ARGS} ${ALL_TARGET})
382 . if !target(do-test) && defined(TEST_TARGET)
383 TEST_DEPENDS+= ${DEPEND_JAVA}
384 TEST_DEPENDS+= ${ANT}:devel/apache-ant
386 @(cd ${TEST_WRKSRC}; \
387 ${SETENV} ${MAKE_ENV} ${ANT} ${MAKE_ARGS} ${TEST_TARGET})
391 #-----------------------------------------------------------------------------
392 # Stage 5: Define all settings for the port to use
394 # At this stage both JAVA_HOME and JAVA_PORT are definitely given a value.
396 # Define the location of the Java compiler.
398 # Only define JAVAC if a JDK is needed
401 # Then test if a JAVAC has to be set (JAVA_BUILD==jdk)
402 . if defined(JAVA_BUILD)
403 . if (${JAVA_BUILD:tu} == "JDK") && !defined(JAVAC)
404 JAVAC?= ${JAVA_HOME}/bin/javac
408 # Define the location of some more executables.
409 APPLETVIEWER?= ${JAVA_HOME}/bin/appletviewer
410 JAR?= ${JAVA_HOME}/bin/jar
411 JAVA?= ${JAVA_HOME}/bin/java
412 JAVADOC?= ${JAVA_HOME}/bin/javadoc
413 JAVAH?= ${JAVA_HOME}/bin/javah
414 JAVAP?= ${JAVA_HOME}/bin/javap
415 JAVA_N2A?= ${JAVA_HOME}/bin/native2ascii
416 JAVA_SERIALVER?=${JAVA_HOME}/bin/serialver
417 RMIC?= ${JAVA_HOME}/bin/rmic
418 RMIREGISTRY?= ${JAVA_HOME}/bin/rmiregistry
419 JAVA_KEYTOOL?= ${JAVA_HOME}/bin/keytool
420 JAVA_POLICYTOOL?= ${JAVA_HOME}/bin/policytool
421 RMID?= ${JAVA_HOME}/bin/rmid
423 # Set the location of the ZIP or JAR file with all standard Java classes.
424 JAVA_CLASSES= ${JAVA_HOME}/jre/lib/rt.jar
427 #-------------------------------------------------------------------------------
428 # Additional Java support
431 # Use it to check Java dependency while porting
433 @${ECHO_CMD} "# User specified parameters:"
434 @${ECHO_CMD} "JAVA_VERSION= ${JAVA_VERSION} (${_JAVA_VERSION})"
435 @${ECHO_CMD} "JAVA_OS= ${JAVA_OS} (${_JAVA_OS})"
436 @${ECHO_CMD} "JAVA_VENDOR= ${JAVA_VENDOR} (${_JAVA_VENDOR})"
437 @${ECHO_CMD} "JAVA_BUILD= ${JAVA_BUILD}"
438 @${ECHO_CMD} "JAVA_RUN= ${JAVA_RUN}"
439 @${ECHO_CMD} "JAVA_EXTRACT= ${JAVA_EXTRACT}"
441 @${ECHO_CMD} "# JDK port dependency selection process:"
442 @${ECHO_CMD} "_JAVA_PORTS_POSSIBLE= ${_JAVA_PORTS_POSSIBLE}"
443 @${ECHO_CMD} "_JAVA_PORTS_INSTALLED= ${_JAVA_PORTS_INSTALLED}"
444 @${ECHO_CMD} "_JAVA_PORTS_INSTALLED_POSSIBLE= ${_JAVA_PORTS_INSTALLED_POSSIBLE}"
445 @${ECHO_CMD} "_JAVA_PORT= ${_JAVA_PORT}"
446 @${ECHO_CMD} "_JAVA_PORT_INFO= ${_JAVA_PORT_INFO:S/\t/ /}"
448 @${ECHO_CMD} "# Selected JDK port:"
449 @${ECHO_CMD} "JAVA_PORT= ${JAVA_PORT}"
450 @${ECHO_CMD} "JAVA_HOME= ${JAVA_HOME}"
451 @${ECHO_CMD} "JAVA_PORT_VERSION= ${JAVA_PORT_VERSION}"
452 @${ECHO_CMD} "JAVA_PORT_OS= ${JAVA_PORT_OS} (${JAVA_PORT_OS_DESCRIPTION})"
453 @${ECHO_CMD} "JAVA_PORT_VENDOR= ${JAVA_PORT_VENDOR} (${JAVA_PORT_VENDOR_DESCRIPTION})"
455 @${ECHO_CMD} "# Additional variables:"
456 @${ECHO_CMD} "JAVAC= ${JAVAC}"
457 @${ECHO_CMD} "JAVA_CLASSES= ${JAVA_CLASSES}"