MacOS 编译OpenJDK13

官方说明 :

  1. Get the complete source code:
    hg clone http://hg.openjdk.java.net/jdk/jdk

  2. Run configure:
    bash configure

    If configure fails due to missing dependencies (to either the toolchain, build tools, external libraries or the boot JDK), most of the time it prints a suggestion on how to resolve the situation on your platform. Follow the instructions, and try running bash configure again.

  3. Run make:
    make images

  4. Verify your newly built JDK:
    ./build/*/images/jdk/bin/java -version

  5. Run basic tests:
    make run-test-tier1

  6.  

如何构建,可以查看里面的文档说明: doc/building.html

 

 

============  以下为操作实例 ==============================================

 

1. 准备安装环境:

 

1.首先需要准备一个Xcode

我用的是Xcode9.4.1 版本 .  [如果用其他高版本尚未测试.我编译OpenJDK10的时候是报错的.]

官方下载地址:   https://developer.apple.com/download/more/

网盘下载地址:    https://pan.baidu.com/s/1yp0eqLJtHV0X-ppcxeUewg  密码:nnlt

 

2.JDK版本要求 12 或者13

 

3. brew 这个命令我就不说了, 去查一下,怎么安装.

brew install freetype ccache

brew install mercurial

 

在命令行输入 hg 命令有如下输出:

MacOS 编译OpenJDK13_第1张图片

 

2.拉取源码包:

 

git clone  [email protected]:openjdk/jdk13u.git

注: 这个超级难下载,易炸毛.   不过比 hg 下载容易多了...

下载完的目录:

MacOS 编译OpenJDK13_第2张图片

 

3.配置参数

 

接下来配置编译参数,以下是相关选项说明

  • --with-debug-level=slowdebug 启用slowdebug级别调试
  • --enable-dtrace 启用dtrace
  • --with-jvm-variants=server 编译server类型JVM
  • --with-target-bits=64 指定JVM为64位
  • --enable-ccache 启用ccache,加快编译
  • --with-num-cores=8 编译使用CPU核心数
  • --with-memory-size=8000 编译使用内存
  • --disable-warnings-as-errors 忽略警告  , mac 使用 xcode 编译, 官方要求加上这个参数.
  • --with-freetype  设置freetype的路径, 这个路径必须为你机器上的路径,记得修改 !!!! 

 

$ bash configure --with-debug-level=slowdebug --enable-dtrace --with-jvm-variants=server --with-target-bits=64 --enable-ccache --with-num-cores=4 --with-memory-size=8000 --disable-warnings-as-errors

编译完输出:

 

A new configuration has been successfully created in
/workspace/openjdk-13/build/macosx-x86_64-server-slowdebug
using configure arguments '--with-debug-level=slowdebug --enable-dtrace --with-jvm-variants=server --with-target-bits=64 --enable-ccache --with-num-cores=4 --with-memory-size=8000 --disable-warnings-as-errors'.

Configuration summary:
* Debug level:    slowdebug
* HS debug level: debug
* JVM variants:   server
* JVM features:   server: 'aot cds cmsgc compiler1 compiler2 dtrace epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs'
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 13.0.4-internal+0-adhoc.sysadmin.openjdk-13 (13.0.4-internal)

Tools summary:
* Boot JDK:       java version "13.0.2" 2020-01-14 Java(TM) SE Runtime Environment (build 13.0.2+8) Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)  (at /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home)
* Toolchain:      clang (clang/LLVM from Xcode 9.4.1)
* C Compiler:     Version 9.1.0 (at /usr/bin/clang)
* C++ Compiler:   Version 9.1.0 (at /usr/bin/clang++)

Build performance summary:
* Cores to use:   4
* Memory limit:   8000 MB
* ccache status:  Active (3.7.10)

 

 

 

执行编译

$ make images

Creating support/demos/image/jfc/CodePointIM/CodePointIM.jar
Creating support/demos/image/jfc/FileChooserDemo/FileChooserDemo.jar
Creating support/demos/image/jfc/SwingSet2/SwingSet2.jar
Creating support/demos/image/jfc/Font2DTest/Font2DTest.jar
Creating support/demos/image/jfc/J2Ddemo/J2Ddemo.jar
Creating support/demos/image/jfc/Metalworks/Metalworks.jar
Creating support/demos/image/jfc/Notepad/Notepad.jar
Creating support/demos/image/jfc/Stylepad/Stylepad.jar
Creating support/demos/image/jfc/SampleTree/SampleTree.jar
Creating support/demos/image/jfc/TableExample/TableExample.jar
Creating support/demos/image/jfc/TransparentRuler/TransparentRuler.jar
Creating jdk image
Creating CDS archive for jdk image
Stopping sjavac server
Finished building target 'images' in configuration 'macosx-x86_64-server-slowdebug'

 

 

测试

编译后的jdk目录: /workspace/openjdk-13/build/macosx-x86_64-server-slowdebug/jdk

$ ./build/*/images/jdk/bin/java -version

bogon:openjdk-13 sysadmin$
bogon:openjdk-13 sysadmin$ ./build/*/images/jdk/bin/java -version
openjdk version "13.0.4-internal" 2020-07-14
OpenJDK Runtime Environment (slowdebug build 13.0.4-internal+0-adhoc.sysadmin.openjdk-13)
OpenJDK 64-Bit Server VM (slowdebug build 13.0.4-internal+0-adhoc.sysadmin.openjdk-13, mixed mode, sharing)
bogon:openjdk-13 sysadmin$
bogon:openjdk-13 sysadmin$

 

 

 

参考:

https://zhangboyi.blog.csdn.net/article/details/89207433

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

https://github.com/openjdk/jdk13u

 

 

 

你可能感兴趣的:(OpenJDK)