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_SUN_JDK_1_7_INFO= PORT=java/linux-sun-jdk17 HOME=${LOCALBASE}/linux-sun-jdk1.7.0 \
176 VERSION=1.7.0 OS=linux VENDOR=sun
177 _JAVA_PORT_LINUX_ORACLE_JDK_1_8_INFO= PORT=java/linux-oracle-jdk18 HOME=${LOCALBASE}/linux-oracle-jdk1.8.0 \
178 VERSION=1.8.0 OS=linux VENDOR=oracle
180 # Verbose description for each VENDOR
181 _JAVA_VENDOR_openjdk= "OpenJDK BSD Porting Team"
182 _JAVA_VENDOR_oracle= Oracle
183 _JAVA_VENDOR_sun= Sun
185 # Verbose description for each OS
186 _JAVA_OS_native= Native
187 _JAVA_OS_linux= Linux
189 # List all JDK ports in order of preference
190 __JAVA_PORTS_ALL= JAVA_PORT_NATIVE_OPENJDK_JDK_1_7 \
191 JAVA_PORT_NATIVE_OPENJDK_JDK_1_8 \
192 JAVA_PORT_NATIVE_OPENJDK_JDK_1_6 \
193 JAVA_PORT_LINUX_SUN_JDK_1_7 \
194 JAVA_PORT_LINUX_ORACLE_JDK_1_8
195 _JAVA_PORTS_ALL= ${JAVA_PREFERRED_PORTS} \
198 # Set the name of the file that indicates that a JDK is indeed installed, as a
199 # relative path within the JAVA_HOME directory.
202 #-------------------------------------------------------------------------------
203 # Stage 2: Determine which JDK ports are suitable and which JDK ports are
207 # From here, the port is using bsd.java.mk v2.0
209 # Error checking: defined JAVA_{HOME,PORT,PORT_VERSION,PORT_VENDOR,PORT_OS}
210 . for variable in JAVA_HOME JAVA_PORT JAVA_PORT_VERSION JAVA_PORT_VENDOR JAVA_PORT_OS
211 . if defined(${variable})
213 @${ECHO_CMD} "${PKGNAME}: Environment error: \"${variable}\" should not be defined -- clearing."
218 # Error checking: JAVA_VERSION
219 .if !defined(_JAVA_VERSION_LIST_REGEXP)
220 . for v in ${_JAVA_VERSION_LIST}
221 . if defined(_JAVA_VERSION_LIST_REGEXP)
222 _JAVA_VERSION_LIST_REGEXP:= ${_JAVA_VERSION_LIST_REGEXP}\|
224 _JAVA_VERSION_LIST_REGEXP:= ${_JAVA_VERSION_LIST_REGEXP}$v
230 @test ! -z "${JAVA_VERSION}" && ( ${ECHO_CMD} "${JAVA_VERSION}" | ${TR} " " "\n" | ${GREP} -q "${_JAVA_VERSION_LIST_REGEXP}" || \
231 (${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
233 # Error checking: JAVA_VENDOR
234 .if !defined(_JAVA_VENDOR_LIST_REGEXP)
235 . for v in ${_JAVA_VENDOR_LIST}
236 . if defined(_JAVA_VENDOR_LIST_REGEXP)
237 _JAVA_VENDOR_LIST_REGEXP:= ${_JAVA_VENDOR_LIST_REGEXP}\|
239 _JAVA_VENDOR_LIST_REGEXP:= ${_JAVA_VENDOR_LIST_REGEXP}$v
243 @test ! -z "${JAVA_VENDOR}" && ( ${ECHO_CMD} "${JAVA_VENDOR}" | ${TR} " " "\n" | ${GREP} -q "${_JAVA_VENDOR_LIST_REGEXP}" || \
244 (${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}"; \
247 # Error checking: JAVA_OS
248 .if !defined(_JAVA_OS_LIST_REGEXP)
249 . for v in ${_JAVA_OS_LIST}
250 . if defined(_JAVA_OS_LIST_REGEXP)
251 _JAVA_OS_LIST_REGEXP:= ${_JAVA_OS_LIST_REGEXP}\|
253 _JAVA_OS_LIST_REGEXP:= ${_JAVA_OS_LIST_REGEXP}$v
257 @test ! -z "${JAVA_OS}" && ( ${ECHO_CMD} "${JAVA_OS}" | ${TR} " " "\n" | ${GREP} -q "${_JAVA_OS_LIST_REGEXP}" || \
258 (${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}"; \
261 # Set default values for JAVA_BUILD and JAVA_RUN
262 # When nothing is set, assume JAVA_BUILD=jdk and JAVA_RUN=jre
263 # (unless NO_BUILD is set)
264 . if !defined(JAVA_EXTRACT) && !defined(JAVA_BUILD) && !defined(JAVA_RUN)
265 . if !defined(NO_BUILD)
271 # JDK dependency setting
272 . undef _JAVA_PORTS_INSTALLED
273 . undef _JAVA_PORTS_POSSIBLE
274 . if defined(JAVA_VERSION)
275 _JAVA_VERSION= ${JAVA_VERSION:S/1.6+/1.6 1.7+/:S/1.7+/1.7 1.8+/:S/1.8+/1.8/}
277 _JAVA_VERSION= ${__JAVA_VERSION_LIST}
279 . if defined(JAVA_OS)
282 _JAVA_OS= ${_JAVA_OS_LIST}
284 . if defined(JAVA_VENDOR)
285 _JAVA_VENDOR= ${JAVA_VENDOR}
287 _JAVA_VENDOR= ${_JAVA_VENDOR_LIST}
290 . for A_JAVA_PORT in ${_JAVA_PORTS_ALL}
291 A_JAVA_PORT_INFO:= ${A_JAVA_PORT:S/^/\${_/:S/$/_INFO}/}
292 A_JAVA_PORT_HOME= ${A_JAVA_PORT_INFO:MHOME=*:S,HOME=,,}
293 A_JAVA_PORT_VERSION= ${A_JAVA_PORT_INFO:MVERSION=*:C/VERSION=([0-9])\.([0-9])(.*)/\1.\2/}
294 A_JAVA_PORT_OS= ${A_JAVA_PORT_INFO:MOS=*:S,OS=,,}
295 A_JAVA_PORT_VENDOR= ${A_JAVA_PORT_INFO:MVENDOR=*:S,VENDOR=,,}
296 .if !defined(_JAVA_PORTS_INSTALLED) && exists(${A_JAVA_PORT_HOME}/${_JDK_FILE})
297 __JAVA_PORTS_INSTALLED+= ${A_JAVA_PORT}
300 # Because variables inside for loops are special (directly replaced as strings),
301 # we are allowed to use them inside modifiers, where normally ${FOO:M${BAR}} is
304 .for ver in ${A_JAVA_PORT_VERSION}
305 .for os in ${A_JAVA_PORT_OS}
306 .for vendor in ${A_JAVA_PORT_VENDOR}
307 .if ${_JAVA_VERSION:M${ver}} && ${_JAVA_OS:M${os}} && ${_JAVA_VENDOR:M${vendor}}
308 __JAVA_PORTS_POSSIBLE+= ${A_JAVA_PORT}
315 .if !defined(_JAVA_PORTS_INSTALLED)
316 _JAVA_PORTS_INSTALLED= ${__JAVA_PORTS_INSTALLED:C/ [ ]+/ /g}
318 _JAVA_PORTS_POSSIBLE= ${__JAVA_PORTS_POSSIBLE:C/ [ ]+/ /g}
321 #-------------------------------------------------------------------------------
322 # Stage 3: Decide the exact JDK to use (or install)
325 # Find an installed JDK port that matches the requirements of the port
327 . undef _JAVA_PORTS_INSTALLED_POSSIBLE
329 . for A_JAVA_PORT in ${_JAVA_PORTS_POSSIBLE}
330 __JAVA_PORTS_INSTALLED_POSSIBLE+= ${_JAVA_PORTS_INSTALLED:M${A_JAVA_PORT}}
332 _JAVA_PORTS_INSTALLED_POSSIBLE= ${__JAVA_PORTS_INSTALLED_POSSIBLE:C/[ ]+//g}
334 . if ${_JAVA_PORTS_INSTALLED_POSSIBLE} != ""
335 . for i in ${_JAVA_PORTS_INSTALLED_POSSIBLE}
336 . if !defined(_JAVA_PORTS_INSTALLED_POSSIBLE_shortcircuit)
338 _JAVA_PORTS_INSTALLED_POSSIBLE_shortcircuit= 1
341 # If no installed JDK port fits, then pick one from the list of possible ones
343 . for i in ${_JAVA_PORTS_POSSIBLE}
344 . if !defined(_JAVA_PORTS_POSSIBLE_shortcircuit)
346 _JAVA_PORTS_POSSIBLE_shortcircuit= 1
351 _JAVA_PORT_INFO:= ${_JAVA_PORT:S/^/\${_/:S/$/_INFO}/}
352 JAVA_PORT= ${_JAVA_PORT_INFO:MPORT=*:S,PORT=,,}
353 JAVA_HOME= ${_JAVA_PORT_INFO:MHOME=*:S,HOME=,,}
354 JAVA_PORT_VERSION= ${_JAVA_PORT_INFO:MVERSION=*:S,VERSION=,,}
355 JAVA_PORT_OS= ${_JAVA_PORT_INFO:MOS=*:S,OS=,,}
356 JAVA_PORT_VENDOR= ${_JAVA_PORT_INFO:MVENDOR=*:S,VENDOR=,,}
358 JAVA_PORT_VENDOR_DESCRIPTION:= ${JAVA_PORT_VENDOR:S/^/\${_JAVA_VENDOR_/:S/$/}/}
359 JAVA_PORT_OS_DESCRIPTION:= ${JAVA_PORT_OS:S/^/\${_JAVA_OS_/:S/$/}/}
361 #-------------------------------------------------------------------------------
362 # Stage 4: Add any dependencies if necessary
365 # Ant Support: USE_ANT --> JAVA_BUILD=jdk
366 . if defined(USE_ANT)
370 # Add the JDK port to the dependencies
371 DEPEND_JAVA= ${JAVA}:${PORTSDIR}/${JAVA_PORT}
372 . if defined(JAVA_EXTRACT)
373 EXTRACT_DEPENDS+= ${DEPEND_JAVA}
375 . if defined(JAVA_BUILD)
376 . if defined(NO_BUILD)
378 @${ECHO_CMD} "${PKGNAME}: Makefile error: JAVA_BUILD and NO_BUILD cannot be set at the same time.";
381 BUILD_DEPENDS+= ${DEPEND_JAVA}
383 . if defined(JAVA_RUN)
384 RUN_DEPENDS+= ${DEPEND_JAVA}
387 # Ant support: default do-build target
388 . if defined(USE_ANT)
389 DESTDIRNAME?= -Dfreebsd.ports.destdir
390 ANT?= ${LOCALBASE}/bin/ant
391 MAKE_ENV+= JAVA_HOME=${JAVA_HOME}
392 BUILD_DEPENDS+= ${ANT}:${PORTSDIR}/devel/apache-ant
394 . if !target(do-build)
396 @(cd ${BUILD_WRKSRC}; \
397 ${SETENV} ${MAKE_ENV} ${ANT} ${MAKE_ARGS} ${ALL_TARGET})
401 #-----------------------------------------------------------------------------
402 # Stage 5: Define all settings for the port to use
404 # At this stage both JAVA_HOME and JAVA_PORT are definitely given a value.
406 # Define the location of the Java compiler.
408 # Only define JAVAC if a JDK is needed
411 # Then test if a JAVAC has to be set (JAVA_BUILD==jdk)
412 . if defined(JAVA_BUILD)
413 . if (${JAVA_BUILD:tu} == "JDK") && !defined(JAVAC)
414 JAVAC?= ${JAVA_HOME}/bin/javac
418 # Define the location of some more executables.
419 APPLETVIEWER?= ${JAVA_HOME}/bin/appletviewer
420 JAR?= ${JAVA_HOME}/bin/jar
421 JAVA?= ${JAVA_HOME}/bin/java
422 JAVADOC?= ${JAVA_HOME}/bin/javadoc
423 JAVAH?= ${JAVA_HOME}/bin/javah
424 JAVAP?= ${JAVA_HOME}/bin/javap
425 JAVA_N2A?= ${JAVA_HOME}/bin/native2ascii
426 JAVA_SERIALVER?=${JAVA_HOME}/bin/serialver
427 RMIC?= ${JAVA_HOME}/bin/rmic
428 RMIREGISTRY?= ${JAVA_HOME}/bin/rmiregistry
429 JAVA_KEYTOOL?= ${JAVA_HOME}/bin/keytool
430 JAVA_POLICYTOOL?= ${JAVA_HOME}/bin/policytool
431 RMID?= ${JAVA_HOME}/bin/rmid
433 # Set the location of the ZIP or JAR file with all standard Java classes.
434 JAVA_CLASSES= ${JAVA_HOME}/jre/lib/rt.jar
437 #-------------------------------------------------------------------------------
438 # Additional Java support
441 # Use it to check Java dependency while porting
443 @${ECHO_CMD} "# User specified parameters:"
444 @${ECHO_CMD} "JAVA_VERSION= ${JAVA_VERSION} (${_JAVA_VERSION})"
445 @${ECHO_CMD} "JAVA_OS= ${JAVA_OS} (${_JAVA_OS})"
446 @${ECHO_CMD} "JAVA_VENDOR= ${JAVA_VENDOR} (${_JAVA_VENDOR})"
447 @${ECHO_CMD} "JAVA_BUILD= ${JAVA_BUILD}"
448 @${ECHO_CMD} "JAVA_RUN= ${JAVA_RUN}"
449 @${ECHO_CMD} "JAVA_EXTRACT= ${JAVA_EXTRACT}"
451 @${ECHO_CMD} "# JDK port dependency selection process:"
452 @${ECHO_CMD} "_JAVA_PORTS_POSSIBLE= ${_JAVA_PORTS_POSSIBLE}"
453 @${ECHO_CMD} "_JAVA_PORTS_INSTALLED= ${_JAVA_PORTS_INSTALLED}"
454 @${ECHO_CMD} "_JAVA_PORTS_INSTALLED_POSSIBLE= ${_JAVA_PORTS_INSTALLED_POSSIBLE}"
455 @${ECHO_CMD} "_JAVA_PORT= ${_JAVA_PORT}"
456 @${ECHO_CMD} "_JAVA_PORT_INFO= ${_JAVA_PORT_INFO:S/\t/ /}"
458 @${ECHO_CMD} "# Selected JDK port:"
459 @${ECHO_CMD} "JAVA_PORT= ${JAVA_PORT}"
460 @${ECHO_CMD} "JAVA_HOME= ${JAVA_HOME}"
461 @${ECHO_CMD} "JAVA_PORT_VERSION= ${JAVA_PORT_VERSION}"
462 @${ECHO_CMD} "JAVA_PORT_OS= ${JAVA_PORT_OS} (${JAVA_PORT_OS_DESCRIPTION})"
463 @${ECHO_CMD} "JAVA_PORT_VENDOR= ${JAVA_PORT_VENDOR} (${JAVA_PORT_VENDOR_DESCRIPTION})"
465 @${ECHO_CMD} "# Additional variables:"
466 @${ECHO_CMD} "JAVAC= ${JAVAC}"
467 @${ECHO_CMD} "JAVA_CLASSES= ${JAVA_CLASSES}"