-
Notifications
You must be signed in to change notification settings - Fork 0
Building OpenJDK 8 on Mac OS X Yosemite
Building OpenJDK 8 (update 40) on OS X 10.10 (Yosemite) was not a cakewalk, until recently the OpenJDK community released a series of patches for the same. These patches, combined with some mailing list replies, seem to be enough to build and enhance OpenJDK 8 successfully on Yosemite systems.
OpenJDK 8 doesn't work with the default llvm-clang compilers supplied with Mac OS X. So the first step is to download an older version of Xcode, which has the older gcc compilers available.
- Login to https://developer.apple.com/downloads/ with your Apple ID.
- Download Xcode 4.6.3 (release date June 13, 2013).
- Create a directory called
Xcode4
inside/Applications/
, and putXcode.app
inside it. This ensures that you could still use the default Xcode6x for other purposes.
OpenJDK 8 has different versions; you must download jdk8u
to get the most up-to-date code, which includes buildfixes for Mac OSX.
- Install mercurial (if not present, already). Check by writing
hg --version
on terminal. - Clone jdk8 from its mercurial repository:
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u jdk8
. - Get the complete sources:
cd jdk8; bash get_source.sh
. This will take time depending on your internet speed (about 20 minutes on broadband).
If './configure' fails with the error 'unable to find freetype', then you have to install it. It's easy to build and install freetype in Mac OS.
- Download FreeType 2.6.5 sources
- Extract it
- cd into the folder and run
- ./configure
- make
- sudo make install
OpenJDK's configure script will require setting JAVA_HOME
, MACOSX_DEPLOYMENT_TARGET
, and SDKPATH
variables:
# prevent "couldn't understand kern.osversion" and "The tested number of bits in the target (0) differs
# from the number of bits expected to be found in the target (64)" errors
export MACOSX_DEPLOYMENT_TARGET=10.8
# If you've put your Xcode4 in a different location, update this accordingly.
export SDKPATH=/Applications/Xcode4/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
# Must be set such that $JAVA_HOME/javac -version reports 1.7.0
export JAVA_HOME=<path_to_jdk7>
Earlier, it was required to switch the default Xcode version (using sudo xcode-select -s /Path-to-Xcode4.app
). But now the path can be supplied using a flag while configuring. Thus, the final build steps are:
bash configure --with-xcode-path=/Applications/Xcode4/Xcode.app
make images
If successful, this step would take approximately 30 minutes (I suggest installing ccache
for faster re-builds). If some error is thrown, try the patches mentioned in the next section.
The information below is old, and with the environment variables set properly they should be unnecessary. Most likely they were build system bugs that have since been fixed. They are left for archival purposes, just in case.
Based on my experience, different people may need to do one or more of the things below for a successful build. Please check whether the build works by doing things one-by-one, in the given order.
- Apply the following patch to
jdk8/hotspot/make/bsd/makefiles/saproc.make
:
- SALIBS = -g -framework Foundation -F/System/Library/Frameworks/JavaVM.framework/Frameworks -framework JavaNativeFoundation -framework Security -framework CoreFoundation
+ SALIBS = -isysroot /Applications/Xcode4/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -g -framework Foundation -F/System/Library/Frameworks/JavaVM.framework/Frameworks -framework JavaNativeFoundation -framework Security -framework CoreFoundation
- Apply the following patch to
jdk8/hotspot/make/bsd.makefiles/gcc.make
:
# The macro takes the version with no dots, ex: 1070
CFLAGS += -DMAC_OS_X_VERSION_MAX_ALLOWED=$(subst .,,$(MACOSX_VERSION_MIN)) \ -mmacosx-version-min=$(MACOSX_VERSION_MIN)
- LDFLAGS += -mmacosx-version-min=$(MACOSX_VERSION_MIN)
+ LFLAGS += -mmacosx-version-min=$(MACOSX_VERSION_MIN)
endif
- Apply the following patch to
jdk8/hotspot/make/bsd/makefiles/saproc.make
:
ifneq ($(OS_VENDOR), Darwin)
SA_LFLAGS = $(MAPFLAG:FILENAME=$(SAMAPFILE))
+ else
+ # bring in minimum version argument or we'll fail on OSX 10.10
+ SA_LFLAGS = $(LFLAGS)
endif
SA_LFLAGS += $(LDFLAGS_HASH_STYLE)
The newly-built binaries (javac, java, etc.) are found at:
jdk8/build/macosx-x86_64-normal-server-release/images/j2sdk-image/bin/
Hurray!!!