Subject: Improving Java VM and SDK installation
To: None <tech-pkg@netbsd.org>
From: Julio M. Merino Vidal <jmmv@menta.net>
List: tech-pkg
Date: 05/17/2004 17:49:23
Hi all,

I have to agree with <pancake at phreaker.net>: the way we handle
installations of Java VM's and SDK's is suboptimal.  Simply put,
they don't work out of the box, and this bothers me a lot (I can
stand having to mount procfs, but not having to tune PATH nor ulimit
resources).

So I have written something that hopefully improves this situation.
It is a makefile fragment, which I've called java-env.mk [1].  It
automatically generates wrapper scripts for the most common java
utilities (or not so common); these small scripts take care to set
up the environment (classpath, JVM_HOME, unlimit resources, etc.)
and then launch their respective java binary.

These scripts are named <java_name>-<program_name> so that there are
no collisions between different Java implementations.  They are all
installed in ${PREFIX}/bin.

Note that the actual behavior of packages is preserved; I mean,
nothing changes in them except for the installation of some simple
scripts.  I have a doubt though... what to do with the "EVAL_PREFIX"
stuff in some buildlink files?  See sun-jre14/buildlink3.mk for an
example.

The next step (after all java packages in pkgsrc are converted to
make use of this stuff, which is trivial) will be to write a simple
wrapper (in a completely independent package) that installs "generic"
binaries (like 'java', 'javac', etc), which simply call any other
*-java script, according to some configuration file (idea based on
what pancake said on a previous mail).  But more on this when it's
time for it; not now ;)

I've attached the new file, as well as a patch to convert sun-*14 to
use it.  Note that the later misses patches for the PLIST's.  I've
done this intentionally because they were *big* (it's a matter of
changing _all_ entries to have java/sun-1.4 in front of them and
registering the new wrappers in bin/*).

So... what do you think of this stuff?  Any objections and/or major
problems in it?

Thanks!

[1]: Any better name for the file, please?  It can easily cause
     confusion with java-vm.mk, in mk/ too.



# $NetBSD$
#
# This Makefile fragment handles Java wrappers and is meant to be included
# by packages that provide a Java build-time and/or run-time environment.
#
# The following variables can be defined in package Makefiles to tune the
# behavior of this file:
#
#	JAVA_CLASSPATH	Classpath that will be prepended on all invocations
#			to this implementation.  Optional.
#
#	JAVA_HOME	Path to the directory holding the Java implementation.
#			Required.
#
#	JAVA_NAME	Base name of the Java implementation.  This will be
#			used as part of wrappers' names.  Required.
#
#	JAVA_UNLIMIT	List of resources to be unlimited at runtime.
#			Can include any of cmdsize, datasize and stacksize.
#			Optional.
#
#	JAVA_WRAPPERS	List of wrappers to be created under ${PREFIX}/bin,
#			pointing to binaries under ${JAVA_HOME}/bin.  The
#			names must match files in the later directory.
#			Required (if empty, the inclusion of this file is
#			useless).
#

.if !defined(JAVA_ENV_MK)
JAVA_ENV_MK=		# defined

JAVA_NAME?=		# undefined
JAVA_HOME?=		# undefined
JAVA_CLASSPATH?=	# empty
JAVA_UNLIMIT?=		# empty
JAVA_WRAPPERS?=		# empty

.for w in ${JAVA_WRAPPERS}

post-build:		${WRKDIR}/${w}

.PHONY:			install-java-wrapper-${w}
post-install:		install-java-wrapper-${w}

.  if !target(${WRKDIR}/${w})
${WRKDIR}/${w}:
	@${ECHO} 'Generating ${w} wrapper...'
	@${ECHO} '#! ${SH}' >${WRKDIR}/${w}
	@${ECHO} 'PATH=${JAVA_HOME}/bin:$${PATH}; export PATH' >>${WRKDIR}/${w}
	@${ECHO} 'JAVA_HOME=${JAVA_HOME}; export JAVA_HOME' >>${WRKDIR}/${w}
	@${ECHO} 'JVM_HOME=${JAVA_HOME}; export JDK_HOME' >>${WRKDIR}/${w}
.    if !empty(JAVA_CLASSPATH)
	@${ECHO} 'CLASSPATH=${JAVA_CLASSPATH}:$${CLASSPATH}; export CLASSPATH' \
		>>${WRKDIR}/${w}
.    endif
.    for f in ${JAVA_UNLIMIT}
	@${ECHO} '${ULIMIT_CMD_${f}}' >>${WRKDIR}/${w}
.    endfor
.    undef f
	@${ECHO} '${JAVA_HOME}/bin/${w} "$$@"' >>${WRKDIR}/${w}
.  endif

install-java-wrapper-${w}:
	${INSTALL_SCRIPT} ${WRKDIR}/${w} ${PREFIX}/bin/${JAVA_NAME}-${w}

.endfor
.undef w

.endif	# JAVA_ENV_MK



Index: sun-jre14/MESSAGE.NetBSD
===================================================================
RCS file: /cvsroot/pkgsrc/lang/sun-jre14/MESSAGE.NetBSD,v
retrieving revision 1.6
diff -u -r1.6 MESSAGE.NetBSD
--- sun-jre14/MESSAGE.NetBSD	2 Apr 2004 10:12:34 -0000	1.6
+++ sun-jre14/MESSAGE.NetBSD	17 May 2004 15:41:21 -0000
@@ -10,18 +10,13 @@
 
 procfs /emul/linux/proc procfs rw,linux
 
-Furthermore, the data segment size set by your shell's 'ulimit' builtin
-must be at least 262144 -- please refer to your shell's manual page for
-details.
+Furthermore, the maximum data segment size assigned to your user must be
+at least 262144.
 
 You may want to read
 
-	${PREFIX}/README
+	${JAVA_HOME}/README
 
-for details about running this JDK.  In a nutshell you may want to set the
-following in your shell environment:
-
-	JAVA_HOME to ${PREFIX}
-	PATH to include ${PREFIX}/bin
+for details about running this JDK.
 
 ===========================================================================
Index: sun-jre14/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/lang/sun-jre14/Makefile,v
retrieving revision 1.16
diff -u -r1.16 Makefile
--- sun-jre14/Makefile	17 Mar 2004 22:01:43 -0000	1.16
+++ sun-jre14/Makefile	17 May 2004 15:41:21 -0000
@@ -2,6 +2,7 @@
 
 DISTNAME=	j2re-1_4_2_04-linux-i586
 PKGNAME=	sun-jre14-2.4
+PKGREVISION=	1
 MASTER_SITES=	# empty
 
 COMMENT=	Sun's Java(tm) 2 Runtime Environment 1.4.2
@@ -10,12 +11,13 @@
 
 WRKSRC=		${WRKDIR}/j2re1.4.2_04
 USE_PKGINSTALL=	yes
-OWN_DIRS=	${PREFIX}
-OWN_DIRS+=	${PREFIX}/lib
-OWN_DIRS+=	${PREFIX}/lib/applet
-OWN_DIRS+=	${PREFIX}/lib/images
-OWN_DIRS+=	${PREFIX}/lib/images/cursors
-OWN_DIRS+=	${PREFIX}/lib/security
+JAVA_WRAPPERS=	java
+OWN_DIRS=	${JAVA_HOME}
+OWN_DIRS+=	${JAVA_HOME}/lib
+OWN_DIRS+=	${JAVA_HOME}/lib/applet
+OWN_DIRS+=	${JAVA_HOME}/lib/images
+OWN_DIRS+=	${JAVA_HOME}/lib/images/cursors
+OWN_DIRS+=	${JAVA_HOME}/lib/security
 SFILES=		content-types.properties	flavormap.properties
 SFILES+=	font.properties.Redhat6.1	font.properties
 SFILES+=	font.properties.ja.Redhat6.1	font.properties.ja.Redhat6.2
@@ -26,7 +28,7 @@
 SFILES+=	psfontj2d.properties		security/java.security
 SUPPORT_FILES=	# empty
 .for FILE in ${SFILES}
-SUPPORT_FILES+=	${PREFIX}/lib/${FILE}.default ${PREFIX}/lib/${FILE}
+SUPPORT_FILES+=	${JAVA_HOME}/lib/${FILE}.default ${JAVA_HOME}/lib/${FILE}
 .endfor
 
 do-configure:
@@ -35,5 +37,3 @@
 	done
 
 .include "../../lang/sun-jre14/Makefile.common"
-
-PREFIX=		${JVM_HOME}
Index: sun-jre14/Makefile.common
===================================================================
RCS file: /cvsroot/pkgsrc/lang/sun-jre14/Makefile.common,v
retrieving revision 1.18
diff -u -r1.18 Makefile.common
--- sun-jre14/Makefile.common	5 May 2004 17:20:29 -0000	1.18
+++ sun-jre14/Makefile.common	17 May 2004 15:41:21 -0000
@@ -21,7 +21,11 @@
 
 .include "../../mk/bsd.prefs.mk"
 
-JVM_HOME=	${LOCALBASE}/java/sun-1.4
+JAVA_HOME=	${LOCALBASE}/java/sun-1.4
+JAVA_NAME=	sun14
+JAVA_UNLIMIT=	datasize
+
+MESSAGE_SUBST+=	JAVA_HOME="${JAVA_HOME}"
 
 .if ${OPSYS} == "NetBSD"
 DEPENDS+=	suse_compat-[0-9]*:../../emulators/${SUSE_DIR_PREFIX}_compat
@@ -61,11 +65,12 @@
 do-build:	# nothing
 
 do-install:
-	${INSTALL_PROGRAM_DIR} ${PREFIX}
-	cd ${WRKSRC} && ${PAX} -rwp ma . ${PREFIX}
+	${INSTALL_PROGRAM_DIR} ${JAVA_HOME}
+	cd ${WRKSRC} && ${PAX} -rwp ma . ${JAVA_HOME}
 
 .if ${OPSYS} == "NetBSD"
 .  include "../../emulators/suse_linux/Makefile.application"
 .endif
 
+.include "../../mk/java-env.mk"
 .include "../../mk/bsd.pkg.mk"
Index: sun-jdk14/MESSAGE.NetBSD
===================================================================
RCS file: /cvsroot/pkgsrc/lang/sun-jdk14/MESSAGE.NetBSD,v
retrieving revision 1.6
diff -u -r1.6 MESSAGE.NetBSD
--- sun-jdk14/MESSAGE.NetBSD	2 Apr 2004 10:12:33 -0000	1.6
+++ sun-jdk14/MESSAGE.NetBSD	17 May 2004 15:41:22 -0000
@@ -10,18 +10,13 @@
 
 procfs /emul/linux/proc procfs rw,linux
 
-Furthermore, the data segment size set by your shell's 'ulimit' builtin
-must be at least 262144 -- please refer to your shell's manual page for
-details.
+Furthermore, the maximum data segment size assigned to your user must be
+at least 262144.
 
 You may want to read
 
-	${PREFIX}/README
+	${JAVA_HOME}/README
 
-for details about running this JDK.  In a nutshell you may want to set the
-following in your shell environment:
-
-	JAVA_HOME to ${PREFIX}
-	PATH to include ${PREFIX}/bin
+for details about running this JDK.
 
 ===========================================================================
Index: sun-jdk14/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/lang/sun-jdk14/Makefile,v
retrieving revision 1.17
diff -u -r1.17 Makefile
--- sun-jdk14/Makefile	17 Mar 2004 22:01:43 -0000	1.17
+++ sun-jdk14/Makefile	17 May 2004 15:41:22 -0000
@@ -2,6 +2,7 @@
 
 DISTNAME=	j2sdk-1_4_2_04-linux-i586
 PKGNAME=	sun-jdk14-2.4
+PKGREVISION=	1
 MASTER_SITES=	# empty
 
 COMMENT=	Sun's Java(tm) 2 SDK, Standard Edition 1.4.2
@@ -11,6 +12,7 @@
 DEPENDS=	sun-jre14>=2.4:../../lang/sun-jre14
 
 WRKSRC=		${WRKDIR}/j2sdk1.4.2_04
+JAVA_WRAPPERS=	appletviewer jar javac javadoc javah javap
 
 # Remove parts that are in common with the JRE
 #
@@ -26,5 +28,3 @@
 	${LN} -sf . ${WRKSRC}/jre
 
 .include "../../lang/sun-jre14/Makefile.common"
-
-PREFIX=		${JVM_HOME}

-- 
Julio M. Merino Vidal <jmmv@menta.net>
The NetBSD Project - http://www.NetBSD.org/