環境準備
- macOS Ventura 13.5.2
- freetype (可使用
brew install freetype
安裝) - jdk1.8.0_333
- XQuartz XQuartz 2.7.11(xorg-server 1.18.4)
- gawk(可使用
brew install gawk
安裝)
拉取 openjdk8 源碼
git clone https://github.com/openjdk/jdk8u jdk8u
安裝 ccache 加速編譯
必須大於 3,我目前是 4.8.3
brew install ccache
檢測
- 可以通過
sh ./configure --help
查看字段意義,也可能看官網的解釋:http://hg.openjdk.java.net/jdk8u/jdk8u/raw-file/tip/README-builds.html#configure -
sh ./configure --help
最終的檢測命令
sh ./configure --with-xcode-path=/Applications/Xcode_12.4.app \
--with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home \
--with-freetype-include=/usr/local/include/freetype2 \
--with-freetype-lib=/usr/local/lib/ \
--with-debug-level=slowdebug \
--enable-ccache \
--enable-debug-symbols \
--with-target-bits=64 \
--with-jvm-variants=server \
OBJCOPY=gobjcopy
構建
輸出結果
====================================================
A new configuration has been successfully created in
/Users/terwer/Documents/code/jdk/jdk8u/build/macosx-x86_64-normal-server-slowdebug
using configure arguments '--with-xcode-path=/Applications/Xcode_12.4.app --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home --with-freetype-include=/usr/local/include/freetype2 --with-freetype-lib=/usr/local/lib/ --with-debug-level=slowdebug --enable-ccache --enable-debug-symbols --with-target-bits=64 --with-jvm-variants=server OBJCOPY=gobjcopy'.
Configuration summary:
* Debug level: slowdebug
* 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_333" Java(TM) SE Runtime Environment (build 1.8.0_333-b02) Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM)
* C Compiler: Version 12.0.0 (at /usr/bin/clang)
* C++ Compiler: Version 12.0.0 (at /usr/bin/clang++)
Build performance summary:
* Cores to use: 7
* Memory limit: 32768 MB
* ccache status: disabled
➜ jdk8u git:(master)
編譯
進入 jdk 目錄 執行 make all 執行成功後會有如下輸出,編譯後 jdk 目錄將近 3G 左右,編譯的過程中存在很多的 Warning,直接忽略了。
默認構建
make
結果輸出
----- Build times -------
Start 2023-09-19 18:36:44
End 2023-09-19 18:41:27
00:00:14 corba
00:01:35 hotspot
00:00:09 jaxp
00:00:18 jaxws
00:02:08 jdk
00:00:18 langtools
00:04:43 TOTAL
-------------------------
Finished building OpenJDK for target 'default'
➜ jdk8u git:(master) ✗
查看 java -version
編譯之後的 jdk 在這個目錄下 macosx-x86_64-normal-server-slowdebug
➜ jdk8u git:(master) ✗ ./build/macosx-x86_64-normal-server-slowdebug/jdk/bin/java -version
openjdk version "1.8.0_392-internal-debug"
OpenJDK Runtime Environment (build 1.8.0_392-internal-debug-terer_2023_09_19_18_36-b00)
OpenJDK 64-Bit Server VM (build 25.392-b00-debug, mixed mode)
➜ jdk8u git:(master) ✗
問題解決
-
具體錯誤:
configure: error: Xcode 6, 9-12 is required to build JDK 8, the version found was 15.0. Use --with-xcode-path to specify the location of Xcode or make Xcode active by using xcode-select.
解決辦法:
安裝 Xcode12,並設置
--with-xcode-path=/Applications/Xcode_12.4.app
-
具體錯誤:
checking if we should generate debug symbols... configure: error: Unable to find objcopy, cannot enable debug-symbols
解決方案:需要安裝
binutils
,並且需要在configure
時添加參數OBJCOPY
# 安裝 binutils brew install binutils
# configure 添加參數 OBJCOPY=gobjcopy
-
具體錯誤:
https://github.com/akinomyoga/ble.sh/issues/190
解決方案
安裝 gawk
brew install gawk
參考
https://github.com/openjdk/jdk8u
https://github.com/manheiba/jdk8mhb
MacOS 編譯 openjdk8 並導入 Clion 調試
Mac10.14 下使用 Xcode10 編譯調試 OpenJDK8 最新教程