# # Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License version 2 only, as # published by the Free Software Foundation. Oracle designates this # particular file as subject to the "Classpath" exception as provided # by Oracle in the LICENSE file that accompanied this code. # # This code is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # version 2 for more details (a copy is included in the LICENSE file that # accompanied this code). # # You should have received a copy of the GNU General Public License version # 2 along with this work; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. # # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA # or visit www.oracle.com if you need additional information or have any # questions. # include MakeFileStart.gmk ################################################################################ include CopyFiles.gmk include DebugInfoUtils.gmk include Modules.gmk include modules/LauncherCommon.gmk include Execute.gmk ################################################################################ # # Create the static java launcher # ################################################################################ STATIC_JDK_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/static-jdk STATIC_LAUNCHER_OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/static-native/launcher HOTSPOT_STATIC_LIB_PATH := $(HOTSPOT_OUTPUTDIR)/*/libjvm/objs/static ifneq ($(word 2, $(wildcard $(HOTSPOT_STATIC_LIB_PATH))), ) $(error Cannot perform static linking when building more than one JVM library) endif # Find all modules with static libraries STATIC_LIB_MODULES := $(sort $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-libs/%, \ %, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-libs/*))) # Filter out known broken libraries. This is a temporary measure until # proper support for these libraries can be provided. ifeq ($(call isTargetOs, linux), true) # libsplashscreen has a name conflict with libawt in the function # BitmapToYXBandedRectangles, so we exclude it for now. BROKEN_STATIC_LIBS += splashscreen else ifeq ($(call isTargetOs, macosx), true) # libosxsecurity has a name conflict with libosxapp in the function # JavaStringToNSString, so we exclude it for now. BROKEN_STATIC_LIBS += osxsecurity else ifeq ($(call isTargetOs, windows), true) # libsplashscreen has a name conflict with libawt in the function # BitmapToYXBandedRectangles, so we exclude it for now. BROKEN_STATIC_LIBS += splashscreen # libsspi_bridge has name conflicts with sunmscapi BROKEN_STATIC_LIBS += sspi_bridge # dt_shmem define jdwpTransport_OnLoad which conflict with dt_socket BROKEN_STATIC_LIBS += dt_shmem else ifeq ($(call isTargetOs, aix), true) # libsplashscreen has a name conflict with libawt in the function # BitmapToYXBandedRectangles, so we exclude it for now. BROKEN_STATIC_LIBS += splashscreen endif $(foreach module, $(STATIC_LIB_MODULES), \ $(eval LIBS_$(module) := $(filter-out $(BROKEN_STATIC_LIBS), $(shell cat \ $(SUPPORT_OUTPUTDIR)/modules_static-libs/$(module)/module-included-libs.txt))) \ ) STATIC_LIB_FILES := $(foreach module, $(STATIC_LIB_MODULES), \ $(foreach lib, $(LIBS_$(module)), \ $(SUPPORT_OUTPUTDIR)/native/$(module)/lib$(lib)/static/$(LIBRARY_PREFIX)$(lib)$(STATIC_LIBRARY_SUFFIX))) # Add Hotspot STATIC_LIB_FILES += $(wildcard $(HOTSPOT_STATIC_LIB_PATH)/$(LIBRARY_PREFIX)jvm$(STATIC_LIBRARY_SUFFIX)) # Figure out what external libraries are required to link these static JDK # libraries. LIB_FLAGS_FILES := $(addsuffix .lib-flags.txt, $(STATIC_LIB_FILES)) # Gather the lib flags from all individual libraries. There are many duplicates, # so sort and just keep unique instances. On macOS, a common pattern is # "-framework FooFramework", so we must make sure we keep the two words together. EXTERNAL_LIBS := $(strip $(shell $(CAT) $(LIB_FLAGS_FILES) | \ $(SED) -e 's/-framework /-framework_/g' | $(TR) ' ' '\n' | $(SORT) -u | \ $(SED) -e 's/-framework_/-framework /g')) ifeq ($(call isTargetOs, macosx), true) STATIC_LIBS := $(addprefix -force_load$(SPACE), $(STATIC_LIB_FILES)) else ifeq ($(call isTargetOs, linux), true) STATIC_LIBS := -Wl,--export-dynamic -Wl,--whole-archive $(STATIC_LIB_FILES) -Wl,--no-whole-archive else ifeq ($(call isTargetOs, windows), true) STATIC_LIBS := $(addprefix -wholearchive:, $(STATIC_LIB_FILES)) else ifeq ($(call isTargetOs, aix), true) # on AIX we have to generate export files for all static libs, because we have no whole-archive linker flag $(foreach lib, $(STATIC_LIB_FILES), \ $(eval $(call SetupExecute, generate_export_list_$(notdir $(lib)), \ INFO := Generating export list for $(notdir $(lib)), \ DEPS := $(lib), \ OUTPUT_FILE := $(lib).exp, \ COMMAND := $(AR) $(ARFLAGS) -w $(lib) | $(GREP) -v '^\.' | $(AWK) '{print $$1}' | $(SORT) -u > $(lib).exp, \ )) \ $(eval STATIC_LIB_EXPORT_FILES += $(lib).exp) \ ) STATIC_LIBS := -Wl,-bexpfull $(STATIC_LIB_FILES) $(addprefix -Wl$(COMMA)-bE:, $(STATIC_LIB_EXPORT_FILES)) ifeq ($(DEBUG_LEVEL), slowdebug) STATIC_LIBS += -Wl,-bbigtoc endif else $(error Unsupported platform) endif ################################################################################ # Build the java static launcher ################################################################################ $(eval $(call SetupBuildLauncher, java, \ ENABLE_ARG_FILES := true, \ EXPAND_CLASSPATH_WILDCARDS := true, \ EXTRA_RCFLAGS := $(JAVA_RCFLAGS), \ VERSION_INFO_RESOURCE := $(JAVA_VERSION_INFO_RESOURCE), \ OPTIMIZATION := HIGH, \ MACOSX_PRIVILEGED := true, \ STATIC_LAUNCHER := true, \ CFLAGS := -DSTATIC_BUILD, \ LDFLAGS := $(LDFLAGS_STATIC_JDK), \ LIBS := $(STATIC_LIBS) $(EXTERNAL_LIBS), \ LINK_TYPE := C++, \ OUTPUT_DIR := $(STATIC_LAUNCHER_OUTPUT_DIR), \ OBJECT_DIR := $(STATIC_LAUNCHER_OUTPUT_DIR), \ )) $(java): $(STATIC_LIB_FILES) ifeq ($(call isTargetOs, aix), true) $(java): $(STATIC_LIB_EXPORT_FILES) endif TARGETS += $(java) JAVA_LAUNCHER := $(BUILD_LAUNCHER_java_TARGET) static-launchers: $(java) ################################################################################ # Build relaunchers (thin wrappers calling the java binary) for all other # JDK launchers. ################################################################################ RELAUNCHER_SRC := $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/launcher # $1: The module name # $2: The launcher name define SetupRelauncher $1_$2_LAUNCHER_ARGS_LINE := $$(call ReadFile, $$(SUPPORT_OUTPUTDIR)/static-native/relaunchers/$1/$2-relauncher-arguments.txt) # Restore |||| with space $1_$2_LAUNCHER_ARGS := '{ $$(subst ||||,$(SPACE),$$(strip $$(foreach a, $$($1_$2_LAUNCHER_ARGS_LINE), "-J$$a"$$(COMMA) )) ) }' $$(eval $$(call SetupJdkExecutable, BUILD_relauncher_$2, \ NAME := $2, \ EXTRA_FILES := $$(RELAUNCHER_SRC)/relauncher.c, \ CFLAGS := -DLAUNCHER_ARGS=$$($1_$2_LAUNCHER_ARGS), \ LIBS_windows := shlwapi.lib, \ OUTPUT_DIR := $$(STATIC_LAUNCHER_OUTPUT_DIR), \ OBJECT_DIR := $$(STATIC_LAUNCHER_OUTPUT_DIR)/relaunchers/$2, \ )) TARGETS += $$(BUILD_relauncher_$2) RELAUNCHERS += $$(BUILD_relauncher_$2_TARGET) static-launchers: $$(BUILD_relauncher_$2) endef # Find all modules with launchers LAUNCHER_MODULES := $(sort $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-launchers/%, \ %, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-launchers/*))) # Find launchers for each module $(foreach module, $(LAUNCHER_MODULES), \ $(eval LAUNCHERS_$(module) := $(if $(wildcard \ $(SUPPORT_OUTPUTDIR)/modules_static-launchers/$(module)/module-included-launchers.txt), \ $(shell cat \ $(SUPPORT_OUTPUTDIR)/modules_static-launchers/$(module)/module-included-launchers.txt))) \ ) # For all launchers (except java and javaw), setup a relauncher build $(foreach module, $(LAUNCHER_MODULES), \ $(foreach launcher, $(filter-out java javaw, $(LAUNCHERS_$(module))), \ $(eval $(call SetupRelauncher,$(module),$(launcher))))) ################################################################################ # # Create the static-jdk image with the statically built java launcher # ################################################################################ # Until we get proper support in jlink for generating an image with static # builds, we need to create the image ourselves. We base it on a normal # dynamically linked JDK image. # All these files/dirs should be copied as-is JDK_IMAGE_COPY_FILES := $(addprefix $(JDK_IMAGE_DIR)/, conf demo include jmods \ legal man/man1/java.1 release README) # We need to copy some files from lib, but not the dynamic libraries themselves ALL_LIB_FILES := $(call FindFiles, $(JDK_IMAGE_DIR)/lib) # Remove all dynamic libraries from the list JDK_IMAGE_COPY_LIB_FILES := $(filter-out %$(SHARED_LIBRARY_SUFFIX), $(ALL_LIB_FILES)) # Remove all debug files from the list ifeq ($(call isTargetOs, macosx), true) JDK_IMAGE_COPY_LIB_FILES := $(call not-containing, .dSYM, $(JDK_IMAGE_COPY_LIB_FILES)) else JDK_IMAGE_COPY_LIB_FILES := $(filter-out %.debuginfo %.pdb %.map, $(JDK_IMAGE_COPY_LIB_FILES)) endif static-jdk-info: $(call LogWarn, Creating static-jdk image) $(eval $(call SetupCopyFiles, copy-from-jdk-image, \ SRC := $(JDK_IMAGE_DIR), \ DEST := $(STATIC_JDK_IMAGE_DIR), \ FILES := $(call FindFiles, $(JDK_IMAGE_COPY_FILES)) \ $(JDK_IMAGE_COPY_LIB_FILES), \ )) TARGETS += $(copy-from-jdk-image) $(copy-from-jdk-image): | static-jdk-info $(eval $(call SetupCopyFiles, copy-static-launchers, \ FILES := $(JAVA_LAUNCHER) $(RELAUNCHERS), \ DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \ )) TARGETS += $(copy-static-launchers) $(eval $(call SetupCopyFiles, copy-static-launchers-debuginfo, \ SRC := $(STATIC_LAUNCHER_OUTPUT_DIR), \ DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \ FILES := $(call FindDebuginfoFiles, $(STATIC_LAUNCHER_OUTPUT_DIR)), \ )) TARGETS += $(copy-static-launchers-debuginfo) # Copy the microsoft runtime libraries on windows ifeq ($(call isTargetOs, windows), true) # Chmod to avoid permission issues if bundles are unpacked on unix platforms. # Use separate macro calls in case the source files are not in the same # directory. $(eval $(call SetupCopyFiles, copy-windows-msvcr, \ DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \ FILES := $(MSVCR_DLL), \ MACRO := copy-and-chmod-executable, \ )) TARGETS += $(copy-windows-msvcr) $(eval $(call SetupCopyFiles, copy-windows-vcruntime, \ DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \ FILES := $(VCRUNTIME_1_DLL), \ MACRO := copy-and-chmod-executable, \ )) TARGETS += $(copy-windows-vcruntime) $(eval $(call SetupCopyFiles, copy-windows-msvcp, \ DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \ FILES := $(MSVCP_DLL), \ MACRO := copy-and-chmod-executable, \ )) TARGETS += $(copy-windows-msvcp) copy-windows-libs := $(copy-windows-msvcr) $(copy-windows-vcruntime) $(copy-windows-msvcp) ifneq ($(UCRT_DLL_DIR), ) $(eval $(call SetupCopyFiles, copy-windows-ucrt, \ DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \ SRC := $(UCRT_DLL_DIR), \ FILES := $(wildcard $(UCRT_DLL_DIR)/*.dll), \ MACRO := copy-and-chmod-executable, \ )) TARGETS += $(copy-windows-ucrt) copy-windows-libs += $(copy-windows-ucrt) endif endif static-jdk-image: $(copy-from-jdk-image) $(copy-static-launchers) \ $(copy-static-launchers-debuginfo) $(copy-windows-libs) TARGETS += static-jdk-image .PHONY: static-launchers static-jdk-image ################################################################################ include MakeFileEnd.gmk