view j2se/make/common/Defs.gmk @ 2:16f2b6c91171 trunk

[svn] Load openjdk/jdk7/b14 into jdk/trunk.
author xiomara
date Fri, 22 Jun 2007 00:46:43 +0000
parents a4ed3fb96592
children bf1d8af0651f
line wrap: on
line source

#
# Copyright 1995-2007 Sun Microsystems, Inc.  All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#

#
# Common variables used by all the Java makefiles.  This file should
# not contain rules.
#

# WARNING: This file is shared with other workspaces.
#          So when it includes other files, it must use J2SE_TOPDIR.
#

#
# On Solaris, the 'make' utility from Sun will not work with these makefiles.
#    This little rule is only understood by Sun's make, and is harmless
#    when seen by the GNU make tool. If using Sun's make, this causes the
#    make command to fail.
#
SUN_MAKE_TEST:sh = echo "ERROR: PLEASE USE GNU VERSION OF MAKE"; exit 33

ifndef J2SE_TOPDIR
  J2SE_TOPDIR=$(BUILDDIR)/..
endif
ifndef J2SE_SHARED_DIR
  J2SE_SHARED_DIR=$(J2SE_TOPDIR)/make/common/shared
endif

include $(J2SE_SHARED_DIR)/Platform.gmk

TOPDIR=$(BUILDDIR)/..

include $(J2SE_TOPDIR)/make/common/CancelImplicits.gmk

# Historically PLATFORM_SRC used to be src/$(PLATFORM), but we switched it to
# src/solaris so if you want to build on Linux you didn't need a src/linux
# directory.  In an ideal world it would be called src/genunix but we are not
# there yet.
#
ifndef SHARE_SRC
  SHARE_SRC    = $(J2SE_TOPDIR)/src/share
endif

# Files that cannot be included in the OpenJDK distribution are
# collected under a parent directory which contains just those files.
ifndef CLOSED_SRC
  CLOSED_SRC  = $(J2SE_TOPDIR)/src/closed
endif

# If we have no closed directory, force it to an openjdk build
CLOSED_SRC_DIR_EXISTS := $(shell \
  if [ -d $(CLOSED_SRC) ] ; then \
    echo true; \
  else \
    echo false; \
  fi)
ifeq ($(CLOSED_SRC_DIR_EXISTS), false)
  OPENJDK = true
endif

# Check for strange explicit settings (change to empty or true)
ifdef OPENJDK
  ifeq ($(OPENJDK),false)
    # Silently treat as not defined
    OPENJDK =
  else
    ifneq ($(OPENJDK),true)
      dummy := $(warning "WARNING: OPENKJDK=$(OPENJDK) being treated as true")
      OPENJDK = true
    endif
  endif
endif

# Define where closed directories are
ifdef OPENJDK
  CLOSED_SRC =
  CLOSED_SHARE_SRC =
else
  ifndef CLOSED_SHARE_SRC
    CLOSED_SHARE_SRC    = $(CLOSED_SRC)/share
  endif
endif

# If OPENJDK is defined, we may still need to use some native libraries that
# exist only as part of the closed source. If the closed sources are not
# available, the libraries must have been pre-built. Since these libraries
# and the JDK internal interfaces to these are reasonably stable this is not
# a significant problem. But we do need to provide a way to locate them,
# including a way to point to a new one when there have been changes.
# Use a similar mechanism as used to locate the VM. Allow overrides
# of the path (useful for builds of multiple architectures), and
# to specify the precise directory, useful for single architecture builds
# which is what most external developers will likely prefer.
#
# But since these have to have been built at some point, they probably
# should be built under the OPENJDK target with access to the closed sources
# To that end a mechanism is provided to override this behaviour and
# the libraries will be built, rather than looking for pre-built ones.
# Although these variables are then available to the Makefiles for all
# libraries, only the ones that specify USE_CLOSED_LIB will copy them.
# The actual copying is according to rules in Library.gmk
# The logic ends up being a bit complicated but important goals are that
# - internally all platforms can be built without setting anything in the case
# that the previous promoted build can be used
# - externally a developer has to set just one variable to point either to a
# complete JRE or more probably to a directory containing just the required
# native closed libs and a jar file containing just the closed classes.
# In this latter case, ALT_CLOSED_LIB_DIR is the location of the required
# files: native libraries and a jar file containing compiled java classes.
# If necessary the latter can be separately overridden
# Usage notes :
# ALT_CLOSED_BUILD_PATH points to a directory containing builds of
# multiple architectures named using the standard conventions
# This is useful for build scripts that need to build multiple architectures
# of the OpenJDK against multiple builds of the 'production' JDK.
# This defaults to the location of the current promoted build.
# 
# ALT_CLOSED_JDK_IMPORT_PATH points to the top-level of a specific platform
# JDK image.
#
# ALT_CLOSED_LIB_DIR points to a directory containing precisely the
# binaries needed to build. This is created by the target
# gnumake closed-binaries-dir
# after a full JDK build is completed. This creates a directory at
# the top-level of the build called 'closed' The directory will contain
# shared objects and a jar archive named 'closed.jar'
#
# ALT_CLOSED_JAR_FILE is probably rarely needed. It can be used
# to identify the exact jar file to be used.
# The precedence is that
# 1. ALT_CLOSED_JAR_FILE overrides any other location of the classes
# 2. ALT_CLOSED_LIB_DIR overrides any other location of the shared objects.
# 3. In the absence of the first two, ALT_CLOSED_JDK_IMPORT_PATH is
# used to locate classes and shared objects
# 4. In the additional absence of ALT_CLOSED_JDK_IMPORT_PATH, its
# location is derived from ALT_CLOSED_BUILD_PATH
# 5. If none of these are specified then the current promoted build
# location is presumed, and this will work only if you have access to
# /java/re via the standard NFS or windows drive mounts.
ifdef OPENJDK

  ifdef ALT_CLOSED_BUILD_PATH
    CLOSED_BUILD_PATH = $(ALT_CLOSED_BUILD_PATH)
  else
    CLOSED_BUILD_PATH = $(PROMOTED_BUILD_BINARIES)
  endif

  ifdef ALT_CLOSED_JDK_IMPORT_PATH
     CLOSED_JDK_IMPORT_PATH = $(ALT_CLOSED_JDK_IMPORT_PATH)
  else
     CLOSED_JDK_IMPORT_PATH = $(CLOSED_BUILD_PATH)/$(PLATFORM)-$(ARCH)
  endif

  ifdef ALT_CLOSED_LIB_DIR
    CLOSED_LIB_DIR  = $(ALT_CLOSED_LIB_DIR)
  else
    ifeq ($(PLATFORM), windows)
      CLOSED_LIB_DIR = $(CLOSED_JDK_IMPORT_PATH)/jre/bin
    else
      CLOSED_LIB_DIR = $(CLOSED_JDK_IMPORT_PATH)/jre/lib/$(LIBARCH)
    endif
  endif

  ifdef ALT_CLOSED_JAR_FILE
    CLOSED_JAR_FILE = $(ALT_CLOSED_JAR_FILE)
  else
    ifdef ALT_CLOSED_LIB_DIR
      CLOSED_JAR_FILE = $(ALT_CLOSED_LIB_DIR)/closed.jar
    else
      CLOSED_JAR_FILE = $(CLOSED_JDK_IMPORT_PATH)/jre/lib/rt.jar
    endif
  endif
endif # OPENJDK

# Default output directory
ifdef OPENJDK
_OUTPUTDIR=$(J2SE_TOPDIR)/build/$(PLATFORM)-$(ARCH)$(OPENJDK_SUFFIX)
else
_OUTPUTDIR=$(J2SE_TOPDIR)/build/$(PLATFORM)-$(ARCH)
endif

#
# Java tools. 
# The standard build procedure is to use the generated tools
# to build the product. When build the J2RE only the tools
# are not generated, so the bootstrap ones must be used. The
# bootstrap tools are also retained for cross-compiling (currently 
# only done with win64). 
#
ifdef J2RE_ONLY
  USE_ONLY_BOOTDIR_TOOLS = true
endif

#
# Motif is should not be built with the openjdk target.
# Set this before including the platform definitions.
#
ifndef OPENJDK
  ifndef MOTIF_REQUIRED
    MOTIF_REQUIRED = true
  endif
endif 

#
# Get platform definitions
#

include $(J2SE_TOPDIR)/make/common/Defs-$(PLATFORM).gmk

#
# Localizations for the different parts of the product beyond English
#

J2RE_LOCALES   = de es fr it ja ko sv zh_CN zh_TW zh_HK
PLUGIN_LOCALES = de es fr it ja ko sv zh_CN zh_TW zh_HK
J2SDK_LOCALES  = ja zh_CN

#
# A list of locales we support but don't have resource files.
# This is defined to optimize the search of resource bundles.
#
J2RE_NONEXIST_LOCALES = en en_US de_DE es_ES fr_FR it_IT ja_JP ko_KR sv_SE zh

#
# All libraries except libjava and libjvm itself link against libjvm and
# libjava, the latter for its exported common utilities.  libjava only links
# against libjvm.  Programs' makefiles take their own responsibility for
# adding other libs.
#
ifdef PACKAGE
# put JAVALIB first, but do not lose any platform specific values....
  LDLIBS_COMMON = $(JAVALIB)
endif # PACKAGE

#
# Libraries that must appear ahead of libc.so on the link command line
#
ifdef PROGRAM

  ifeq ($(PLATFORM), solaris)
    LDLIBS_COMMON = -lthread -ldl
  endif

  ifeq ($(PLATFORM), linux)
    LDLIBS_COMMON = -ldl
  endif

endif # PROGRAM

LDLIBS_COMMON += $(EXTRA_LIBS)

TARGDIR      = 

#
# Default is to build, not import native binaries
#
ifndef IMPORT_NATIVE_BINARIES
  IMPORT_NATIVE_BINARIES=false
endif
# If importing libraries in, no incremental builds
ifeq ($(IMPORT_NATIVE_BINARIES),true)
 INCREMENTAL_BUILD=false
endif

#
# Default for INCREMENTAL_BUILD
#
ifndef INCREMENTAL_BUILD
 INCREMENTAL_BUILD=false
endif

# for generated libraries
LIBDIR              = $(OUTPUTDIR)/lib
ABS_LIBDIR          = $(ABS_OUTPUTDIR)/lib
# for ext jre files
EXTDIR              = $(LIBDIR)/ext
# for generated include files
INCLUDEDIR          = $(OUTPUTDIR)/include
# for generated class files
CLASSBINDIR         = $(OUTPUTDIR)/classes
# for generated source files
GENSRCDIR           = $(OUTPUTDIR)/gensrc
# for generated demo
DEMODIR             = $(OUTPUTDIR)/demo
# for sample code
SAMPLEDIR           = $(OUTPUTDIR)/sample
# for generated documentation
DOCSDIR             = $(OUTPUTDIR)/docs$(DOCSDIRSUFFIX)
DOCSDIRSUFFIX       =

# The MESSAGE, WARNING and ERROR files are used to store sanityck and 
# SCCS check messages, warnings and errors. 
ifndef ERROR_FILE
  ERROR_FILE   = $(OUTPUTDIR)/sanityCheckErrors.txt
endif
ifndef WARNING_FILE
  WARNING_FILE = $(OUTPUTDIR)/sanityCheckWarnings.txt
endif
ifndef MESSAGE_FILE
  MESSAGE_FILE = $(OUTPUTDIR)/sanityCheckMessages.txt
endif

JDK_IMAGE_DIR = $(ABS_OUTPUTDIR)/j2sdk-image
JRE_IMAGE_DIR = $(ABS_OUTPUTDIR)/j2re-image

#where the demo source can be found
DEMOSRCDIR          = $(SHARE_SRC)/demo

# An attempt is made to generate unique enough directories for the
# generated files to not have name collisisons. Most build units
# defines PRODUCT (except Release.gmk), but then they may or may 
# not define PACKAGE, THREADIR (only HPI uses this), PROGRAM, and 
# LIBRARY. This code chunk attempts to generate a unique 
# OBJDIR/CLASSHDRDIR for each build unit based on which of those 
# values are set within each build unit.

UNIQUE_LOCATION_STRING = tmp

ifneq ($(PRODUCT),)
  UNIQUE_LOCATION_STRING += /$(PRODUCT)
endif

ifneq ($(PACKAGE),)
  UNIQUE_LOCATION_STRING += /$(PACKAGE)
endif

ifneq ($(PROGRAM),)
  UNIQUE_LOCATION_STRING += /$(PROGRAM)
endif

ifneq ($(LIBRARY),)
  ifneq ($(LIBRARY_OUTPUT),)
    UNIQUE_LOCATION_STRING += /$(LIBRARY_OUTPUT)
  else
    UNIQUE_LOCATION_STRING += /$(LIBRARY)
  endif
endif

ifneq ($(THREADDIR),)
  UNIQUE_LOCATION_STRING += /$(THREADDIR)
endif

# the use of += above makes a space separated list which we need to 
# remove for filespecs.
#
NULLSTRING :=
ONESPACE := $(NULLSTRING) # space before this comment is required.
UNIQUE_PATH = $(subst $(ONESPACE),,$(UNIQUE_LOCATION_STRING))

# TEMPDIR is a unique general purpose directory
# need to use 'override' because GNU Make on Linux exports the wrong
# value.
override TEMPDIR      = $(OUTPUTDIR)/$(UNIQUE_PATH)
override ABS_TEMPDIR  = $(ABS_OUTPUTDIR)/$(UNIQUE_PATH)

# This must be created right away for pattern rules in Sanity.gmk to work.
dummy1:=$(shell $(MKDIR) -p $(TEMPDIR))
dummy2:=$(shell $(MKDIR) -p $(TEMP_DISK))

# OBJDIRNAME is the name of the directory where the object code is to
#   be placed. It's name depends on whether the data model architecture 
#   is 32-bit or not.
ifneq ($(ARCH_DATA_MODEL), 32)
  OBJDIRNAME  = obj$(ARCH_DATA_MODEL)$(OBJDIRNAME_SUFFIX)
else
  OBJDIRNAME  = obj$(OBJDIRNAME_SUFFIX)
endif
OBJDIR      = $(TEMPDIR)/$(OBJDIRNAME)

# CLASSHDRDIR is where the generated C Class Header files go.
CLASSHDRDIR = $(TEMPDIR)/CClassHeaders

#
# CLASSDESTDIR can be used to specify the directory where generated classes
# are to be placed. The default is CLASSBINDIR.
#
ifndef CLASSDESTDIR
CLASSDESTDIR = $(CLASSBINDIR)
endif

INCLUDES = -I. -I$(CLASSHDRDIR) \
	$(patsubst %,-I%,$(subst $(CLASSPATH_SEPARATOR), ,$(VPATH.h))) $(OTHER_INCLUDES)
OTHER_CPPFLAGS = $(INCLUDES)


#
# vpaths.  These are the default locations searched for source files.
# GNUmakefiles of individual areas often override the default settings.
# There are no longer default vpath entries for C and assembler files
# so we can ensure that libraries don't get their hands on JVM files.
#
# We define an intermediate variable for Java files because
# we use its value later to help define $SOURCEPATH

VPATH0.java = $(GENSRCDIR)$(CLASSPATH_SEPARATOR)$(PLATFORM_SRC)/classes$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/classes
ifdef OPENJDK
  VPATH.java = $(VPATH0.java)
else
  VPATH.java = $(VPATH0.java)$(CLASSPATH_SEPARATOR)$(CLOSED_PLATFORM_SRC)/classes$(CLASSPATH_SEPARATOR)$(CLOSED_SHARE_SRC)/classes
endif
vpath %.java $(VPATH.java)
vpath %.class $(CLASSBINDIR)
vpath %.$(OBJECT_SUFFIX) $(OBJDIR)

#
# VPATH.h is used elsewhere to generate include flags.  By default, 
# anyone has access to the include files that the JVM area exports,
# namely jni.h, jvm.h, and jni_utils.h, plus their platform-specific
# relatives.
#
VPATH.h =   $(PLATFORM_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/include$(CLASSPATH_SEPARATOR)$(PLATFORM_SRC)/javavm/include
vpath %.h   $(VPATH.h)

#
# Used in two ways: helps link against libjava.so. Also if overridden
# determines where your shared library is installed.
#
ifndef LIB_LOCATION
  LIB_LOCATION    =  $(LIBDIR)/$(LIBARCH)
endif

#
# Java header and stub variables
#
CLASSHDRS     = $(patsubst %,$(CLASSHDRDIR)/%.h,$(subst .,_,$(CLASSES.export)))
CLASSSTUBOBJS = classstubs.$(OBJECT_SUFFIX)
STUBPREAMBLE  = $(INCLUDEDIR)/StubPreamble.h

#
# Classpath seen by javac (different from the one seen by the VM
# running javac), and useful variables.
#
SOURCEPATH	= $(VPATH.java)
PKG		= $(shell $(EXPR) $(PACKAGE) : '\([a-z]*\)')
PKGDIR		= $(subst .,/,$(PACKAGE))

#
# Memory related -J flags that all uses of java tools should use.
#
JAVA_MEM_FLAGS   = -Xmx$(MAX_VM_MEMORY)m
ifeq ($(ARCH), ia64)
  # Special flags for javac on ia64 to work around a VM problem with
  #   bad code generation during inlining (what version had this problem?):
  #   Suspect this may not be needed anymore.
  JAVA_MEM_FLAGS   += -Xms$(MAX_VM_MEMORY)m -XX:-Inline
else
  JAVA_MEM_FLAGS   += -Xms$(MIN_VM_MEMORY)m -XX:PermSize=32m -XX:MaxPermSize=160m
endif
JAVA_MEM_JFLAGS   = $(JAVA_MEM_FLAGS:%=-J%)

# 
# All java tools (javac, javah, and javadoc) run faster with certain java
#    options, this macro should be used with all these tools.
#    In particular, the client VM makes these tools run faster when
#    it's available.
#
ADD_CLIENT_VM_OPTION = false
ifeq ($(PLATFORM), solaris)
  ADD_CLIENT_VM_OPTION = true
else
  ifeq ($(ARCH_DATA_MODEL), 32)
    ADD_CLIENT_VM_OPTION = true
  endif
endif
ifeq ($(ADD_CLIENT_VM_OPTION), true)
  JAVA_JVM_FLAGS += -client
endif
ifdef USE_HOTSPOT_INTERPRETER_MODE
  JAVA_JVM_FLAGS += -Xint
endif

JAVA_JVM_JFLAGS   = $(JAVA_JVM_FLAGS:%=-J%)
JAVA_TOOLS_FLAGS  = $(JAVA_JVM_FLAGS) $(JAVA_MEM_FLAGS)
JAVA_TOOLS_JFLAGS = $(JAVA_JVM_JFLAGS) $(JAVA_MEM_JFLAGS)
# The javac and javah are the ones that need the larger stacksize
JAVAC_FLAGS       = $(STACKSIZEFLAG) $(JAVA_JVM_FLAGS) $(JAVA_MEM_FLAGS)
# If all compiler warnings should be fatal errors, add the -Werror option
ifeq ($(COMPILER_WARNINGS_FATAL), true)
  JAVAC_FLAGS    += -Werror
endif
JAVAC_JFLAGS      = $(JAVAC_FLAGS:%=-J%)
# The jar command just gets the memory settings (jar -J options are special)
JAR_JFLAGS        = $(JAVA_JVM_JFLAGS) $(JAVA_MEM_JFLAGS)

# JAVA_TOOLS_DIR is defined in common/shared/Defs.gmk
#    Normally this will refer to the tools being built, but could refer to
#    the boot tools in some cases where the tools being built cannot be used
#    to build itself (like in a cross compilation situation).
JAVA		= $(JAVA_TOOLS_DIR)/java $(JAVA_TOOLS_FLAGS)
JAVAC		= $(JAVA_TOOLS_DIR)/javac $(JAVAC_JFLAGS)
JAR		= $(JAVA_TOOLS_DIR)/jar
ABS_JAR         = $(ABS_JAVA_TOOLS_DIR)/jar
ABS_JAVA        = $(ABS_JAVA_TOOLS_DIR)/java $(JAVA_TOOLS_FLAGS)
JAVADOC	        = $(JAVA_TOOLS_DIR)/javadoc $(JAVA_TOOLS_JFLAGS)
APT		= $(JAVA_TOOLS_DIR)/apt $(JAVA_TOOLS_JFLAGS)
JAVAH_CMD   	= $(JAVA_TOOLS_DIR)/javah $(JAVAC_JFLAGS)
NATIVE2ASCII    = $(JAVA_TOOLS_DIR)/native2ascii $(JAVA_TOOLS_JFLAGS)
RMIC		= $(JAVA_TOOLS_DIR)/rmic $(JAVA_TOOLS_JFLAGS)
  
#
# 64-bit builds require a larger thread stack size.
#
ifeq ($(ARCH_DATA_MODEL), 32)
  STACKSIZE	= 768
else
  STACKSIZE	= 1536
endif
STACKSIZEFLAG	= -XX:ThreadStackSize=$(STACKSIZE)

#
# Invoking the Java compiler.   In leaf makefiles, choose as follows:
#  -- Use JAVAC if you want to take full control of what options get
#     passed to javac.
#  -- Use JAVAC_CMD if you want to take the defaults given to you.
#
JAVAC_SRC_FLAG     = -sourcepath "$(SOURCEPATH)"
LANGUAGE_VERSION   = -source 1.5
CLASS_VERSION      = -target 5
JAVAC_DST_FLAG     = -d $(CLASSDESTDIR)

ifdef DEMOS
  JAVAC_BCP        = $(BOOTCLASSPATH)
else
  JAVAC_BCP        = "$(LIBDIR)/jce.jar"
endif

JAVAC_CP           = $(CLASSBINDIR)
JAVAC_CLS_FLAG     = -classpath $(JAVAC_CP) -bootclasspath $(JAVAC_BCP)

JAVAC_ENCODINGFLAGS=-encoding ascii
JAVAC_PATHFLAGS    = $(JAVAC_CLS_FLAG) $(JAVAC_SRC_FLAG) $(JAVAC_DST_FLAG)
JAVACFLAGS_COMMON  = $(JAVAC_PATHFLAGS) $(JAVAC_ENCODINGFLAGS)

# Any debug build should include all debug info inside the classfiles
ifeq ($(VARIANT), DBG)
  DEBUG_CLASSFILES = true
endif
ifeq ($(DEBUG_CLASSFILES),true)
  JAVACFLAGS_COMMON += -g
endif

JAVACFLAGS	   = $(JAVACFLAGS_COMMON) $(OTHER_JAVACFLAGS)
JAVAC_CMD 	   = $(JAVAC) $(JIT_OPTION) $(JAVACFLAGS) $(LANGUAGE_VERSION) $(CLASS_VERSION)

#
# The bootstrap java compiler. Use must be restricted to BOOTSUBDIRS
# variable in $(J2SE_TOPDIR)/make/java/Makefile.
#
# WARNING: Use of the bootstrap compiler should be restricted to
# classes which will not be part of the final deliverable.  For
# example, java.lang classes compiled with this compiler should never
# reach rt.jar.  Currently, this is not the case.
#
# Ideally, bootstrapping should be a staged process:
#
# Stage 1: The BOOTDIR javac is used to build javac.
#
# The stage 1 compiler can be used to generate a compiler and any
# required classes which can be executed on the product VM:
#
# Stage 2: compiler and any classes required by the compiler are
#          produced using the compiler from previous stage as part of
#          the build process.  The classes produced during this stage
#          should not be saved in $(CLASSDESTDIR).  The VM used to run
#          the stage 1 compiler is $(JAVA_BOOT).
#
# Stage 3: Basically, repeat stage 2.  However, this time the stage 2
#          compiler is run on the new VM and used to compile the stage
#          3 compiler.
#
# Stage 4: Repeat stage 3, but use stage 3 compiler.  This is sanity
#          check which is necessary only to catch potential bootstrap
#          problems.
#
# After completing stage 4 the resulting compiler and libraries are
# used during the rest of the build process.  Note that this results
# in a "stage 5" version of the compiler which eventually will be put
# into tools.jar of the final deliverable.
#
# In summary:
# Stage 1: is provided by the compiler team.
# Stage 2: run stage 1 on boot VM to produce stage 2.
# Stage 3: run stage 2 on new VM to produce stage 3.
# Stage 4: run stage 3 on new VM to produce stage 4.
# Regular build: use stage 4 on new VM to produce the JDK.
#
JAVA_BOOT      = $(BOOTDIR)/bin/java $(JAVA_TOOLS_FLAGS)
JAVAC_BOOT     = $(BOOTDIR)/bin/javac $(JAVAC_JFLAGS) -target 5
JAVAC_BOOT_CMD = $(JAVAC_BOOT) $(JAVACFLAGS) $(LANGUAGE_VERSION)
JAVAH_BOOT     = $(BOOTDIR)/bin/javah $(JAVAC_JFLAGS)
JAVAH_BOOT_CMD = $(JAVAH_BOOT)
JAR_BOOT       = $(BOOTDIR)/bin/jar

# Setting USEBOOTENV in the environment allows using the boot environment
# for all targets - very useful to allow a merge to proceed while debugging
# jvm failures.

ifdef USEBOOTENV
  JAVAC_CMD	= $(JAVAC_BOOT_CMD)
  JAVAH_CMD   = $(JAVAH_BOOT_CMD)
endif

#
# Set opt level to ALT_OPT if set otherwise _OPT
#
POPT = $(_OPT$(ALT_OPT))$(ALT_OPT)

#
# Convenient macros
#

# Prepare $@ target, remove old one and making sure directory exists
define prep-target
$(MKDIR) -p $(@D)
$(RM) $@
endef

# Simple install of $< file to $@
define install-file
$(prep-target)
$(CP) $< $@
endef

# Cleanup rule for after debug java run (hotspot.log file is left around)
#   (This could be an old leftover file in a read-only area, use the @- prefix)
HOTSPOT_LOG_NAME = hotspot.log
define java-vm-cleanup
if [ -w $(HOTSPOT_LOG_NAME) ] ; then $(RM) $(HOTSPOT_LOG_NAME); fi
endef

# Default make settings for processing SUBDIRS with clobber or clean names
SUBDIRS_MAKEFLAGS-clobber = INCREMENTAL_BUILD=false
SUBDIRS_MAKEFLAGS-clean   = INCREMENTAL_BUILD=false

# Current directory
CURRENT_DIRECTORY := $(shell $(PWD))

# If no timing wanted, we need to define these as empty
ifdef NO_TIMING

TIMING_ID:=NA

define TIMING_start
t=0:0:0:0
endef

define TIMING_end
time_used=0
endef

else # NO_TIMING

# Default timing id
TIMING_ID:=$(shell $(BASENAME) $(CURRENT_DIRECTORY))

# Timing start (must be used in same shell, e.g. same command line)
#    Defines the shell variable $1 to have the start time.
define TIMING_start
$1=`$(DATE) +%j:%H:%M:%S`
endef

# Timing end (must be used in same shell, e.g. same command line)
#    Expects shell variable $1 to have been defined as the start time.
#    Expects shell variable $2 to have timing id string
#    Sets total_seconds shell variable as the total seconds used.
#    Sets time_used shell variable to contain format "%dh%dm%ds"
define TIMING_end
begTime="$${$1}"; \
timing_id="$${$2}"; \
endTime=`$(DATE) +%j:%H:%M:%S`; \
d1=`$(ECHO) $${begTime} | $(CUT) -d':' -f1 | $(SED) -e 's@^0*@@'`; \
if [ "$${d1}" = "" ] ; then d1=0; fi; \
h1=`$(ECHO) $${begTime} | $(CUT) -d':' -f2 | $(SED) -e 's@^0*@@'`; \
if [ "$${h1}" = "" ] ; then h1=0; fi; \
m1=`$(ECHO) $${begTime} | $(CUT) -d':' -f3 | $(SED) -e 's@^0*@@'`; \
if [ "$${m1}" = "" ] ; then m1=0; fi; \
s1=`$(ECHO) $${begTime} | $(CUT) -d':' -f4 | $(SED) -e 's@^0*@@'`; \
if [ "$${s1}" = "" ] ; then s1=0; fi; \
d2=`$(ECHO) $${endTime} | $(CUT) -d':' -f1 | $(SED) -e 's@^0*@@'`; \
if [ "$${d2}" = "" ] ; then d2=0; fi; \
h2=`$(ECHO) $${endTime} | $(CUT) -d':' -f2 | $(SED) -e 's@^0*@@'`; \
if [ "$${h2}" = "" ] ; then h2=0; fi; \
m2=`$(ECHO) $${endTime} | $(CUT) -d':' -f3 | $(SED) -e 's@^0*@@'`; \
if [ "$${m2}" = "" ] ; then m2=0; fi; \
s2=`$(ECHO) $${endTime} | $(CUT) -d':' -f4 | $(SED) -e 's@^0*@@'`; \
if [ "$${s2}" = "" ] ; then s2=0; fi; \
t1_secs=`$(EXPR) $${d1} '*' 60 '*' 60 '*' 24 '+' $${h1} '*' 60 '*' 60 \
		 '+' $${m1} '*' 60 '+' $${s1}`; \
t2_secs=`$(EXPR) $${d2} '*' 60 '*' 60 '*' 24 '+' $${h2} '*' 60 '*' 60 \
		 '+' $${m2} '*' 60 '+' $${s2}`; \
total_seconds=`$(EXPR) $${t2_secs} '-' $${t1_secs}`; \
if [ "$${total_seconds}" -lt 0 ] ; then total_seconds=0; fi; \
t_hour=`$(EXPR) $${total_seconds} '/' '(' 60 '*' 60 ')'`h; \
t_min=`$(EXPR) '(' $${total_seconds} '%' '(' 60 '*' 60 ')' ')' '/' 60`m; \
t_sec=`$(EXPR) $${total_seconds} '%' 60`s; \
time_used=$${t_sec}; \
if [ "$${t_hour}" != "0h" ] ; then \
time_used=$${t_hour}$${t_min}$${t_sec}; \
elif [ "$${t_min}" != "0m" ] ; then \
time_used=$${t_min}$${t_sec}; \
else \
time_used=$${t_sec}; \
fi; \
$(PRINTF) "  Timing: %05d seconds or %s for %s\n" \
    $${total_seconds} $${time_used} $${timing_id}
endef

endif # NO_TIMING

# Given a SUBDIRS list, cd into them and make them
#   SUBDIRS_MAKEFLAGS      Make settings for a subdir make
#   SUBDIRS_MAKEFLAGS-$@   Make settings specific to this target
define SUBDIRS-loop
@$(ECHO) "Begin Processing SUBDIRS: $(SUBDIRS)"
@for i in DUMMY $(SUBDIRS) ; do \
  if [ "$$i" != "DUMMY" ] ; then \
    $(ECHO) ">>>Recursively making "$$i" "$@" @ `$(DATE)` ..."; \
    timing_id="$(TIMING_ID)-`$(BASENAME) $${i}`"; \
    $(call TIMING_start,startTime); \
    curDir=$(CURRENT_DIRECTORY); \
    $(CD) $$i; $(MAKE) $@ TIMING_ID=$${timing_id} \
			  $(SUBDIRS_MAKEFLAGS) \
			  $(SUBDIRS_MAKEFLAGS-$@) \
			  FULL_VERSION=$(FULL_VERSION) \
			  RELEASE=$(RELEASE) || exit 1; \
	       $(CD) $${curDir}; \
    $(call TIMING_end,startTime,timing_id); \
    $(ECHO) "<<<Finished Recursively making "$$i" "$@" @ `$(DATE)`." ; \
  fi ; \
done
@$(ECHO) "Done Processing SUBDIRS: $(SUBDIRS)"
endef

# Given a OTHERSUBDIRS list, cd into them and make them (extra loop define)
#   OTHERSUBDIRS_MAKEFLAGS      Make settings for a subdir make
define OTHERSUBDIRS-loop
@$(ECHO) "Begin Processing OTHERSUBDIRS: $(OTHERSUBDIRS)"
@for i in DUMMY $(OTHERSUBDIRS) ; do \
  if [ "$$i" != "DUMMY" ] ; then \
    $(ECHO) ">>>Recursively making "$$i" "$@" @ `$(DATE)` ..."; \
    timing_id="$(TIMING_ID)-`$(BASENAME) $${i}`"; \
    $(call TIMING_start,startTime); \
    curDir=$(CURRENT_DIRECTORY); \
    $(CD) $$i; $(MAKE) $@ TIMING_ID=$${timing_id} \
		          $(OTHERSUBDIRS_MAKEFLAGS) \
			  FULL_VERSION=$(FULL_VERSION) \
			  RELEASE=$(RELEASE) || exit 1; \
	       $(CD) $${curDir}; \
    $(call TIMING_end,startTime,timing_id); \
    $(ECHO) "<<<Finished Recursively making "$$i" "$@" @ `$(DATE)`." ; \
  fi ; \
done
@$(ECHO) "Done Processing OTHERSUBDIRS: $(OTHERSUBDIRS)"
endef

#
# Create BYFILE OPT and DBG settings, if CFLAGS_OPT/foobar.o is set then it is
#    used for this file, otherwise the default settings are used.
#
CFLAGS_$(VARIANT)/BYFILE    = $(CFLAGS_$(VARIANT)/$(@F)) \
                              $(CFLAGS_$(VARIANT)$(CFLAGS_$(VARIANT)/$(@F)))
CXXFLAGS_$(VARIANT)/BYFILE  = $(CXXFLAGS_$(VARIANT)/$(@F)) \
                              $(CXXFLAGS_$(VARIANT)$(CXXFLAGS_$(VARIANT)/$(@F)))

#
# Tool flags
#
ASFLAGS         = $(ASFLAGS_$(VARIANT)) $(ASFLAGS_COMMON) $(OTHER_ASFLAGS)
CFLAGS          = $(CFLAGS_$(VARIANT)/BYFILE)   $(CFLAGS_COMMON) $(OTHER_CFLAGS)
CXXFLAGS        = $(CXXFLAGS_$(VARIANT)/BYFILE) $(CXXFLAGS_COMMON) $(OTHER_CXXFLAGS)
CPPFLAGS        = $(CPPFLAGS_$(VARIANT)) $(CPPFLAGS_COMMON) $(OTHER_CPPFLAGS) \
		  $(DEFINES) $(OPTIONS:%=-D%)
LDFLAGS         = $(LDFLAGS_$(VARIANT)) $(LDFLAGS_COMMON) $(OTHER_LDFLAGS)
LDLIBS          = $(OTHER_LDLIBS) $(LDLIBS_$(VARIANT)) $(LDLIBS_COMMON)
LINTFLAGS       = $(LINTFLAGS_$(VARIANT)) $(LINTFLAGS_COMMON) \
		  $(OTHER_LINTFLAGS)

# this should be moved into Defs-<platform>.gmk.....
ifeq ($(PLATFORM), windows)
  VERSION_DEFINES = -DRELEASE="\"$(RELEASE)\"" -DFULL_VERSION="\"$(FULL_VERSION)\""
else
  VERSION_DEFINES = -DRELEASE='"$(RELEASE)"' -DFULL_VERSION='"$(FULL_VERSION)"'
endif

# Note: As a rule, GNU Make rules should not appear in any of the 
# Defs*.gmk files. These were added for Kestrel-Solaris and do address
# a TeamWare bug. They should be moved elsewhere for Merlin.
# 
#  Override gnumake built-in rules which do sccs get operations badly.
#  (They put the checked out code in the current directory, not in the
#  directory of the original file.) 
# Since this is a symptom of a teamware failure, complain and die on the spot.

# This message immediately goes to stdout and the build terminates.
define SCCS-trouble
$(error  \
"ERROR: File $@ referenced while building in $(CURRENT_DIRECTORY) \
 is out of date with respect to its SCCS file $<. \
 This can happen from an unresolved Teamware conflict, a file movement, or \
 a failure in which SCCS files are updated but the 'sccs get' was not done. \
 You should double check for other out of date files in your workspace. \
 Or run: cd $(TOPDIR) && $(MAKE) sccs_get")
endef

%:: s.%
	@$(SCCS-trouble)
%:: SCCS/s.%
	@$(SCCS-trouble)
	@$(ECHO) "         is out of date with respect to its SCCS file." >> $(WARNING_FILE)
	@$(ECHO) "         This file may be from an unresolved Teamware conflict." >> $(WARNING_FILE)
	@$(ECHO) "         This is also a symptom of a Teamware bringover/putback failure" >> $(WARNING_FILE)
	@$(ECHO) "         in which SCCS files are updated but not checked out." >> $(WARNING_FILE)
	@$(ECHO) "         Check for other out of date files in your workspace." >> $(WARNING_FILE)
	@$(ECHO) "" >> $(WARNING_FILE)
	@#exit 666

ifdef INSANE
  export INSANE
endif

ifdef ALT_COPYRIGHT_YEAR
  COPYRIGHT_YEAR = $(ALT_COPYRIGHT_YEAR)
else
  COPYRIGHT_YEAR = $(shell $(DATE) '+%Y')
endif

# Install of imported file (JDK_IMPORT_PATH, or some other external location)
define install-import-file
@$(ECHO) "ASSEMBLY_IMPORT: $@"
$(install-file)
endef

# Install of closed files into an openjdk build image (CLOSED_JDK_IMPORT_PATH)
define install-closed-file
@$(ECHO) "ASSEMBLY_EXCEPTION: $(@F)"
$(install-file)
endef

# Install closed classes into CLASSDESTDIR (CLOSED_JDK_IMPORT_PATH rt.jar)
#    Example: $(call install-closed-classes,files_or_dirs)
define install-closed-classes
$(MKDIR) -p $(CLASSDESTDIR)
($(CD) $(CLASSDESTDIR) && $(JAR_BOOT) xvf $(CLOSED_JAR_FILE) $1) \
 | $(SED) -e "s/^extracted:/ASSEMBLY_EXCEPTION:/"
endef

.PHONY: all build clean clobber