一、編譯前一些必要的安裝
1、macOS不可或缺的套件管理器 - Homebrew安裝
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2淳地、openjdk代碼由hg管理捡偏,因此需要安裝mercurial
$ brew install mercurial
3唤冈、openjdk代碼由hg管理,因此需要安裝mercurial
$ brew install mercurial
若失敗银伟,則:
$ sudo brew link mercurial
4你虹、安裝ccache提高編譯速度
$ brew install ccache
5绘搞、安裝freetype(編譯時需要)
$ brew install freetype
二、編譯過程
1傅物、源碼獲取
$ hg clone http://hg.openjdk.java.net/jdk9/jdk9 openJdkPath
$cd openJdkPath
$ bash ./get_source.sh
2夯辖、編譯配置
$ ./configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.0 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" --disable-zip-debug-info --disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_mac_x64.log
編譯配制簡介
編譯參數(shù)簡介:
--with-target-bits:設(shè)置32位/64位編譯
--with-freetype:設(shè)置freetype路徑
--enable-ccache:設(shè)置啟用ccache
--with-jvm-variants=client,server:為了保證兼容性,編譯時JVM的Client和Server都會被編譯
--with-boot-jdk-jvmargs:提供運行Bootstrap JDK所需要的JVM參數(shù)
--disable-zip-debug-info:禁用zip調(diào)試信息
--disable-warnings-as-errors:禁用將警告當(dāng)做錯誤董饰,避免因為警告而中斷編譯
--with-debug-level:設(shè)置調(diào)試等級
2>&1 | tee configure_mac_x64.log:將錯誤信息重定向至標(biāo)準(zhǔn)輸出楼雹,并輸出到configure_mac_x64.log
a、可能錯誤1
-bash: ./configure: Permission denied
在./configure前加上bash尖阔, bash ./configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.0 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" --disable-zip-debug-info --disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_mac_x64.log
b贮缅、可能錯誤2
Can not find or use freetype at location given by --with-freetype
--with-freetype=/usr/local/Cellar/freetype/2.10.0配置項中,版本2.10.0和你本地的freetype版本不一樣
$ cd /usr/local/Cellar/freetype
看下你本地的版本介却,進行對應(yīng)替換
c谴供、編譯配置成功
3、編譯
$ export LANG=C
$ make all LOG=debug 2>&1 | tee make_mac_x64.log
a齿坷、編譯報錯
google一下桂肌,這個錯誤是 XCode 版本不一致造成的,官網(wǎng)文檔上說 Mac 下 JDK 9 的代碼是用 XCode 8.3.2 和 --disable-warnings-as-errors
編譯成功的 [官網(wǎng)參考 ]永淌。
改下這幾個文件報錯地方的代碼就好了崎场, 官網(wǎng)參考 , github參考 遂蛀。
編譯完成結(jié)果
Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-slowdebug'
4谭跨、測試
localhost:openJDK wangteng$ cd build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/bin/
localhost:bin wangteng$ ./java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (slowdebug build 9-internal+0-adhoc.wangteng.openJDK)
OpenJDK 64-Bit Server VM (slowdebug build 9-internal+0-adhoc.wangteng.openJDK, mixed mode)