歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Mac OSX 10.10 Yosemite編譯OpenJDK 9

Mac OSX 10.10 Yosemite編譯OpenJDK 9

日期:2017/2/28 14:00:48   编辑:Linux教程

在Mac OSX 10.10系統上編譯了下OpenJDK9,以下僅是個人安裝記錄,供參考。

編譯時間:2015-06-13

系統版本:Mac OS X Yosemite 10.10.4

編譯OpenJDK版本:JDK 9

相關軟件版本

  • XCode版本:XCode6-Beat4 Version 6.0 (6A267n)
  • JDK版本:1.8.0_45
  • 軟件管理工具:brew
  • Xquartz(X11):2.7.7

參考資料:

  • OpenJDK Home Page

  • OpenJDK官方編譯步驟(下載完源碼裡面就有README-builds文件)

  • JDK BUG System(編譯遇到問題可以上面搜索)

  • OpenJDK官網操作系統等要求

編譯前期准備:

•大致了解官網系統要求:


https://wiki.openjdk.java.net/display/Build/Supported+Build+Platforms

•源碼下載工具安裝(此處采用Mercurial工具[OpenJDK的版本管控工具]從官網下載):


安裝參考資料:

http://openjdk.java.net/guide/repositories.html

https://mercurial.selenic.com/wiki/Download#Mac_OS_X

本機安裝腳本:

安裝:

$ brew install mercurial

若link失敗,則:

$ sudo brew link mercurial

驗證版本不低於2.6.3:hg version

安裝後版本3.0.2,改為官網下載安裝3.4.1了

•安裝ccache提高編譯速度

$ brew search ccache
$ brew install ccache

•安裝freetype(編譯時需要):

brew install freetype

安裝失敗,提示依賴的libpng無法下載。手工安裝:

下載libpng最新版1.6.17(http://sourceforge.net/projects/libpng/files/)並解壓:

$ pwd
$ cd ./libpng-1.6.17
$ ./configure --prefix=/usr/local/libpng-1.6.17
$ make
$ make install
$ cd /usr/local/
$ ln -s libpng-1.6.17 /usr/local/libpng
$ brew install freetype

•獲取JDK源碼:

$ mkdir OpenJDK9;cd OpenJDK9
$ hg clone
$ cd dev
$ chmod u+x get_source.sh
$ ./get_source.sh

編譯配置

$ bash ./configure --help=short
$ bash ./configure --enable-debug --with-target-bits=64
...
====================================================
A new configuration has been successfully created in
OpenJDK9/jdk9/build/macosx-x86_64-normal-server-fastdebug
using configure arguments '--enable-debug --with-target-bits=64'.

Configuration summary:
* Debug level: fastdebug
* HS debug level: fastdebug
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK: java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM)
* C Compiler: Version Apple LLVM version 6.0 (clang-600.0.41.2) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.4.0 Thread model: posix (at /usr/bin/clang)
* C++ Compiler: Version Apple LLVM version 6.0 (clang-600.0.41.2) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.4.0 Thread model: posix (at /usr/bin/clang++)

Build performance summary:
* Cores to use: 2
* Memory limit: 4096 MB

編譯:

$ make
...
OpenJDK9/jdk9/jdk/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m:387:29: error: sending 'id<NSApplicationDelegate>' to parameter of incompatible type 'id<NSFileManagerDelegate>' [-Werror]
[NSApp setDelegate: applicationDelegate];
^~~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSFileManager.h:109:47: note: passing argument to parameter 'delegate' here
@property (assign) id <NSFileManagerDelegate> delegate NS_AVAILABLE(10_5, 2_0);
^
1 error generated.
make[3]: *** [OpenJDK9/jdk9/build/macosx-x86_64-normal-server-fastdebug/support/native/java.desktop/libosxapp/NSApplicationAWT.o] Error 1
make[2]: *** [java.desktop-libs] Error 2
make[2]: *** Waiting for unfinished jobs....

解決辦法如下或者替換XCode版本為6.3.2或者5.幾的:

//OpenJDK9/jdk9/jdk/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m
//387行改成:
if (NSApp != nil) {
//[NSApp setDelegate: applicationDelegate];
[(NSApplication*)NSApp setDelegate: applicationDelegate];

if (applicationDelegate && qad) {
[qad processQueuedEventsWithTargetDelegate: applicationDelegate];
qad = nil;
}
}

重新編譯:

$ make clean
$ make
...
OpenJDK9/jdk9/jdk/src/java.desktop/share/native/libawt/awt/image/awt_parseImage.c:855:33: error: comparison of array 'rasterP->sppsm.offsets' not equal to a null pointer is always true [-Werror,-Wtautological-pointer-compare]
else if (rasterP->sppsm.offsets != NULL) {
~~~~~~~~~~~~~~~^~~~~~~ ~~~~
1 error generated.
make[3]: *** [OpenJDK9/jdk9/build/macosx-x86_64-normal-server-fastdebug/support/native/java.desktop/libawt/awt_parseImage.o] Error 1
make[2]: *** [java.desktop-libs] Error 2
make[2]: *** Waiting for unfinished jobs....

ERROR: Build failed for target 'default' in configuration 'macosx-x86_64-normal-server-fastdebug' (exit code 2)
Hint: If caused by a warning, try configure --disable-warnings-as-errors

make[1]: *** [main] Error 2
make: *** [default] Error 2

解決辦法:

//OpenJDK9/jdk9/jdk/src/java.desktop/share/native/libawt/awt/image/awt_parseImage.c
//855行改成如下的(注釋掉IF條件):
else /** if (rasterP->sppsm.offsets != NULL) **/ {

再重新編譯:

$ make clean
$ make
...
1 error generated.
make[3]: *** [OpenJDK9/jdk9/build/macosx-x86_64-normal-server-fastdebug/support/native/java.desktop/libsplashscreen/splashscreen_sys.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [java.desktop-libs] Error 2

ERROR: Build failed for target 'default' in configuration 'macosx-x86_64-normal-server-fastdebug' (exit code 2)
Hint: If caused by a warning, try configure --disable-warnings-as-errors

make[1]: *** [main] Error 2
make: *** [default] Error 2

解決辦法:

//OpenJDK/openJDK9/jdk9/jdk/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m
//注釋掉278行:
//[image setScalesWhenResized:YES];

再編,沒出現錯誤了:

$ make clean
$ make
...
Finished building target 'default' in configuration 'macosx-x86_64-normal-server-fastdebug'

•編譯結果初步驗證:

$ cd ./build/*
$ ls
Makefile configure-support jdk
bootcycle-spec.gmk configure.log make-support
build.log configure.log.old spec.gmk
build.log.old hotspot support
buildtools hotspot-spec.gmk
compare.sh images
$ cd jdk/bin
$ ./java -versionopen
openjdk version "1.9.0-internal-fastdebug"
OpenJDK Runtime Environment (build 1.9.0-internal-fastdebug-stxpons_2015_06_13_16_14-b00)
OpenJDK 64-Bit Server VM (build 1.9.0-internal-fastdebug-stxpons_2015_06_13_16_14-b00, mixed mode)

•參考JDK源碼目錄下README-builds.html文件裡的Testing章節:


哎呀媽啊,都折騰半天了,還來啊,要先安裝jtreg,懶得折騰了。。。下回有空再按官方方法驗證。。。

$ cd test
$ make PRODUCT_HOME=`pwd`/../build/*/images/j2sdk-image all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -k -C ../jdk/test TEST=jdk_all jdk_all
echo "Running tests: jdk_all"
Running tests: jdk_all
for each in jdk_all; do \
/Applications/Xcode.app/Contents/Developer/usr/bin/make -j 1 TEST_SELECTION=":$each" UNIQUE_DIR=$each jtreg_tests; \
done
make[2]: *** No rule to make target `OpenJDK9/jdk9/test/../build/macosx-x86_64-normal-server-fastdebug/images/j2sdk-image', needed by `jtreg_tests'.
make[2]: *** No rule to make target `/java/re/jtreg/4.1/promoted/latest/binaries/jtreg', needed by `/java/re/jtreg/4.1/promoted/latest/binaries/jtreg/bin/jtreg'.
make[2]: Target `jtreg_tests' not remade because of errors.
make[1]: *** [jdk_all] Error 2
make: *** [jdk_all] Error 2

CentOS 6.5上編譯安裝OpenJDK7源碼 http://www.linuxidc.com/Linux/2015-05/117248.htm

RHEL6.5安裝OpenJDK1.7.0 + JBoss7.1.1 + Maven3.0.4 http://www.linuxidc.com/Linux/2014-04/99854.htm

Fedora 20下安裝官方JDK替換OpenJDK並配置環境變量 http://www.linuxidc.com/Linux/2014-03/97523.htm

Ubuntu OpenJDK + Tomcat7 的安裝 http://www.linuxidc.com/Linux/2014-02/96398.htm

Ubuntu 13.04下升級到Maven3.10 以支持 OpenJDK7 http://www.linuxidc.com/Linux/2013-08/88844.htm

Ubuntu 12.10中編譯安裝OpenJDK 7 http://www.linuxidc.com/Linux/2013-03/81948.htm

Copyright © Linux教程網 All Rights Reserved