Step-by-step OpenJDK on OS X?
Stephen Bannasch
stephen.bannasch at deanbrook.org
Sat Jan 31 18:43:24 PST 2009
At 2:30 PM -0600 1/30/09, Charles Oliver Nutter wrote:
>I've read through some of the backthreads and there's a lot of noise
>about getting OpenJDK to build, having this issue, applying that patch.
>I'm wondering what the bottom line is today:
>
>- Is it possible to build OpenJDK on OS X right now? Which
>versions/branches/etc?
>- Has anyone aggregated the instructions required to do so yet? I mostly
>got an older revision to build using Landon Fuller's walkthrough, but
>that's pretty dated now.
Building the BSD port of OpenJDK -- Java 1.7 on Max OS X 10.5.x
This is lightly adapted from Landon Fuller's instructions here:
http://landonf.bikemonkey.org/2008/08/20#SoyLatte_Meets_OpenJDK.20080819
Dependencies:
I'm using Landon Fuller's 32-bit SoyLatte binaries to build the
OpenJDK bsd port:
http://landonf.bikemonkey.org/static/soylatte/
http://hg.bikemonkey.org/archive/javasrc_1_6_jrl_darwin/soylatte16-i386-1.0.3.tar.bz2
After downloading the binaries I copied then to:
/usr/local/soylatte16-i386-1.0.3
Get Mercurial:
sudo port install mercurial +bash_completion
and add the Forest extension:
hg clone http://hg.akoha.org/hgforest
I'm actually using Patrick Mézard's clone of hgforest (just a couple
of fixes to Simons work):
hg clone http://bitbucket.org/pmezard/hgforest-crew
And after that add an 'hgext.forest' item with the path to forest.py
in the extensions section in your ~/.hgrc file.
Here's mine:
$ cat ~/.hgrc
[ui]
username = Stephen Bannasch <stephen.bannasch at gmail.com>
[extensions]
hgext.forest=/Users/stephen/dev/mercurial/hgforest-crew/forest.py
You'll also need Kurt Miller's binary plugs for the BSD port:
http://landonf.bikemonkey.org/static/soylatte/jdk-7-icedtea-plugs-1.6.tar.gz
I unpacked them here:
~/dev/java/jdk-7-icedtea-plugs
Checkout all the code using hg/forest:
hg fclone http://hg.openjdk.java.net/bsd-port/bsd-port
Here's what my bsd-port dir looks like:
$ cd bsd-port/
$ ls -l
total 528
-rw-r--r-- 1 stephen staff 1503 Dec 15 12:29 ASSEMBLY_EXCEPTION
-rw-r--r-- 1 stephen staff 19241 Dec 15 12:29 LICENSE
-rw-r--r-- 1 stephen staff 16336 Dec 15 12:29 Makefile
-rw-r--r-- 1 stephen staff 1207 Dec 15 12:29 README
-rw-r--r-- 1 stephen staff 87215 Jan 25 23:04 README-builds.html
-rw-r--r-- 1 stephen staff 127532 Dec 15 12:29 THIRD_PARTY_README
drwxr-xr-x 4 stephen staff 136 Jan 26 00:51 build
-rwxr--r--@ 1 stephen staff 373 Jan 26 03:00 build.sh
drwxr-xr-x 11 stephen staff 374 Jan 25 23:06 corba
drwxr-xr-x 13 stephen staff 442 Jan 25 23:06 hotspot
drwxr-xr-x 11 stephen staff 374 Jan 25 23:06 jaxp
drwxr-xr-x 11 stephen staff 374 Jan 25 23:06 jaxws
drwxr-xr-x 12 stephen staff 408 Jan 25 23:07 jdk
drwxr-xr-x 12 stephen staff 408 Jan 25 23:07 langtools
drwxr-xr-x 18 stephen staff 612 Dec 15 12:29 make
I added the script build.sh:
$ cat build.sh
# source build.sh
LC_ALL=C
LANG=C
unset CLASSPATH
unset JAVA_HOME
make \
ALT_BOOTDIR=/usr/local/soylatte16-i386-1.0.3/ \
ALT_BINARY_PLUGS_PATH=/Users/stephen/dev/java/jdk-7-icedtea-plugs \
ALT_FREETYPE_HEADERS_PATH=/usr/X11R6/include \
ALT_FREETYPE_LIB_PATH=/usr/X11R6/lib \
ALT_CUPS_HEADERS_PATH=/usr/include \
ANT_HOME=/usr/share/ant \
NO_DOCS=true \
HOTSPOT_BUILD_JOBS=1
I build openjdk like this:
source build.sh
This takes about 10m on my 2.5 GHz Intel Core 2 Duo MacBook Pro.
If it works I then copy it to /usr/local adding a suffix of my
username and the date:
sudo mv build/bsd-i586/j2sdk-image
/usr/local/java-1.7.0-internal-`date "+%Y_%m_%d"``
$ /usr/local/java-1.7.0/bin/java -version
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build
1.7.0-internal-stephen_2009_01_25_23_54-b00)
OpenJDK Server VM (build 14.0-b10, mixed mode)
Then I link /usr/local/java-1.7.0 to the latest build:
$ cd /usr/local
$ sudo ln -s java-1.7.0-internal-`date "+%Y_%m_%d"` java-1.7.0
THese functions are in update-usr-local.sh:
#!/bin/sh
buildname=java-1.7.0-internal-`date "+%Y_%m_%d"`
cp -r build/bsd-i586/j2sdk-image /usr/local/$buildname
cd /usr/local
sudo rm -f java-1.7.0
sudo ln -s $buildname java-1.7.0
This results in:
$ ls -l /usr/local
...
lrwxr-xr-x 1 root wheel 38 Jan 31 20:58 java-1.7.0 ->
java-1.7.0-internal-2009_01_31
drwxr-xr-x 15 root wheel 510 Jan 31 21:37 java-1.7.0-internal-2009_01_31
Updating:
$ cd bsd-port
$ hg fpull -u
$ source build.sh
$ sudo ./update-usr-local.sh
I've modified the function pickjdk in my ~./bash_profile like this to
add java 1.7.0
#
# pickjdk: for switching between Java versions:
# From Nick Sieger: http://pastie.org/170326
# "I just symlink soylatte to:
#
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0-soylatte/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0-soylatte"
#
_macosx()
{
if [ $(uname -s) = Darwin ]; then
return 0
else
return 1
fi
}
JDKS_ROOT=
if [ $(uname -s) = Darwin ]; then
JDKS_ROOT=/System/Library/Frameworks/JavaVM.framework/Versions
fi
SOYLATTE_HOME=${HOME}/dev/java/src/soylatte/control/build/bsd-amd64
SOYLATTE_32_HOME=/usr/local/soylatte16-i386-1.0.3
JAVA_1_7_0_HOME=/usr/local/java-1.7.0
pickjdk()
{
if [ -z "$JDKS_ROOT" ]; then
return 1
fi
declare -a JDKS
local n=1 jdk total_jdks choice=0 currjdk=$JAVA_HOME explicit_jdk
for jdk in $JDKS_ROOT/[0-9]*; do
if [ -d $jdk -a ! -L $jdk ]; then
echo -n " $n) $(basename $jdk)"
if _macosx; then
jdk=$jdk/Home
fi
if [ $jdk = "$currjdk" ]; then
echo " < CURRENT"
else
echo
fi
JDKS[$n]=$jdk
total_jdks=$n
n=$[ $n + 1 ]
fi
done
echo " $n) Soylatte-amd64"
JDKS[$n]=$SOYLATTE_HOME
n=$[ $n + 1 ]
echo " $n) Soylatte16-i386-1.0.3"
JDKS[$n]=$SOYLATTE_32_HOME
n=$[ $n + 1 ]
echo " $n) 1.7.0"
JDKS[$n]=$JAVA_1_7_0_HOME
n=$[ $n + 1 ]
echo " $n) None"
JDKS[$n]=None
total_jdks=$n
if [ $total_jdks -gt 1 ]; then
while [ -z "${JDKS[$choice]}" ]; do
echo -n "Choose one of the above [1-$total_jdks]: "
read choice
done
else
choice=1
fi
if [ -z "$currjdk" ]; then
currjdk=$(dirname $(dirname $(type -path java)))
fi
if [ ${JDKS[$choice]} != None ]; then
export JAVA_HOME=${JDKS[$choice]}
else
unset JAVA_HOME
fi
explicit_jdk=
for jdk in ${JDKS[*]}; do
if [ "$currjdk" = "$jdk" ]; then
explicit_jdk=$jdk
break
fi
done
if [ "$explicit_jdk" ]; then
if [ -z "$JAVA_HOME" ]; then
PATH=$(echo $PATH | sed "s|$explicit_jdk/bin:*||g")
else
PATH=$(echo $PATH | sed "s|$explicit_jdk|$JAVA_HOME|g")
fi
elif [ "$JAVA_HOME" ]; then
PATH="$JAVA_HOME/bin:$PATH"
fi
hash -r
unset JDKS
}
More information about the bsd-port-dev
mailing list