blob: 25e1bd0905c733c0b9891cf8f16213c8250503df [file] [log] [blame]
#
# Copyright (c) 2004, 2011, Oracle and/or its affiliates. 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. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
LINK.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
# JDK Demo building jar file.
# Some names are defined with LIBRARY inside the Defs.gmk file
LIBRARY=$(DEMONAME)
OBJDIR=$(TEMPDIR)/$(DEMONAME)
# Input:
# DEMONAME - name of the demo
# DEMO_ROOT - path to root of all demo files
# DEMO_DESTDIR - path to final demo destination directory
#
# Optional Input:
# DEMO_SRCDIR - path to source if different from DEMO_ROOT
# DEMO_PSRCDIR - path to additional platform specific source
# DEMO_PKGDIR - sub directory of sources we want
# DEMO_TOPFILES - names of top-level files relative to DEMO_ROOT
# DEMO_MAINCLASS - name of the main class for the jar manifest
# DEMO_NATIVECLASS - name of the class with native methods
# DEMO_DESCRIPTOR - name of service file for jar (relative to DEMO_SRCDIR)
# DEMO_EXTRA_SRCDIR - path to directory that holds extra sources to add
# DEMO_EXTRA_FILES - extra sources relative to DEMO_EXTRA_SRCDIR
# DEMO_OBJECTS - extra native object files needed
# DEMO_MANIFEST_ATTR - extra line to add to the jar manifest file
# Assume the source directory is the root directory if not set
ifndef DEMO_SRCDIR
DEMO_SRCDIR = $(DEMO_ROOT)
endif
ifndef DEMO_PKGDIR
DEMO_PKGDIR = .
endif
# Some demos have special needs
ifneq ($(DEMONAME),agent_util)
DEMO_NEEDS_AGENT_UTIL = $(findstring agent_util,$(DEMO_OBJECTS))
endif
ifneq ($(DEMONAME),java_crw_demo)
DEMO_NEEDS_JAVA_CRW_DEMO = $(findstring java_crw_demo,$(DEMO_OBJECTS))
endif
ifeq ($(DEMONAME),hprof)
DEMO_NEEDS_NPT = true
endif
# Place to hold the build area (kind of a temp area)
DEMO_BUILD_AREA = $(DEMOCLASSDIR)/$(PRODUCT)/$(DEMONAME)
# Destination "src" directory
DEMO_BUILD_SRCDIR = $(DEMO_BUILD_AREA)/src
ifndef DEMO_SKIP_SRCZIP
DEMO_BUILD_SRCZIP = $(DEMO_BUILD_AREA)/src.zip
DEMO_SOURCE_ZIP = $(DEMO_DESTDIR)/src.zip
endif
# Place to hold the jar image we are creating
DEMO_JAR_IMAGE = $(DEMO_BUILD_AREA)/jar_image
# The jar manifest file we will create and use
DEMO_MANIFEST = $(DEMO_BUILD_AREA)/manifest.mf
# The list of source files or options we will supply to javac
DEMO_JAVAC_INPUT = $(DEMO_BUILD_AREA)/javac_input.txt
# Any name of javah file
DEMO_JAVAH_FILE = $(DEMO_NATIVECLASS:%=$(DEMO_BUILD_SRCDIR)/%.h)
# Get complete list of files for this demo
ifdef DEMO_PSRCDIR
DEMO_ALL_FILES2 := $(shell ( $(CD) $(DEMO_PSRCDIR) \
&& $(FIND) $(DEMO_PKGDIR) $(SCM_DIRS_prune) -o -type f -print ) \
| $(SED) 's@^\./@@' )
DEMO_ALL_FILES += $(DEMO_ALL_FILES2)
endif
ifdef DEMO_EXTRA_SRCDIR
DEMO_ALL_FILES += $(DEMO_EXTRA_FILES)
endif
DEMO_ALL_FILES1 := $(shell ( $(CD) $(DEMO_SRCDIR) \
&& $(FIND) $(DEMO_PKGDIR) $(SCM_DIRS_prune) -o -type f -print ) \
| $(SED) 's@^\./@@' )
DEMO_ALL_FILES += $(DEMO_ALL_FILES1)
# Just the java sources
DEMO_JAVA_SOURCES = $(filter %.java,$(DEMO_ALL_FILES))
# Just the C and C++ sources
DEMO_C_SRC_FILES = $(filter %.c,$(DEMO_ALL_FILES))
DEMO_CPP_SRC_FILES = $(filter %.cpp,$(DEMO_ALL_FILES))
# All the native source files
DEMO_ALL_NATIVE_SOURCES = $(DEMO_C_SRC_FILES)
DEMO_ALL_NATIVE_SOURCES += $(DEMO_CPP_SRC_FILES)
DEMO_ALL_NATIVE_SOURCES += $(filter %.h,$(DEMO_ALL_FILES))
DEMO_ALL_NATIVE_SOURCES += $(filter %.hpp,$(DEMO_ALL_FILES))
# If we have java sources, then define the jar file we will create
ifndef DEMO_JAR_NAME
DEMO_JAR_NAME = $(DEMONAME).jar
endif
ifneq ($(strip $(DEMO_JAVA_SOURCES)),)
DEMO_JAR = $(DEMO_DESTDIR)/$(DEMO_JAR_NAME)
endif
# If we have native sources, define the native library we will create
ifneq ($(strip $(DEMO_ALL_NATIVE_SOURCES)),)
# Path to native library we will create
DEMO_LIBRARY = \
$(DEMO_DESTDIR)/lib$(ISA_DIR)/$(LIB_PREFIX)$(DEMONAME).$(LIBRARY_SUFFIX)
# C and C++ compiler flags we need to add to standard flags
DEMO_CPPFLAGS += -I$(DEMO_BUILD_SRCDIR)
# If the npt library is used we need to find the npt.h file
ifneq ($(DEMO_NEEDS_NPT),)
# The npt library is delivered as part of the JRE
DEMO_CPPFLAGS += -I$(SHARE_SRC)/npt -I$(PLATFORM_SRC)/npt
endif
# Is the shared agent_util code needed
ifneq ($(DEMO_NEEDS_AGENT_UTIL),)
DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/agent_util.c
DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/agent_util.h
endif
# Is the shared java_crw_demo code needed
ifneq ($(DEMO_NEEDS_JAVA_CRW_DEMO),)
DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/java_crw_demo.c
DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/java_crw_demo.h
endif
# All the native object files we need to build the library
DEMO_OBJECTS += $(DEMO_C_SRC_FILES:%.c=%.$(OBJECT_SUFFIX)) \
$(DEMO_CPP_SRC_FILES:%.cpp=%.$(OBJECT_SUFFIX))
# Linking is special depending on whether we had C++ code or on windows
DEMO_NEEDS_CPP = $(strip $(DEMO_CPP_SRC_FILES))
CPPFLAGS += $(DEMO_CPPFLAGS)
ifeq ($(PLATFORM),windows)
# Note: This is a link with cl.exe, not link.exe, options differ quite
# bit between them.
LINK.demo = $(LINK.c)
LDLIBS.demo = $(EXTRA_LIBS) $(LFLAGS_$(COMPILER_VERSION))
DEMO_VERSION_INFO = $(OBJDIR)/$(LIBRARY).res
LDLIBS.demo += $(DEMO_VERSION_INFO)
else
ifneq ($(DEMO_NEEDS_CPP),)
LINK.demo = $(LINK.cpp)
LDLIBS.demo = $(LIBCXX)
ifeq ($(PLATFORM),solaris)
LDLIBS.demo += -lc
endif
else
LINK.demo = $(LINK.c)
LDLIBS.demo = $(LDLIBS)
endif
endif
endif
# Files that are considered resources (need to be in the jar file)
DEMO_RESOURCES += $(filter-out %.java,$(DEMO_ALL_FILES))
# All destination files (top level readme files and all sources)
# Note: We exclude the topfiles from the src tree.
DEMO_DEST_TOPFILES = $(DEMO_TOPFILES:%=$(DEMO_DESTDIR)/%)
DEMO_FILTERED_SOURCES = $(filter-out $(DEMO_TOPFILES),$(DEMO_ALL_FILES))
DEMO_FULL_SOURCES += $(DEMO_FILTERED_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%)
# Default rule
all: build demo_info
# Used to populate the destination directories
$(DEMO_DESTDIR)/%: $(DEMO_ROOT)/%
$(install-file)
ifneq ($(DEMO_SRCDIR),$(DEMO_ROOT))
$(DEMO_DESTDIR)/%: $(DEMO_SRCDIR)/%
$(install-file)
endif
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/%
$(install-file)
ifdef DEMO_PSRCDIR
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_PSRCDIR)/%
$(install-file)
endif
ifdef DEMO_EXTRA_SRCDIR
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_EXTRA_SRCDIR)/%
$(install-file)
endif
ifneq ($(DEMO_NEEDS_AGENT_UTIL),)
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/../agent_util/%
$(install-file)
endif
ifneq ($(DEMO_NEEDS_JAVA_CRW_DEMO),)
$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/../java_crw_demo/%
$(install-file)
endif
# Jar manifest file
MAINMANIFEST = $(JDK_TOPDIR)/make/tools/manifest.mf
$(DEMO_MANIFEST): $(MAINMANIFEST)
@$(prep-target)
$(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
-e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" \
$(MAINMANIFEST) >> $@
$(ECHO) "Main-Class: $(DEMO_MAINCLASS)" >> $@
ifdef DEMO_MANIFEST_ATTR
$(ECHO) "$(DEMO_MANIFEST_ATTR)" >> $@
endif
# Populating the jar image directory
$(DEMO_JAR_IMAGE)/%: $(DEMO_SRCDIR)/%
$(install-file)
ifdef DEMO_PSRCDIR
$(DEMO_JAR_IMAGE)/%: $(DEMO_PSRCDIR)/%
$(install-file)
endif
ifdef DEMO_EXTRA_SRCDIR
$(DEMO_JAR_IMAGE)/%: $(DEMO_EXTRA_SRCDIR)/%
$(install-file)
endif
ifdef DEMO_DESCRIPTOR
$(DEMO_JAR_IMAGE)/META-INF/services/$(DEMO_DESCRIPTOR): \
$(DEMO_SRCDIR)/$(DEMO_DESCRIPTOR)
$(install-file)
endif
# If we are creating a jar file (we have java code)
ifdef DEMO_JAR
# Input file for javac
$(DEMO_JAVAC_INPUT): $(DEMO_JAVA_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%)
@$(prep-target)
@for i in $(DEMO_JAVA_SOURCES) ; do \
$(ECHO) "$(DEMO_BUILD_SRCDIR)/$$i" >> $@ ; \
done
# Jar file creation
$(DEMO_JAR): \
$(DEMO_JAVAC_INPUT) \
$(DEMO_MANIFEST) \
$(DEMO_DESCRIPTOR:%=$(DEMO_JAR_IMAGE)/META-INF/services/%) \
$(DEMO_RESOURCES:%=$(DEMO_JAR_IMAGE)/%)
@$(prep-target)
$(MKDIR) -p $(DEMO_JAR_IMAGE)
$(JAVAC_CMD) -d $(DEMO_JAR_IMAGE) -sourcepath $(DEMO_BUILD_SRCDIR) \
@$(DEMO_JAVAC_INPUT)
ifeq ($(DEMO_INCL_SRC),true)
$(CP) $(DEMO_JAVA_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%) $(DEMO_JAR_IMAGE)
endif
ifeq ($(DEMO_ONLY_SRC),true)
$(RM) -r $(DEMO_JAR_IMAGE)
$(MKDIR) -p $(DEMO_JAR_IMAGE)
$(CP) -r $(DEMO_BUILD_SRCDIR)/* $(DEMO_JAR_IMAGE)
ifneq ($(DEMO_TOPFILES),)
$(CP) $(DEMO_ROOT)/$(DEMO_TOPFILES) $(DEMO_JAR_IMAGE)
endif
endif
$(BOOT_JAR_CMD) -cfm $@ $(DEMO_MANIFEST) \
-C $(DEMO_JAR_IMAGE) . \
$(BOOT_JAR_JFLAGS)
@$(java-vm-cleanup)
endif
ifndef DEMO_SKIP_SRCZIP
# Create a src.zip file
$(DEMO_BUILD_SRCZIP): $(DEMO_FULL_SOURCES)
@$(prep-target)
$(CD) $(DEMO_BUILD_AREA)/src && $(ZIPEXE) -q -r ../$(@F) .
# Install the destination src.zip file and create the src tree
$(DEMO_SOURCE_ZIP): $(DEMO_BUILD_SRCZIP)
$(install-file)
endif
ifeq ($(PLATFORM),windows)
# JDK name required here
RC_FLAGS += /D "JDK_FNAME=$(LIBRARY).dll" \
/D "JDK_INTERNAL_NAME=$(LIBRARY)" \
/D "JDK_FTYPE=0x2L"
endif
# Native library building
ifdef DEMO_LIBRARY
# Full paths to object files
DEMO_FULL_OBJECTS = $(DEMO_OBJECTS:%=$(OBJDIR)/%)
VPATH=
# Native compile rules
$(OBJDIR)/%.$(OBJECT_SUFFIX): $(DEMO_BUILD_SRCDIR)/%.c
@$(prep-target)
$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $<
ifneq ($(DEMO_NEEDS_CPP),)
$(OBJDIR)/%.$(OBJECT_SUFFIX): $(DEMO_BUILD_SRCDIR)/%.cpp
@$(prep-target)
$(COMPILE.cpp) $(CC_OBJECT_OUTPUT_FLAG)$@ $<
endif
# Actual creation of the native shared library (C++ and C are different)
$(DEMO_LIBRARY): $(DEMO_FULL_OBJECTS)
@$(prep-target)
ifeq ($(PLATFORM),windows)
$(RC) $(RC_FLAGS) $(CC_OBJECT_OUTPUT_FLAG)$(DEMO_VERSION_INFO) $(VERSIONINFO_RESOURCE)
$(LINK.demo) $(SHARED_LIBRARY_FLAG) -Fe$@ \
$(DEMO_FULL_OBJECTS) $(LDLIBS.demo)
else
$(LINK.demo) $(SHARED_LIBRARY_FLAG) -o $@ \
$(DEMO_FULL_OBJECTS) $(LDLIBS.demo)
endif
@$(call binary_file_verification,$@)
# Generation of any javah include file, make sure objects are dependent on it
ifdef DEMO_NATIVECLASS
$(DEMO_JAVAH_FILE): $(DEMO_JAR)
@$(prep-target)
$(JAVAH_CMD) -d $(DEMO_BUILD_SRCDIR) -classpath $(DEMO_JAR) \
$(DEMO_NATIVECLASS)
@$(java-vm-cleanup)
$(DEMO_FULL_OBJECTS): $(DEMO_JAVAH_FILE)
endif
endif
# Build involves populating the destination "src" tree, building the jar and
# native library, and creating a source bundle
sources: $(DEMO_FULL_SOURCES)
@$(ECHO) "Created $@"
objects:
@$(ECHO) "Created $@"
# Why the nested make here? It only works this way, don't know why.
bundles: $(DEMO_BUILD_SRCZIP)
$(RM) -r $(DEMO_DESTDIR)
$(MKDIR) -p $(DEMO_DESTDIR)
$(MAKE) $(DEMO_LIBRARY) $(DEMO_JAR) $(DEMO_SOURCE_ZIP) $(DEMO_DEST_TOPFILES)
# Applets are special, no jar file, no src.zip, everything expanded.
ifdef DEMO_IS_APPLET
@$(ECHO) "Expanding jar file into demos area at $(DEMO_DESTDIR)"
( $(CD) $(DEMO_DESTDIR) && \
$(BOOT_JAR_CMD) -xfv $(DEMO_JAR_NAME) \
$(BOOT_JAR_JFLAGS) && \
$(RM) -r META-INF $(DEMO_JAR_NAME) && \
$(java-vm-cleanup) )
@( $(CD) $(DEMO_DESTDIR) && $(java-vm-cleanup) )
@$(ECHO) "Expanding source into demos area at $(DEMO_DESTDIR)"
( $(CD) $(DEMO_DESTDIR) && $(UNZIP) -o src.zip && $(RM) src.zip )
endif
build: sources bundles
# Printing out a demo information line
define printDemoSetting
if [ "$2" != "" ] ; then $(PRINTF) "%-20s %s\n" "$1:" "$2"; fi
endef
# Print out the demo information
demo_info:
@$(ECHO) "========================================================="
@$(call printDemoSetting,DEMONAME,$(DEMONAME))
@$(call printDemoSetting,DEMO_ROOT,$(DEMO_ROOT))
@$(call printDemoSetting,DEMO_SRCDIR,$(DEMO_SRCDIR))
@$(call printDemoSetting,DEMO_DESTDIR,$(DEMO_DESTDIR))
@$(call printDemoSetting,DEMO_JAR,$(DEMO_JAR))
@$(call printDemoSetting,DEMO_MANIFEST_ATTR,$(DEMO_MANIFEST_ATTR))
@$(call printDemoSetting,DEMO_PSRCDIR,$(DEMO_PSRCDIR))
@$(call printDemoSetting,DEMO_EXTRA_SRCDIR,$(DEMO_EXTRA_SRCDIR))
@$(call printDemoSetting,DEMO_EXTRA_FILES,$(DEMO_EXTRA_FILES))
@$(call printDemoSetting,DEMO_TOPFILES,$(DEMO_TOPFILES))
@$(call printDemoSetting,DEMO_MAINCLASS,$(DEMO_MAINCLASS))
@$(call printDemoSetting,DEMO_DESCRIPTOR,$(DEMO_DESCRIPTOR))
@$(call printDemoSetting,DEMO_NATIVECLASS,$(DEMO_NATIVECLASS))
@$(call printDemoSetting,DEMO_LIBRARY,$(DEMO_LIBRARY))
@$(call printDemoSetting,DEMO_OBJECTS,$(DEMO_OBJECTS))
@$(call printDemoSetting,DEMO_SOURCE_ZIP,$(DEMO_SOURCE_ZIP))
@$(ECHO) "========================================================="
# Clean rule
clean clobber:
$(RM) -r $(DEMO_BUILD_AREA)
$(RM) -r $(DEMO_DESTDIR)
# This should not be needed, but some versions of GNU make have a bug that
# sometimes deleted these files for some strange and unknown reason
# (GNU make version 3.78.1 has the problem, GNU make version 3.80 doesn't?)
.PRECIOUS: $(DEMO_FULL_SOURCES) $(DEMO_BUILD_SRCZIP) $(DEMO_SOURCE_ZIP)
# List phony targets
.PHONY: all build clean clobber demo_info \
sources bundles