Skip to content

Instantly share code, notes, and snippets.

@timfel
Forked from stepheneb/01-building-mlvm-openjdk.md
Created October 28, 2010 22:01
Show Gist options
  • Save timfel/652422 to your computer and use it in GitHub Desktop.
Save timfel/652422 to your computer and use it in GitHub Desktop.

Building MLVM version of OpenJDK (Java 1.7) on Mac OS X

Take a look at the comments and code in 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.

I use create_tarball.sh to make a copy of the build to share.

Alternatively here's how I build the NON-MLVM version of OpenJDK.

#!/bin/sh
#
# Creates a symbolic link to the last successful build and
# generates a tarball for the build.
#
if [ -e .last_build ]
then buildname=`cat .last_build`
else echo "file '.last_build' does not exist"; exit
fi
if [ -e $buildname ]
then rm -f $buildname
fi
ln -Ffs build/bsd-i586/j2sdk-image/ $buildname
echo "creating $buildname.tar.gz"
if [ -e $buildname.tar.gz ]
then rm -f $buildname=`cat .last_build`
fi
tar czf $buildname.tar.gz $buildname/*
# 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
# copies build dir to /usr/local and links
# /usr/local/java-1.7.0 to new build
buildname=java-1.7.0-internal-`date "+%Y_%m_%d"`
echo "copying build/bsd-i586/j2sdk-image/* to /usr/local/$buildname"
sudo rm -rf /usr/local/$buildname
sudo mkdir /usr/local/$buildname
sudo 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
echo '
/usr/local/java-1.7.0/bin/java -version
'
/usr/local/java-1.7.0/bin/java -version
# Building the Java 1.7 Da Vinci Machine (mlvm) on Mac OS X
#
# filename: update.sh
# latest version available here: http://gist.github.com/243072
#
# 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
# The bsd port forest is checked out into: ./sources/
# The mlvm patchsets are checked out into: ./patches/
# SoyLatte 32-bit Java 1.6 is located here:
# /usr/local/soylatte16-i386-1.0.3
# ALT_JIBX_LIBS_PATH points to JIBX v1.1.5
#
# 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://sourceforge.net/projects/jibx/files/
#
# 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)
#
# JiBX v1.1.5 (Binding XML to Java libraries)
#
# Download and install v1.1.5 of JIBX from sourceforge
# http://sourceforge.net/projects/jibx/files/
# update the ALT_JIBX_LIBS_PATH variable in this script.
#
# Basic setup after installing prerequisites:
# mkdir davinci
# cd davinci
# hg fclone http://hg.openjdk.java.net/bsd-port/bsd-port sources
# hg fclone http://hg.openjdk.java.net/mlvm/mlvm patches
#
# 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 davinci
# source update.sh
#
# After building see if the new build can report it's version number:
# $ ./build/bsd-i586/j2sdk-image/bin/java -version
# openjdk version "1.7.0-internal"
# OpenJDK Runtime Environment (build 1.7.0-internal-stephen_2009_11_25_22_57-b00)
# OpenJDK Server VM (build 17.0-b05, mixed mode)
#
cd sources
echo '
*** popping previously applied patches to bsdport sources: hotspot, jdk, and langtools ...'
echo '
[hotspot] '
cd hotspot; hg qpop -a; cd -
echo '
[jdk] '
cd jdk; hg qpop -a; cd -
echo '
[langtools] '
cd langtools; hg qpop -a; cd -
echo '
*** updating bsdport sources...
'
hg fpull -u
echo '
*** updating mlvm patchsets ...
'
cd ../patches
hg fpull -u
cd ..
echo '
*** integrating mlvm patchsets into bsdport sources ...
'
bash patches/make/link-patch-dirs.sh sources patches
ls -il patches/hotspot/series sources/hotspot/.hg/patches/series
export davinci=$(pwd) guards="buildable testable"
echo '
*** running: hg qselect --reapply $guards
'
sh patches/make/each-patch-repo.sh "hg qselect --reapply $guards" '$(sh $davinci/patches/make/current-release.sh)'
echo '
*** running: hg qselect --pop $guards
'
sh patches/make/each-patch-repo.sh "hg qselect --pop $guards" '$(sh $davinci/patches/make/current-release.sh)'
echo '
*** running: hg qselect; hg qunapplied
'
sh patches/make/each-patch-repo.sh "hg qselect; hg qunapplied"
echo '
*** running: hg update -r
'
sh patches/make/each-patch-repo.sh "hg update -r" '$(sh $davinci/patches/make/current-release.sh)'
echo '
*** running: hg qpush -a
'
sh patches/make/each-patch-repo.sh "hg qpush -a"
echo '
*** cleaning previous build products ...
'
cd sources
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 davinci (mlvm) ...
'
export LC_ALL=C
export LANG=C
unset CLASSPATH
unset JAVA_HOME
sets="
ALT_BOOTDIR=/usr/local/soylatte16-i386-1.0.3
ALT_JDK_IMPORT_PATH=/usr/local/soylatte16-i386-1.0.3
ALT_BINARY_PLUGS_PATH=$HOME/dev/java/jdk-7-icedtea-plugs
ALT_FREETYPE_HEADERS_PATH=/usr/X11R6/include
ALT_FREETYPE_LIB_PATH=/usr/X11R6/lib
ALT_JIBX_LIBS_PATH=$HOME/dev/java/jibx/lib
ANT_HOME=/usr/share/ant
NO_DOCS=true
HOTSPOT_BUILD_JOBS=2
BUILD_LANGTOOLS=true
BUILD_JAXP=false
BUILD_JAXWS=false
BUILD_CORBA=false
BUILD_HOTSPOT=true
BUILD_JDK=true
DEBUG_NAME=fastdebug
SKIP_FASTDEBUG_BUILD=true
CC=gcc-4.0
CXX=g++-4.0
ALT_COMPILER_PATH=$(pwd -P)/ALT_COMPILER_PATH/
LD_LIBRARY_PATH=
"
echo '
*** executing sets into the environment ...
'
# Execute the above sets, into the environment.
for s in $sets; do eval export $s; done
echo '
*** preview sets in command line ...
'
# Preview sets in command line
for s
do case $s in
*'[ ;]'*) break;;
*'='*) eval "$s";;
*) break;;
esac
done
echo '
*** removing *.gch files ...
'
# Incremental JVM rebuilds have trouble with *.gch files.
# The *.gch file does not get regenerated unless you remove it,
# even if 20 header files have changed.
# This is not a problem for batch builds, of course.
$BUILD_HOTSPOT && {
${KEEP_HOTSPOT_HEADERS:-false} ||
rm -f $(find build -name _precompiled.incl.gch)
}
# If COMMAND_MODE=legacy then the archive command: 'ar' will not create or update
# catalog entries when creating an archive resulting in errors like this:
#
# libfdlibm.i586.a, archive has no table of contents
#
# This only appears to be a problem when using iTerm as the terminal program.
# Using the Terminal.app program that comes with Mac OS X sets COMMAND_MODE=unix2003.
# See: http://old.nabble.com/Why-ar-doesn't-call-ranlib-on-Mac--td22319721.html
if [ "$COMMAND_MODE" = "legacy" ]
then
echo '
*** changing COMMAND_MODE from legacy to unix2003
'
export COMMAND_MODE=unix2003
fi
echo '
*** running make ...
'
# Run make, or whatever, in the resulting environment.
eval "${@-make}"
# Usage example: For a partial (re-)build of JDK only:
# sh build.sh BUILD_{HOTSPOT,LANGTOOLS}=false make
echo '
testing build: ./build/bsd-i586/j2sdk-image/bin/java -version
'
./build/bsd-i586/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-i586/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