openjdk6在linux上的编译手顺
我在xubuntu上编译openjdk6是按照http://rednaxelafx.iteye.com/blog/875957撒加这篇文章编译的,可是仔细琢磨才知道这篇文章是编译sun以jrl许可证发放出来的jdk源码的,不过大体思路差不多,有少许差别(就是这少许区别搞了很久。。。)。
环境:在virtual4.2.4装上xubuntu10.04.2
一开始是按照OpenJDK6 Build README
http://hg.openjdk.java.net/jdk6/jdk6/raw-file/tip/README-builds.html里面的步骤来的,下载并安装gcc,openjdk等。。。这里我的gcc版本为4.3,openjdk版本为6
hg clonehttps://bitbucket.org/pmezard/hgforest-crew/overview/ MyHgForest
默认下载到/etc/MyHgForest目录
然后将命令添加到Mercurial (/etc/mrcurial)的hgrc文件中
[extensions]
forest = YourHgForest/forest.py
用hg命令下载openjdk6
hg fclone http://hg.openjdk.java.net/jdk6/jdk6openjdk6 (openjdk6会下载到当前目录)
然后执行命令(暂时不知道这个有什么作用。。。)
cd openjdk6
sh./make/scripts/hgforest.sh pull –u
然后安装jdk6相关的依赖和用来编译c的gcc等工具
sudo aptitude build-dep openjdk-6
sudo aptitude install openjdk-6-jdk gcc-4.3 g++-4.3
(我这里gcc-4.2安装失败)
sudo aptitude installlibmotif-dev
配置环境变量
export LANG=CALT_BOOTDIR=/usr/lib/jvm/java-1.6.0-openjdk(启动级的jdk,我这里装系统时已自动安装好)
export
ALLOW_DOWNLOADS=true(JAXP和JAXWS部分的源码要动态下载)
unset JAVA_HOME
当时是按照撒加那篇文章的编译的,所以也把撒加安装过的相关工具也一并安装了。。。
sudo apt-get install build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev
sudo apt-get install binutils
build-essential gawk m4 binutils:
这些是Linux上的一些基本工具,build许多东西都需要它们。build-essential主要用来装g++(GNU C++编译器)及C++标准库;gawk是GNU版awk,用来做文本操作;m4是一种模板语言,AWT的DebugHelper依赖它来生成部分源 码;binutils主要是链接器、汇编器、反汇编器之类的。
libasound2-dev:
这是Advanced Linux Sound Architecture (ALSA)相关的依赖。
libcups2-dev:
这是Common UNIX Printing System (CUPS)相关的依赖。
libxrender-dev xorg-dev xutils-dev x11proto-print-dev:
这些全部都是X相关的依赖,主要是为了build出AWT的部分才会需要的。这部分依赖非常非常蛋疼。在安装完依赖后,还得造个符号链接,把/usr/lib映射为/usr/X11R6的别名,这样build过程才能正确找到X11的头文件:
sudo mkdir/usr/X11R6
cd /usr/X11R6/
sudo ln -s -T/usr/lib lib
相关工具和环境变量已经配置好,可以开始编译了
先进行编译检查,在openjdk6目录下,
make dev-sanity BUILD_DEPLOY=false SKIP_COMPARE_IMAGES=true ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk ALT_DEVTOOLS_PATH=/usr/bin HOTSPOT_BUILD_JOBS=2
尽量把出现的errors和warning是都解决掉。
最后开始编译
make dev BUILD_DEPLOY=false SKIP_COMPARE_IMAGES=true ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk ALT_DEVTOOLS_PATH=/usr/bin HOTSPOT_BUILD_JOBS=2
一开始编译JAXP部分出现URLConnection异常,应该是下载JAXP的url地址无效了,索性吧jaxp、jaxws、corba部分都删掉,只剩下langtools,hotspot和JDK。
再次编译。。。
make dev BUILD_DEPLOY=false SKIP_COMPARE_IMAGES=true ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk ALT_DEVTOOLS_PATH=/usr/bin HOTSPOT_BUILD_JOBS=2
编译了几十分钟后,又出现了errors,查看日志,hotspot应该编译成功,问题出现的jdk/make/java/redist 文件夹,can’t cd to/NOT-SET/re/openjdk/6/promoted/latest/binaries/linux-i586(好像是这个),我了个去,就是因为这个问题,搞了几天,不知道是哪个环境变量没设置。。。
google了N多把。。。没有找到相关的信息。。。
终于有一篇文章有提到相关错误。。。
cd 到jdk/make 下,检查编译变量
make-sanity
这时候出现几个warnings和errors,大概是说没有设置ALT_JDK_IMPORT_PATH、ALT_HOTSPOT_IMPORT_PATH、ALT_HOTSPOT_CLIENT_PATH、ALT_HOTSPOT_SERVER_PATH,没有找到相关的.h文件和libjvm.so文件
于是在jdk/make再次make检查
make dev-sanity BUILD_DEPLOY=false SKIP_COMPARE_IMAGES=true ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk ALT_DEVTOOLS_PATH=/usr/bin HOTSPOT_BUILD_JOBS=2
ALT_JDK_IMPORT_PATH=/usr/lib/jvm/ java-6-openjdk
ALT_HOTSPOT_IMPORT_PATH==/usr/lib/jvm/ java-6-openjdk
ALT_HOTSPOT_CLIENT_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client
ALT_HOTSPOT_SERVER_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/server
这次warnings和error是都消失了。。。
最后再次编译
make dev BUILD_DEPLOY=false SKIP_COMPARE_IMAGES=true ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk ALT_DEVTOOLS_PATH=/usr/bin HOTSPOT_BUILD_JOBS=2
ALT_JDK_IMPORT_PATH=/usr/lib/jvm/ java-6-openjdk
ALT_HOTSPOT_IMPORT_PATH==/usr/lib/jvm/ java-6-openjdk
ALT_HOTSPOT_CLIENT_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client
ALT_HOTSPOT_SERVER_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/server
过了几十分钟后,jdk目录编译通过了,在cd到openjdk6路径下再整体编译检查一次
make sanity BUILD_DEPLOY=false SKIP_COMPARE_IMAGES=true ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk ALT_DEVTOOLS_PATH=/usr/bin HOTSPOT_BUILD_JOBS=2
ALT_JDK_IMPORT_PATH=/usr/lib/jvm/ java-6-openjdk
ALT_HOTSPOT_IMPORT_PATH ==/usr/lib/jvm/ java-6-openjdk
ALT_HOTSPOT_CLIENT_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client
ALT_HOTSPOT_SERVER_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/server
又出现了warnings和errors,好像说不用设置ALT_HOTSPOT_IMPORT_PATH。。。这真奇葩,不管了,就把ALT_HOTSPOT_IMPORT_PATH去掉。。。
make sanity BUILD_DEPLOY=false SKIP_COMPARE_IMAGES=true ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk ALT_DEVTOOLS_PATH=/usr/bin HOTSPOT_BUILD_JOBS=2
ALT_JDK_IMPORT_PATH=/usr/lib/jvm/ java-6-openjdk
ALT_HOTSPOT_CLIENT_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client
ALT_HOTSPOT_SERVER_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/server
这次编译检查通过了,于是开始编译。。。
make dev BUILD_DEPLOY=false SKIP_COMPARE_IMAGES=true ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk ALT_DEVTOOLS_PATH=/usr/bin HOTSPOT_BUILD_JOBS=2
ALT_JDK_IMPORT_PATH=/usr/lib/jvm/ java-6-openjdk
ALT_HOTSPOT_CLIENT_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client
ALT_HOTSPOT_SERVER_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/server
最后编译成功。
build出的hotspot,langtools和jdk都在build/linux-i586/j2sdk-image下
将PATH中的/usr/bin(因为里面有java命令)去掉,将/home/nature/workplace/openjdk6/build/linux-i586/j2sdk-image/bin添加到PATH中
然后测试下 java –version
确定编译成功。。。
最后在openjdk6下make-sanity再看下
nature@nature-desktop:~/workplace/openjdk6$ make sanity
make[1]: Entering directory `/home/nature/workplace/openjdk6/jdk/make'
make[2]: Entering directory`/home/nature/workplace/openjdk6/jdk/make/tools/freetypecheck'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/nature/workplace/openjdk6/jdk/make/tools/freetypecheck'
make[1]: Leaving directory `/home/nature/workplace/openjdk6/jdk/make'
Build Machine Information:
build machine = nature-desktop
Build Directory Structure:
CWD = /home/nature/workplace/openjdk6
TOPDIR = .
LANGTOOLS_TOPDIR = ./langtools
HOTSPOT_TOPDIR = ./hotspot
JDK_TOPDIR = ./jdk
Build Directives:
BUILD_LANGTOOLS = true
BUILD_HOTSPOT = true
BUILD_JDK = true
DEBUG_CLASSFILES =
DEBUG_BINARIES =
Hotspot Settings:
HOTSPOT_BUILD_JOBS =
HOTSPOT_OUTPUTDIR =/home/nature/workplace/openjdk6/build/linux-i586/hotspot/outputdir
HOTSPOT_EXPORT_PATH =/home/nature/workplace/openjdk6/build/linux-i586/hotspot/import
Bootstrap Settings:
BOOTDIR = /usr/lib/jvm/java-6-openjdk
ALT_BOOTDIR = /usr/lib/jvm/java-6-openjdk
BOOT_VER = 1.6 [requires at least 1.6]
OUTPUTDIR = /home/nature/workplace/openjdk6/build/linux-i586
ALT_OUTPUTDIR = /home/nature/workplace/openjdk6/build/linux-i586
ABS_OUTPUTDIR = /home/nature/workplace/openjdk6/build/linux-i586
Build Tool Settings:
SLASH_JAVA = /NOT-SET
ALT_SLASH_JAVA =
VARIANT = OPT
JDK_DEVTOOLS_DIR = /NOT-SET/devtools
ALT_JDK_DEVTOOLS_DIR =
ANT_HOME =
UNIXCOMMAND_PATH = /bin/
ALT_UNIXCOMMAND_PATH =
COMPILER_PATH = /usr/bin/
ALT_COMPILER_PATH =
DEVTOOLS_PATH = /usr/bin/
ALT_DEVTOOLS_PATH =
UNIXCCS_PATH = /usr/ccs/bin/
ALT_UNIXCCS_PATH =
USRBIN_PATH = /usr/bin/
ALT_USRBIN_PATH =
MOTIF_DIR = /usr
ALT_MOTIF_DIR =
MOTIF_REQUIRED = false
COMPILER_NAME = GCC
COMPILER_VERSION =
CC_VER = 4.4 [requires at least 3.2]
ZIP_VER = 3.0 [requires at least 2.2]
UNZIP_VER = 6.00 [requires at least 5.12]
ANT_VER = 1.7 [requires at least 1.6.3]
TEMPDIR = /home/nature/workplace/openjdk6/build/linux-i586/tmp
Build Directives:
OPENJDK = true
USE_HOTSPOT_INTERPRETER_MODE =
PEDANTIC =
DEV_ONLY =
NO_DOCS =
NO_IMAGES =
TOOLS_ONLY =
INSANE =
COMPILE_APPROACH = parallel
PARALLEL_COMPILE_JOBS = 2
ALT_PARALLEL_COMPILE_JOBS =
FASTDEBUG =
COMPILER_WARNINGS_FATAL = false
COMPILER_WARNING_LEVEL =
INCREMENTAL_BUILD = false
CC_HIGHEST_OPT = -O3
CC_HIGHER_OPT = -O3
CC_LOWER_OPT = -O2
CXXFLAGS = -O2 -fPIC -DCC_NOEX -W -Wall -Wno-unused-Wno-parentheses -fno-omit-frame-pointer -D_LITTLE_ENDIAN
CFLAGS = -O2 -fno-strict-aliasing -fPIC -W-Wall -Wno-unused -Wno-parentheses -fno-omit-frame-pointer-D_LITTLE_ENDIAN
BOOT_JAVA_CMD = /usr/lib/jvm/java-6-openjdk/bin/java -client-Xmx369m -Xms128m -XX:PermSize=32m -XX:MaxPermSize=160m
BOOT_JAVAC_CMD = /usr/lib/jvm/java-6-openjdk/bin/javac -J-XX:ThreadStackSize=768 -J-client -J-Xmx369m -J-Xms128m -J-XX:PermSize=32m-J-XX:MaxPermSize=160m -encoding ascii -source 5 -target 5-XDignore.symbol.file=true
BOOT_JAR_CMD = /usr/lib/jvm/java-6-openjdk/bin/jar
BOOT_JARSIGNER_CMD = /usr/lib/jvm/java-6-openjdk/bin/jarsigner
JAVAC_CMD = /usr/lib/jvm/java-6-openjdk/bin/java -client -Xmx369m-Xms128m -XX:PermSize=32m -XX:MaxPermSize=160m-Xbootclasspath/p:/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javac.jar-jar/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javac.jar -source 1.5 -target 5 -encoding ascii-Xbootclasspath:/home/nature/workplace/openjdk6/build/linux-i586/classes
JAVAH_CMD = /usr/lib/jvm/java-6-openjdk/bin/java -client -Xmx369m-Xms128m -XX:PermSize=32m -XX:MaxPermSize=160m -Xbootclasspath/p:/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javah.jar:/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javadoc.jar:/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javac.jar-jar/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javah.jar-bootclasspath /home/nature/workplace/openjdk6/build/linux-i586/classes
JAVADOC_CMD = /usr/lib/jvm/java-6-openjdk/bin/java -client-Xmx369m -Xms128m -XX:PermSize=32m -XX:MaxPermSize=160m-Xbootclasspath/p:/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javadoc.jar:/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javac.jar:/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/doclets.jar-jar/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist/bootstrap/lib/javadoc.jar
Build Platform Settings:
USER = nature
PLATFORM = linux
ARCH = i586
LIBARCH = i386
ARCH_FAMILY = i586
ARCH_DATA_MODEL = 32
ARCHPROP = i386
LINUX_VERSION = Unknown linux
ALSA_VERSION = 1.0.22
OS_VERSION = 2.6.32-28-generic [requires at least 2.4.9-e.3]
OS_NAME = linux
MB_OF_MEMORY = 497
GNU Make Settings:
MAKE = make
MAKE_VER = 3.81 [requires at least 3.78]
MAKECMDGOALS = sanity
MAKEFLAGS = w
SHELL = /bin/sh
Target Build Versions:
JDK_VERSION = 1.6.0
MILESTONE = internal
RELEASE = 1.6.0-internal
FULL_VERSION = 1.6.0-internal-nature_07_mar_2013_15_47-b00
BUILD_NUMBER = b00
External File/Binary Locations:
USRJDKINSTANCES_PATH = /opt/java
BUILD_JDK_IMPORT_PATH = /NOT-SET/re/openjdk/6/promoted/latest/binaries
ALT_BUILD_JDK_IMPORT_PATH =
JDK_IMPORT_PATH = /NOT-SET/re/openjdk/6/promoted/latest/binaries/linux-i586
ALT_JDK_IMPORT_PATH =
LANGTOOLS_DIST =/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist
ALT_LANGTOOLS_DIST =/home/nature/workplace/openjdk6/build/linux-i586/langtools/dist
CORBA_DIST =
ALT_CORBA_DIST =
JAXP_DIST =
ALT_JAXP_DIST =
JAXWS_DIST =
ALT_JAXWS_DIST =
HOTSPOT_DOCS_IMPORT_PATH =/home/nature/workplace/openjdk6/build/linux-i586/hotspot/import/docs
ALT_HOTSPOT_DOCS_IMPORT_PATH =
HOTSPOT_IMPORT_PATH = /home/nature/workplace/openjdk6/build/linux-i586/hotspot/import
ALT_HOTSPOT_IMPORT_PATH =/home/nature/workplace/openjdk6/build/linux-i586/hotspot/import
HOTSPOT_CLIENT_PATH =/home/nature/workplace/openjdk6/build/linux-i586/hotspot/import/jre/lib/i386/client
ALT_HOTSPOT_CLIENT_PATH =
HOTSPOT_SERVER_PATH =/home/nature/workplace/openjdk6/build/linux-i586/hotspot/import/jre/lib/i386/server
ALT_HOTSPOT_SERVER_PATH =
CACERTS_FILE = ./../src/share/lib/security/cacerts
ALT_CACERTS_FILE =
CUPS_HEADERS_PATH = /usr/include
ALT_CUPS_HEADERS_PATH =
OpenJDK-specific settings:
FREETYPE_HEADERS_PATH = /usr/include
ALT_FREETYPE_HEADERS_PATH =
FREETYPE_LIB_PATH = /usr/lib
ALT_FREETYPE_LIB_PATH =
PLUG_LIBRARY_NAMES =
Previous JDK Settings:
PREVIOUS_RELEASE_PATH =/NOT-SET/re/jdk/1.6.0/archive/fcs/bundles/linux-i586
ALT_PREVIOUS_RELEASE_PATH =
PREVIOUS_JDK_VERSION = 1.6.0
ALT_PREVIOUS_JDK_VERSION =
PREVIOUS_JDK_FILE = jdk-6-linux-i586.tar.gz
ALT_PREVIOUS_JDK_FILE =
PREVIOUS_JRE_FILE = jre-6-linux-i586.tar.gz
ALT_PREVIOUS_JRE_FILE =
PREVIOUS_RELEASE_IMAGE =
ALT_PREVIOUS_RELEASE_IMAGE =
WARNING: This machine appears to only have 497Mb of physical memory,
builds on this machine could beslow.
Sanity check passed.
nature@nature-desktop:~/workplace/openjdk6$