Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenJDK 21 compilation issue #6359

Open
tofuHero opened this issue Dec 24, 2024 · 7 comments
Open

OpenJDK 21 compilation issue #6359

tofuHero opened this issue Dec 24, 2024 · 7 comments

Comments

@tofuHero
Copy link

I finally succeeded in compiling OpenJDK 21, but there were issues during the compilation process.

When compiling cross/java-21-jdk, I encountered the error --defined-only: command not found. The reason is that the $(NM) variable in line 56 of the spk/java-21-openjdk/work-x64-7.2/jdk21u-jdk-21.0.6-6/make/hotspot/lib/JvmMapfile.gmk file was not defined as nm. Therefore, I added NM=/usr/bin/nm before the compile command, so the command became NM=/usr/bin/nm make arch-x64-7.2, and it compiled successfully.

When compiling spk/java-21-jdk, I encountered the error Could not find all X11 headers (shape.h Xrender.h Xrandr.h XTest.h Intrinsic.h) once again. I had already encountered this issue when compiling cross/java-21-jdk, and based on the prompt, I executed sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev to install the corresponding header files.

In order to successfully compile this package, I modified the code located in spk/java-21-openjdk/work-x64-7.2/jdk21u-jdk-21.0.6-6/make/autoconf/lib-x11.m4.

AC_CHECK_HEADERS([X11/extensions/shape.h X11/extensions/Xrender.h X11/extensions/XTest.h X11/Intrinsic.h X11/extensions/Xrandr.h],
          [X11_HEADERS_OK=yes],
          # [X11_HEADERS_OK=no; break],
          [X11_HEADERS_OK=yes], 
          [
            # include <X11/Xlib.h>
            # include <X11/Xutil.h>
          ]
      )

I know that modifying the source code this way is not correct. How can I ensure that the X11 header libraries are properly recognized and that the $(NM) variable correctly points to /usr/bin/nm?

  • OS: Debian 12

  • Host: KVM on Proxmox VE

  • cross/java-21-jdk/Makefile (copy from cross/java-17-jdk/Makefile):

    PKG_NAME = java-21-openjdk
    JAVA_REPO_NAME = jdk21u
    JAVA_NAME = jdk
    JAVA_RELEASE = 6
    JAVA_VERSION = 21.0.6
    PKG_VERS = $(JAVA_VERSION).$(JAVA_RELEASE)
    PKG_EXT = tar.gz
    PKG_DIST_NAME = $(JAVA_NAME)-$(JAVA_VERSION)+$(JAVA_RELEASE).$(PKG_EXT)
    PKG_DIST_SITE = https://github.com/openjdk/$(JAVA_REPO_NAME)/archive
    PKG_DIR = $(JAVA_REPO_NAME)-$(JAVA_NAME)-$(JAVA_VERSION)-$(JAVA_RELEASE)
    
    # build instructions:
    # https://openjdk.java.net/groups/build/doc/building.html
    
    BUILD_DEPENDS = native/openjdk-21
    # Dependencies required at build time only:
    BUILD_DEPENDS += cross/cups
    BUILD_DEPENDS += cross/alsa-lib
    BUILD_DEPENDS += cross/libX11
    BUILD_DEPENDS += cross/libXrender
    
    # Dependencies used as system dependencies:
    DEPENDS  = cross/alsa-lib
    DEPENDS += cross/fontconfig
    DEPENDS += cross/libffi
    DEPENDS += cross/zlib
    DEPENDS += cross/libpng
    DEPENDS += cross/libjpeg
    DEPENDS += cross/giflib
    DEPENDS += cross/lcms2
    
    HOMEPAGE = https://openjdk.org/projects/jdk/21/
    COMMENT  = OpenJDK 21 is the open-source reference implementation of version 21 of the Java SE Platform as specified by JSR 396 in the Java Community Process.
    LICENSE  = GPLv2 with the Classpath Exception
    
    # Use our own configure since the one supplied by openjdk has no shebang
    CONFIGURE_TARGET = java-21-openjdk_configure
    
    # Force openjdk to install into the package install folder
    PRE_COMPILE_TARGET = java-21-openjdk_pre_compile
    
    # Fix symlinks
    POST_INSTALL_TARGET = java-21-openjdk_post_compile
    
    CONFIGURE_ARGS  = --openjdk-target=$(TC_TARGET)
    CONFIGURE_ARGS += --with-boot-jdk=$(WORK_DIR)/../../../native/openjdk-21/work-native/jdk-21
    CONFIGURE_ARGS += --with-version-build=$(JAVA_RELEASE)
    CONFIGURE_ARGS += --with-version-pre=
    CONFIGURE_ARGS += --with-version-opt=LTS
    CONFIGURE_ARGS += --with-native-debug-symbols=none
    CONFIGURE_ARGS += --prefix=$(INSTALL_PREFIX)
    CONFIGURE_ARGS += --with-zlib=system
    CONFIGURE_ARGS += --with-libjpeg=system
    CONFIGURE_ARGS += --with-giflib=system
    CONFIGURE_ARGS += --with-libpng=system
    CONFIGURE_ARGS += --with-lcms=system
    CONFIGURE_ARGS += --with-alsa=$(INSTALL_DIR)/$(INSTALL_PREFIX)
    CONFIGURE_ARGS += --with-stdc++lib=dynamic
    CONFIGURE_ARGS += --disable-javac-server
    CONFIGURE_ARGS += --disable-warnings-as-errors
    CONFIGURE_ARGS += --with-cups=$(INSTALL_DIR)/$(INSTALL_PREFIX)
    CONFIGURE_ARGS += --with-fontconfig=$(INSTALL_DIR)/$(INSTALL_PREFIX)
    CONFIGURE_ARGS += --with-freetype=system
    CONFIGURE_ARGS += --with-freetype-include=$(INSTALL_DIR)/$(INSTALL_PREFIX)/include/freetype2
    CONFIGURE_ARGS += --with-freetype-lib=$(INSTALL_DIR)/$(INSTALL_PREFIX)/lib
    CONFIGURE_ARGS += --with-extra-cflags="$(CFLAGS) -fno-stack-protector -Wno-deprecated-declarations"
    CONFIGURE_ARGS += --with-extra-cxxflags="$(CPPFLAGS) -fno-stack-protector -Wno-deprecated-declarations"
    CONFIGURE_ARGS += --with-extra-ldflags="$(LDFLAGS) -Xlinker -z -Xlinker relro -Xlinker -Bsymbolic-functions"
    CONFIGURE_ARGS += --with-libffi=$(INSTALL_DIR)/$(INSTALL_PREFIX)
    CONFIGURE_ARGS += --disable-manpages
    CONFIGURE_ARGS += --with-cacerts-file=/etc/ssl/certs/ca-certificates.crt
    CONFIGURE_ARGS += --with-cacerts-src=/etc/ssl/certs
    # Disable all GUI related
    CONFIGURE_ARGS += --enable-headless-only
    # customize for SynoCommunity
    CONFIGURE_ARGS += --with-vendor-name=SynoCommunity
    CONFIGURE_ARGS += --with-vendor-url=https://synocommunity.com/package/java-21-openjdk
    CONFIGURE_ARGS += --with-vendor-bug-url=https://github.com/SynoCommunity/spksrc/issues
    CONFIGURE_ARGS += --with-vendor-vm-bug-url=https://github.com/SynoCommunity/spksrc/issues
    
    # arguments not taken from environment
    CONFIGURE_ARGS += READELF=$(READELF)
    CONFIGURE_ARGS += AR=$(AR)
    CONFIGURE_ARGS += STRIP=$(STRIP)
    CONFIGURE_ARGS += NM=$(NM)
    CONFIGURE_ARGS += OBJCOPY=$(OBJCOPY)
    CONFIGURE_ARGS += OBJDUMP=$(OBJDUMP)
    
    # Build images twice, second time with newly built JDK
    COMPILE_MAKE_OPTIONS += product-images
    
    PATCHES_LEVEL = 1
    
    ADDITIONAL_CFLAGS = -O2
    
    # Filter out any -jN since java's configure will autodetect number of CPU's
    # Use make JOBS=N to set number of CPU's in this package
    DISABLE_PARALLEL_MAKE = 1
    COMPILE_MAKE_OPTIONS += JOBS=$(NCPUS)
    
    include ../../mk/spksrc.cross-cc.mk
    
    .PHONY: java-21-openjdk_configure
    # Use CONFIGURE_ARGS instead of REAL_CONFIGURE_ARGS to ignore TC_CONFIGURE_ARGS
    # Disable the normal host build target triplets since openjdk uses its own openjdk-target
    # Avoid the use of $(RUN) since configure complains about env variables
    java-21-openjdk_configure:
    	cd $(WORK_DIR)/$(PKG_DIR) && bash ./configure $(CONFIGURE_ARGS)
    
    .PHONY: java-21-openjdk_pre_compile
    # As DESTDIR is not supported we must patch the make file for make install.
    java-21-openjdk_pre_compile:
    	sed -i -e "s|\$$(INSTALL_PREFIX)|$(STAGING_INSTALL_PREFIX)|g" $(WORK_DIR)/$(PKG_DIR)/make/Install.gmk
    
    .PHONY: java-21-openjdk_post_compile
    java-21-openjdk_post_compile:
    	@cd $(STAGING_INSTALL_PREFIX)/bin && ln -sf ../jvm/openjdk-$(JAVA_VERSION)/bin/* .
    	@cp -pf $(WORK_DIR)/$(PKG_DIR)/LICENSE                   $(STAGING_INSTALL_PREFIX)/jvm/openjdk-$(JAVA_VERSION)/
    	@cp -pf $(WORK_DIR)/$(PKG_DIR)/ADDITIONAL_LICENSE_INFO   $(STAGING_INSTALL_PREFIX)/jvm/openjdk-$(JAVA_VERSION)/
    	@cp -pf $(WORK_DIR)/$(PKG_DIR)/ASSEMBLY_EXCEPTION        $(STAGING_INSTALL_PREFIX)/jvm/openjdk-$(JAVA_VERSION)/
  • spk/java-21-jdk/Makefile (copy from spk/java-17-jdk/Makefile):

    SPK_NAME = java-21-openjdk
    JAVA_REPO_NAME = jdk21u
    JAVA_NAME = jdk
    JAVA_RELEASE = 6
    JAVA_VERSION = 21.0.6
    SPK_VERS = $(JAVA_VERSION).$(JAVA_RELEASE)
    SPK_REV = 1
    SPK_ICON = src/java-openjdk.png
    
    DEPENDS = cross/java-21-openjdk
    
    # gcc >= 5.0 required
    REQUIRED_MIN_DSM = 7.0
    UNSUPPORTED_ARCHS = comcerto2k
    
    MAINTAINER = SynoCommunity
    DESCRIPTION = OpenJDK version $(JAVA_VERSION)+$(JAVA_RELEASE). OpenJDK 21 is the open-source reference implementation of version 21 of the Java SE Platform as specified by JSR 396 in the Java Community Process.
    
    STARTABLE = no
    DISPLAY_NAME = Java 21 OpenJDK
    CHANGELOG = "Initial Java 21 package release"
    
    HOMEPAGE = https://openjdk.org/projects/jdk/21/
    LICENSE_FILE = src/LICENSE
    
    SPK_COMMANDS += bin/jar
    SPK_COMMANDS += bin/jarsigner
    SPK_COMMANDS += bin/java
    SPK_COMMANDS += bin/javac
    SPK_COMMANDS += bin/javadoc
    SPK_COMMANDS += bin/javap
    SPK_COMMANDS += bin/jcmd
    SPK_COMMANDS += bin/jconsole
    SPK_COMMANDS += bin/jdb
    SPK_COMMANDS += bin/jdeprscan
    SPK_COMMANDS += bin/jdeps
    SPK_COMMANDS += bin/jfr
    SPK_COMMANDS += bin/jhsdb
    SPK_COMMANDS += bin/jimage
    SPK_COMMANDS += bin/jinfo
    SPK_COMMANDS += bin/jlink
    SPK_COMMANDS += bin/jmap
    SPK_COMMANDS += bin/jmod
    SPK_COMMANDS += bin/jpackage
    SPK_COMMANDS += bin/jps
    SPK_COMMANDS += bin/jrunscript
    SPK_COMMANDS += bin/jshell
    SPK_COMMANDS += bin/jstack
    SPK_COMMANDS += bin/jstat
    SPK_COMMANDS += bin/jstatd
    SPK_COMMANDS += bin/jwebserver
    SPK_COMMANDS += bin/keytool
    SPK_COMMANDS += bin/rmiregistry
    SPK_COMMANDS += bin/serialver
    
    include ../../mk/spksrc.spk.mk
@tofuHero
Copy link
Author

图片
图片

@hgy59
Copy link
Contributor

hgy59 commented Dec 24, 2024

@tofuHero I guess you need to use nm of the toolchain?

The regular way would be to use $(RUN) and you get all tools in the env (environment), but there is a comment that RUN can't be used here:

.PHONY: java-21-openjdk_configure
# Use CONFIGURE_ARGS instead of REAL_CONFIGURE_ARGS to ignore TC_CONFIGURE_ARGS
# Disable the normal host build target triplets since openjdk uses its own openjdk-target
# Avoid the use of $(RUN) since configure complains about env variables
java-21-openjdk_configure:
	cd $(WORK_DIR)/$(PKG_DIR) && bash ./configure $(CONFIGURE_ARGS)

The toolchain tools are defined in tc_vars.mk that is created in mk/spksrc.tc.mk and the list of the tools is defined in mk/spksrc.tc-flags.mk as

TOOLS = ld ldshared:"gcc -shared" cpp nm cc:gcc as ranlib cxx:g++ ar strip objdump objcopy readelf

if you need NM only, you could try to define it as

NM = $(TC_PATH)/$(TC_PREFIX)nm

If you create a PR here, it will be much easier for you to get help.
Be sure to create a dedicated branch first, otherwise you will have problems keeping your fork in sync with the upstream repository.
See section Pull requests in https://github.com/SynoCommunity/spksrc/blob/master/CONTRIBUTING.md

@hgy59
Copy link
Contributor

hgy59 commented Dec 24, 2024

@tofuHero regarding x11: you should try to avoid the installation of x11 dev packages.
There is no X Window System available under DSM and the JDK must be built without X11 support (where possible).
To provide the required files we already have cross/libX11 and other cross modules (DEPENDS in cross/libX11/Makefile). It might be a solution to update those and/or add additional cross modules.

You may find more information in previous PRs #5610 and #4784

@tofuHero
Copy link
Author

@tofuHero I guess you need to use nm of the toolchain?

The regular way would be to use $(RUN) and you get all tools in the env (environment), but there is a comment that RUN can't be used here:

.PHONY: java-21-openjdk_configure
# Use CONFIGURE_ARGS instead of REAL_CONFIGURE_ARGS to ignore TC_CONFIGURE_ARGS
# Disable the normal host build target triplets since openjdk uses its own openjdk-target
# Avoid the use of $(RUN) since configure complains about env variables
java-21-openjdk_configure:
	cd $(WORK_DIR)/$(PKG_DIR) && bash ./configure $(CONFIGURE_ARGS)

The toolchain tools are defined in tc_vars.mk that is created in mk/spksrc.tc.mk and the list of the tools is defined in mk/spksrc.tc-flags.mk as

TOOLS = ld ldshared:"gcc -shared" cpp nm cc:gcc as ranlib cxx:g++ ar strip objdump objcopy readelf

if you need NM only, you could try to define it as

NM = $(TC_PATH)/$(TC_PREFIX)nm

If you create a PR here, it will be much easier for you to get help. Be sure to create a dedicated branch first, otherwise you will have problems keeping your fork in sync with the upstream repository. See section Pull requests in https://github.com/SynoCommunity/spksrc/blob/master/CONTRIBUTING.md

I added NM = $(TC_PATH)/$(TC_PREFIX)nm to cross/java-21-jdk/Makefile, and it worked successfully.

@tofuHero
Copy link
Author

@tofuHero regarding x11: you should try to avoid the installation of x11 dev packages. There is no X Window System available under DSM and the JDK must be built without X11 support (where possible). To provide the required files we already have cross/libX11 and other cross modules (DEPENDS in cross/libX11/Makefile). It might be a solution to update those and/or add additional cross modules.

You may find more information in previous PRs #5610 and #4784

I tried to disable X while compiling. so I added CONFIGURE_ARGS += --with-x=no to cross/java-21-jdk/Makefile, and it print configure: error: It is not possible to disable the use of X11. Remove the --without-x option.

It seems that OpenJDK 21 requires an X environment.

@hgy59
Copy link
Contributor

hgy59 commented Dec 24, 2024

@tofuHero I got the x11 header files with this three lines:

BUILD_DEPENDS += cross/libXrandr
BUILD_DEPENDS += cross/libXtst
BUILD_DEPENDS += cross/libXt

There is another issue with libpng and lcms that are not found.
so I removed --with-libpng=system and --with-lcms=system (default is bundled instead of system)
and configure works now

====================================================
A new configuration has been successfully created in
/spksrc/cross/java-21-openjdk/work-x64-7.1/jdk21u-jdk-21.0.5-11/build/linux-x86_64-server-release

I used 21.0.5-11 since this is the latest (unstable) version in debian 21

BTW when building cross/java-17-openjdk I had the same issues with libpng, lcms and NM.

@hgy59
Copy link
Contributor

hgy59 commented Dec 24, 2024

It seems that OpenJDK 21 requires an X environment.

Yes, this is required to build openJDK, but not at runtime, so we do not include the X11 libraries in the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants