Bootstrapping OpenJDK for a new architecture

Install build dependencies

First install the basic build dependencies:

# apt -y build-dep openjdk-17

Then install the cross-toolchain as well as the OpenJDK build dependencies for the target. For a Debian Ports target, also install debian-ports-archive-keyring and add the Debian Ports repository to /etc/apt/sources.list.

# apt install gcc-sh4-linux-gnu g++-sh4-linux-gnu
# apt install git debian-ports-archive-keyring
# dpkg --add-architecture sh4
# echo "deb [arch=sh4] http://ftp.ports.debian.org/debian-ports/ unstable main" >> /etc/apt/sources.list
# apt update
# apt install libffi-dev:sh4 libfreetype6-dev:sh4 libx11-dev:sh4 libxext-dev:sh4 libxrender-dev:sh4 libxtst-dev:sh4 libxi-dev:sh4 libjpeg62-turbo-dev:sh4 libpng-dev:sh4 libgif-dev:sh4 libasound2-dev:sh4 liblcms2-dev:sh4 libpcsclite-dev:sh4

For a release architecture, modifying /etc/apt/sources.list and installing debian-ports-archive-keyring is not necessary.

# apt install gcc-loongarch64-linux-gnu g++-loongarch64-linux-gnu
# dpkg --add-architecture loong64
apt update
apt install libffi-dev:loong64 libfreetype6-dev:loong64 libx11-dev:loong64 libxext-dev:loong64 libxrender-dev:loong64 libxtst-dev:loong64 libxi-dev:loong64 libjpeg62-turbo-dev:loong64 libpng-dev:loong64 libgif-dev:loong64 libasound2-dev:loong64 liblcms2-dev:loong64 libpcsclite-dev:loong64

(If there is no pre-built cross-toolchain package for your arch, use Helmut's rebootstrap script from https://salsa.debian.org/helmutg/rebootstrap to create some)

Download Debian package source

$ dget -u https://deb.debian.org/debian/pool/main/o/openjdk-17/openjdk-17_17.0.20~7ea-1.dsc

Cross-building packages

OpenJDK 8

For OpenJDK 8, some preparations to the source code have to be made before starting the build.

$ fakeroot ./debian/rules clean
$ ./debian/rules unpack
$ ./debian/rules patch
$ cd src
$ sh common/autoconf/autogen.sh
$ CONF=linux-loongarch64-normal-zero-release MAKE_VERBOSE=y QUIETLY= LOG=debug make clean CONF=linux-loongarch64-normal-zero-release ; sh ./configure --openjdk-target=loongarch64-linux-gnu  --with-jvm-variants=server --with-jvm-variants=zero --with-boot-jdk=/usr/lib/jvm/java-8-openjdk-amd64/ --disable-precompiled-headers --with-extra-cflags="-std=gnu89 -Wno-error"  CC=loongarch64-linux-gnu-gcc LD=loongarch64-linux-gnu-ld CXX=loongarch64-linux-gnu-g++ --with-libjpeg=system --with-giflib=system --with-libpng=system --with-zlib=system && make JOBS=64 LOG=debug CONF=linux-loongarch64-normal-zero-release images

Newer OpenJDK

For newer OpenJDK versions, no preparations are necessary. Downloading the package source with dget is sufficient.

$ CONF=linux-loongarch64-zero-release MAKE_VERBOSE=y QUIETLY= LOG=debug make clean CONF=linux-loongarch64-zero-release ; sh ./configure --openjdk-target=loongarch64-linux-gnu  --with-jvm-variants=server --with-jvm-variants=zero --with-boot-jdk=/usr/lib/jvm/java-17-openjdk-amd64/ --without-jtreg --disable-precompiled-headers  CC=loongarch64-linux-gnu-gcc LD=loongarch64-linux-gnu-ld CXX=loongarch64-linux-gnu-g++ --with-libjpeg=system --with-giflib=system --with-libpng=system --with-zlib=system --with-pcsclite=system && make JOBS=64 LOG=debug CONF=linux-loongarch64-zero-release images

Copy build result into target system

OpenJDK 8

# rsync --progress -avz /home/glaubitz/openjdk-8/openjdk-8-8u492-ga/src/build/linux-loongarch64-normal-zero-release/images/j2sdk-image/ /path/to/target/system/usr/lib/java-8-openjdk-loong64/

Newer OpenJDK versions

# rsync --progress -avzL /home/glaubitz/openjdk-17/openjdk-17-17.0.20~7ea/build/linux-loongarch64-zero-release/jdk/ /path/to/target/system/usr/lib/java-17-openjdk-loong64/

Build Debian package on target machine

Install build dependencies

For OpenJDK 8

$ apt install quilt m4 lsb-release sharutils gawk procps wdiff tzdata debhelper cpio zip unzip autoconf automake pkgconf xvfb xauth xfonts-base libgl1-mesa-dri xfwm4 x11-xkb-utils dbus-x11 jtreg libasmtools-java testng ant ant-optional fastjar zlib1g-dev libattr1-dev libpng-dev libjpeg-dev libgif-dev libcups2t64 libglib2.0-0t64 libgtk2.0-0t64 libxtst-dev libxi-dev libxt-dev libxaw7-dev libxrender-dev libcups2-dev libasound2-dev liblcms2-dev libxinerama-dev libkrb5-dev xsltproc libpcsclite-dev libfreetype-dev libgtk2.0-dev libffi-dev libpulse-dev systemtap-sdt-dev libnss3-dev time

For newer OpenJDK versions

These require the OpenJDK 8 build dependencies plus the following extra packages

# apt install strip-nondeterminism debugedit jtreg7 libtestng7-java

Download sources

$ dget -u https://deb.debian.org/debian/pool/main/o/openjdk-17/openjdk-17_17.0.20~7ea-1.dsc

Build OpenJDK package

$ cd openjdk-17-17.0.20~7ea
$ export DEB_BUILD_OPTIONS="nocheck parallel=64" ; dpkg-buildpackage -B -d