Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stepheneb
Created October 8, 2010 20:15
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stepheneb/617451 to your computer and use it in GitHub Desktop.
Save stepheneb/617451 to your computer and use it in GitHub Desktop.

Building the BSD-port version of OpenJDK (Java 1.7) on Mac OS X

Take a look at the comments and code in update.sh.

$ source update.sh

I use update-usr-local.sh after a successful build to copy the new JVM into /usr/local.

I add pickjdk.sh into my ~/.bash_profile to allow easy switching between multiple JVMs.

Alternative OpenJDK 1.7 builds for Mac OS X:

# bash function: pickjdk
#
# I add this to my ~/.bash_profile
#
# pickjdk: for switching between Java versions:
# From Nick Sieger: http://pastie.org/170326
#
# Set these paths for the install locations on your system:
# SOYLATTE_64_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
_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_64_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
}
#!/bin/sh
#
# file: update-usr-local.sh
#
# Remove file with versioned name of last build and symbolic link to last build.
# Used when referring to a build when copying to /usr/local or creating a tarball.
if [ -e .last_build ]
then buildname=`cat .last_build`
fi
echo "copying build/bsd-amd64/j2sdk-image/* to /usr/local/$buildname"
sudo rm -rf /usr/local/$buildname
sudo mkdir /usr/local/$buildname
sudo cp -r build/bsd-amd64/j2sdk-image/* /usr/local/$buildname
cd /usr/local
sudo rm -f java-1.7.0
sudo ln -s $buildname java-1.7.0
echo '
/usr/local/java-1.7.0/bin/java -version
'
/usr/local/java-1.7.0/bin/java -version
cd -
# Building the Java 1.7 BSD version of OpenJDK on Mac OS X
#
# filename: update.sh
# latest version available here: http://gist.github.com/617451
#
# Stephen Bannasch, 2009 11 29, tested on Mac OS X 10.5.8
#
# This script assumes:
# Apple's Mac OX X developer tools are installed
# hg (mercurial) is installed
# The forest extension to hg is installed
# SoyLatte 32-bit Java 1.6 is located here:
# /usr/local/soylatte16-i386-1.0.3
#
# References:
# http://wikis.sun.com/display/mlvm
# http://wikis.sun.com/display/mlvm/Building
# http://hg.openjdk.java.net/mlvm/mlvm/file/tip/README.txt
# http://bit.ly/8TKqcS
# http://landonf.bikemonkey.org/static/soylatte/
# http://hg.openjdk.java.net/jdk7/build/raw-file/tip/README-builds.html
#
# http://hgbook.red-bean.com/read/advanced-uses-of-mercurial-queues.html
#
# Prerequisites:
# SoyLatte 32-bit Java 1.6
#
# Download v1.0.3 of Landon Fuller's SoyLatte Java 1.6 32 bit release
# and install or link it to /usr/local/soylatte16-i386-1.0.3 and test it:
#
# $ /usr/local/soylatte16-i386-1.0.3/bin/java -version
# java version "1.6.0_03-p3"
# Java(TM) SE Runtime Environment (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00)
# Java HotSpot(TM) Server VM (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00, mixed mode)
#
# Basic setup after installing prerequisites:
# hg fclone http://hg.openjdk.java.net/bsd-port/bsd-port bsd
# cd bsd
#
# Create the ALT_COMPILER_PATH directoru and compiler links:
# In the sources/ dir create the ALT_COMPILER_PATH dir and
# the following symbolic links to the gcc 4.0 compilers:
#
# cd sources
# mkdir ALT_COMPILER_PATH
# cd ALT_COMPILER_PATH
# ln -s /usr/bin .SOURCE
# ln -s .SOURCE/g++-4.0 g++
# ln -s .SOURCE/gcc-4.0 gcc
#
# Building:
# cd bsd
# source update.sh
#
# After building see if the new build can report it's version number:
# $ ./build/bsd-amd64/j2sdk-image/bin/java -version
# openjdk version "1.7.0-internal"
# OpenJDK Runtime Environment (build 1.7.0-internal-stephen_2010_10_08_15_33-b00)
# OpenJDK 64-Bit Server VM (build 19.0-b05, mixed mode)
SOYLATTE=/usr/local/soylatte16-i386-1.0.3
OPENJDK17=/usr/local/java-1.7.0
MLVM=/usr/local/java-1.7.0-mlvm
# echo '
# *** popping previously applied patches to bsdport sources: hotspot, jdk, and langtools ...
# '
# cd hotspot; hg qpop -a; hg parent; cd -
# cd jdk; hg qpop -a; hg parent; cd -
# cd langtools; hg qpop -a; hg parent; cd -
echo '
*** updating bsdport sources...
'
hg fpull -u
echo '
*** cleaning previous build products ...
'
mv build build.del; rm -rf build.del &
# Remove file with versioned name of last build and symbolic link to last build.
# Used when referring to a build when copying to /usr/local or creating a tarball.
if [ -e .last_build ]
then
echo '
removing references to last build
'
buildname=`cat .last_build`
rm -f .last_build
rm -f $buildname
fi
echo '
*** building bsd-port: java 1.7.0 ...
'
unset CLASSPATH
unset JAVA_HOME
unset LD_LIBRARY_PATH
env -i PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin \
LANG=C \
CC=gcc-4.0 \
CXX=g++-4.0 \
make \
ALT_BOOTDIR=$SOYLATTE \
ALT_JDK_IMPORT_PATH=$SOYLATTE \
ALT_FREETYPE_HEADERS_PATH=/usr/X11R6/include \
ALT_FREETYPE_LIB_PATH=/usr/X11R6/lib \
ALT_CUPS_HEADERS_PATH=/usr/include \
ALLOW_DOWNLOADS=true \
ANT_HOME=/usr/share/ant \
NO_DOCS=true \
HOTSPOT_BUILD_JOBS=2 \
ARCH_DATA_MODEL=64 \
ALT_COMPILER_PATH=$(pwd -P)/ALT_COMPILER_PATH/ \
LD_LIBRARY_PATH=
echo '
testing build: ./build/bsd-amd64/j2sdk-image/bin/java -version
'
./build/bsd-amd64/j2sdk-image/bin/java -version
# Save a name with the date to use when referring to this build
# when copying to /usr/local or creating a tarball later.
buildname=java-1.7.0-internal-`date "+%Y_%m_%d"`
ln -Ffs build/bsd-amd64/j2sdk-image/ $buildname
echo $buildname > .last_build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment