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 # Prepare the find cache.
  29 $(eval $(call FillCacheFind, $(JDK_TOPDIR)/src/java.base/share/native/launcher))
  30 
  31 # When building a legacy overlay image (on solaris 64 bit), the launchers
  32 # need to be built with a different rpath and a different output dir.
  33 ifeq ($(OVERLAY_IMAGES), true)
  34   ORIGIN_ROOT := /../..
  35   OUTPUT_SUBDIR := $(OPENJDK_TARGET_CPU_ISADIR)
  36 else
  37   ORIGIN_ROOT := /..
  38 endif
  39 
  40 ifeq ($(OPENJDK_TARGET_OS), macosx)
  41   ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN)
  42 else
  43   ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN,$(ORIGIN_ROOT)/lib$(OPENJDK_TARGET_CPU_LIBDIR)/jli)
  44 endif
  45 
  46 #
  47 # Applications expect to be able to link against libjawt without invoking
  48 # System.loadLibrary("jawt") first. This was the behaviour described in the
  49 # devloper documentation of JAWT and what worked with OpenJDK6.
  50 #
  51 ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
  52   ORIGIN_ARG += $(call SET_EXECUTABLE_ORIGIN,$(ORIGIN_ROOT)/lib$(OPENJDK_TARGET_CPU_LIBDIR))
  53 endif
  54 
  55 LAUNCHER_SRC := $(JDK_TOPDIR)/src/java.base/share/native/launcher
  56 LAUNCHER_CFLAGS := -I$(JDK_TOPDIR)/src/java.base/share/native/launcher \
  57     -I$(JDK_TOPDIR)/src/java.base/share/native/libjli \
  58     -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \
  59     -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli \
  60     #
  61 GLOBAL_VERSION_INFO_RESOURCE := $(JDK_TOPDIR)/src/java.base/windows/native/common/version.rc
  62 JAVA_VERSION_INFO_RESOURCE := $(JDK_TOPDIR)/src/java.base/windows/native/launcher/java.rc
  63 MACOSX_PLIST_DIR := $(JDK_TOPDIR)/src/java.base/macosx/native/launcher
  64 # Until the shuffle is permanent, we can't add this in configure
  65 CFLAGS_JDKEXE := $(filter-out %javavm/export, $(CFLAGS_JDKEXE))
  66 CFLAGS_JDKEXE += -I$(JDK_TOPDIR)/src/java.base/share/native/include \
  67     -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/include
  68 CXXFLAGS_JDKEXE := $(filter-out %javavm/export, $(CXXFLAGS_JDKEXE))
  69 CXXFLAGS_JDKEXE += -I$(JDK_TOPDIR)/src/java.base/share/native/include \
  70     -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/include
  71 JAVA_MANIFEST := $(JDK_TOPDIR)/src/java.base/windows/native/launcher/java.manifest
  72 
  73 define SetupLauncher
  74   # TODO: Fix mapfile on solaris. Won't work with ld as linker.
  75   # Parameter 1 is the name of the launcher (java, javac, jar...)
  76   # Parameter 2 is extra CFLAGS
  77   # Parameter 3 is extra LDFLAGS
  78   # Parameter 4 is extra LDFLAGS_SUFFIX_unix
  79   # Parameter 5 is extra LDFLAGS_SUFFIX_windows
  80   # Parameter 6 is optional Windows JLI library (full path)
  81   # Parameter 7 is optional Windows resource (RC) flags
  82   # Parameter 8 is optional Windows version resource file (.rc)
  83   # Parameter 9 is different output dir
  84   # Parameter 10 if set, link statically with c runtime on windows.
  85   # Parameter 11 if set, override plist file on macosx.
  86   $(call LogSetupMacroEntry,SetupLauncher($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11))
  87   $(if $(13),$(error Internal makefile error: Too many arguments to SetupLauncher, please update CompileLaunchers.gmk))
  88 
  89   $1_WINDOWS_JLI_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/libjli/jli.lib
  90   ifneq ($6, )
  91     $1_WINDOWS_JLI_LIB := $6
  92   endif
  93   $1_VERSION_INFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE)
  94   ifneq ($8, )
  95     $1_VERSION_INFO_RESOURCE := $8
  96   endif
  97 
  98   $1_LDFLAGS := $3
  99   $1_LDFLAGS_SUFFIX :=
 100   ifeq ($(OPENJDK_TARGET_OS), macosx)
 101     $1_PLIST_FILE := Info-cmdline.plist
 102     ifneq ($(11), )
 103       $1_PLIST_FILE := $(11)
 104       ifneq ($$(findstring privileged, $$($1_PLIST_FILE)), )
 105         $1_CODESIGN := true
 106       endif
 107     endif
 108 
 109     ifeq ($(STATIC_BUILD), true)
 110       $1_LDFLAGS += -Wl,-all_load \
 111           $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/modules_libs/java.base -name "*.a") \
 112           $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libdt_socket.a \
 113           $(SUPPORT_OUTPUTDIR)/modules_libs/jdk.jdwp.agent/libjdwp.a \
 114           $(SUPPORT_OUTPUTDIR)/native/java.base/$(LIBRARY_PREFIX)fdlibm$(STATIC_LIBRARY_SUFFIX) \
 115           -framework CoreFoundation \
 116           -framework Foundation \
 117           -framework SystemConfiguration \
 118           -framework Cocoa -framework Security \
 119           -framework ApplicationServices \
 120           -lstdc++ -liconv \
 121           -sectcreate __TEXT __info_plist \
 122           $(MACOSX_PLIST_DIR)/$$($1_PLIST_FILE) \
 123           -exported_symbols_list \
 124               $(SUPPORT_OUTPUTDIR)/build-static/exported.symbols
 125     else
 126       $1_LDFLAGS += -Wl,-all_load $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a \
 127           -framework Cocoa -framework Security -framework ApplicationServices \
 128           -sectcreate __TEXT __info_plist $(MACOSX_PLIST_DIR)/$$($1_PLIST_FILE)
 129           $1_LDFLAGS_SUFFIX += -pthread
 130     endif
 131 
 132 
 133   endif
 134 
 135   ifeq ($(OPENJDK_TARGET_OS), aix)
 136     $1_LDFLAGS_SUFFIX += -L$(SUPPORT_OUTPUTDIR)/native/java.base -ljli_static
 137   endif
 138 
 139   ifeq ($(USE_EXTERNAL_LIBZ), true)
 140     $1_LDFLAGS_SUFFIX += -lz
 141   endif
 142 
 143   $1_OUTPUT_DIR_ARG := $9
 144   ifeq (, $$($1_OUTPUT_DIR_ARG))
 145     $1_OUTPUT_DIR_ARG := $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE)
 146   endif
 147 
 148   # TODO: maybe it's better to move this if-statement out of this function
 149   ifeq ($1, java)
 150     $1_OPTIMIZATION_ARG := HIGH
 151     $1_LDFLAGS_solaris := -R$(OPENWIN_HOME)/lib$(OPENJDK_TARGET_CPU_ISADIR)
 152   else
 153   $1_OPTIMIZATION_ARG := LOW
 154   endif
 155 
 156   $1_CFLAGS := $(CFLAGS_JDKEXE)
 157   ifeq ($(10), true)
 158     $1_CFLAGS := $(filter-out -MD, $(CFLAGS_JDKEXE))
 159   endif
 160 
 161   # The linker on older SuSE distros (e.g. on SLES 10) complains with:
 162   # "Invalid version tag `SUNWprivate_1.1'. Only anonymous version tag is allowed in executable."
 163   # if feeded with a version script which contains named tags.
 164   ifeq ($(USING_BROKEN_SUSE_LD),yes)
 165     ifneq ($(wildcard $(JDK_TOPDIR)/make/mapfiles/launchers/mapfile-$(OPENJDK_TARGET_CPU).anonymous), )
 166       $1_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/launchers/mapfile-$(OPENJDK_TARGET_CPU).anonymous
 167     else
 168       $1_MAPFILE :=
 169     endif
 170   else
 171     ifneq ($(wildcard $(JDK_TOPDIR)/make/mapfiles/launchers/mapfile-$(OPENJDK_TARGET_CPU)), )
 172       $1_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/launchers/mapfile-$(OPENJDK_TARGET_CPU)
 173     else
 174       $1_MAPFILE :=
 175     endif
 176   endif
 177 
 178   $(call SetupNativeCompilation,BUILD_LAUNCHER_$1, \
 179       SRC := $(LAUNCHER_SRC), \
 180       INCLUDE_FILES := main.c, \
 181       OPTIMIZATION := $$($1_OPTIMIZATION_ARG), \
 182       CFLAGS := $$($1_CFLAGS) \
 183           $(LAUNCHER_CFLAGS) \
 184           -DFULL_VERSION='"$(FULL_VERSION)"' \
 185           -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \
 186           -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"' \
 187           -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"' \
 188           -DPROGNAME='"$1"' $(DPACKAGEPATH) \
 189           $2, \
 190       CFLAGS_linux := -fPIC, \
 191       CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \
 192       LDFLAGS := $(LDFLAGS_JDKEXE) \
 193           $(ORIGIN_ARG) \
 194           $$($1_LDFLAGS), \
 195       LDFLAGS_macosx := $(call SET_SHARED_LIBRARY_NAME,$1), \
 196       LDFLAGS_linux := -lpthread \
 197           $(call SET_SHARED_LIBRARY_NAME,$(LIBRARY_PREFIX)$(SHARED_LIBRARY_SUFFIX)), \
 198       LDFLAGS_solaris := $$($1_LDFLAGS_solaris) \
 199           $(call SET_SHARED_LIBRARY_NAME,$(LIBRARY_PREFIX)$(SHARED_LIBRARY_SUFFIX)), \
 200       MAPFILE := $$($1_MAPFILE), \
 201       LDFLAGS_SUFFIX := $(LDFLAGS_JDKEXE_SUFFIX) $$($1_LDFLAGS_SUFFIX), \
 202       LDFLAGS_SUFFIX_unix := $4, \
 203       LDFLAGS_SUFFIX_windows := $$($1_WINDOWS_JLI_LIB) \
 204           $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib advapi32.lib $5, \
 205       LDFLAGS_SUFFIX_linux := -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.base$(OPENJDK_TARGET_CPU_LIBDIR)/jli -ljli $(LIBDL) -lc, \
 206       LDFLAGS_SUFFIX_solaris := -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.base$(OPENJDK_TARGET_CPU_LIBDIR)/jli -ljli -lthread $(LIBDL) -lc, \
 207       OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/$1_objs$(OUTPUT_SUBDIR), \
 208       OUTPUT_DIR := $$($1_OUTPUT_DIR_ARG)$(OUTPUT_SUBDIR), \
 209       PROGRAM := $1, \
 210       DEBUG_SYMBOLS := true, \
 211       VERSIONINFO_RESOURCE := $$($1_VERSION_INFO_RESOURCE), \
 212       RC_FLAGS := $(RC_FLAGS) \
 213           -D "JDK_FNAME=$1$(EXE_SUFFIX)" \
 214           -D "JDK_INTERNAL_NAME=$1" \
 215           -D "JDK_FTYPE=0x1L" \
 216           $7, \
 217       MANIFEST := $(JAVA_MANIFEST), \
 218       MANIFEST_VERSION := $(JDK_VERSION_FOR_MANIFEST), \
 219       CODESIGN := $$($1_CODESIGN), \
 220   )
 221 
 222   TARGETS += $$(BUILD_LAUNCHER_$1)
 223 
 224   ifneq (,$(filter $(OPENJDK_TARGET_OS), macosx aix))
 225     $$(BUILD_LAUNCHER_$1): $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a
 226   endif
 227 
 228   ifeq ($(OPENJDK_TARGET_OS), windows)
 229     $$(BUILD_LAUNCHER_$1): $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib \
 230         $$($1_WINDOWS_JLI_LIB)
 231   endif
 232 endef
 233 
 234 ##########################################################################################
 235 
 236 XLIBS := $(X_LIBS) -lX11
 237 ifeq ($(OPENJDK_TARGET_OS), macosx)
 238   DPACKAGEPATH := -DPACKAGE_PATH='"$(PACKAGE_PATH)"'
 239   XLIBS :=
 240 endif
 241 
 242 JAVA_RC_FLAGS += -i $(JDK_TOPDIR)/src/java.base/windows/native/common
 243 ifdef OPENJDK
 244   JAVA_RC_FLAGS += -i "$(JDK_TOPDIR)/src/java.base/windows/native/launcher/icons"
 245 else
 246   JAVA_RC_FLAGS += -i "$(JDK_TOPDIR)/src/closed/java.base/windows/native/launcher/icons"
 247 endif