Mac系統安裝
利用brew search查找mercurial
➜ ~ brew search mercurial
安裝
➜ ~ brew install mercuria
Linux系統安裝
sudo apt install mercurial
安裝openjdk8
添加代理
一般在下載代碼的時候都會很慢,故先配置好代理。我這裏是V2Ray。
vim /usr/local/etc/mercurial/hgrc
[http_proxy]
host=127.0.0.1:8001
[https_proxy]
host=127.0.0.1:8001
下載jdk8u的代碼
hg clone https://hg.openjdk.java.net/jdk8u/jdk8u openjdk8
chmod u+x get_source.sh
chmod u+x configure
./get_source.sh # 下載全部源代碼
./configure --with-freetype-include=/usr/local/include/freetype2 --with-freetype-lib=/usr/local/lib/ # configure 編譯環境,若編譯報錯,需要添加 `--disable-warnings-as-errors`
make all
漫長的等待,終於等到你
## Finished docs (build time 00:01:52)
----- Build times -------
Start 2020-05-24 03:18:37
End 2020-05-24 03:30:07
00:00:19 corba
00:00:46 demos
00:01:52 docs
00:02:53 hotspot
00:01:28 images
00:00:12 jaxp
00:00:18 jaxws
00:03:07 jdk
00:00:26 langtools
00:00:09 nashorn
00:11:30 TOTAL
-------------------------
Finished building OpenJDK for target 'all'
如何在CLion裏面做調試,後面我再詳細的寫一篇。敬請期待~
遇到的坑
問題一:Xcode 4 is required to build JDK 8
configure: error: Xcode 4 is required to build JDK 8, the version found was 11.4.1. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.
configure exiting with result code 1
解決方案:
➜ openjdk8 vim common/autoconf/generated-configure.sh
# Fail-fast: verify we're building on Xcode 4, we cannot build with Xcode 5 or later
#XCODE_VERSION=`$XCODEBUILD -version | grep '^Xcode ' | sed 's/Xcode //'`
#XC_VERSION_PARTS=( ${XCODE_VERSION//./ } )
#if test ! "${XC_VERSION_PARTS[0]}" = "4"; then
# as_fn_error $? "Xcode 4 is required to build JDK 8, the version found was $XCODE_VERSION. Use --with-xcode-path to specify the l ocation of Xcode 4 or make Xcode 4 active by using xcode-select." "$LINENO" 5
#fi
問題二:A gcc compiler is required
configure: error: A gcc compiler is required. Try setting --with-tools-dir.
configure exiting with result code
# 第一處代碼 elif test "x$TOOLCHAIN_TYPE" = xgcc; then
# gcc --version output typically looks like
# gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
# Copyright (C) 2013 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
# Check that this is likely to be GCC.
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
# 條件語句註釋掉
# if test $? -ne 0; then
# { $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
# $as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
# { $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$COMPILER_VERSION\"" >&5
# $as_echo "$as_me: The result from running with --version was: \"$COMPILER_VERSION\"" >&6;}
# as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
# fi
# 第二處代碼,
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
# gcc --version output typically looks like
# gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
# Copyright (C) 2013 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
# Check that this is likely to be GCC.
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
# 條件語句註釋掉
# if test $? -ne 0; then
# { $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
# $as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
# { $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$COMPILER_VERSION\"" >&5
# $as_echo "$as_me: The result from running with --version was: \"$COMPILER_VERSION\"" >&6;}
# as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
最後執行sh configure
終於成功:
====================================================
A new configuration has been successfully created in
/Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release
using default settings.
Configuration summary:
* Debug level: release
* 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_162" Java(TM) SE Runtime Environment (build 1.8.0_162-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 11.0.3 (at /usr/bin/gcc)
* C++ Compiler: Version 11.0.3 (at /usr/bin/g++)
Build performance summary:
* Cores to use: 4
* Memory limit: 16384 MB
問題三:include path for libstdc++ headers not found
clang: clangerror: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found]
: error: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found]
make[6]: *** [../generated/adfiles/archDesc.o] Error 1
make[6]: *** Waiting for unfinished jobs....
make[6]: *** [../generated/adfiles/adlparse.o] Error 1
clang: error: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Werror,-Wstdlibcxx-not-found]
make[6]: *** [../generated/adfiles/arena.o] Error 1
make[5]: *** [ad_stuff] Error 2
make[4]: *** [product] Error 2
make[3]: *** [generic_build2] Error 2
make[2]: *** [product] Error 2
make[1]: *** [/Users/chenyuan/Workspaces/Openjdk/openjdk8/build/macosx-x86_64-normal-server-release/hotspot/_hotspot.timestamp] Error 2
make: *** [hotspot-only] Error 2
解決方法
原因:這個原因是Xcode升級到10以後就沒有包含lstdc++庫了。而 hotspot 居然還一直用着這個,於是編譯器找不到 libstdc++ 的頭文件就罷工了 解決辦法: 打開:https://github.com/imkiwa/xcode-missing-libstdc- , clone 到本地,參考 install.sh 將文件鏈接或者複製到對應位置(慎重直接執行,請一定事先覈對路徑是否正確)!
問題四:fatal error: 'iostream' file not found
/Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/archDesc.cpp:#include <iostream>/Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/adlc.hpp
: ^~~~~~~~~~35:10:27
:
fatal error/Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/adlc.hpp: :35'iostream' file not found:
10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
#include <iostream>
^~~~~~~~~~
In file included from /Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/adlparse.cpp:27:
/Users/chenyuan/Workspaces/Openjdk/openjdk8/hotspot/src/share/vm/adlc/adlc.hpp:35:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
make[6]: *** [../generated/adfiles/arena.o] Error 1
make[6]: *** Waiting for unfinished jobs....
解決方案
xcode-select --install
問題五:unknown argument: '-fpch-deps'
解決方案:
hotspot/make/bsd/makefiles/gcc.make
# Compiler warnings are treated as errors
ifneq ($(COMPILER_WARNINGS_FATAL),false)
WARNINGS_ARE_ERRORS = -Werror
endif
這一段也要幹掉,否則在後續編譯中可能會出現clang: error: unknown argument: '-fpch-deps'
ifeq ($(USE_CLANG),)
ifneq ($(CC_VER_MAJOR), 2)
DEPFLAGS += -fpch-deps
endif
endif
問題六:invalid argument ‘-std=gnu++98’ not allowed with ‘C’
Making signal interposition lib...
error: invalid argument '-std=gnu++98' not allowed with 'C'
make[6]: *** [libjsig.dylib] Error 1
解決方案
if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
if test "x$OPENJDK_TARGET_CPU_ARCH" = "xsparc"; then
CFLAGS_JDKLIB_EXTRA="${CFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
CXXFLAGS_JDKLIB_EXTRA="${CXXFLAGS_JDKLIB_EXTRA} -xregs=no%appl"
fi
elif test "x$TOOLCHAIN_TYPE" = xxlc; then
LDFLAGS_JDK="${LDFLAGS_JDK} -q64 -brtl -bnolibpath -liconv -bexpall"
CFLAGS_JDK="${CFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
CXXFLAGS_JDK="${CXXFLAGS_JDK} -qchars=signed -q64 -qfullpath -qsaveopt"
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
LEGACY_EXTRA_CFLAGS="$LEGACY_EXTRA_CFLAGS -fstack-protector"
LEGACY_EXTRA_CXXFLAGS="$LEGACY_EXTRA_CXXFLAGS -fstack-protector"
if test "x$OPENJDK_TARGET_OS" != xmacosx; then
LDFLAGS_JDK="$LDFLAGS_JDK -Wl,-z,relro"
LEGACY_EXTRA_LDFLAGS="$LEGACY_EXTRA_LDFLAGS -Wl,-z,relro"
fi
# CXXSTD_CXXFLAG="-std=gnu++98" # 註釋掉這行
參考地址
- https://zhuanlan.zhihu.com/p/50220757
- https://www.jianshu.com/p/d9a1e1072f37
- https://www.cnblogs.com/zhengshuangxi/p/11063938.html
- https://juejin.im/entry/5a6c36af6fb9a01cb64f05b8
- https://www.zhoujunwen.com/2019/building-openjdk-8-on-mac-osx-catalina-10-15
- https://www.cnblogs.com/micrari/p/7018474.html
- https://rqsir.github.io/2019/04/19/openjdk-8-使用Clion調試源碼/
如果大家喜歡我的文章,可以關注個人訂閱號。歡迎隨時留言、交流。如果想加入微信羣的話一起討論的話,請加管理員簡棧文化-小助手(lastpass4u),他會拉你們進羣。