Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS High Sierra 编译 OpenJDK8.md #2

Open
johnwatsondev opened this issue Jul 12, 2018 · 0 comments
Open

macOS High Sierra 编译 OpenJDK8.md #2

johnwatsondev opened this issue Jul 12, 2018 · 0 comments

Comments

@johnwatsondev
Copy link
Owner

下载代码

根据 jdk8uSource code 中的提示

hg clone http://hg.openjdk.java.net/jdk8u/jdk8u/
cd jdk8u
sh get_source.sh
// 切换分支
hg up jdk8u172-b11

准备工作

构建环境变量脚本

vi setEnv.sh

然后复制以下文本,最后记得执行 :x 保存退出

# 设定语言选项,必须设置
export LANG=C
# Mac平台,C编译器不再是GCC,是clang
export CC=clang
export CXX=clang++
# 跳过clang的一些严格的语法检查,不然会将N多的警告作为Error
export COMPILER_WARNINGS_FATAL=false
# 链接时使用的参数
export LFLAGS='-Xlinker -lstdc++'
# 是否使用clang
export USE_CLANG=true
# 使用64位数据模型
export LP64=1
# 告诉编译平台是64位,不然会按32位来编译
export ARCH_DATA_MODEL=64
# 允许自动下载依赖
export ALLOW_DOWNLOADS=true
# 并行编译的线程数,编译时间长,为了不影响其他工作,我选择为2
export HOTSPOT_BUILD_JOBS=2
# 是否跳过与先前版本的比较
export SKIP_COMPARE_IMAGES=true
# 是否使用预编译头文件,加快编译速度
export USE_PRECOMPILED_HEADER=true
# 是否使用增量编译
export INCREMENTAL_BUILD=true
# 编译内容
export BUILD_LANGTOOLS=true
export BUILD_JAXP=true
export BUILD_JAXWS=true
export BUILD_CORBA=true
export BUILD_HOTSPOT=true
export BUILD_JDK=true
# 编译版本
export SKIP_DEBUG_BUILD=true
export SKIP_FASTDEBUG_BUILD=false
export DEBUG_NAME=debug
# 避开javaws和浏览器Java插件之类的部分的build
export BUILD_DEPLOY=false
export BUILD_INSTALL=false
unset JAVA_HOME

然后 chmod 755 setEnv.sh,执行的时候直接使用 ./setEnv.sh 即可

必须使用 JDK7

详情请查看 README-builds.html 中的解释

安装 freetype

brew install freetype

不需要安装 ccache

请看这里的解释

构建执行 configure 的脚本

vi build.sh

然后复制以下文本:

bash ./configure  --with-freetype-include=/usr/local/include/freetype2 --with-freetype-lib=/usr/local/lib/ --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home --with-debug-level=slowdebug

执行脚本

// 进入根目录
cd jdk8u
// 设置环境变量
./setEnv.sh
// 执行 bash ./configure
./build.sh
// 编译
make all

执行 bash configure 报错

需要 Xcode 4

运行 bash ./configure 报错:

checking for xcodebuild... /usr/bin/xcodebuild
configure: error: Xcode 4 is required to build JDK 8, the version found was 9.3. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.

解决办法:
vi ./common/autoconf/generated-configure.sh
然后,注释掉 19369 行附近代码段中 if block 包含代码

# 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 location of Xcode 4 or make Xcode 4 active by using xcode-select." "$LINENO" 5
#fi

需要 GCC 编译器

configure: error: GCC compiler is required. Try setting --with-tools-dir.

解决办法:

先找到报错文件行数

$ grep -rn "GCC compiler is required." ./common/autoconf
./common/autoconf/toolchain.m4:129:      AC_MSG_ERROR([GCC compiler is required. Try setting --with-tools-dir.])
./common/autoconf/generated-configure.sh:20398:      #as_fn_error $? "GCC compiler is required. Try setting --with-tools-dir." "$LINENO" 5
./common/autoconf/generated-configure.sh:22000:      #as_fn_error $? "GCC compiler is required. Try setting --with-tools-dir." "$LINENO" 5

打开文件 vi ./common/autoconf/generated-configure.sh 然后注释掉即可

make 编译报错

cpp 文件报错

/Users/shenxing/Development/Projects/Java/OpenJdk/jdk8u/hotspot/src/share/vm/opto/lcm.cpp:52:35: error: ordered comparison between pointer and zero ('address' (aka 'unsigned char *') and 'int')
  if (Universe::narrow_oop_base() > 0) { // Implies UseCompressedOops.
/Users/shenxing/Development/Projects/Java/OpenJdk/jdk8u/hotspot/src/share/vm/opto/loopPredicate.cpp:872:73: error: ordered comparison between pointer and zero ('const TypeInt *' and 'int')
      assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() >= 0, "must be");
/Users/shenxing/Development/Projects/Java/OpenJdk/jdk8u/hotspot/src/share/vm/runtime/virtualspace.cpp:345:14: error: ordered comparison between pointer and zero ('char *' and 'int')
  if (base() > 0) {

解决办法:

vi ./hotspot/src/share/vm/opto/lcm.cpp
vi ./hotspot/src/share/vm/opto/loopPredicate.cpp
vi ./hotspot/src/share/vm/runtime/virtualspace.cpp

> 0 改为 != NULL

configure 配置问题

error: invalid argument '-std=gnu++98' not allowed with 'C'

解决办法:

vi common/autoconf/generated-configure.sh

  case $COMPILER_NAME in
    gcc )
      COMMON_CCXXFLAGS_JDK="$COMMON_CCXXFLAGS $COMMON_CCXXFLAGS_JDK -W -Wall -Wno-unused -Wno-parentheses \
      -pipe \
      -D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
      CXXSTD_CXXFLAG="-std=gnu++98"

注释掉 CXXSTD_CXXFLAG="-std=gnu++98" 这一行

找不到 x86_64 符号

Undefined symbols for architecture x86_64:
  "_attachCurrentThread", referenced from:
      +[ThreadUtilities getJNIEnv] in ThreadUtilities.o
      +[ThreadUtilities getJNIEnvUncached] in ThreadUtilities.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决办法:
vi ./jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m
然后把
inline void attachCurrentThread(void** env) {
改为
static inline void attachCurrentThread(void** env) {

Reference

mac 10.13.x编译openjdk8
Mac 编译 OpenJDK 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant