在ubuntu12.04下build自己的openjdk

本文档详细介绍了如何在Ubuntu 12.04环境下准备必要的依赖项并构建OpenJDK。包括解决内核版本、glibc宏冲突及GCC版本问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个流水帐的记录,好多是参考了别人的blog,由于下面会做一些jvm的研究和jdk的hack,经常性build jdk那是必不可少的了。我的系统是ubuntu12.04,之前先装了jdk1.6.0_31

build openjdk之前,需要做一些依赖的准备工作

Common UNIX Printing System (CUPS) Headers (Solaris & Linux)
Solaris & Linux only: CUPS header files are required for building the JDK on Solaris and Linux. The CUPS header files may be downloaded from  http://www.cups.org. The Solaris header files may also be obtained by installing the package  SFWcups from the Solaris Software Companion CD/DVD. The variable  ALT_CUPS_HEADERS_PATH can be used to override the default location of the CUPS Header files.
Motif Headers and Libraries (Solaris & Linux only)
Linux
Motif version 2.1 headers and libraries are required for building the Linux JDK.  NOTE: (Motif 2.2 headers will not work.)

As a convenience, the source bundles include an archive of motif workspace that incorporate a number of JDK-related bug fixes. The control workspace target gnumake dev would automatically take care of building our motif workspace and generate motif headers and libraries and use them when it required in the build.

                +- $(OUTPUTDIR)/
                +- motif/   (Automatically ALT_MOTIF_DIR will get set to this directory.)
                +- include/
                +- lib/
            
Advanced Linux Sound Architecture (ALSA) (Linux only)
Linux only:  Advanced Linux Sound Architecture version 0.9.1 or later is required for building the JDK on Linux.

Redhat AS 2.1 U2, and SuSE 8.1 do not include a sufficiently recent ALSA distribution. Most modern Linux distributions ship with ALSA. On rpm-based systems, you can see if ALSA is installed by running this command: 
rpm -qa | grep alsa 
Both alsa and alsa-devel packages are needed.

There is no ALT* variable to change the assumed locations of ALSA, the makefiles will expect to find the ALSA include files and library at: /usr/include/alsa and /usr/lib/libasound.so.

http://rednaxelafx.iteye.com/blog/875957 里面提到了所有可能需要装的deb包,还要加上ant, libmotif 两个

$ sudo apt-get install build-essential gawk m4 binutils openjdk-6-jdk libasound2-dev libcups2-dev libasound2 libcups2 libxrender-dev xorg-dev xutils-dev x11proto-print-dev libmotif4 libmotif-dev ant


去oracle官网下载jdk source code, 我下的是openjdk-6-src-b24-14_nov_2011.tar.gz,解压到openjdk目录

设置环境变量 export LANG=C

去掉环境变量 export -n JAVA_HOME

执行sudo make sanity检查是否可以编译了,如不通过请依次修复

这里有多个和环境相关的tricky的地方:

1. hotspot默认支持的linux版本只到2.6,而ubuntu12的kernel是3.2,需要简单hack一下hotspot/make/linux/Makefile,修改如下:

SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7% 3.0% 3.1% 3.2% 3.3%

2. ubuntu12的glibc比较新,在linux的头文件cdefs.h里,有个__LEAF的宏,这个和hotspot/src/share/vm/runtime/interfaceSupport.hpp这个头文件中的宏定义有冲突,我们增加一个#undef __LEAF如下:

// LEAF routines do not lock, GC or throw exceptions
#ifdef __LEAF
#undef __LEAF
#define __LEAF(result_type, header)                                  \
  TRACE_CALL(result_type, header)                                    \
  debug_only(NoHandleMark __hm;)                                     \
  /* begin of body */
#endif

3. ubuntu12的gcc版本过高,会报一个编译错误,打上相应的补丁就好了

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7031385

4. 头文件./build/linux-i586/tmp/sun/sun.security.pkcs11/j2pkcs11/CClassHeaders/sun_security_pkcs11_Secmod.h中的函数定义,和./jdk/src/share/native/sun/security/pkcs11/j2secmod.c的的调用明显不符,这个bug记录在

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7058133


最后,执行sudo make SKIP_COMPARE_IMAGES=true BUILD_DEPLOY=false BUILD_INSTALL=false ALT_BOOTDIR=/usr/bin/jdk1.6.0_31 ALT_JDK_IMPORT_PATH=/usr/bin/jdk1.6.0_31 ALT_DEVTOOLS_PATH=/usr/bin BUILD_CORBA=false BUILD_JAXP=false BUILD_JAXWS=false






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值