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