1 # 2 # Copyright (c) 2011, 2020, 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 include JdkNativeCompilation.gmk 27 include Modules.gmk 28 include ProcessMarkdown.gmk 29 include ToolsJdk.gmk 30 31 # Tell the compiler not to export any functions unless declared so in 32 # the source code. On Windows, this is the default and cannot be changed. 33 # On Mac, we have always exported all symbols, probably due to oversight 34 # and/or misunderstanding. To emulate this, don't hide any symbols 35 # by default. 36 # On AIX/xlc we need at least xlc 13.1 for the symbol hiding (see JDK-8214063) 37 # Also provide an override for non-conformant libraries. 38 ifeq ($(TOOLCHAIN_TYPE), gcc) 39 LAUNCHER_CFLAGS += -fvisibility=hidden 40 LDFLAGS_JDKEXE += -Wl,--exclude-libs,ALL 41 else ifeq ($(TOOLCHAIN_TYPE), clang) 42 LAUNCHER_CFLAGS += -fvisibility=hidden 43 endif 44 45 LAUNCHER_SRC := $(TOPDIR)/src/java.base/share/native/launcher 46 LAUNCHER_CFLAGS += -I$(TOPDIR)/src/java.base/share/native/launcher \ 47 -I$(TOPDIR)/src/java.base/share/native/libjli \ 48 -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \ 49 -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli \ 50 # 51 GLOBAL_VERSION_INFO_RESOURCE := $(TOPDIR)/src/java.base/windows/native/common/version.rc 52 MACOSX_PLIST_DIR := $(TOPDIR)/src/java.base/macosx/native/launcher 53 JAVA_MANIFEST := $(TOPDIR)/src/java.base/windows/native/launcher/java.manifest 54 55 ################################################################################ 56 # Build standard launcher. 57 58 # Setup make rules for building a standard launcher. 59 # 60 # Parameter 1 is the name of the rule. This name is used as variable prefix, 61 # and the targets generated are listed in a variable by that name. It is also 62 # used as the name of the executable. 63 # 64 # Remaining parameters are named arguments. These include: 65 # MAIN_MODULE The module of the main class to launch if different from the 66 # current module 67 # MAIN_CLASS The Java main class to launch 68 # JAVA_ARGS Processed into a -DJAVA_ARGS and added to CFLAGS 69 # EXTRA_JAVA_ARGS Processed into a -DEXTRA_JAVA_ARGS and is prepended 70 # before JAVA_ARGS to CFLAGS, primarily to allow long string literal 71 # compile time defines exceeding Visual Studio 2013 limitations. 72 # CFLAGS Additional CFLAGS 73 # CFLAGS_windows Additional CFLAGS_windows 74 # EXTRA_RC_FLAGS Additional EXTRA_RC_FLAGS 75 # MACOSX_PRIVILEGED On macosx, allow to access other processes 76 # OPTIMIZATION Override default optimization level (LOW) 77 # OUTPUT_DIR Override default output directory 78 # VERSION_INFO_RESOURCE Override default Windows resource file 79 SetupBuildLauncher = $(NamedParamsMacroTemplate) 80 define SetupBuildLauncherBody 81 # Setup default values (unless overridden) 82 ifeq ($$($1_OPTIMIZATION), ) 83 $1_OPTIMIZATION := LOW 84 endif 85 86 ifeq ($$($1_MAIN_MODULE), ) 87 $1_MAIN_MODULE := $(MODULE) 88 endif 89 90 $1_JAVA_ARGS += -ms8m 91 ifneq ($$($1_MAIN_CLASS), ) 92 $1_LAUNCHER_CLASS := -m $$($1_MAIN_MODULE)/$$($1_MAIN_CLASS) 93 endif 94 95 ifneq ($$($1_EXTRA_JAVA_ARGS), ) 96 $1_EXTRA_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \ 97 $$(addprefix -J, $$($1_EXTRA_JAVA_ARGS)), "$$a"$(COMMA) )) }' 98 $1_CFLAGS += -DEXTRA_JAVA_ARGS=$$($1_EXTRA_JAVA_ARGS_STR) 99 endif 100 $1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \ 101 $$(addprefix -J, $$($1_JAVA_ARGS)) $$($1_LAUNCHER_CLASS), "$$a"$(COMMA) )) }' 102 $1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR) 103 104 ifeq ($(call isTargetOs, macosx), true) 105 ifeq ($$($1_MACOSX_PRIVILEGED), true) 106 $1_PLIST_FILE := Info-privileged.plist 107 else 108 $1_PLIST_FILE := Info-cmdline.plist 109 endif 110 111 $1_LDFLAGS += -sectcreate __TEXT __info_plist $(MACOSX_PLIST_DIR)/$$($1_PLIST_FILE) 112 113 ifeq ($(STATIC_BUILD), true) 114 $1_LDFLAGS += -exported_symbols_list \ 115 $(SUPPORT_OUTPUTDIR)/build-static/exported.symbols 116 $1_LIBS += \ 117 $$(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_libs/java.base -name "*.a") \ 118 $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libdt_socket.a \ 119 $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libjdwp.a \ 120 $(SUPPORT_OUTPUTDIR)/native/java.base/$(LIBRARY_PREFIX)fdlibm$(STATIC_LIBRARY_SUFFIX) \ 121 -framework CoreFoundation \ 122 -framework Foundation \ 123 -framework SystemConfiguration \ 124 -lstdc++ -liconv 125 endif 126 endif 127 128 ifeq ($(USE_EXTERNAL_LIBZ), true) 129 $1_LIBS += -lz 130 endif 131 132 $1_WINDOWS_JLI_LIB := $(call FindStaticLib, java.base, jli, /libjli) 133 134 $$(eval $$(call SetupJdkExecutable, BUILD_LAUNCHER_$1, \ 135 NAME := $1, \ 136 EXTRA_FILES := $(LAUNCHER_SRC)/main.c, \ 137 OPTIMIZATION := $$($1_OPTIMIZATION), \ 138 CFLAGS := $$(CFLAGS_JDKEXE) \ 139 $$(LAUNCHER_CFLAGS) \ 140 $$(VERSION_CFLAGS) \ 141 -DLAUNCHER_NAME='"$$(LAUNCHER_NAME)"' \ 142 -DPROGNAME='"$1"' \ 143 $$($1_CFLAGS), \ 144 CFLAGS_windows := $$($1_CFLAGS_windows), \ 145 DISABLED_WARNINGS_gcc := unused-function, \ 146 LDFLAGS := $$(LDFLAGS_JDKEXE) \ 147 $$(call SET_EXECUTABLE_ORIGIN) \ 148 $$($1_LDFLAGS), \ 149 LDFLAGS_linux := $$(call SET_EXECUTABLE_ORIGIN,/../lib) \ 150 -L$(call FindLibDirForModule, java.base), \ 151 LDFLAGS_macosx := $$(call SET_EXECUTABLE_ORIGIN,/../lib) \ 152 -L$(call FindLibDirForModule, java.base), \ 153 LDFLAGS_aix := -L$(SUPPORT_OUTPUTDIR)/native/java.base, \ 154 LIBS := $(JDKEXE_LIBS) $$($1_LIBS), \ 155 LIBS_linux := -ljli -lpthread $(LIBDL), \ 156 LIBS_macosx := -ljli -framework Cocoa -framework Security \ 157 -framework ApplicationServices, \ 158 LIBS_aix := -ljli_static, \ 159 LIBS_windows := $$($1_WINDOWS_JLI_LIB) \ 160 $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib, \ 161 OUTPUT_DIR := $$($1_OUTPUT_DIR), \ 162 VERSIONINFO_RESOURCE := $$($1_VERSION_INFO_RESOURCE), \ 163 EXTRA_RC_FLAGS := $$($1_EXTRA_RC_FLAGS), \ 164 MANIFEST := $(JAVA_MANIFEST), \ 165 MANIFEST_VERSION := $(VERSION_NUMBER_FOUR_POSITIONS), \ 166 )) 167 168 $1 += $$(BUILD_LAUNCHER_$1) 169 TARGETS += $$($1) 170 171 ifeq ($(call isTargetOs, aix), true) 172 $$(BUILD_LAUNCHER_$1): $(call FindStaticLib, java.base, jli_static) 173 endif 174 175 ifeq ($(call isTargetOs, windows), true) 176 $$(BUILD_LAUNCHER_$1): $(call FindStaticLib, java.base, java, /libjava) \ 177 $$($1_WINDOWS_JLI_LIB) 178 endif 179 endef 180 181 ################################################################################ 182 # Create man pages for jmod to pick up. There should be a one-to-one 183 # relationship between executables and man pages (even if this is not always 184 # the case), so piggyback man page generation on the launcher compilation. 185 186 ifeq ($(call isTargetOsType, unix), true) 187 # Only build manpages on unix systems. 188 # We assume all our man pages should reside in section 1. 189 190 MAN_FILES_MD := $(wildcard $(addsuffix /*.md, $(call FindModuleManDirs, $(MODULE)))) 191 MAN_FILES_TROFF := $(wildcard $(addsuffix /*.1, $(call FindModuleManDirs, $(MODULE)))) 192 193 ifneq ($(MAN_FILES_MD), ) 194 # If we got markdown files, ignore the troff files 195 ifeq ($(ENABLE_PANDOC), false) 196 $(info Warning: pandoc not found. Not generating man pages) 197 else 198 # Create dynamic man pages from markdown using pandoc. We need 199 # PANDOC_TROFF_MANPAGE_FILTER, a wrapper around 200 # PANDOC_TROFF_MANPAGE_FILTER_JAVASCRIPT. This is created by buildtools-jdk. 201 202 # We should also depend on the source javascript filter 203 PANDOC_TROFF_MANPAGE_FILTER_JAVASCRIPT := \ 204 $(TOPDIR)/make/scripts/pandoc-troff-manpage-filter.js 205 206 # The norm in man pages is to display code literals as bold, but pandoc 207 # "correctly" converts these constructs (encoded in markdown using `...` 208 # or ```...```) to \f[C]. Ideally, we should use the filter to encapsulate 209 # the Code/CodeBlock in Strong. While this works for Code, pandoc cannot 210 # correctly render man page output for CodeBlock wrapped in Strong. So we 211 # take the easy way out, and post-process the troff output, replacing 212 # \f[C] with \f[CB]. This has the added benefit of working correctly on 213 # pandoc prior to version 2.0, which cannot properly produced nested 214 # formatting in man pages (see https://github.com/jgm/pandoc/issues/3568). 215 # 216 # As of pandoc 2.3, the termination of formatting is still broken 217 # (see https://github.com/jgm/pandoc/issues/4973). We need to replace 218 # \f[] with \f[R]. 219 MAN_POST_PROCESS := $(SED) -e 's/\\f\[C\]/\\f\[CB\]/g' \ 220 -e 's/\\f\[\]/\\f\[R\]/g' 221 222 # Now generate the man pages from markdown using pandoc 223 $(eval $(call SetupProcessMarkdown, BUILD_MAN_PAGES, \ 224 DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \ 225 FILES := $(MAN_FILES_MD), \ 226 FORMAT := man, \ 227 FILTER := $(PANDOC_TROFF_MANPAGE_FILTER), \ 228 POST_PROCESS := $(MAN_POST_PROCESS), \ 229 REPLACEMENTS := \ 230 @@COPYRIGHT_YEAR@@ => $(COPYRIGHT_YEAR) ; \ 231 @@VERSION_SHORT@@ => $(VERSION_SHORT) ; \ 232 @@VERSION_SPECIFICATION@@ => $(VERSION_SPECIFICATION), \ 233 EXTRA_DEPS := $(PANDOC_TROFF_MANPAGE_FILTER) \ 234 $(PANDOC_TROFF_MANPAGE_FILTER_JAVASCRIPT), \ 235 )) 236 237 TARGETS += $(BUILD_MAN_PAGES) 238 endif 239 else 240 # No markdown man pages present 241 ifeq ($(BUILD_MANPAGES), true) 242 # BUILD_MANPAGES is a mis-nomer. It really means "copy the pre-generated man pages". 243 $(eval $(call SetupCopyFiles, COPY_MAN_PAGES, \ 244 DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \ 245 FILES := $(MAN_FILES_TROFF), \ 246 )) 247 248 TARGETS += $(COPY_MAN_PAGES) 249 endif 250 endif 251 endif