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