From dad0f7c33d58a971cd9234f4f25dd7d488bb8e9d Mon Sep 17 00:00:00 2001
From: Thomas Devoogdt
Date: Thu, 13 Nov 2025 17:23:44 +0100
Subject: [PATCH 1/3] awt: fix HEADLESS compilation without X11
Signed-off-by: Thomas Devoogdt
---
make/modules/java.desktop/lib/AwtLibraries.gmk | 16 ++++++++++++++--
.../unix/native/common/awt/utility/rect.h | 4 ++--
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/make/modules/java.desktop/lib/AwtLibraries.gmk b/make/modules/java.desktop/lib/AwtLibraries.gmk
index 463e09e12dcee..8b6b50b9e6236 100644
--- a/make/modules/java.desktop/lib/AwtLibraries.gmk
+++ b/make/modules/java.desktop/lib/AwtLibraries.gmk
@@ -88,6 +88,10 @@ LIBAWT_EXTRA_HEADER_DIRS := \
LIBAWT_CFLAGS := -D__MEDIALIB_OLD_NAMES -D__USE_J2D_NAMES -DMLIB_NO_LIBSUNMATH
+ifeq ($(ENABLE_HEADLESS_ONLY), true)
+ LIBAWT_CFLAGS += -DHEADLESS
+endif
+
ifeq ($(call isTargetOs, windows), true)
LIBAWT_CFLAGS += -EHsc -DUNICODE -D_UNICODE -DMLIB_OS64BIT
LIBAWT_RCFLAGS ?= -I$(TOPDIR)/src/java.base/windows/native/launcher/icons
@@ -167,11 +171,18 @@ ifeq ($(call isTargetOs, windows macosx), false)
$(TOPDIR)/src/$(MODULE)/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
#
+ LIBAWT_HEADLESS_EXCLUDE_FILES := \
+ GLXGraphicsConfig.c \
+ GLXSurfaceData.c \
+ X11PMBlitLoops.c \
+ X11Renderer.c \
+ X11SurfaceData.c \
+ #
+
LIBAWT_HEADLESS_EXTRA_HEADER_DIRS := \
$(LIBAWT_DEFAULT_HEADER_DIRS) \
common/awt/debug \
common/font \
- common/java2d/opengl \
java.base:libjvm \
#
@@ -191,7 +202,8 @@ ifeq ($(call isTargetOs, windows macosx), false)
$(eval $(call SetupJdkLibrary, BUILD_LIBAWT_HEADLESS, \
NAME := awt_headless, \
EXTRA_SRC := $(LIBAWT_HEADLESS_EXTRA_SRC), \
- EXCLUDES := medialib, \
+ EXCLUDES := medialib opengl, \
+ EXCLUDE_FILES := $(LIBAWT_HEADLESS_EXCLUDE_FILES), \
ONLY_EXPORTED := $(LIBAWT_HEADLESS_ONLY_EXPORTED), \
OPTIMIZATION := LOW, \
CFLAGS := -DHEADLESS=true $(CUPS_CFLAGS) $(FONTCONFIG_CFLAGS) \
diff --git a/src/java.desktop/unix/native/common/awt/utility/rect.h b/src/java.desktop/unix/native/common/awt/utility/rect.h
index ceea38f4349a7..91b5a17ec58c8 100644
--- a/src/java.desktop/unix/native/common/awt/utility/rect.h
+++ b/src/java.desktop/unix/native/common/awt/utility/rect.h
@@ -28,7 +28,7 @@
#ifndef _AWT_RECT_H
#define _AWT_RECT_H
-#ifndef MACOSX
+#if !defined(HEADLESS) && !defined(MACOSX)
#include
typedef XRectangle RECT_T;
#else
@@ -39,7 +39,7 @@ typedef struct {
int width;
int height;
} RECT_T;
-#endif /* !MACOSX */
+#endif /* !HEADLESS && !MACOSX */
#define RECT_EQ_X(r1,r2) ((r1).x==(r2).x && (r1).width==(r2).width)
From 7b0abac7aa2a44b3de3acb2315c3b2d42765b943 Mon Sep 17 00:00:00 2001
From: Thomas Devoogdt
Date: Thu, 13 Nov 2025 23:10:20 +0100
Subject: [PATCH 2/3] autoconf: libraries: drop the need for X11 in headless
mode
Signed-off-by: Thomas Devoogdt
---
make/autoconf/libraries.m4 | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/make/autoconf/libraries.m4 b/make/autoconf/libraries.m4
index 8dc3d55ed0c83..5daacdc1ced54 100644
--- a/make/autoconf/libraries.m4
+++ b/make/autoconf/libraries.m4
@@ -42,12 +42,12 @@ m4_include([lib-tests.m4])
AC_DEFUN_ONCE([LIB_DETERMINE_DEPENDENCIES],
[
# Check if X11 is needed
- if test "x$OPENJDK_TARGET_OS" = xwindows || test "x$OPENJDK_TARGET_OS" = xmacosx; then
- # No X11 support on windows or macosx
+ if test "x$OPENJDK_TARGET_OS" = xwindows ||
+ test "x$OPENJDK_TARGET_OS" = xmacosx ||
+ test "x$ENABLE_HEADLESS_ONLY" = xtrue; then
NEEDS_LIB_X11=false
else
- # All other instances need X11, even if building headless only, libawt still
- # needs X11 headers.
+ # All other instances need X11 for libawt.
NEEDS_LIB_X11=true
fi
From 5a672d088189962665dc60dcec3b53dda9c26355 Mon Sep 17 00:00:00 2001
From: Thomas Devoogdt
Date: Sat, 15 Nov 2025 19:11:20 +0100
Subject: [PATCH 3/3] doc: fix X11 description when compiling headless
Signed-off-by: Thomas Devoogdt
---
doc/building.html | 7 +++----
doc/building.md | 6 ++----
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/doc/building.html b/doc/building.html
index 99eb3e0c473f1..51118c7ce392b 100644
--- a/doc/building.html
+++ b/doc/building.html
@@ -1380,10 +1380,9 @@ ALSA
can specify it by --with-alsa.
X11
-You will need X11 libraries suitable for your target system.
-In most cases, using Debian's pre-built libraries work fine.
-Note that X11 is needed even if you only want to build a headless
-JDK.
+When not building a headless JDK, you will need X11 libraries
+suitable for your target system. In most cases, using Debian's
+pre-built libraries work fine.
Go to Debian
Package Search, search for the following packages for your
diff --git a/doc/building.md b/doc/building.md
index 047255d184803..7e7e90c10e1c4 100644
--- a/doc/building.md
+++ b/doc/building.md
@@ -1173,10 +1173,8 @@ Note that alsa is needed even if you only want to build a headless JDK.
#### X11
-You will need X11 libraries suitable for your *target* system. In most cases,
-using Debian's pre-built libraries work fine.
-
-Note that X11 is needed even if you only want to build a headless JDK.
+When not building a headless JDK, you will need X11 libraries suitable for your
+*target* system. In most cases, using Debian's pre-built libraries work fine.
* Go to [Debian Package Search](https://www.debian.org/distrib/packages),
search for the following packages for your *target* system, and download them