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