1 #
   2 # Copyright (c) 2011, 2015, 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 NativeCompilation.gmk
  27 
  28 # SetupNativeCompilation now supports debug symbols on macosx for hotspot.
  29 # Disable it here for the jdk binaries until we decide to enable them.
  30 ifeq ($(OPENJDK_TARGET_OS), macosx)
  31   ENABLE_DEBUG_SYMBOLS := false
  32 endif
  33 
  34 # Prepare the find cache.
  35 $(eval $(call FillCacheFind, $(JDK_TOPDIR)/src/java.base/share/native/launcher))
  36 
  37 ifeq ($(OPENJDK_TARGET_OS), macosx)
  38   ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN)
  39 else
  40   ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN,/../lib$(OPENJDK_TARGET_CPU_LIBDIR)/jli)
  41 
  42   # Applications expect to be able to link against libjawt without invoking
  43   # System.loadLibrary("jawt") first. This was the behaviour described in the
  44   # devloper documentation of JAWT and what worked with OpenJDK6.
  45   ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
  46     ORIGIN_ARG += $(call SET_EXECUTABLE_ORIGIN,/../lib$(OPENJDK_TARGET_CPU_LIBDIR))
  47   endif
  48 endif
  49 
  50 LAUNCHER_SRC := $(JDK_TOPDIR)/src/java.base/share/native/launcher
  51 LAUNCHER_CFLAGS := -I$(JDK_TOPDIR)/src/java.base/share/native/launcher \
  52     -I$(JDK_TOPDIR)/src/java.base/share/native/libjli \
  53     -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \
  54     -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli \
  55     #
  56 GLOBAL_VERSION_INFO_RESOURCE := $(JDK_TOPDIR)/src/java.base/windows/native/common/version.rc
  57 JAVA_VERSION_INFO_RESOURCE := $(JDK_TOPDIR)/src/java.base/windows/native/launcher/java.rc
  58 MACOSX_PLIST_DIR := $(JDK_TOPDIR)/src/java.base/macosx/native/launcher
  59 JAVA_MANIFEST := $(JDK_TOPDIR)/src/java.base/windows/native/launcher/java.manifest
  60 
  61 ################################################################################
  62 # Build standard launcher.
  63 
  64 # Setup make rules for building a standard launcher.
  65 #
  66 # Parameter 1 is the name of the rule. This name is used as variable prefix,
  67 # and the targets generated are listed in a variable by that name. It is also
  68 # used as the name of the executable.
  69 #
  70 # Remaining parameters are named arguments. These include:
  71 # MAIN_CLASS   The Java main class to launch
  72 # JAVA_ARGS   Processed into a -DJAVA_ARGS C flag
  73 # CFLAGS   Additional CFLAGS
  74 # CFLAGS_windows   Additional CFLAGS_windows
  75 # LIBS_unix   Additional LIBS_unix
  76 # LIBS_windows   Additional LIBS_windows
  77 # LDFLAGS_solaris Additional LDFLAGS_solaris
  78 # RC_FLAGS   Additional RC_FLAGS
  79 # MACOSX_SIGNED   On macosx, sign this binary
  80 # WINDOWS_STATIC_LINK   On windows, link statically with C runtime and libjli.
  81 # OPTIMIZATION   Override default optimization level (LOW)
  82 # OUTPUT_DIR   Override default output directory
  83 # VERSION_INFO_RESOURCE   Override default Windows resource file
  84 # NO_JAVA_MS   Do not add -ms8m to JAVA_ARGS.
  85 SetupBuildLauncher = $(NamedParamsMacroTemplate)
  86 define SetupBuildLauncherBody
  87   # Setup default values (unless overridden)
  88   ifeq ($$($1_VERSION_INFO_RESOURCE), )
  89     $1_VERSION_INFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE)
  90   endif
  91 
  92   ifeq ($$($1_OUTPUT_DIR), )
  93     $1_OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE)
  94   endif
  95 
  96   ifeq ($$($1_OPTIMIZATION), )
  97     $1_OPTIMIZATION := LOW
  98   endif
  99 
 100   ifneq ($$($1_NO_JAVA_MS), true)
 101     # The norm is to append -ms8m, unless otherwise instructed.
 102     $1_JAVA_ARGS += -ms8m
 103   endif
 104 
 105   ifneq ($$($1_JAVA_ARGS), )
 106     $1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \
 107         $$(addprefix -J, $$($1_JAVA_ARGS)) $$($1_MAIN_CLASS), "$$a"$(COMMA) )) }'
 108     $1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR)
 109   endif
 110 
 111   $1_LIBS :=
 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_CFLAGS += -DPACKAGE_PATH='"$(PACKAGE_PATH)"'
 121     $1_LDFLAGS += -Wl,-all_load \
 122         -sectcreate __TEXT __info_plist $(MACOSX_PLIST_DIR)/$$($1_PLIST_FILE)
 123     ifeq ($(STATIC_BUILD), true)
 124       $1_LDFLAGS += -exported_symbols_list \
 125               $(SUPPORT_OUTPUTDIR)/build-static/exported.symbols
 126       $1_LIBS += \
 127           $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_libs/java.base -name "*.a") \
 128           $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libdt_socket.a \
 129           $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libjdwp.a \
 130           $(SUPPORT_OUTPUTDIR)/native/java.base/$(LIBRARY_PREFIX)fdlibm$(STATIC_LIBRARY_SUFFIX) \
 131           -framework CoreFoundation \
 132           -framework Foundation \
 133           -framework SystemConfiguration \
 134           -lstdc++ -liconv
 135     else
 136       $1_LIBS += $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a
 137     endif
 138     $1_LIBS += -framework Cocoa -framework Security \
 139         -framework ApplicationServices
 140   endif
 141 
 142   ifeq ($(OPENJDK_TARGET_OS), aix)
 143     $1_LDFLAGS += -L$(SUPPORT_OUTPUTDIR)/native/java.base
 144     $1_LIBS += -ljli_static
 145   endif
 146 
 147   ifeq ($(USE_EXTERNAL_LIBZ), true)
 148     $1_LIBS += -lz
 149   endif
 150 
 151   ifeq ($$($1_WINDOWS_STATIC_LINK), true)
 152     $1_CFLAGS += $(filter-out -MD, $(CFLAGS_JDKEXE))
 153     $1_WINDOWS_JLI_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/jli_static.lib
 154   else
 155     $1_CFLAGS += $(CFLAGS_JDKEXE)
 156     $1_WINDOWS_JLI_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/libjli/jli.lib
 157   endif
 158 
 159   # The linker on older SuSE distros (e.g. on SLES 10) complains with:
 160   # "Invalid version tag `SUNWprivate_1.1'. Only anonymous version tag is allowed in executable."
 161   # if feeded with a version script which contains named tags.
 162   ifeq ($(USING_BROKEN_SUSE_LD),yes)
 163     ifneq ($(wildcard $(JDK_TOPDIR)/make/mapfiles/launchers/mapfile-$(OPENJDK_TARGET_CPU).anonymous), )
 164       $1_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/launchers/mapfile-$(OPENJDK_TARGET_CPU).anonymous
 165     else
 166       $1_MAPFILE :=
 167     endif
 168   else
 169     ifneq ($(wildcard $(JDK_TOPDIR)/make/mapfiles/launchers/mapfile-$(OPENJDK_TARGET_CPU)), )
 170       $1_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/launchers/mapfile-$(OPENJDK_TARGET_CPU)
 171     else
 172       $1_MAPFILE :=
 173     endif
 174   endif
 175 
 176   $$(eval $$(call SetupNativeCompilation, BUILD_LAUNCHER_$1, \
 177       SRC := $(LAUNCHER_SRC), \
 178       INCLUDE_FILES := main.c, \
 179       OPTIMIZATION := $$($1_OPTIMIZATION), \
 180       CFLAGS := $$($1_CFLAGS) \
 181           $(LAUNCHER_CFLAGS) \
 182           $(VERSION_CFLAGS) \
 183           -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"' \
 184           -DPROGNAME='"$1"' \
 185           $$($1_CFLAGS), \
 186       CFLAGS_linux := -fPIC, \
 187       CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \
 188       CFLAGS_windows := $$($1_CFLAGS_windows), \
 189       LDFLAGS := $$(LDFLAGS_JDKEXE) \
 190           $$(ORIGIN_ARG) \
 191           $$($1_LDFLAGS), \
 192       LDFLAGS_linux := \
 193           -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.base$(OPENJDK_TARGET_CPU_LIBDIR)/jli, \
 194       LDFLAGS_solaris := $$($1_LDFLAGS_solaris) \
 195           -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.base$(OPENJDK_TARGET_CPU_LIBDIR)/jli, \
 196       MAPFILE := $$($1_MAPFILE), \
 197       LIBS := $(JDKEXE_LIBS) $$($1_LIBS), \
 198       LIBS_unix := $$($1_LIBS_unix), \
 199       LIBS_linux := -lpthread -ljli $(LIBDL) -lc, \
 200       LIBS_solaris := -ljli -lthread $(LIBDL) -lc, \
 201       LIBS_windows := $$($1_WINDOWS_JLI_LIB) \
 202           $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib advapi32.lib \
 203           $$($1_LIBS_windows), \
 204       OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/$1_objs, \
 205       OUTPUT_DIR := $$($1_OUTPUT_DIR), \
 206       PROGRAM := $1, \
 207       DEBUG_SYMBOLS := true, \
 208       VERSIONINFO_RESOURCE := $$($1_VERSION_INFO_RESOURCE), \
 209       RC_FLAGS := $$(RC_FLAGS) \
 210           -D "JDK_FNAME=$1$(EXE_SUFFIX)" \
 211           -D "JDK_INTERNAL_NAME=$1" \
 212           -D "JDK_FTYPE=0x1L" \
 213           $$($1_RC_FLAGS), \
 214       MANIFEST := $(JAVA_MANIFEST), \
 215       MANIFEST_VERSION := $(VERSION_NUMBER_FOUR_POSITIONS), \
 216       CODESIGN := $$($1_CODESIGN), \
 217   ))
 218 
 219   $1 += $$(BUILD_LAUNCHER_$1)
 220   TARGETS += $$($1)
 221 
 222   ifneq (,$(filter $(OPENJDK_TARGET_OS), macosx aix))
 223     $$(BUILD_LAUNCHER_$1): $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a
 224   endif
 225 
 226   ifeq ($(OPENJDK_TARGET_OS), windows)
 227     $$(BUILD_LAUNCHER_$1): $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib \
 228         $$($1_WINDOWS_JLI_LIB)
 229   endif
 230 endef