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 28 # Tell the compiler not to export any functions unless declared so in 29 # the source code. On Windows, this is the default and cannot be changed. 30 # On Mac, we have always exported all symbols, probably due to oversight 31 # and/or misunderstanding. To emulate this, don't hide any symbols 32 # by default. 33 # On AIX/xlc we need at least xlc 13.1 for the symbol hiding (see JDK-8214063) 34 # Also provide an override for non-conformant libraries. 35 ifeq ($(TOOLCHAIN_TYPE), gcc) 36 LAUNCHER_CFLAGS += -fvisibility=hidden 37 LDFLAGS_JDKEXE += -Wl,--exclude-libs,ALL 38 else ifeq ($(TOOLCHAIN_TYPE), clang) 39 LAUNCHER_CFLAGS += -fvisibility=hidden 40 else ifeq ($(TOOLCHAIN_TYPE), solstudio) 41 LAUNCHER_CFLAGS += -xldscope=hidden 42 endif 43 44 LAUNCHER_SRC := $(TOPDIR)/src/java.base/share/native/launcher 45 LAUNCHER_CFLAGS += -I$(TOPDIR)/src/java.base/share/native/launcher \ 46 -I$(TOPDIR)/src/java.base/share/native/libjli \ 47 -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \ 48 -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli \ 49 # 50 GLOBAL_VERSION_INFO_RESOURCE := $(TOPDIR)/src/java.base/windows/native/common/version.rc 51 JAVA_VERSION_INFO_RESOURCE := $(TOPDIR)/src/java.base/windows/native/launcher/java.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 # LDFLAGS_solaris Additional LDFLAGS_solaris 75 # RC_FLAGS Additional RC_FLAGS 76 # MACOSX_SIGNED On macosx, sign this binary 77 # OPTIMIZATION Override default optimization level (LOW) 78 # OUTPUT_DIR Override default output directory 79 # VERSION_INFO_RESOURCE Override default Windows resource file 80 SetupBuildLauncher = $(NamedParamsMacroTemplate) 81 define SetupBuildLauncherBody 82 # Setup default values (unless overridden) 83 ifeq ($$($1_OPTIMIZATION), ) 84 $1_OPTIMIZATION := LOW 85 endif 86 87 ifeq ($$($1_MAIN_MODULE), ) 88 $1_MAIN_MODULE := $(MODULE) 89 endif 90 91 $1_JAVA_ARGS += -ms8m 92 ifneq ($$($1_MAIN_CLASS), ) 93 $1_LAUNCHER_CLASS := -m $$($1_MAIN_MODULE)/$$($1_MAIN_CLASS) 94 endif 95 96 ifneq ($$($1_EXTRA_JAVA_ARGS), ) 97 $1_EXTRA_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \ 98 $$(addprefix -J, $$($1_EXTRA_JAVA_ARGS)), "$$a"$(COMMA) )) }' 99 $1_CFLAGS += -DEXTRA_JAVA_ARGS=$$($1_EXTRA_JAVA_ARGS_STR) 100 endif 101 $1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \ 102 $$(addprefix -J, $$($1_JAVA_ARGS)) $$($1_LAUNCHER_CLASS), "$$a"$(COMMA) )) }' 103 $1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR) 104 105 ifeq ($(OPENJDK_TARGET_OS), macosx) 106 ifeq ($$($1_MACOSX_SIGNED), true) 107 $1_PLIST_FILE := Info-privileged.plist 108 $1_CODESIGN := true 109 else 110 $1_PLIST_FILE := Info-cmdline.plist 111 endif 112 113 $1_LDFLAGS += -sectcreate __TEXT __info_plist $(MACOSX_PLIST_DIR)/$$($1_PLIST_FILE) 114 115 ifeq ($(STATIC_BUILD), true) 116 $1_LDFLAGS += -exported_symbols_list \ 117 $(SUPPORT_OUTPUTDIR)/build-static/exported.symbols 118 $1_LIBS += \ 119 $$(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_libs/java.base -name "*.a") \ 120 $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libdt_socket.a \ 121 $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libjdwp.a \ 122 $(SUPPORT_OUTPUTDIR)/native/java.base/$(LIBRARY_PREFIX)fdlibm$(STATIC_LIBRARY_SUFFIX) \ 123 -framework CoreFoundation \ 124 -framework Foundation \ 125 -framework SystemConfiguration \ 126 -lstdc++ -liconv 127 endif 128 endif 129 130 ifeq ($(USE_EXTERNAL_LIBZ), true) 131 $1_LIBS += -lz 132 endif 133 134 $1_WINDOWS_JLI_LIB := $(call FindStaticLib, java.base, jli, /libjli) 135 136 $$(eval $$(call SetupJdkExecutable, BUILD_LAUNCHER_$1, \ 137 NAME := $1, \ 138 EXTRA_FILES := $(LAUNCHER_SRC)/main.c, \ 139 OPTIMIZATION := $$($1_OPTIMIZATION), \ 140 CFLAGS := $$(CFLAGS_JDKEXE) $$($1_CFLAGS) \ 141 $(LAUNCHER_CFLAGS) \ 142 $(VERSION_CFLAGS) \ 143 -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"' \ 144 -DPROGNAME='"$1"' \ 145 $$($1_CFLAGS), \ 146 CFLAGS_linux := -fPIC, \ 147 CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \ 148 CFLAGS_windows := $$($1_CFLAGS_windows), \ 149 DISABLED_WARNINGS_gcc := unused-function, \ 150 LDFLAGS := $$(LDFLAGS_JDKEXE) \ 151 $$(call SET_EXECUTABLE_ORIGIN) \ 152 $$($1_LDFLAGS), \ 153 LDFLAGS_linux := $$(call SET_EXECUTABLE_ORIGIN,/../lib) \ 154 -L$(call FindLibDirForModule, java.base), \ 155 LDFLAGS_macosx := $$(call SET_EXECUTABLE_ORIGIN,/../lib) \ 156 -L$(call FindLibDirForModule, java.base), \ 157 LDFLAGS_solaris := $$(call SET_EXECUTABLE_ORIGIN,/../lib) \ 158 -L$(call FindLibDirForModule, java.base), \ 159 LDFLAGS_aix := -L$(SUPPORT_OUTPUTDIR)/native/java.base, \ 160 LIBS := $(JDKEXE_LIBS) $$($1_LIBS), \ 161 LIBS_linux := -ljli -lpthread $(LIBDL), \ 162 LIBS_macosx := -ljli -framework Cocoa -framework Security \ 163 -framework ApplicationServices, \ 164 LIBS_solaris := -ljli -lthread $(LIBDL), \ 165 LIBS_aix := -ljli_static, \ 166 LIBS_windows := $$($1_WINDOWS_JLI_LIB) \ 167 $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib, \ 168 OUTPUT_DIR := $$($1_OUTPUT_DIR), \ 169 VERSIONINFO_RESOURCE := $$($1_VERSION_INFO_RESOURCE), \ 170 EXTRA_RC_FLAGS := $$($1_EXTRA_RC_FLAGS), \ 171 MANIFEST := $(JAVA_MANIFEST), \ 172 MANIFEST_VERSION := $(VERSION_NUMBER_FOUR_POSITIONS), \ 173 CODESIGN := $$($1_CODESIGN), \ 174 )) 175 176 $1 += $$(BUILD_LAUNCHER_$1) 177 TARGETS += $$($1) 178 179 ifeq ($(OPENJDK_TARGET_OS), aix) 180 $$(BUILD_LAUNCHER_$1): $(call FindStaticLib, java.base, jli_static) 181 endif 182 183 ifeq ($(OPENJDK_TARGET_OS), windows) 184 $$(BUILD_LAUNCHER_$1): $(call FindStaticLib, java.base, java, /libjava) \ 185 $$($1_WINDOWS_JLI_LIB) 186 endif 187 endef