メモ:OpenJDK 6 のビルド手順

OpenJDKをビルドしたので、手順をメモしておきます。

クラスローダを理解するために読んでみることにしました。じつは先週、クラスローダの仕組みを知らないせいで先輩に迷惑をかけ、「正月休みにOpenJDKのコード読んで、1行1行ブログで説明しろ」と言い渡されてしまいました。

ちょwムリwと思いましたが、ひとまず読んでみます、ハイ。…でも、どこから?(←イマココ!)

ビルド対象
OpenJDK 6 Build b20

X64 only: The minimum recommended hardware for building the Linux version is an AMD Opteron class processor, at least 512 MB of RAM, and approximately 4 GB of free disk space.

OpenJDKのダウンロード

openjdk-6-src-b20-21_jun_2010.tar.gzをダウンロードして展開します。

READMEに「ブート用のJDKを入れたらとりあえずmakeしてみて、エラーを解決していく」と書いてあるので、したがいます。

Sun JDKのインストール

jdk1.6.0_19をrpm.binでインストールします。

環境変数を設定します。

export PATH=$PATH:{jdk-install-dir}/bin
export ALT_BOOTDIR={jdk-install-dir}
留意点1: JAVA_HOMEを設定しない

この時、環境変数JAVA_HOMEを設定してはいけないようです。make sanityでエラーになり、unsetを勧められます。

留意点2: バージョン

ビルド対象のOpenJDKが2010年6月にリリースされたものなので、その前にリリースされたSunJDKを使いました。

JDK Updateのリリース日の情報はWikipediaにまとまっています。

留意点3: SunJDK? OpenJDK + gcj?

ここでインストールするJDKは、OpenJDKのブート用です。README-builds.htmlには、LinuxにパッケージングされているOpenJDKが使えると書いてあります。SunJDKを使ったのは、単に自分がgcjに不慣れだからです・・・

make sanityを実行してみる

gccがなければインストールしておきます。gcc4が必要です。

yum install gcc

OpenJDKのルートディレクトリで、次のコマンドを実行します。

make sanity

README-builds.htmlを参照しながらエラーを解決していきます。

Antのインストール

Ant 1.6.5のバイナリをダウンロードします。

解凍して /usr/local/antに配置します。

環境変数を設定します。

export ANT_HOME={ant-install-dir}
export PATH=$PATH:ANT_HOME/bin

Advanced Linux Sound Architecture (ALSA) のインストール

/{build-dir}/build/linux-amd64/tmp/alsaversioncheck.c:1:28: error: alsa/asoundlib.h: No such file or directory

ALSAのヘッダファイルが必要なので、インストールします。

yum install alsa-lib-devel

FreeType2のインストール

FreeType2.3.0のDevelopment versionをインストールします。

公式リリースバージョン以外のFreeType2をビルドする場合、FreeTypeのルートディレクトリにあるautogen.shを実行して、configureファイルを生成する必要があります。

autogen.shの実行には、automakeやautoconfが使われるので、libtoolがなければインストールしておきます。

yum instlal libtool
sh autogen.sh
./configure
make
make install

環境変数を設定します。

export ALT_FREETYPE_LIB_PATH=/usr/local/lib
export ALT_FREETYPE_HEADERS_PATH=/{freetype-install-dir}/include
留意点: FreeType2 のバージョン

最初はOpenJDK6リリース直前に出た2.3.12を使おうとしたのですが、ビルドではまったのでバージョンを下げました。2.3.12のautogen.shでは、libtoolsやautomakeのバージョンチェックをしており、古いとエラーになります。しかし、これらのツールのアップグレードはハマリどころのようなので、回避しました。

2.3.0のautogen.shではバージョンチェックをしていないので、すんなりとconfigureファイルが作られます。

OpenMotifのヘッダファイルの配置

openmotif-2.1.30.5p1.tgzを入手します。README-builds.htmlにあるリンク先は消えているので、ミラーサイトなどから適宜ダウンロードします。

解凍し、include/Xmディレクトリを/usr/include/Xmに配置します。

環境変数を設定します。

export ALT_MOTIF_DIR=/usr

Cupsのインストール

http://www.cups.org/からCUPS 1.4.5をダウンロードして、インストールします。

./configure
make
make install

環境変数を設定します。

export ALT_CUPS_HEADERS_PATH=/usr/include

CupsのコンパイルにはC++コンパイラが必要なので、なければインストールしておきます。

yum install gcc-c++

Binary Plugsインストール

Binary Plugsをインストールします。ダウンロードしたjarを実行すると、ディレクトリを選んでインストールする画面が開きます。openjdk-binary-plugsというディレクトリが作成されるので、任意の場所に配置します。オプションなので、インストールしなくてもビルドできます。

環境変数を設定します。

export ALT_BINARY_PLUGS_PATH={binary-plugs-install-dir}/openjdk-binary-plugs

make

make sanityをパスしたら、makeを実行します。

make

ここまでに、次の記事が参考になりました。

ビルドエラー対処

エラーが出なくなるまで、修正とmakeの実行を繰り返します。

結論として、次のパッケージのインストールが必要でした。

yum install libXt-devel libXtst-devel libXi-devel libXext-devel libXp libXp-devel libXpm-devel

また、スクリプトの修正を2箇所行います。

以下は詳細です(一応、後々のために・・・)

ビルドエラー対処(1) jaxwsとjafソースコード取得先の変更
    [echo] + Starting ant project jaxp +
(略)
-use-drop:

-src-help:

BUILD FAILED
/{openjdk-build-dir}/jaxp/build-defs.xml:70: ERROR: Cannot find source
for project jaxp.

HINT: Try setting drops.dir to indicate where the bundles can be
found, or try setting the ant property allow.downloads=true to
download the bundle from the URL.
e.g. ant -Dallow.downloads=true -OR- ant -Ddrops.dir=some_directory

環境変数を設定します。

export ALLOW_DOWNLOADS=true

これだけで通ればOKですが、まだダメなら、{openjdk-build-dir}/jaxws/jaxws.propertiesを編集してソースの取得先を変更します。

jaxws_src.bundle.name=jdk6-jaxws-b20.zip
jaxws_src.bundle.md5.checksum=91adfd41e6f001add4f92ae31216b1e3
jaxws_src.master.bundle.dir=${drops.master.copy.base}
#jaxws_src.master.bundle.url.base=https://jax-ws.dev.java.net/files/documents/4202/150724
jaxws_src.master.bundle.url.base=http://icedtea.classpath.org/download/drops

jaf_src.bundle.name=jdk6-jaf-b20.zip
jaf_src.bundle.md5.checksum=bc95c133620bd68c161cac9891592901
jaf_src.master.bundle.dir=${drops.master.copy.base}
#jaf_src.master.bundle.url.base=https://jax-ws.dev.java.net/files/documents/4202/150725
jaf_src.master.bundle.url.base=http://icedtea.classpath.org/download/drops

jdk6-jaxws-b20.zip、jdk6-jaf-b20.zipは、icedtea.classpath.orgでも配布されていたので、そちらを使うことにします。

ちなみに、ALLOW_DOWNLOADS=trueの設定だけだと、次のエラーが出ました。

BUILD FAILED
/{openjdk-build-dir}/build/linux-amd64/jaxws/build/xml_generated/build-drop-jaxws_src.xml:96:
javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: No subject alternative DNS name matching jax-ws.dev.java.net found.

検索すると関連の話題が出てきますが、正直むずかしいのでスルーして取得先を変えました。

なお、zipファイルを手動でダウンロードしてローカルに置き、環境変数ALT_DROPS_DIRを設定する方法は、なぜか上手くいきませんでした。この方法でもいけると思うのですが・・・

ビルドエラー対処(2) Xt、Xst系パッケージのインストール
../../../src/solaris/native/sun/awt/utility/rect.h:31:22: error:
X11/Xlib.h: No such file or directory
In file included from
../../../src/share/native/sun/awt/../java2d/pipe/Region.h:34,
                from
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:30:
../../../src/solaris/native/sun/awt/utility/rect.h:32: error: expected
'=', ',', ';', 'asm' or '__attribute__' before 'RECT_T'
In file included from
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:30:
../../../src/share/native/sun/awt/../java2d/pipe/Region.h:211: error:
expected declaration specifiers or '...' before 'RECT_T'
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:243: error:
expected declaration specifiers or '...' before 'RECT_T'
../../../src/share/native/sun/awt/../java2d/pipe/Region.c: In function
'RegionToYXBandedRectangles':
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:254: error:
'pRect' undeclared (first use in this function)
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:254: error:
(Each undeclared identifier is reported only once
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:254: error:
for each function it appears in.)
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:263:
warning: comparison between signed and unsigned
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:264: error:
'RECT_T' undeclared (first use in this function)
../../../src/share/native/sun/awt/../java2d/pipe/Region.c:264: error:
expected expression before ')' token
make[5]: *** [{openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/awt/obj64/Region.o]
Error 1

libXt-develとlibXtst-develをインストールします。次の記事が参考になりました。

ビルドエラー対処(3) Makefileの修正
make[4]: *** [{openjdk-build-dir}/build/linux-amd64/lib/amd64/libsplashscreen.so]
Error 1
make[4]: Leaving directory `{openjdk-build-dir}/jdk/make/sun/splashscreen'
make[3]: *** [all] Error 1
make[3]: Leaving directory `{openjdk-build-dir}/jdk/make/sun'
make[2]: *** [all] Error 1
make[2]: Leaving directory `{openjdk-build-dir}/jdk/make'
make[1]: *** [jdk-build] Error 2
make[1]: Leaving directory `{openjdk-build-dir}'
make: *** [build_product_image] Error 2

{openjdk-build-dir}のjdk/make/sun/splashscreen/Makefileを修正します。

ifeq ($(PLATFORM), linux)
 ifeq ($(ARCH_DATA_MODEL), 64)
   # 64-bit gcc has problems compiling MMX instructions.
   # Google it for more details. Possibly the newer versions of
   # the PNG-library and/or the new compiler will not need this
   # option in the future.
   # (追加/ ここから)
   C_INCLUDE_PATH=$(SHARE_SRC)/native/$(PKGDIR)/splashscreen
   # (追加/ ここまで)
   CPPFLAGS += -DPNG_NO_MMX_CODE
 endif
endif
ビルドエラー対処(4) Xiパッケージのインストール
/splashscreen/obj64/jcmaster.o
{openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jcparam.o
  {openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jcphuff.o
  {openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jcprepct.o
  {openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jcsample.o
  {openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jctrans.o
  {openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jdtrans.o
  {openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jfdctflt.o
  {openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jfdctfst.o
  {openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jfdctint.o
 -L/usr/X11R6/lib64 -lX11 -lXext -lm -lpthread   -lc
/usr/bin/ld: cannot find -lXext
collect2: ld returned 1 exit status
make[4]: *** [{openjdk-build-dir}/build/linux-amd64/lib/amd64/libsplashscreen.so]
Error 1

libXi-develをインストールします。次の記事が参考になりました。

ビルドエラー対処(5) Xp系パッケージのインストール
{openjdk-build-dir}/build/linux-amd64/tmp/sun/sun.awt/splashscreen/obj64/jfdctint.o
 -L/usr/X11R6/lib64 -lX11 -lXext -lm -lpthread   -lc
/usr/bin/ld: cannot find -lXext
collect2: ld returned 1 exit status
make[4]: *** [{openjdk-build-dir}/build/linux-amd64/lib/amd64/libsplashscreen.so]
Error 1

libXp、libXp-devel、libXpm-develをインストールします。

以上です。