1 #
   2 # Copyright 1999-2007 Sun Microsystems, Inc.  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.
   8 #
   9 # This code is distributed in the hope that it will be useful, but WITHOUT
  10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 # version 2 for more details (a copy is included in the LICENSE file that
  13 # accompanied this code).
  14 #
  15 # You should have received a copy of the GNU General Public License version
  16 # 2 along with this work; if not, write to the Free Software Foundation,
  17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 #
  19 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20 # CA 95054 USA or visit www.sun.com if you need additional information or
  21 # have any questions.
  22 #  
  23 #
  24 
  25 # Rules to build JVM and related libraries, included from vm.make in the build
  26 # directory.
  27 
  28 # Common build rules.
  29 MAKEFILES_DIR=$(GAMMADIR)/build/$(Platform_os_family)/makefiles
  30 include $(MAKEFILES_DIR)/rules.make
  31 
  32 default: build
  33 
  34 #----------------------------------------------------------------------
  35 # Defs
  36 
  37 GENERATED     = ../generated
  38 
  39 # read a generated file defining the set of .o's and the .o .h dependencies
  40 include $(GENERATED)/Dependencies
  41 
  42 # read machine-specific adjustments (%%% should do this via buildtree.make?)
  43 include $(MAKEFILES_DIR)/$(BUILDARCH).make
  44 
  45 # set VPATH so make knows where to look for source files
  46 # Src_Dirs is everything in src/share/vm/*, plus the right os/*/vm and cpu/*/vm
  47 # The incls directory contains generated header file lists for inclusion.
  48 # The adfiles directory contains ad_<arch>.[ch]pp.
  49 # The jvmtifiles directory contains jvmti*.[ch]pp
  50 Src_Dirs_V = $(GENERATED)/adfiles $(GENERATED)/jvmtifiles ${Src_Dirs} $(GENERATED)/incls
  51 VPATH    += $(Src_Dirs_V:%=%:)
  52 
  53 # set INCLUDES for C preprocessor
  54 Src_Dirs_I = $(PRECOMPILED_HEADER_DIR) $(GENERATED)/adfiles $(GENERATED)/jvmtifiles ${Src_Dirs} $(GENERATED)
  55 INCLUDES += $(Src_Dirs_I:%=-I%)
  56 
  57 ifeq (${VERSION}, debug)
  58   SYMFLAG = -g
  59 else
  60   SYMFLAG =
  61 endif
  62 
  63 # HOTSPOT_RELEASE_VERSION and HOTSPOT_BUILD_VERSION are defined 
  64 # in $(GAMMADIR)/make/defs.make
  65 ifeq ($(HOTSPOT_BUILD_VERSION),)
  66   BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)\""
  67 else
  68   BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)-$(HOTSPOT_BUILD_VERSION)\""
  69 endif
  70 
  71 # The following variables are defined in the generated flags.make file.
  72 BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HS_BUILD_VER)\""
  73 JRE_VERSION   = -DJRE_RELEASE_VERSION="\"$(JRE_RELEASE_VER)\""
  74 HS_LIB_ARCH   = -DHOTSPOT_LIB_ARCH=\"$(LIBARCH)\"
  75 BUILD_TARGET  = -DHOTSPOT_BUILD_TARGET="\"$(TARGET)\""
  76 BUILD_USER    = -DHOTSPOT_BUILD_USER="\"$(HOTSPOT_BUILD_USER)\""
  77 VM_DISTRO     = -DHOTSPOT_VM_DISTRO="\"$(HOTSPOT_VM_DISTRO)\""
  78 
  79 CPPFLAGS =           \
  80   ${SYSDEFS}         \
  81   ${INCLUDES}        \
  82   ${BUILD_VERSION}   \
  83   ${BUILD_TARGET}    \
  84   ${BUILD_USER}      \
  85   ${HS_LIB_ARCH}     \
  86   ${JRE_VERSION}     \
  87   ${VM_DISTRO}
  88 
  89 # CFLAGS_WARN holds compiler options to suppress/enable warnings.
  90 CFLAGS += $(CFLAGS_WARN/BYFILE)
  91 
  92 # Do not use C++ exception handling
  93 CFLAGS += $(CFLAGS/NOEX)
  94 
  95 # Extra flags from gnumake's invocation or environment
  96 CFLAGS += $(EXTRA_CFLAGS)
  97 
  98 LIBS += -lm -ldl -lpthread
  99 
 100 # By default, link the *.o into the library, not the executable.
 101 LINK_INTO$(LINK_INTO) = LIBJVM
 102 
 103 JDK_LIBDIR = $(JAVA_HOME)/jre/lib/$(LIBARCH)
 104 
 105 #----------------------------------------------------------------------
 106 # jvm_db & dtrace
 107 include $(MAKEFILES_DIR)/dtrace.make
 108 
 109 #----------------------------------------------------------------------
 110 # JVM
 111 
 112 JVM    = jvm$(G_SUFFIX)
 113 LIBJVM = lib$(JVM).so
 114 
 115 JVM_OBJ_FILES = $(Obj_Files)
 116 
 117 vm_version.o: $(filter-out vm_version.o,$(JVM_OBJ_FILES))
 118 
 119 mapfile : $(MAPFILE)
 120         rm -f $@
 121         cat $^ > $@
 122 
 123 mapfile_reorder : mapfile $(REORDERFILE)
 124         rm -f $@
 125         cat $^ > $@
 126 
 127 STATIC_CXX = true
 128 
 129 ifeq ($(LINK_INTO),AOUT)
 130   LIBJVM.o                 =
 131   LIBJVM_MAPFILE           =
 132   LIBS_VM                  = $(LIBS)
 133 else
 134   LIBJVM.o                 = $(JVM_OBJ_FILES)
 135   LIBJVM_MAPFILE$(LDNOMAP) = mapfile_reorder
 136   LFLAGS_VM$(LDNOMAP)      += $(MAPFLAG:FILENAME=$(LIBJVM_MAPFILE))
 137   LFLAGS_VM                += $(SONAMEFLAG:SONAME=$(LIBJVM))
 138 
 139   # JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
 140   # get around library dependency and compatibility issues. Must use gcc not
 141   # g++ to link.
 142   ifeq ($(STATIC_CXX), true)
 143     LFLAGS_VM              += $(STATIC_LIBGCC)
 144     LIBS_VM                += $(STATIC_STDCXX)
 145   else
 146     LIBS_VM                += -lstdc++
 147   endif
 148 
 149   LIBS_VM                  += $(LIBS)
 150 endif
 151 
 152 LINK_VM = $(LINK_LIB.c)
 153 
 154 # rule for building precompiled header
 155 $(PRECOMPILED_HEADER): $(Precompiled_Files)
 156         $(QUIETLY) echo Generating precompiled header $@
 157         $(QUIETLY) mkdir -p $(PRECOMPILED_HEADER_DIR)/incls
 158         $(QUIETLY) $(COMPILE.CC) -x c++-header -c $(GENERATED)/incls/_precompiled.incl -o $@ $(COMPILE_DONE)
 159 
 160 # making the library:
 161 
 162 ifneq ($(JVM_BASE_ADDR),)
 163 # By default shared library is linked at base address == 0. Modify the
 164 # linker script if JVM prefers a different base location. It can also be
 165 # implemented with 'prelink -r'. But 'prelink' is not (yet) available on
 166 # our build platform (AS-2.1).
 167 LD_SCRIPT = libjvm.so.lds
 168 $(LD_SCRIPT): $(LIBJVM_MAPFILE)
 169         $(QUIETLY) {                                                \
 170           rm -rf $@;                                                \
 171           $(LINK_VM) -Wl,--verbose $(LFLAGS_VM) 2>&1             |  \
 172             sed -e '/^======/,/^======/!d'                          \
 173                 -e '/^======/d'                                     \
 174                 -e 's/0\( + SIZEOF_HEADERS\)/$(JVM_BASE_ADDR)\1/'   \
 175                 > $@;                                               \
 176         }
 177 LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
 178 endif
 179 
 180 # With more recent Redhat releases (or the cutting edge version Fedora), if
 181 # SELinux is configured to be enabled, the runtime linker will fail to apply
 182 # the text relocation to libjvm.so considering that it is built as a non-PIC
 183 # DSO. To workaround that, we run chcon to libjvm.so after it is built. See 
 184 # details in bug 6538311.
 185 $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
 186         $(QUIETLY) {                                                    \
 187             echo Linking vm...;                                         \
 188             $(LINK_LIB.CC/PRE_HOOK)                                     \
 189             $(LINK_VM) $(LD_SCRIPT_FLAG)                                \
 190                        $(LFLAGS_VM) -o $@ $(LIBJVM.o) $(LIBS_VM);       \
 191             $(LINK_LIB.CC/POST_HOOK)                                    \
 192             rm -f $@.1; ln -s $@ $@.1;                                  \
 193             if [ -x /usr/sbin/selinuxenabled ] ; then                   \
 194               /usr/sbin/selinuxenabled;                                 \
 195               if [ $$? = 0 ] ; then                                     \
 196                 /usr/bin/chcon -t textrel_shlib_t $@;                   \
 197                 if [ $$? != 0 ]; then                                   \
 198                   echo "ERROR: Cannot chcon $@"; exit 1;                \
 199                 fi                                                      \
 200               fi                                                        \
 201             fi                                                          \
 202         }
 203 
 204 DEST_JVM = $(JDK_LIBDIR)/$(VM_SUBDIR)/$(LIBJVM)
 205 
 206 install_jvm: $(LIBJVM)
 207         @echo "Copying $(LIBJVM) to $(DEST_JVM)"
 208         $(QUIETLY) cp -f $(LIBJVM) $(DEST_JVM) && echo "Done"
 209 
 210 #----------------------------------------------------------------------
 211 # Other files
 212 
 213 # Gamma launcher
 214 include $(MAKEFILES_DIR)/launcher.make
 215 
 216 # Signal interposition library
 217 include $(MAKEFILES_DIR)/jsig.make
 218 
 219 # Serviceability agent
 220 include $(MAKEFILES_DIR)/saproc.make
 221 
 222 #----------------------------------------------------------------------
 223 
 224 build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) $(LIBJVM_DB) checkAndBuildSA
 225 
 226 install: install_jvm install_jsig install_saproc
 227 
 228 .PHONY: default build install install_jvm