在ubuntu12.04下build自己的openjdk

来源:互联网 发布:飞利浦电视软件升级 编辑:程序博客网 时间:2024/05/02 00:12

一个流水帐的记录,好多是参考了别人的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






原创粉丝点击