MacOS编译OpenJDK12
编译环境
- MacOS Catalina 10.15.4
- Xcode 11.5
- command line tools
- Homebrew 2.2.5
编译准备
OpenJDK12源码下载
浏览器打开地址:https://hg.openjdk.java.net/jdk/jdk12/
点击左侧Browse,将显示源码根目录页面:
点击左侧bz2、zip、gz 中任意一个,即可下载压缩好的源码包。
如果下载较慢或者下载失败,可使用百度网盘下载。建议从官网下载,可以获取最新源码。
链接: OpenJDK12源码
提取密码: sbcf
安装JDK11
由于JDK源码中大部分代码还是采用JAVA语言实现,所以在编译前需要准备好另一个编译期可用的JDK,官方称此JDK为Bootstrap JDK。假设需要编译的JDK大版本号为N,我们必须准备好另外一个大版本号至少为N-1的JDK。
安装Xcode
App Store安装
安装command line tools
从App Store上下载的Xcode,默认是不会安装Command Line Tools的,Command Line Tools是在Xcode中的一款工具,可以在命令行中运行C程序。
打开终端,在终端中输入命令
xcode-select --install
安装完成后,在终端中执行 gcc -v 命令查看是否安装成功。
如果显示如下内容,则安装成功。
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
安装Homebrew
进入Homebrew官网获取最新下载链接;
打开终端,运行拷贝的命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
执行过程中会要求输入密码,输入密码回车继续安装;
安装完成后,会出现 Installation successful! 字样,即安装成功。
终端运行如下命令,可查看安装的版本信息:
brew -v
输出示例:
Homebrew 2.2.5
Homebrew/homebrew-core (git revision e6c5f; last commit 2020-02-09)
安装依赖库
打开终端,执行如下命令:
brew install ccache
brew install freetype
brew install autoconf
编译JDK
编译参数
编译参数可通过在JDK源码目录下执行以下命令查询:
bash configure --help
查询结果示例如下:
`configure' configures OpenJDK openjdk to adapt to many kinds of systems.
Usage: /Users/fcc/Project/JDKSource/jdk12-06222165c35f/configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR