Mac 编译openjdk8

1. 先拉取openjdk8 源码

To get the entire set of OpenJDK Mercurial repositories use the script get_source.sh located in the root repository:

hg clone http://hg.openjdk.java.net/jdk8/jdk8 YourOpenJDK 
cd YourOpenJDK 
bash ./get_source.sh

2. Oracle官网安装jdk7, 因为openjdk8 的编译需要是用jdk7 ,编译当前jdk的版本需要使用上一版本的jdk 作为bootstrap jdk,具体详见拉取的jdk8根目录下的 README-builds.html 文件

3. 编译前先做好相关准备工作

 可参考 https://www.jianshu.com/p/4e01daf8c357 

 

4. 进入到 YourOpenJDK  目录进行编译,使用命令

bash ./configure --with-debug-level=slowdebug --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home --with-target-bits=64 --with-jvm-variants=server --with-jdk-variant=normal --with-milestone=internal --with-num-cores=2 --with-jobs=4 CC=clang CXX=clang++

5. 进行编译

make COMPILER_WARNINGS_FATAL=false LFLAGS='-Xlinker -lstdc++' CC=clang USE_CLANG=true LP64=1
 
6. 如果重新编译 先执行 make clean ,再依次执行 4 5 两步
 
不过,上述过程还只能在人家试验的mac 10.15系统版本上进行测试,我本地Mac系统是12.2.1,经过一天试验,结论是无法编译,具体原因如下:
1. Openjdk8源码中,从mac中找相关头文件是从一个指定目录下查找,具体可看下图。这个目录在Mac旧系统上,jdk一些头文件安装都是安装到这个目录;但是对于新系统,这个目录已经全部移到/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk 这个目录下,对于Mac新系统,/System/Library 目录下如果想要新建文件,或者新建软连,一定要先关闭SIP,关闭SIP我不敢尝试,使用OC这个实验性功能可能会破坏Mac系统稳定性,我采用第二种方案,openjdk8源码文件中全局搜索/System/Library/Frameworks/JavaVM.framworks 这个关键字,人工手动替换成正确目录
 

 

2. 搜索结果如下图

 

全量手工替换,再次进行编译

3. 再次编译后,依然不行,应该是openjdk8 中一些语法特性已经不能够在Mac新系统上支持了,这个是我放弃的主要原因,我目前也找不到解决办法

 

 

下次编译我将会在虚拟加上使用Windows10 系统进行尝试。

 

参考网址

https://www.cnblogs.com/JunFengChan/p/9266033.html

https://gvsmirnov.ru/blog/tech/2014/02/07/building-openjdk-8-on-osx-maverick.html

https://blog.csdn.net/Dongguabai/article/details/106384400

https://www.cnblogs.com/micrari/p/7018474.html

https://segmentfault.com/q/1010000017752615

https://blog.csdn.net/qq_25905629/article/details/107485000

https://blog.csdn.net/qq_31865983/article/details/90729892

https://blog.csdn.net/lizhengjava/article/details/105629780

https://blog.csdn.net/quantum7/article/details/108487437    ---> ld: library not found for -lstdc++ 我的解决办法是下载了 libstdc++.tbd 这个文件,然后放入到 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib 这个目录下

https://blog.csdn.net/u010416101/article/details/84839103

https://codertang.com/2019/11/11/build-jdk8/

 

posted @ 2022-03-07 10:34  margo  阅读(327)  评论(0编辑  收藏  举报