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 ifeq ($(OPENJDK_TARGET_OS), macosx) 29 ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN) 30 else 31 ifeq ($(OPENJDK_TARGET_OS), windows) 32 endif 33 ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN,/../lib/jli) 34 35 # Applications expect to be able to link against libjawt without invoking 36 # System.loadLibrary("jawt") first. This was the behaviour described in the 37 # devloper documentation of JAWT and what worked with OpenJDK6. 38 ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), ) 39 ORIGIN_ARG += $(call SET_EXECUTABLE_ORIGIN,/../lib) 40 endif 41 endif 42 43 # Tell the compiler not to export any functions unless declared so in 44 # the source code. On Windows, this is the default and cannot be changed. 45 # On Mac, we have always exported all symbols, probably due to oversight 46 # and/or misunderstanding. To emulate this, don't hide any symbols 47 # by default. 48 # On AIX/xlc we need at least xlc 13.1 for the symbol hiding 49 # Also provide an override for non-conformant libraries. 50 ifeq ($(TOOLCHAIN_TYPE), gcc) 51 LAUNCHER_CFLAGS += -fvisibility=hidden 52 LDFLAGS_JDKEXE += -Wl,--exclude-libs,ALL 53 else ifeq ($(TOOLCHAIN_TYPE), clang) 54 ifneq ($(OPENJDK_TARGET_OS), macosx) 55 LAUNCHER_CFLAGS += -fvisibility=hidden 56 endif 57 else ifeq ($(TOOLCHAIN_TYPE), solstudio) 58 LAUNCHER_CFLAGS += -xldscope=hidden 59 else ifeq ($(TOOLCHAIN_TYPE), xlc) 60 ifneq ($(CC_VERSION_NUMBER), 12.1) 61 CXXFLAGS_JDKEXE += -qvisibility=hidden 62 endif 63 endif 64 65 LAUNCHER_SRC := $(TOPDIR)/src/java.base/share/native/launcher 66 LAUNCHER_CFLAGS += -I$(TOPDIR)/src/java.base/share/native/launcher \ 67 -I$(TOPDIR)/src/java.base/share/native/libjli \ 68 -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \ 69 -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli \ 70 # 71 GLOBAL_VERSION_INFO_RESOURCE := $(TOPDIR)/src/java.base/windows/native/common/version.rc 72 JAVA_VERSION_INFO_RESOURCE := $(TOPDIR)/src/java.base/windows/native/launcher/java.rc 73 MACOSX_PLIST_DIR := $(TOPDIR)/src/java.base/macosx/native/launcher 74 JAVA_MANIFEST := $(TOPDIR)/src/java.base/windows/native/launcher/java.manifest 75 76 ################################################################################ 77 # Build standard launcher. 78 79 # Setup make rules for building a standard launcher. 80 # 81 # Parameter 1 is the name of the rule. This name is used as variable prefix, 82 # and the targets generated are listed in a variable by that name. It is also 83 # used as the name of the executable. 84 # 85 # Remaining parameters are named arguments. These include: 86 # MAIN_MODULE The module of the main class to launch if different from the 87 # current module 88 # MAIN_CLASS The Java main class to launch 89 # JAVA_ARGS Processed into a -DJAVA_ARGS and added to CFLAGS 90 # EXTRA_JAVA_ARGS Processed into a -DEXTRA_JAVA_ARGS and is prepended 91 # before JAVA_ARGS to CFLAGS, primarily to allow long string literal 92 # compile time defines exceeding Visual Studio 2013 limitations. 93 # CFLAGS Additional CFLAGS 94 # CFLAGS_windows Additional CFLAGS_windows 95 # LIBS_unix Additional LIBS_unix 96 # LIBS_windows Additional LIBS_windows 97 # LDFLAGS_solaris Additional LDFLAGS_solaris 98 # RC_FLAGS Additional RC_FLAGS 99 # MACOSX_SIGNED On macosx, sign this binary 100 # WINDOWS_STATIC_LINK On windows, link statically with C runtime and libjli. 101 # OPTIMIZATION Override default optimization level (LOW) 102 # OUTPUT_DIR Override default output directory 103 # VERSION_INFO_RESOURCE Override default Windows resource file 104 # NO_JAVA_MS Do not add -ms8m to JAVA_ARGS. 105 SetupBuildLauncher = $(NamedParamsMacroTemplate) 106 define SetupBuildLauncherBody 107 # Setup default values (unless overridden) 108 ifeq ($$($1_OPTIMIZATION), ) 109 $1_OPTIMIZATION := LOW 110 endif 111 112 ifneq ($$($1_NO_JAVA_MS), true) 113 # The norm is to append -ms8m, unless otherwise instructed. 114 $1_JAVA_ARGS += -ms8m 115 endif 116 117 ifeq ($$($1_MAIN_MODULE), ) 118 $1_MAIN_MODULE := $(MODULE) 119 endif 120 121 ifneq ($$($1_JAVA_ARGS), ) 122 ifneq ($$($1_EXTRA_JAVA_ARGS), ) 123 $1_EXTRA_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \ 124 $$(addprefix -J, $$($1_EXTRA_JAVA_ARGS)), "$$a"$(COMMA) )) }' 125 $1_CFLAGS += -DEXTRA_JAVA_ARGS=$$($1_EXTRA_JAVA_ARGS_STR) 126 endif 127 $1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \ 128 $$(addprefix -J, $$($1_JAVA_ARGS)) -m $$($1_MAIN_MODULE)/$$($1_MAIN_CLASS), "$$a"$(COMMA) )) }' 129 $1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR) 130 endif 131 132 $1_LIBS := 133 ifeq ($(OPENJDK_TARGET_OS), macosx) 134 ifeq ($$($1_MACOSX_SIGNED), true) 135 $1_PLIST_FILE := Info-privileged.plist 136 $1_CODESIGN := true 137 else 138 $1_PLIST_FILE := Info-cmdline.plist 139 endif 140 141 $1_CFLAGS += -DPACKAGE_PATH='"$(PACKAGE_PATH)"' 142 $1_LDFLAGS += -Wl,-all_load \ 143 -sectcreate __TEXT __info_plist $(MACOSX_PLIST_DIR)/$$($1_PLIST_FILE) 144 ifeq ($(STATIC_BUILD), true) 145 $1_LDFLAGS += -exported_symbols_list \ 146 $(SUPPORT_OUTPUTDIR)/build-static/exported.symbols 147 $1_LIBS += \ 148 $$(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_libs/java.base -name "*.a") \ 149 $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libdt_socket.a \ 150 $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libjdwp.a \ 151 $(SUPPORT_OUTPUTDIR)/native/java.base/$(LIBRARY_PREFIX)fdlibm$(STATIC_LIBRARY_SUFFIX) \ 152 -framework CoreFoundation \ 153 -framework Foundation \ 154 -framework SystemConfiguration \ 155 -lstdc++ -liconv 156 else 157 $1_LIBS += $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a 158 endif 159 $1_LIBS += -framework Cocoa -framework Security \ 160 -framework ApplicationServices 161 endif 162 163 ifeq ($(OPENJDK_TARGET_OS), aix) 164 $1_LDFLAGS += -L$(SUPPORT_OUTPUTDIR)/native/java.base 165 $1_LIBS += -ljli_static 166 endif 167 168 ifeq ($(USE_EXTERNAL_LIBZ), true) 169 $1_LIBS += -lz 170 endif 171 172 ifeq ($$($1_WINDOWS_STATIC_LINK), true) 173 $1_CFLAGS += $(filter-out -MD, $(CFLAGS_JDKEXE)) 174 $1_WINDOWS_JLI_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/jli_static.lib 175 else 176 $1_CFLAGS += $(CFLAGS_JDKEXE) 177 $1_WINDOWS_JLI_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/libjli/jli.lib 178 endif 179 180 $$(eval $$(call SetupJdkExecutable, BUILD_LAUNCHER_$1, \ 181 NAME := $1, \ 182 EXTRA_FILES := $(LAUNCHER_SRC)/main.c, \ 183 OPTIMIZATION := $$($1_OPTIMIZATION), \ 184 CFLAGS := $$($1_CFLAGS) \ 185 $(LAUNCHER_CFLAGS) \ 186 $(VERSION_CFLAGS) \ 187 -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"' \ 188 -DPROGNAME='"$1"' \ 189 $$($1_CFLAGS), \ 190 CFLAGS_linux := -fPIC, \ 191 CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \ 192 CFLAGS_windows := $$($1_CFLAGS_windows), \ 193 LDFLAGS := $$(LDFLAGS_JDKEXE) \ 194 $$(ORIGIN_ARG) \ 195 $$($1_LDFLAGS), \ 196 LDFLAGS_linux := \ 197 -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.base/jli, \ 198 LDFLAGS_solaris := $$($1_LDFLAGS_solaris) \ 199 -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.base/jli, \ 200 LIBS := $(JDKEXE_LIBS) $$($1_LIBS), \ 201 LIBS_unix := $$($1_LIBS_unix), \ 202 LIBS_linux := -lpthread -ljli $(LIBDL), \ 203 LIBS_solaris := -ljli -lthread $(LIBDL), \ 204 LIBS_windows := $$($1_WINDOWS_JLI_LIB) \ 205 $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib advapi32.lib \ 206 $$($1_LIBS_windows), \ 207 OUTPUT_DIR := $$($1_OUTPUT_DIR), \ 208 VERSIONINFO_RESOURCE := $$($1_VERSION_INFO_RESOURCE), \ 209 EXTRA_RC_FLAGS := $$($1_EXTRA_RC_FLAGS), \ 210 MANIFEST := $(JAVA_MANIFEST), \ 211 MANIFEST_VERSION := $(VERSION_NUMBER_FOUR_POSITIONS), \ 212 CODESIGN := $$($1_CODESIGN), \ 213 )) 214 215 $1 += $$(BUILD_LAUNCHER_$1) 216 TARGETS += $$($1) 217 218 ifneq (,$(filter $(OPENJDK_TARGET_OS), macosx aix)) 219 $$(BUILD_LAUNCHER_$1): $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a 220 endif 221 222 ifeq ($(OPENJDK_TARGET_OS), windows) 223 $$(BUILD_LAUNCHER_$1): $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib \ 224 $$($1_WINDOWS_JLI_LIB) 225 endif 226 endef