Ubuntu 10.10编译OpenJdk8

By AverageJoeWang
 标签:

一.环境准备

编译的思路就是用低版本的java环境去编译高版本的openjdk,比如我这篇笔记就是用jdk1.7.0_80编译openjdk-8-src-b132-03_mar_2014.zip

操作系统

$ uname -a

Linux ubuntu 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux

$ lsb_release -a

No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 10.10
Release:    10.10
Codename:    maverick

修改Ubuntu10.10的源

  • 备份

    $ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    $ sudo vim /etc/apt/sources.list
    
  • 换成以下的源

deb http://old-releases.ubuntu.com/ubuntu/ maverick main restricted
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick main restricted
deb http://old-releases.ubuntu.com/ubuntu/ maverick-updates main restricted
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick-updates main restricted
deb http://old-releases.ubuntu.com/ubuntu/ maverick universe
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick universe
deb http://old-releases.ubuntu.com/ubuntu/ maverick-updates universe
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick-updates universe
deb http://old-releases.ubuntu.com/ubuntu/ maverick multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick multiverse
deb http://old-releases.ubuntu.com/ubuntu/ maverick-updates multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick-updates multiverse
deb http://old-releases.ubuntu.com/ubuntu maverick main
deb-src http://old-releases.ubuntu.com/ubuntu maverick main
deb http://old-releases.ubuntu.com/ubuntu maverick-security main restricted
deb-src http://old-releases.ubuntu.com/ubuntu maverick-security main restricted
deb http://old-releases.ubuntu.com/ubuntu maverick-security universe
deb-src http://old-releases.ubuntu.com/ubuntu maverick-security universe
deb http://old-releases.ubuntu.com/ubuntu maverick-security multiverse
deb-src http://old-releases.ubuntu.com/ubuntu maverick-security multiverse

编译器

$gcc -v
Using built-in specs.
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5.1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5.1)

openjdk版本

Java环境

  • Java环境查看
$java -version
ava version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) Client VM (build 24.80-b11, mixed mode)
  • Java环境配置

系统是32位的,所以在下载的时候下载的是java x86版本的jdk-7u80-linux-i586.tar.gz

  • 创建目录解压与编辑配置文件
$ sudo mkdir -p /usr/lib/jvm
$ sudo tar -vxf jdk-7u80-linux-i586.tar.gz
$ sudo vim /etc/profile
  • 配置文件内容
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_80
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
  • 使配置文件生效
$ source /etc/profile

二.编译

编译准备

  • 安装依赖项
$ sudo apt-get install build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif3 libmotif-dev ant libfreetype6-dev libx11-dev libxext-dev libxtst-dev ccache

编译

  • 生成Makefile
$ unzip openjdk-8-src-b132-03_mar_2014.zip
$ cd openjdk
$ bash configure
  • 生成makefile日志
A new configuration has been successfully created in
/home/oliverwang/openjdk/build/linux-x86-normal-server-release
using default settings.

Configuration summary:
* Debug level:    release
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 32

Tools summary:
* Boot JDK:       java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) Client VM (build 24.80-b11, mixed mode)  (at /usr/lib/jvm/jdk1.7.0_80)
* C Compiler:     gcc-4.4 (Ubuntu/Linaro 4.4.4-14ubuntu5.1) version 4.4.5 (at /usr/bin/gcc-4.4)
* C++ Compiler:   g++-4.4 (Ubuntu/Linaro 4.4.4-14ubuntu5.1) version 4.4.5 (at /usr/bin/g++-4.4)

Build performance summary:
* Cores to use:   1
* Memory limit:   748 MB
* ccache status:  installed, but disabled (version older than 3.1.4)
  • 编译
$ make all

编译结果

----- Build times -------
Start 2018-02-10 00:24:18
End   2018-02-10 00:42:43
00:00:19 corba
00:00:27 demos
00:02:17 docs
00:09:07 hotspot
00:00:31 images
00:00:12 jaxp
00:00:18 jaxws
00:04:53 jdk
00:00:15 langtools
00:00:06 nashorn
00:18:25 TOTAL
-------------------------
Finished building OpenJDK for target 'all'

结果验证

编译之后的JDK可执行文件都保存在JDK根目录的build/linux-x86_64-normal-server-release目录下

  • 运行如下命令
$ cd build/linux-x86-normal-server-release/jdk/bin
$ ./java -version
  • 结果
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-oliverang_2018_02_10_00_24-b00)
OpenJDK Server VM (build 25.0-b70, mixed mode)

三.目录说明

简要介绍下OpenJDK中的目录

  • hotspot: 放有OpenJDK Hotspot Virtual Machine 的源代码和make文件
  • langtools: 放有OpenJDK 的javac 等工具的源代码和make文件
  • cobra: 放有OpenJDK Cobra 的源代码和make文件
  • jaxws: 放有OpenJDK JAXWS 的相关信息和make文件, 具体的源代码再编译时会下载
  • jaxp: 放有OpenJDK JAXP 相关信息和make文件,具体的源代码再编译时会下载
  • jdk: 放有OpenJDK runtime libraries 的源代码和make文件

四.遇到问题

内核版本问题

  • 问题再现
make[3]: *** [check_os_version] Error 1 make[3]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux' /home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile:255: recipe for target 'linux_i486_compiler2/fastdebug' failed make[2]: *** [linux_i486_compiler2/fastdebug] Error 2 make[2]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'Makefile:216: recipe for target 'generic_build2' failed make[1]: *** [generic_build2] Error 2 make[1]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/make'Makefile:167: recipe for target 'debug' failed make: *** [debug] Error 2
  • 问题解决
    修改hotspot/make/linux/Makefile,找到SUPPORTED_OS_VERSION变量定义的地方,在后面追加4%,如下所示
SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3% 4%

ad_stuff问题

  • 问题再现
/home/uta/jdk8/openjdk/hotspot/make/linux/makefiles/top.make:91: recipe for target 'ad_stuff' failed
make[5]: *** [ad_stuff] Error 2
/home/uta/jdk8/openjdk/hotspot/make/linux/Makefile:289: recipe for target 'product' failed
make[4]: *** [product] Error 2
  • 问题解决
$ vim hotspot/make/linux/makefiles/adjust-mflags.sh

# 删除以下行
s/ -\([^        ][^     ]*\)j/ -\1 -j/

五.参考