diff --git a/doc/building.html b/doc/building.html index 8774e5562d6..318a24aa840 100644 --- a/doc/building.html +++ b/doc/building.html @@ -629,21 +629,30 @@ cp: cannot stat `arm-linux-gnueabihf/libXt.so': No such file or directoryFortunately, you can create sysroots for foreign architectures with tools provided by your OS. On Debian/Ubuntu systems, one could use qemu-deboostrap to create the target system chroot, which would have the native libraries and headers specific to that target system. After that, we can use the cross-compiler on the build system, pointing into chroot to get the build dependencies right. This allows building for foreign architectures with native compilation speed.

For example, cross-compiling to AArch64 from x86_64 could be done like this:

-
apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
- -
sudo qemu-debootstrap --arch=arm64 --verbose \
-       --include=fakeroot,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng12-dev \
-       --resolve-deps jessie /chroots/arm64 http://httpredir.debian.org/debian/
- -
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure --openjdk-target=aarch64-linux-gnu --with-sysroot=/chroots/arm64/ --with-toolchain-path=/chroots/arm64/
+
  • Install cross-compiler on the build system:

    +
    apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
  • +
  • Create chroot on the build system, configuring it for target system:

    +
    sudo qemu-debootstrap \
    +  --arch=arm64 \
    +  --verbose \
    +  --include=fakeroot,symlinks,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng-dev \
    +  --resolve-deps \
    +  buster \
    +  ~/sysroot-arm64 \
    +  http://httpredir.debian.org/debian/
  • +
  • Make sure the symlinks inside the newly created chroot point to proper locations:

    +
    sudo chroot ~/sysroot-arm64 symlinks -cr .
  • +
  • Configure and build with newly created chroot as sysroot/toolchain-path:

    +
    CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure \
    + --openjdk-target=aarch64-linux-gnu \
    + --with-sysroot=~/sysroot-arm64 \
    + --with-toolchain-path=~/sysroot-arm64 \
    + --with-freetype-lib=~/sysroot-arm64/usr/lib/aarch64-linux-gnu/ \
    + --with-freetype-include=~/sysroot-arm64/usr/include/freetype2/ \
    + --x-libraries=~/sysroot-arm64/usr/lib/aarch64-linux-gnu/
     make images
    -ls build/linux-aarch64-normal-server-release/
    +ls build/linux-aarch64-server-release/
  • +

    The build does not create new files in that chroot, so it can be reused for multiple builds without additional cleanup.

    Architectures that are known to successfully cross-compile like this are:

    diff --git a/doc/building.md b/doc/building.md index fa6b0ae31b6..e0ac5c7b6c7 100644 --- a/doc/building.md +++ b/doc/building.md @@ -1086,23 +1086,39 @@ for foreign architectures with native compilation speed. For example, cross-compiling to AArch64 from x86_64 could be done like this: * Install cross-compiler on the *build* system: -``` -apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -``` + ``` + apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu + ``` * Create chroot on the *build* system, configuring it for *target* system: -``` -sudo qemu-debootstrap --arch=arm64 --verbose \ - --include=fakeroot,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng12-dev \ - --resolve-deps jessie /chroots/arm64 http://httpredir.debian.org/debian/ -``` + ``` + sudo qemu-debootstrap \ + --arch=arm64 \ + --verbose \ + --include=fakeroot,symlinks,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng-dev \ + --resolve-deps \ + buster \ + ~/sysroot-arm64 \ + http://httpredir.debian.org/debian/ + ``` + + * Make sure the symlinks inside the newly created chroot point to proper locations: + ``` + sudo chroot ~/sysroot-arm64 symlinks -cr . + ``` * Configure and build with newly created chroot as sysroot/toolchain-path: -``` -CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure --openjdk-target=aarch64-linux-gnu --with-sysroot=/chroots/arm64/ --with-toolchain-path=/chroots/arm64/ -make images -ls build/linux-aarch64-normal-server-release/ -``` + ``` + CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure \ + --openjdk-target=aarch64-linux-gnu \ + --with-sysroot=~/sysroot-arm64 \ + --with-toolchain-path=~/sysroot-arm64 \ + --with-freetype-lib=~/sysroot-arm64/usr/lib/aarch64-linux-gnu/ \ + --with-freetype-include=~/sysroot-arm64/usr/include/freetype2/ \ + --x-libraries=~/sysroot-arm64/usr/lib/aarch64-linux-gnu/ + make images + ls build/linux-aarch64-server-release/ + ``` The build does not create new files in that chroot, so it can be reused for multiple builds without additional cleanup.