| # |
| # Copyright (c) 2011, 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 MakeIncludeStart.gmk |
| ifeq ($(INCLUDE), true) |
| |
| ################################################################################ |
| |
| include CopyFiles.gmk |
| include JdkNativeCompilation.gmk |
| include Modules.gmk |
| include ProcessMarkdown.gmk |
| include $(TOPDIR)/make/ToolsJdk.gmk |
| |
| LAUNCHER_SRC := $(TOPDIR)/src/java.base/share/native/launcher |
| LAUNCHER_CFLAGS += -I$(TOPDIR)/src/java.base/share/native/launcher \ |
| -I$(TOPDIR)/src/java.base/share/native/libjli \ |
| -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \ |
| -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli \ |
| # |
| MACOSX_PLIST_DIR := $(TOPDIR)/src/java.base/macosx/native/launcher |
| JAVA_MANIFEST := $(TOPDIR)/src/java.base/windows/native/launcher/java.manifest |
| |
| ################################################################################ |
| # Build standard launcher. |
| |
| # Setup make rules for building a standard launcher. |
| # |
| # Parameter 1 is the name of the rule. This name is used as variable prefix, |
| # and the targets generated are listed in a variable by that name. It is also |
| # used as the name of the executable. |
| # |
| # Remaining parameters are named arguments. These include: |
| # MAIN_CLASS The Java main class to launch |
| # JAVA_ARGS Additional arguments to pass to Java when launching the main class |
| # EXPAND_CLASSPATH_WILDCARDS Set to true to pass EXPAND_CLASSPATH_WILDCARDS |
| # ENABLE_ARG_FILES Set to true to pass ENABLE_ARG_FILES |
| # WINDOWS_JAVAW Set to true to pass JAVAW on Windows |
| # EXTRA_RCFLAGS Additional EXTRA_RCFLAGS |
| # MACOSX_PRIVILEGED On macosx, allow to access other processes |
| # OPTIMIZATION Override default optimization level (LOW) |
| # OUTPUT_DIR Override default output directory |
| # VERSION_INFO_RESOURCE Override default Windows resource file |
| # STATIC_LAUNCHER If true, will use settings for building a static launcher |
| # LIBS Additional libraries to pass as LIBS argument to SetupJdkExecutable |
| SetupBuildLauncher = $(NamedParamsMacroTemplate) |
| define SetupBuildLauncherBody |
| # Setup default values (unless overridden) |
| ifeq ($$($1_OPTIMIZATION), ) |
| $1_OPTIMIZATION := LOW |
| endif |
| |
| $1_MAIN_MODULE := $(MODULE) |
| |
| ifneq ($$($1_MAIN_CLASS), ) |
| $1_JAVA_ARGS += -Xms8m |
| $1_LAUNCHER_CLASS := -m $$($1_MAIN_MODULE)/$$($1_MAIN_CLASS) |
| endif |
| |
| ifeq ($$($1_EXPAND_CLASSPATH_WILDCARDS), true) |
| $1_CFLAGS += -DEXPAND_CLASSPATH_WILDCARDS |
| endif |
| |
| ifeq ($$($1_ENABLE_ARG_FILES), true) |
| $1_CFLAGS += -DENABLE_ARG_FILES |
| endif |
| |
| ifeq ($(call isTargetOs, windows), true) |
| ifeq ($$($1_WINDOWS_JAVAW), true) |
| $1_CFLAGS += -DJAVAW |
| endif |
| endif |
| |
| ifneq ($$($1_JAVA_ARGS), ) |
| $1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \ |
| $$(addprefix -J, $$($1_JAVA_ARGS)) $$($1_LAUNCHER_CLASS), "$$a"$(COMMA) )) }' |
| $1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR) |
| endif |
| |
| ifeq ($(call isTargetOs, macosx), true) |
| ifeq ($$($1_MACOSX_PRIVILEGED), true) |
| $1_PLIST_EXTRA := <key>SecTaskAccess</key><string>allowed</string> |
| endif |
| |
| $1_PLIST_FILE := $$(SUPPORT_OUTPUTDIR)/native/$$(MODULE)/$1/Info.plist |
| |
| $$(eval $$(call SetupTextFileProcessing, BUILD_PLIST_$1, \ |
| SOURCE_FILES := $(TOPDIR)/make/data/bundle/cmdline-Info.plist.template, \ |
| OUTPUT_FILE := $$($1_PLIST_FILE), \ |
| REPLACEMENTS := \ |
| @@ID@@ => $(MACOSX_BUNDLE_ID_BASE).$1 ; \ |
| @@VERSION@@ => $(VERSION_NUMBER) ; \ |
| @@BUILD_VERSION@@ => $(MACOSX_BUNDLE_BUILD_VERSION) ; \ |
| @@EXTRA@@ => $$($1_PLIST_EXTRA), \ |
| )) |
| |
| $1_LDFLAGS += -sectcreate __TEXT __info_plist $$($1_PLIST_FILE) |
| endif |
| |
| $1_EXTRA_FILES := $(LAUNCHER_SRC)/main.c |
| |
| ifeq ($(ASAN_ENABLED), true) |
| $1_EXTRA_FILES += $(TOPDIR)/make/data/asan/asan_default_options.c |
| endif |
| |
| ifeq ($(LSAN_ENABLED), true) |
| $1_EXTRA_FILES += $(TOPDIR)/make/data/lsan/lsan_default_options.c |
| endif |
| |
| ifneq ($$($1_STATIC_LAUNCHER), true) |
| $1_JDK_LIBS := java.base:libjli |
| $1_JDK_LIBS_windows := java.base:libjava |
| else |
| ifneq ($(findstring $(TOOLCHAIN_TYPE), gcc clang), ) |
| $1_LDFLAGS_FILTER_OUT := -Wl$(COMMA)--exclude-libs$(COMMA)ALL |
| endif |
| endif |
| |
| ############################################################################## |
| ## Build launcher "$1" |
| ############################################################################## |
| |
| $$(eval $$(call SetupJdkExecutable, BUILD_LAUNCHER_$1, \ |
| NAME := $1, \ |
| EXTRA_FILES := $$($1_EXTRA_FILES), \ |
| OPTIMIZATION := $$($1_OPTIMIZATION), \ |
| CFLAGS := $$(LAUNCHER_CFLAGS) \ |
| $$(VERSION_CFLAGS) \ |
| -DLAUNCHER_NAME='"$$(LAUNCHER_NAME)"' \ |
| -DPROGNAME='"$1"' \ |
| $$($1_CFLAGS), \ |
| EXTRA_HEADER_DIRS := java.base:libjvm, \ |
| JAVA_HEADERS := false, \ |
| DISABLED_WARNINGS_gcc := unused-function unused-variable, \ |
| DISABLED_WARNINGS_clang := unused-function, \ |
| LDFLAGS := $$($1_LDFLAGS), \ |
| LDFLAGS_linux := $$(call SET_EXECUTABLE_ORIGIN,/../lib), \ |
| LDFLAGS_macosx := $$(call SET_EXECUTABLE_ORIGIN,/../lib), \ |
| LDFLAGS_FILTER_OUT := $$($1_LDFLAGS_FILTER_OUT), \ |
| JDK_LIBS := $$($1_JDK_LIBS), \ |
| JDK_LIBS_windows := $$($1_JDK_LIBS_windows), \ |
| LIBS := $$($1_LIBS), \ |
| LINK_TYPE := $$($1_LINK_TYPE), \ |
| OUTPUT_DIR := $$($1_OUTPUT_DIR), \ |
| OBJECT_DIR := $$($1_OBJECT_DIR), \ |
| VERSIONINFO_RESOURCE := $$($1_VERSION_INFO_RESOURCE), \ |
| EXTRA_RCFLAGS := $$($1_EXTRA_RCFLAGS), \ |
| MANIFEST := $(JAVA_MANIFEST), \ |
| MANIFEST_VERSION := $(VERSION_NUMBER_FOUR_POSITIONS), \ |
| )) |
| |
| $1 += $$(BUILD_LAUNCHER_$1) |
| TARGETS += $$($1) |
| |
| $$(BUILD_LAUNCHER_$1): $$(BUILD_PLIST_$1) |
| |
| ifeq ($(call isTargetOs, macosx), true) |
| $$(BUILD_LAUNCHER_$1): $$($1_PLIST_FILE) |
| endif |
| endef |
| |
| ################################################################################ |
| # Create man pages for jmod to pick up. There should be a one-to-one |
| # relationship between executables and man pages (even if this is not always |
| # the case), so piggyback man page generation on the launcher compilation. This |
| # file may be included from other places as well, so only process man pages |
| # when called from <module>/Launcher.gmk. |
| |
| ifeq ($(call isTargetOsType, unix)+$(MAKEFILE_PREFIX), true+Launcher) |
| # Only build manpages on unix systems. |
| # We assume all our man pages should reside in section 1. |
| |
| MAN_FILES_MD := $(wildcard $(addsuffix /*.md, $(call FindModuleManDirs, $(MODULE)))) |
| |
| ifneq ($(MAN_FILES_MD), ) |
| ifeq ($(ENABLE_PANDOC), true) |
| # Create dynamic man pages from markdown using pandoc. We need |
| # PANDOC_TROFF_MANPAGE_FILTER, a wrapper around |
| # PANDOC_TROFF_MANPAGE_FILTER_JAVASCRIPT. This is created by buildtools-jdk. |
| |
| # We should also depend on the source code for the filter |
| PANDOC_TROFF_MANPAGE_FILTER_SOURCE := $(call FindFiles, \ |
| $(TOPDIR)/make/jdk/src/classes/build/tools/pandocfilter) |
| |
| # The norm in man pages is to display code literals as bold, but pandoc |
| # "correctly" converts these constructs (encoded in markdown using `...` |
| # or ```...```) to \f[C]. Ideally, we should use the filter to encapsulate |
| # the Code/CodeBlock in Strong. While this works for Code, pandoc cannot |
| # correctly render man page output for CodeBlock wrapped in Strong. So we |
| # take the easy way out, and post-process the troff output, replacing |
| # \f[C] with \f[CB]. This has the added benefit of working correctly on |
| # pandoc prior to version 2.0, which cannot properly produced nested |
| # formatting in man pages (see https://github.com/jgm/pandoc/issues/3568). |
| # |
| # As of pandoc 2.3, the termination of formatting is still broken |
| # (see https://github.com/jgm/pandoc/issues/4973). We need to replace |
| # \f[] with \f[R]. |
| MAN_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' \ |
| -e 's/\\f\[\]/\\f\[R\]/g' |
| |
| # Now generate the man pages from markdown using pandoc |
| $(eval $(call SetupProcessMarkdown, BUILD_MAN_PAGES, \ |
| DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \ |
| FILES := $(MAN_FILES_MD), \ |
| FORMAT := man, \ |
| FILTER := $(PANDOC_TROFF_MANPAGE_FILTER), \ |
| POST_PROCESS := $(MAN_POST_PROCESS), \ |
| REPLACEMENTS := \ |
| @@COPYRIGHT_YEAR@@ => $(COPYRIGHT_YEAR) ; \ |
| @@VERSION_SHORT@@ => $(VERSION_SHORT) ; \ |
| @@VERSION_SPECIFICATION@@ => $(VERSION_SPECIFICATION), \ |
| EXTRA_DEPS := $(PANDOC_TROFF_MANPAGE_FILTER) \ |
| $(PANDOC_TROFF_MANPAGE_FILTER_SOURCE), \ |
| )) |
| |
| TARGETS += $(BUILD_MAN_PAGES) |
| endif |
| endif |
| endif |
| |
| ################################################################################ |
| |
| endif # include guard |
| include MakeIncludeEnd.gmk |