|
| 1 | +# |
| 2 | +# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. |
| 3 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | +# |
| 5 | +# This code is free software; you can redistribute it and/or modify it |
| 6 | +# under the terms of the GNU General Public License version 2 only, as |
| 7 | +# published by the Free Software Foundation. Oracle designates this |
| 8 | +# particular file as subject to the "Classpath" exception as provided |
| 9 | +# by Oracle in the LICENSE file that accompanied this code. |
| 10 | +# |
| 11 | +# This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | +# version 2 for more details (a copy is included in the LICENSE file that |
| 15 | +# accompanied this code). |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License version |
| 18 | +# 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | +# |
| 21 | +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | +# or visit www.oracle.com if you need additional information or have any |
| 23 | +# questions. |
| 24 | +# |
| 25 | + |
| 26 | +default: all |
| 27 | + |
| 28 | +include $(SPEC) |
| 29 | +include MakeBase.gmk |
| 30 | + |
| 31 | +include CopyFiles.gmk |
| 32 | +include Modules.gmk |
| 33 | +include modules/LauncherCommon.gmk |
| 34 | + |
| 35 | +################################################################################ |
| 36 | +# |
| 37 | +# Create the static java launcher |
| 38 | +# |
| 39 | +################################################################################ |
| 40 | + |
| 41 | +STATIC_JDK_IMAGE_DIR := $(IMAGES_OUTPUTDIR)/static-jdk |
| 42 | +STATIC_LAUNCHER_OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/static-native/launcher |
| 43 | +HOTSPOT_STATIC_LIB_PATH := $(HOTSPOT_OUTPUTDIR)/*/libjvm/objs/static |
| 44 | + |
| 45 | +ifneq ($(word 2, $(wildcard $(HOTSPOT_STATIC_LIB_PATH))), ) |
| 46 | + $(error Cannot perform static linking when building more than one JVM library) |
| 47 | +endif |
| 48 | + |
| 49 | +# Find all modules with static libraries |
| 50 | +STATIC_LIB_MODULES := $(patsubst $(SUPPORT_OUTPUTDIR)/modules_static-libs/%, \ |
| 51 | + %, $(wildcard $(SUPPORT_OUTPUTDIR)/modules_static-libs/*)) |
| 52 | + |
| 53 | +# Filter out known broken libraries. This is a temporary measure until |
| 54 | +# proper support for these libraries can be provided. |
| 55 | +ifeq ($(call isTargetOs, linux), true) |
| 56 | + # libsplashscreen has a name conflict with libawt in the function |
| 57 | + # BitmapToYXBandedRectangles, so we exclude it for now. |
| 58 | + BROKEN_STATIC_LIBS += splashscreen |
| 59 | +else ifeq ($(call isTargetOs, macosx), true) |
| 60 | + # libosxsecurity has a name conflict with libosxapp in the function |
| 61 | + # JavaStringToNSString, so we exclude it for now. |
| 62 | + BROKEN_STATIC_LIBS += osxsecurity |
| 63 | +else ifeq ($(call isTargetOs, windows), true) |
| 64 | + # libsplashscreen has a name conflict with libawt in the function |
| 65 | + # BitmapToYXBandedRectangles, so we exclude it for now. |
| 66 | + BROKEN_STATIC_LIBS += splashscreen |
| 67 | + # libsspi_bridge has name conflicts with sunmscapi |
| 68 | + BROKEN_STATIC_LIBS += sspi_bridge |
| 69 | + # These libs define DllMain which conflict with Hotspot |
| 70 | + BROKEN_STATIC_LIBS += awt dt_shmem dt_socket |
| 71 | + # These libs are dependent on any of the above disabled libs |
| 72 | + BROKEN_STATIC_LIBS += fontmanager jawt lcms net nio |
| 73 | +endif |
| 74 | + |
| 75 | +$(foreach module, $(STATIC_LIB_MODULES), \ |
| 76 | + $(eval LIBS_$(module) := $(filter-out $(BROKEN_STATIC_LIBS), $(shell cat \ |
| 77 | + $(SUPPORT_OUTPUTDIR)/modules_static-libs/$(module)/module-included-libs.txt))) \ |
| 78 | +) |
| 79 | + |
| 80 | +STATIC_LIB_FILES := $(foreach module, $(STATIC_LIB_MODULES), \ |
| 81 | + $(foreach lib, $(LIBS_$(module)), \ |
| 82 | + $(SUPPORT_OUTPUTDIR)/native/$(module)/lib$(lib)/static/$(LIBRARY_PREFIX)$(lib)$(STATIC_LIBRARY_SUFFIX))) |
| 83 | + |
| 84 | +# Add Hotspot |
| 85 | +STATIC_LIB_FILES += $(wildcard $(HOTSPOT_STATIC_LIB_PATH)/$(LIBRARY_PREFIX)jvm$(STATIC_LIBRARY_SUFFIX)) |
| 86 | + |
| 87 | +# Figure out what external libraries are required to link these static JDK |
| 88 | +# libraries. |
| 89 | +LIB_FLAGS_FILES := $(addsuffix .lib-flags.txt, $(STATIC_LIB_FILES)) |
| 90 | + |
| 91 | +# Gather the lib flags from all individual libraries. There are many duplicates, |
| 92 | +# so sort and just keep unique instances. On macOS, a common pattern is |
| 93 | +# "-framework FooFramework", so we must make sure we keep the two words together. |
| 94 | +EXTERNAL_LIBS := $(strip $(shell $(CAT) $(LIB_FLAGS_FILES) | \ |
| 95 | + $(SED) -e 's/-framework /-framework_/g' | $(TR) ' ' '\n' | $(SORT) -u | \ |
| 96 | + $(SED) -e 's/-framework_/-framework /g')) |
| 97 | + |
| 98 | +ifeq ($(call isTargetOs, macosx), true) |
| 99 | + STATIC_LIBS := $(addprefix -force_load$(SPACE), $(STATIC_LIB_FILES)) |
| 100 | + STANDARD_LIBS += -lstdc++ |
| 101 | +else ifeq ($(call isTargetOs, linux), true) |
| 102 | + STATIC_LIBS := -Wl,--export-dynamic -Wl,--whole-archive $(STATIC_LIB_FILES) -Wl,--no-whole-archive |
| 103 | + STANDARD_LIBS := -l:libstdc++.a |
| 104 | +else ifeq ($(call isTargetOs, windows), true) |
| 105 | + STATIC_LIBS := $(addprefix -wholearchive:, $(STATIC_LIB_FILES)) |
| 106 | +else |
| 107 | + $(error Unsupported platform) |
| 108 | +endif |
| 109 | + |
| 110 | +$(eval $(call SetupBuildLauncher, java, \ |
| 111 | + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS -DENABLE_ARG_FILES, \ |
| 112 | + EXTRA_RCFLAGS := $(JAVA_RCFLAGS), \ |
| 113 | + VERSION_INFO_RESOURCE := $(JAVA_VERSION_INFO_RESOURCE), \ |
| 114 | + OPTIMIZATION := HIGH, \ |
| 115 | + STATIC_LAUNCHER := true, \ |
| 116 | + LDFLAGS := $(LDFLAGS_STATIC_JDK), \ |
| 117 | + LIBS := $(STATIC_LIBS) $(EXTERNAL_LIBS) $(STANDARD_LIBS), \ |
| 118 | + OUTPUT_DIR := $(STATIC_LAUNCHER_OUTPUT_DIR), \ |
| 119 | + OBJECT_DIR := $(STATIC_LAUNCHER_OUTPUT_DIR), \ |
| 120 | +)) |
| 121 | + |
| 122 | +$(java): $(STATIC_LIB_FILES) |
| 123 | + |
| 124 | +TARGETS += $(java) |
| 125 | + |
| 126 | +JAVA_LAUNCHER := $(BUILD_LAUNCHER_java_TARGET) |
| 127 | + |
| 128 | +static-launcher: $(java) |
| 129 | + |
| 130 | +################################################################################ |
| 131 | +# |
| 132 | +# Create the static-jdk image with the statically built java launcher |
| 133 | +# |
| 134 | +################################################################################ |
| 135 | + |
| 136 | +# Until we get proper support in jlink for generating an image with static |
| 137 | +# builds, we need to create the image ourselves. We base it on a normal |
| 138 | +# dynamically linked JDK image. |
| 139 | + |
| 140 | +# All these files/dirs should be copied as-is |
| 141 | +JDK_IMAGE_COPY_FILES := $(addprefix $(JDK_IMAGE_DIR)/, conf demo include jmods \ |
| 142 | + legal man/man1/java.1 release README) |
| 143 | + |
| 144 | +# We need to copy some files from lib, but not the dynamic libraries themselves |
| 145 | +ALL_LIB_FILES := $(call FindFiles, $(JDK_IMAGE_DIR)/lib) |
| 146 | + |
| 147 | +# Remove all dynamic libraries from the list |
| 148 | +JDK_IMAGE_COPY_LIB_FILES := $(filter-out %$(SHARED_LIBRARY_SUFFIX), $(ALL_LIB_FILES)) |
| 149 | +# Remove all debug files from the list |
| 150 | +ifeq ($(call isTargetOs, macosx), true) |
| 151 | + JDK_IMAGE_COPY_LIB_FILES := $(call not-containing, .dSYM, $(JDK_IMAGE_COPY_LIB_FILES)) |
| 152 | +else |
| 153 | + JDK_IMAGE_COPY_LIB_FILES := $(filter-out %.debuginfo %.pdb %.map, $(JDK_IMAGE_COPY_LIB_FILES)) |
| 154 | +endif |
| 155 | + |
| 156 | +static-jdk-info: |
| 157 | + $(call LogWarn, Creating static-jdk image) |
| 158 | + |
| 159 | +$(eval $(call SetupCopyFiles, copy-from-jdk-image, \ |
| 160 | + SRC := $(JDK_IMAGE_DIR), \ |
| 161 | + DEST := $(STATIC_JDK_IMAGE_DIR), \ |
| 162 | + FILES := $(call FindFiles, $(JDK_IMAGE_COPY_FILES)) \ |
| 163 | + $(JDK_IMAGE_COPY_LIB_FILES), \ |
| 164 | +)) |
| 165 | + |
| 166 | +TARGETS += $(copy-from-jdk-image) |
| 167 | + |
| 168 | +$(copy-from-jdk-image): | static-jdk-info |
| 169 | + |
| 170 | +$(eval $(call SetupCopyFiles, copy-static-launcher, \ |
| 171 | + FILES := $(JAVA_LAUNCHER), \ |
| 172 | + DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \ |
| 173 | +)) |
| 174 | + |
| 175 | +TARGETS += $(copy-static-launcher) |
| 176 | + |
| 177 | +$(eval $(call SetupCopyFiles, copy-static-launcher-debuginfo, \ |
| 178 | + SRC := $(STATIC_LAUNCHER_OUTPUT_DIR), \ |
| 179 | + DEST := $(STATIC_JDK_IMAGE_DIR)/bin, \ |
| 180 | + FILES := $(call FindDebuginfoFiles, $(STATIC_LAUNCHER_OUTPUT_DIR)), \ |
| 181 | +)) |
| 182 | + |
| 183 | +TARGETS += $(copy-static-launcher-debuginfo) |
| 184 | + |
| 185 | +static-jdk-image: $(copy-from-jdk-image) $(copy-static-launcher) $(copy-static-launcher-debuginfo) |
| 186 | + |
| 187 | +TARGETS += static-jdk-image |
| 188 | + |
| 189 | +all: $(TARGETS) |
| 190 | + |
| 191 | +.PHONY: all static-launcher static-jdk-image |
0 commit comments