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