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 . for v in ${_JAVA_VERSION_LIST}
218 . if defined(_JAVA_VERSION_LIST_REGEXP)
219 _JAVA_VERSION_LIST_REGEXP:= ${_JAVA_VERSION_LIST_REGEXP}\|
221 _JAVA_VERSION_LIST_REGEXP:= ${_JAVA_VERSION_LIST_REGEXP}$v
227 @test ! -z "${JAVA_VERSION}" && ( ${ECHO_CMD} "${JAVA_VERSION}" | ${TR} " " "\n" | ${GREP} -q "${_JAVA_VERSION_LIST_REGEXP}" || \
228 (${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
230 # Error checking: JAVA_VENDOR
231 .if !defined(_JAVA_VENDOR_LIST_REGEXP)
232 . for v in ${_JAVA_VENDOR_LIST}
233 . if defined(_JAVA_VENDOR_LIST_REGEXP)
234 _JAVA_VENDOR_LIST_REGEXP:= ${_JAVA_VENDOR_LIST_REGEXP}\|
236 _JAVA_VENDOR_LIST_REGEXP:= ${_JAVA_VENDOR_LIST_REGEXP}$v
240 @test ! -z "${JAVA_VENDOR}" && ( ${ECHO_CMD} "${JAVA_VENDOR}" | ${TR} " " "\n" | ${GREP} -q "${_JAVA_VENDOR_LIST_REGEXP}" || \
241 (${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}"; \
244 # Error checking: JAVA_OS
245 .if !defined(_JAVA_OS_LIST_REGEXP)
246 . for v in ${_JAVA_OS_LIST}
247 . if defined(_JAVA_OS_LIST_REGEXP)
248 _JAVA_OS_LIST_REGEXP:= ${_JAVA_OS_LIST_REGEXP}\|
250 _JAVA_OS_LIST_REGEXP:= ${_JAVA_OS_LIST_REGEXP}$v
254 @test ! -z "${JAVA_OS}" && ( ${ECHO_CMD} "${JAVA_OS}" | ${TR} " " "\n" | ${GREP} -q "${_JAVA_OS_LIST_REGEXP}" || \
255 (${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}"; \
258 # Set default values for JAVA_BUILD and JAVA_RUN
259 # When nothing is set, assume JAVA_BUILD=jdk and JAVA_RUN=jre
260 # (unless NO_BUILD is set)
261 . if !defined(JAVA_EXTRACT) && !defined(JAVA_BUILD) && !defined(JAVA_RUN)
262 . if !defined(NO_BUILD)
268 # JDK dependency setting
269 . undef _JAVA_PORTS_INSTALLED
270 . undef _JAVA_PORTS_POSSIBLE
271 . if defined(JAVA_VERSION)
272 _JAVA_VERSION= ${JAVA_VERSION:S/1.6+/1.6 1.7+/:S/1.7+/1.7 1.8+/:S/1.8+/1.8/}
274 _JAVA_VERSION= ${__JAVA_VERSION_LIST}
276 . if defined(JAVA_OS)
279 _JAVA_OS= ${_JAVA_OS_LIST}
281 . if defined(JAVA_VENDOR)
282 _JAVA_VENDOR= ${JAVA_VENDOR}
284 _JAVA_VENDOR= ${_JAVA_VENDOR_LIST}
287 . for A_JAVA_PORT in ${_JAVA_PORTS_ALL}
288 A_JAVA_PORT_INFO:= ${A_JAVA_PORT:S/^/\${_/:S/$/_INFO}/}
289 A_JAVA_PORT_HOME= ${A_JAVA_PORT_INFO:MHOME=*:S,HOME=,,}
290 A_JAVA_PORT_VERSION= ${A_JAVA_PORT_INFO:MVERSION=*:C/VERSION=([0-9])\.([0-9])(.*)/\1.\2/}
291 A_JAVA_PORT_OS= ${A_JAVA_PORT_INFO:MOS=*:S,OS=,,}
292 A_JAVA_PORT_VENDOR= ${A_JAVA_PORT_INFO:MVENDOR=*:S,VENDOR=,,}
293 .if !defined(_JAVA_PORTS_INSTALLED) && exists(${A_JAVA_PORT_HOME}/${_JDK_FILE})
294 __JAVA_PORTS_INSTALLED+= ${A_JAVA_PORT}
297 # Because variables inside for loops are special (directly replaced as strings),
298 # we are allowed to use them inside modifiers, where normally ${FOO:M${BAR}} is
301 .for ver in ${A_JAVA_PORT_VERSION}
302 .for os in ${A_JAVA_PORT_OS}
303 .for vendor in ${A_JAVA_PORT_VENDOR}
304 .if ${_JAVA_VERSION:M${ver}} && ${_JAVA_OS:M${os}} && ${_JAVA_VENDOR:M${vendor}}
305 __JAVA_PORTS_POSSIBLE+= ${A_JAVA_PORT}
312 .if !defined(_JAVA_PORTS_INSTALLED)
313 _JAVA_PORTS_INSTALLED= ${__JAVA_PORTS_INSTALLED:C/ [ ]+/ /g}
315 _JAVA_PORTS_POSSIBLE= ${__JAVA_PORTS_POSSIBLE:C/ [ ]+/ /g}
318 #-------------------------------------------------------------------------------
319 # Stage 3: Decide the exact JDK to use (or install)
322 # Find an installed JDK port that matches the requirements of the port
324 . undef _JAVA_PORTS_INSTALLED_POSSIBLE
326 . for A_JAVA_PORT in ${_JAVA_PORTS_POSSIBLE}
327 __JAVA_PORTS_INSTALLED_POSSIBLE+= ${_JAVA_PORTS_INSTALLED:M${A_JAVA_PORT}}
329 _JAVA_PORTS_INSTALLED_POSSIBLE= ${__JAVA_PORTS_INSTALLED_POSSIBLE:C/[ ]+//g}
331 . if ${_JAVA_PORTS_INSTALLED_POSSIBLE} != ""
332 . for i in ${_JAVA_PORTS_INSTALLED_POSSIBLE}
333 . if !defined(_JAVA_PORTS_INSTALLED_POSSIBLE_shortcircuit)
335 _JAVA_PORTS_INSTALLED_POSSIBLE_shortcircuit= 1
338 # If no installed JDK port fits, then pick one from the list of possible ones
340 . for i in ${_JAVA_PORTS_POSSIBLE}
341 . if !defined(_JAVA_PORTS_POSSIBLE_shortcircuit)
343 _JAVA_PORTS_POSSIBLE_shortcircuit= 1
348 _JAVA_PORT_INFO:= ${_JAVA_PORT:S/^/\${_/:S/$/_INFO}/}
349 JAVA_PORT= ${_JAVA_PORT_INFO:MPORT=*:S,PORT=,,}
350 JAVA_HOME= ${_JAVA_PORT_INFO:MHOME=*:S,HOME=,,}
351 JAVA_PORT_VERSION= ${_JAVA_PORT_INFO:MVERSION=*:S,VERSION=,,}
352 JAVA_PORT_OS= ${_JAVA_PORT_INFO:MOS=*:S,OS=,,}
353 JAVA_PORT_VENDOR= ${_JAVA_PORT_INFO:MVENDOR=*:S,VENDOR=,,}
355 JAVA_PORT_VENDOR_DESCRIPTION:= ${JAVA_PORT_VENDOR:S/^/\${_JAVA_VENDOR_/:S/$/}/}
356 JAVA_PORT_OS_DESCRIPTION:= ${JAVA_PORT_OS:S/^/\${_JAVA_OS_/:S/$/}/}
358 #-------------------------------------------------------------------------------
359 # Stage 4: Add any dependencies if necessary
362 # Ant Support: USE_ANT --> JAVA_BUILD=jdk
363 . if defined(USE_ANT)
367 # Add the JDK port to the dependencies
368 DEPEND_JAVA= ${JAVA}:${JAVA_PORT}
369 . if defined(JAVA_EXTRACT)
370 EXTRACT_DEPENDS+= ${DEPEND_JAVA}
372 . if defined(JAVA_BUILD)
373 . if defined(NO_BUILD)
375 @${ECHO_CMD} "${PKGNAME}: Makefile error: JAVA_BUILD and NO_BUILD cannot be set at the same time.";
378 BUILD_DEPENDS+= ${DEPEND_JAVA}
380 . if defined(JAVA_RUN)
381 RUN_DEPENDS+= ${DEPEND_JAVA}
384 # Ant support: default do-build target
385 . if defined(USE_ANT)
386 DESTDIRNAME?= -Dfreebsd.ports.destdir
387 ANT?= ${LOCALBASE}/bin/ant
388 MAKE_ENV+= JAVA_HOME=${JAVA_HOME}
389 BUILD_DEPENDS+= ${ANT}:devel/apache-ant
391 . if !target(do-build)
393 @(cd ${BUILD_WRKSRC}; \
394 ${SETENV} ${MAKE_ENV} ${ANT} ${MAKE_ARGS} ${ALL_TARGET})
398 #-----------------------------------------------------------------------------
399 # Stage 5: Define all settings for the port to use
401 # At this stage both JAVA_HOME and JAVA_PORT are definitely given a value.
403 # Define the location of the Java compiler.
405 # Only define JAVAC if a JDK is needed
408 # Then test if a JAVAC has to be set (JAVA_BUILD==jdk)
409 . if defined(JAVA_BUILD)
410 . if (${JAVA_BUILD:tu} == "JDK") && !defined(JAVAC)
411 JAVAC?= ${JAVA_HOME}/bin/javac
415 # Define the location of some more executables.
416 APPLETVIEWER?= ${JAVA_HOME}/bin/appletviewer
417 JAR?= ${JAVA_HOME}/bin/jar
418 JAVA?= ${JAVA_HOME}/bin/java
419 JAVADOC?= ${JAVA_HOME}/bin/javadoc
420 JAVAH?= ${JAVA_HOME}/bin/javah
421 JAVAP?= ${JAVA_HOME}/bin/javap
422 JAVA_N2A?= ${JAVA_HOME}/bin/native2ascii
423 JAVA_SERIALVER?=${JAVA_HOME}/bin/serialver
424 RMIC?= ${JAVA_HOME}/bin/rmic
425 RMIREGISTRY?= ${JAVA_HOME}/bin/rmiregistry
426 JAVA_KEYTOOL?= ${JAVA_HOME}/bin/keytool
427 JAVA_POLICYTOOL?= ${JAVA_HOME}/bin/policytool
428 RMID?= ${JAVA_HOME}/bin/rmid
430 # Set the location of the ZIP or JAR file with all standard Java classes.
431 JAVA_CLASSES= ${JAVA_HOME}/jre/lib/rt.jar
434 #-------------------------------------------------------------------------------
435 # Additional Java support
438 # Use it to check Java dependency while porting
440 @${ECHO_CMD} "# User specified parameters:"
441 @${ECHO_CMD} "JAVA_VERSION= ${JAVA_VERSION} (${_JAVA_VERSION})"
442 @${ECHO_CMD} "JAVA_OS= ${JAVA_OS} (${_JAVA_OS})"
443 @${ECHO_CMD} "JAVA_VENDOR= ${JAVA_VENDOR} (${_JAVA_VENDOR})"
444 @${ECHO_CMD} "JAVA_BUILD= ${JAVA_BUILD}"
445 @${ECHO_CMD} "JAVA_RUN= ${JAVA_RUN}"
446 @${ECHO_CMD} "JAVA_EXTRACT= ${JAVA_EXTRACT}"
448 @${ECHO_CMD} "# JDK port dependency selection process:"
449 @${ECHO_CMD} "_JAVA_PORTS_POSSIBLE= ${_JAVA_PORTS_POSSIBLE}"
450 @${ECHO_CMD} "_JAVA_PORTS_INSTALLED= ${_JAVA_PORTS_INSTALLED}"
451 @${ECHO_CMD} "_JAVA_PORTS_INSTALLED_POSSIBLE= ${_JAVA_PORTS_INSTALLED_POSSIBLE}"
452 @${ECHO_CMD} "_JAVA_PORT= ${_JAVA_PORT}"
453 @${ECHO_CMD} "_JAVA_PORT_INFO= ${_JAVA_PORT_INFO:S/\t/ /}"
455 @${ECHO_CMD} "# Selected JDK port:"
456 @${ECHO_CMD} "JAVA_PORT= ${JAVA_PORT}"
457 @${ECHO_CMD} "JAVA_HOME= ${JAVA_HOME}"
458 @${ECHO_CMD} "JAVA_PORT_VERSION= ${JAVA_PORT_VERSION}"
459 @${ECHO_CMD} "JAVA_PORT_OS= ${JAVA_PORT_OS} (${JAVA_PORT_OS_DESCRIPTION})"
460 @${ECHO_CMD} "JAVA_PORT_VENDOR= ${JAVA_PORT_VENDOR} (${JAVA_PORT_VENDOR_DESCRIPTION})"
462 @${ECHO_CMD} "# Additional variables:"
463 @${ECHO_CMD} "JAVAC= ${JAVAC}"
464 @${ECHO_CMD} "JAVA_CLASSES= ${JAVA_CLASSES}"