Demo.gmk revision 2362
0N/A#
2362N/A# Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A#
0N/A# This code is free software; you can redistribute it and/or modify it
0N/A# under the terms of the GNU General Public License version 2 only, as
2362N/A# published by the Free Software Foundation. Oracle designates this
0N/A# particular file as subject to the "Classpath" exception as provided
2362N/A# by Oracle in the LICENSE file that accompanied this code.
0N/A#
0N/A# This code is distributed in the hope that it will be useful, but WITHOUT
0N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A# version 2 for more details (a copy is included in the LICENSE file that
0N/A# accompanied this code).
0N/A#
0N/A# You should have received a copy of the GNU General Public License version
0N/A# 2 along with this work; if not, write to the Free Software Foundation,
0N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A#
2362N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A# or visit www.oracle.com if you need additional information or have any
2362N/A# questions.
0N/A#
0N/A
0N/A# JDK Demo building jar file.
0N/A
2080N/AMODULE = demos
2080N/A
0N/A# Some names are defined with LIBRARY inside the Defs.gmk file
0N/ALIBRARY=$(DEMONAME)
0N/AOBJDIR=$(TEMPDIR)/$(DEMONAME)
0N/A
0N/A# Input:
0N/A# DEMONAME - name of the demo
0N/A# DEMO_ROOT - path to root of all demo files
0N/A# DEMO_DESTDIR - path to final demo destination directory
0N/A#
0N/A# Optional Input:
0N/A# DEMO_SRCDIR - path to source if different from DEMO_ROOT
0N/A# DEMO_PSRCDIR - path to additional platform specific source
0N/A# DEMO_PKGDIR - sub directory of sources we want
0N/A# DEMO_TOPFILES - names of top-level files relative to DEMO_ROOT
0N/A# DEMO_MAINCLASS - name of the main class for the jar manifest
0N/A# DEMO_NATIVECLASS - name of the class with native methods
0N/A# DEMO_DESCRIPTOR - name of service file for jar (relative to DEMO_SRCDIR)
0N/A# DEMO_EXTRA_SRCDIR - path to directory that holds extra sources to add
0N/A# DEMO_EXTRA_FILES - extra sources relative to DEMO_EXTRA_SRCDIR
0N/A# DEMO_OBJECTS - extra native object files needed
0N/A# DEMO_MANIFEST_ATTR - extra line to add to the jar manifest file
0N/A
0N/A# Assume the source directory is the root directory if not set
0N/Aifndef DEMO_SRCDIR
0N/A DEMO_SRCDIR = $(DEMO_ROOT)
0N/Aendif
0N/Aifndef DEMO_PKGDIR
0N/A DEMO_PKGDIR = .
0N/Aendif
0N/A
0N/A# Some demos have special needs
0N/Aifneq ($(DEMONAME),agent_util)
0N/A DEMO_NEEDS_AGENT_UTIL = $(findstring agent_util,$(DEMO_OBJECTS))
0N/Aendif
0N/Aifneq ($(DEMONAME),java_crw_demo)
0N/A DEMO_NEEDS_JAVA_CRW_DEMO = $(findstring java_crw_demo,$(DEMO_OBJECTS))
0N/Aendif
0N/Aifeq ($(DEMONAME),hprof)
0N/A DEMO_NEEDS_NPT = true
0N/Aendif
0N/A
0N/A# Place to hold the build area (kind of a temp area)
0N/ADEMO_BUILD_AREA = $(DEMOCLASSDIR)/$(PRODUCT)/$(DEMONAME)
0N/A
0N/A# Destination "src" directory
0N/ADEMO_BUILD_SRCDIR = $(DEMO_BUILD_AREA)/src
0N/ADEMO_BUILD_SRCZIP = $(DEMO_BUILD_AREA)/src.zip
0N/ADEMO_SOURCE_ZIP = $(DEMO_DESTDIR)/src.zip
0N/A
0N/A# Place to hold the jar image we are creating
0N/ADEMO_JAR_IMAGE = $(DEMO_BUILD_AREA)/jar_image
0N/A
0N/A# The jar manifest file we will create and use
0N/ADEMO_MANIFEST = $(DEMO_BUILD_AREA)/manifest.mf
0N/A
0N/A# The list of source files or options we will supply to javac
0N/ADEMO_JAVAC_INPUT = $(DEMO_BUILD_AREA)/javac_input.txt
0N/A
0N/A# Any name of javah file
0N/ADEMO_JAVAH_FILE = $(DEMO_NATIVECLASS:%=$(DEMO_BUILD_SRCDIR)/%.h)
0N/A
0N/A# Get complete list of files for this demo
0N/Aifdef DEMO_PSRCDIR
0N/A DEMO_ALL_FILES2 := $(shell ( $(CD) $(DEMO_PSRCDIR) \
0N/A && $(FIND) $(DEMO_PKGDIR) $(SCM_DIRS_prune) -o -type f -print ) \
0N/A | $(SED) 's@^\./@@' )
0N/A DEMO_ALL_FILES += $(DEMO_ALL_FILES2)
0N/Aendif
0N/Aifdef DEMO_EXTRA_SRCDIR
0N/A DEMO_ALL_FILES += $(DEMO_EXTRA_FILES)
0N/Aendif
0N/ADEMO_ALL_FILES1 := $(shell ( $(CD) $(DEMO_SRCDIR) \
0N/A && $(FIND) $(DEMO_PKGDIR) $(SCM_DIRS_prune) -o -type f -print ) \
0N/A | $(SED) 's@^\./@@' )
0N/ADEMO_ALL_FILES += $(DEMO_ALL_FILES1)
0N/A
0N/A# Just the java sources
0N/ADEMO_JAVA_SOURCES = $(filter %.java,$(DEMO_ALL_FILES))
0N/A
0N/A# Just the C and C++ sources
0N/ADEMO_C_SRC_FILES = $(filter %.c,$(DEMO_ALL_FILES))
0N/ADEMO_CPP_SRC_FILES = $(filter %.cpp,$(DEMO_ALL_FILES))
0N/A
0N/A# All the native source files
0N/ADEMO_ALL_NATIVE_SOURCES = $(DEMO_C_SRC_FILES)
0N/ADEMO_ALL_NATIVE_SOURCES += $(DEMO_CPP_SRC_FILES)
0N/ADEMO_ALL_NATIVE_SOURCES += $(filter %.h,$(DEMO_ALL_FILES))
0N/ADEMO_ALL_NATIVE_SOURCES += $(filter %.hpp,$(DEMO_ALL_FILES))
0N/A
0N/A# If we have java sources, then define the jar file we will create
0N/Aifneq ($(strip $(DEMO_JAVA_SOURCES)),)
0N/A DEMO_JAR = $(DEMO_DESTDIR)/$(DEMONAME).jar
0N/Aendif
0N/A
0N/A# If we have native sources, define the native library we will create
0N/Aifneq ($(strip $(DEMO_ALL_NATIVE_SOURCES)),)
0N/A # Path to native library we will create
0N/A DEMO_LIBRARY = \
0N/A $(DEMO_DESTDIR)/lib$(ISA_DIR)/$(LIB_PREFIX)$(DEMONAME).$(LIBRARY_SUFFIX)
0N/A # C and C++ compiler flags we need to add to standard flags
0N/A DEMO_CPPFLAGS += -I$(DEMO_BUILD_SRCDIR)
0N/A # If the npt library is used we need to find the npt.h file
0N/A ifneq ($(DEMO_NEEDS_NPT),)
0N/A # The npt library is delivered as part of the JRE
0N/A DEMO_CPPFLAGS += -I$(SHARE_SRC)/npt -I$(PLATFORM_SRC)/npt
0N/A endif
0N/A # Is the shared agent_util code needed
0N/A ifneq ($(DEMO_NEEDS_AGENT_UTIL),)
0N/A DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/agent_util.c
0N/A DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/agent_util.h
0N/A endif
0N/A # Is the shared java_crw_demo code needed
0N/A ifneq ($(DEMO_NEEDS_JAVA_CRW_DEMO),)
0N/A DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/java_crw_demo.c
0N/A DEMO_FULL_SOURCES += $(DEMO_BUILD_SRCDIR)/java_crw_demo.h
0N/A endif
0N/A # All the native object files we need to build the library
0N/A DEMO_OBJECTS += $(DEMO_C_SRC_FILES:%.c=%.$(OBJECT_SUFFIX)) \
0N/A $(DEMO_CPP_SRC_FILES:%.cpp=%.$(OBJECT_SUFFIX))
0N/A # Linking is special depending on whether we had C++ code or on windows
0N/A DEMO_NEEDS_CPP = $(strip $(DEMO_CPP_SRC_FILES))
0N/A CPPFLAGS += $(DEMO_CPPFLAGS)
0N/A ifeq ($(PLATFORM),windows)
0N/A # Note: This is a link with cl.exe, not link.exe, options differ quite
0N/A # bit between them.
0N/A LINK.demo = $(LINK.c)
0N/A LDLIBS.demo = $(EXTRA_LIBS) $(LFLAGS_$(COMPILER_VERSION))
0N/A else
0N/A ifneq ($(DEMO_NEEDS_CPP),)
0N/A LINK.demo = $(LINK.cpp)
0N/A LDLIBS.demo = $(LIBCXX)
0N/A ifeq ($(PLATFORM),solaris)
0N/A LDLIBS.demo += -lc
0N/A endif
0N/A else
0N/A LINK.demo = $(LINK.c)
0N/A LDLIBS.demo = $(LDLIBS)
0N/A endif
0N/A endif
0N/Aendif
0N/A
0N/A# Files that are considered resources (need to be in the jar file)
0N/ADEMO_RESOURCES += $(filter-out %.java,$(DEMO_ALL_FILES))
0N/A
0N/A# All destination files (top level readme files and all sources)
0N/A# Note: We exclude the topfiles from the src tree.
0N/ADEMO_DEST_TOPFILES = $(DEMO_TOPFILES:%=$(DEMO_DESTDIR)/%)
0N/ADEMO_FILTERED_SOURCES = $(filter-out $(DEMO_TOPFILES),$(DEMO_ALL_FILES))
0N/ADEMO_FULL_SOURCES += $(DEMO_FILTERED_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%)
0N/A
0N/A# Default rule
0N/Aall: build demo_info
0N/A
0N/A# Used to populate the destination directories
0N/A$(DEMO_DESTDIR)/%: $(DEMO_ROOT)/%
0N/A $(install-file)
0N/Aifneq ($(DEMO_SRCDIR),$(DEMO_ROOT))
0N/A$(DEMO_DESTDIR)/%: $(DEMO_SRCDIR)/%
0N/A $(install-file)
0N/Aendif
0N/A$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/%
0N/A $(install-file)
0N/Aifdef DEMO_PSRCDIR
0N/A$(DEMO_BUILD_SRCDIR)/%: $(DEMO_PSRCDIR)/%
0N/A $(install-file)
0N/Aendif
0N/Aifdef DEMO_EXTRA_SRCDIR
0N/A$(DEMO_BUILD_SRCDIR)/%: $(DEMO_EXTRA_SRCDIR)/%
0N/A $(install-file)
0N/Aendif
0N/Aifneq ($(DEMO_NEEDS_AGENT_UTIL),)
0N/A$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/../agent_util/%
0N/A $(install-file)
0N/Aendif
0N/Aifneq ($(DEMO_NEEDS_JAVA_CRW_DEMO),)
0N/A$(DEMO_BUILD_SRCDIR)/%: $(DEMO_SRCDIR)/../java_crw_demo/%
0N/A $(install-file)
0N/Aendif
0N/A
0N/A# Jar manifest file
0N/A$(DEMO_MANIFEST):
0N/A @$(prep-target)
0N/A $(ECHO) "Main-Class: $(DEMO_MAINCLASS)" > $@
0N/Aifdef DEMO_MANIFEST_ATTR
0N/A $(ECHO) "$(DEMO_MANIFEST_ATTR)" >> $@
0N/Aendif
0N/A
0N/A# Populating the jar image directory
0N/A$(DEMO_JAR_IMAGE)/%: $(DEMO_SRCDIR)/%
0N/A $(install-file)
0N/Aifdef DEMO_PSRCDIR
0N/A$(DEMO_JAR_IMAGE)/%: $(DEMO_PSRCDIR)/%
0N/A $(install-file)
0N/Aendif
0N/Aifdef DEMO_EXTRA_SRCDIR
0N/A$(DEMO_JAR_IMAGE)/%: $(DEMO_EXTRA_SRCDIR)/%
0N/A $(install-file)
0N/Aendif
0N/Aifdef DEMO_DESCRIPTOR
0N/A$(DEMO_JAR_IMAGE)/META-INF/services/$(DEMO_DESCRIPTOR): \
0N/A $(DEMO_SRCDIR)/$(DEMO_DESCRIPTOR)
0N/A $(install-file)
0N/Aendif
0N/A
0N/A# If we are creating a jar file (we have java code)
0N/Aifdef DEMO_JAR
0N/A
0N/A# Input file for javac
0N/A$(DEMO_JAVAC_INPUT): $(DEMO_JAVA_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%)
0N/A @$(prep-target)
0N/A @for i in $(DEMO_JAVA_SOURCES) ; do \
0N/A $(ECHO) "$(DEMO_BUILD_SRCDIR)/$$i" >> $@ ; \
0N/A done
0N/A
0N/A# Jar file creation
0N/A$(DEMO_JAR): \
0N/A $(DEMO_JAVAC_INPUT) \
0N/A $(DEMO_MANIFEST) \
0N/A $(DEMO_DESCRIPTOR:%=$(DEMO_JAR_IMAGE)/META-INF/services/%) \
0N/A $(DEMO_RESOURCES:%=$(DEMO_JAR_IMAGE)/%)
0N/A @$(prep-target)
0N/A $(MKDIR) -p $(DEMO_JAR_IMAGE)
0N/A $(JAVAC_CMD) -d $(DEMO_JAR_IMAGE) -sourcepath $(DEMO_BUILD_SRCDIR) \
0N/A @$(DEMO_JAVAC_INPUT)
0N/A $(BOOT_JAR_CMD) -cfm $@ $(DEMO_MANIFEST) \
0N/A -C $(DEMO_JAR_IMAGE) . \
459N/A $(BOOT_JAR_JFLAGS)
0N/A @$(java-vm-cleanup)
0N/A
0N/Aendif
0N/A
0N/A# Create a src.zip file
0N/A$(DEMO_BUILD_SRCZIP): $(DEMO_FULL_SOURCES)
0N/A @$(prep-target)
0N/A $(CD) $(DEMO_BUILD_AREA)/src && $(ZIPEXE) -q -r ../$(@F) .
0N/A
0N/A# Install the destination src.zip file and create the src tree
0N/A$(DEMO_SOURCE_ZIP): $(DEMO_BUILD_SRCZIP)
0N/A $(install-file)
0N/A
0N/A# Native library building
0N/Aifdef DEMO_LIBRARY
0N/A
0N/A # Full paths to object files
0N/A DEMO_FULL_OBJECTS = $(DEMO_OBJECTS:%=$(OBJDIR)/%)
0N/A VPATH=
0N/A
0N/A# Native compile rules
0N/A$(OBJDIR)/%.$(OBJECT_SUFFIX): $(DEMO_BUILD_SRCDIR)/%.c
0N/A @$(prep-target)
0N/A $(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $<
0N/A ifneq ($(DEMO_NEEDS_CPP),)
0N/A$(OBJDIR)/%.$(OBJECT_SUFFIX): $(DEMO_BUILD_SRCDIR)/%.cpp
0N/A @$(prep-target)
0N/A $(COMPILE.cpp) $(CC_OBJECT_OUTPUT_FLAG)$@ $<
0N/A endif
0N/A
0N/A # Actual creation of the native shared library (C++ and C are different)
0N/A$(DEMO_LIBRARY): $(DEMO_FULL_OBJECTS)
0N/A @$(prep-target)
0N/A $(LINK.demo) $(SHARED_LIBRARY_FLAG) $(CC_PROGRAM_OUTPUT_FLAG)$@ \
0N/A $(DEMO_FULL_OBJECTS) $(LDLIBS.demo)
0N/A
0N/A # Generation of any javah include file, make sure objects are dependent on it
0N/A ifdef DEMO_NATIVECLASS
0N/A$(DEMO_JAVAH_FILE): $(DEMO_JAR)
0N/A @$(prep-target)
0N/A $(JAVAH_CMD) -d $(DEMO_BUILD_SRCDIR) -classpath $(DEMO_JAR) \
0N/A $(DEMO_NATIVECLASS)
0N/A @$(java-vm-cleanup)
0N/A$(DEMO_FULL_OBJECTS): $(DEMO_JAVAH_FILE)
0N/A endif
0N/A
0N/Aendif
0N/A
0N/A# Build involves populating the destination "src" tree, building the jar and
0N/A# native library, and creating a source bundle
0N/A
0N/Asources: $(DEMO_FULL_SOURCES)
0N/A @$(ECHO) "Created $@"
0N/A
0N/Aobjects:
0N/A @$(ECHO) "Created $@"
0N/A
0N/A# Why the nested make here? It only works this way, don't know why.
0N/Abundles: $(DEMO_BUILD_SRCZIP)
0N/A $(RM) -r $(DEMO_DESTDIR)
0N/A $(MKDIR) -p $(DEMO_DESTDIR)
0N/A $(MAKE) $(DEMO_LIBRARY) $(DEMO_JAR) $(DEMO_SOURCE_ZIP) $(DEMO_DEST_TOPFILES)
0N/A# Applets are special, no jar file, no src.zip, everything expanded.
0N/Aifdef DEMO_IS_APPLET
0N/A @$(ECHO) "Expanding jar file into demos area at $(DEMO_DESTDIR)"
459N/A ( $(CD) $(DEMO_DESTDIR) && \
459N/A $(BOOT_JAR_CMD) -xfv $(DEMONAME).jar \
459N/A $(BOOT_JAR_JFLAGS) && \
459N/A $(RM) -r META-INF $(DEMONAME).jar && \
459N/A $(java-vm-cleanup) )
0N/A @( $(CD) $(DEMO_DESTDIR) && $(java-vm-cleanup) )
0N/A @$(ECHO) "Expanding source into demos area at $(DEMO_DESTDIR)"
0N/A ( $(CD) $(DEMO_DESTDIR) && $(UNZIP) -o src.zip && $(RM) src.zip )
0N/Aendif
0N/A
0N/Abuild: sources bundles
0N/A
0N/A# Printing out a demo information line
0N/Adefine printDemoSetting
0N/Aif [ "$2" != "" ] ; then $(PRINTF) "%-20s %s\n" "$1:" "$2"; fi
0N/Aendef
0N/A
0N/A# Print out the demo information
0N/Ademo_info:
0N/A @$(ECHO) "========================================================="
0N/A @$(call printDemoSetting,DEMONAME,$(DEMONAME))
0N/A @$(call printDemoSetting,DEMO_ROOT,$(DEMO_ROOT))
0N/A @$(call printDemoSetting,DEMO_SRCDIR,$(DEMO_SRCDIR))
0N/A @$(call printDemoSetting,DEMO_DESTDIR,$(DEMO_DESTDIR))
0N/A @$(call printDemoSetting,DEMO_JAR,$(DEMO_JAR))
0N/A @$(call printDemoSetting,DEMO_MANIFEST_ATTR,$(DEMO_MANIFEST_ATTR))
0N/A @$(call printDemoSetting,DEMO_PSRCDIR,$(DEMO_PSRCDIR))
0N/A @$(call printDemoSetting,DEMO_EXTRA_SRCDIR,$(DEMO_EXTRA_SRCDIR))
0N/A @$(call printDemoSetting,DEMO_EXTRA_FILES,$(DEMO_EXTRA_FILES))
0N/A @$(call printDemoSetting,DEMO_TOPFILES,$(DEMO_TOPFILES))
0N/A @$(call printDemoSetting,DEMO_MAINCLASS,$(DEMO_MAINCLASS))
0N/A @$(call printDemoSetting,DEMO_DESCRIPTOR,$(DEMO_DESCRIPTOR))
0N/A @$(call printDemoSetting,DEMO_NATIVECLASS,$(DEMO_NATIVECLASS))
0N/A @$(call printDemoSetting,DEMO_LIBRARY,$(DEMO_LIBRARY))
0N/A @$(call printDemoSetting,DEMO_OBJECTS,$(DEMO_OBJECTS))
0N/A @$(call printDemoSetting,DEMO_SOURCE_ZIP,$(DEMO_SOURCE_ZIP))
0N/A @$(ECHO) "========================================================="
0N/A
0N/A# Clean rule
0N/Aclean clobber:
0N/A $(RM) -r $(DEMO_BUILD_AREA)
0N/A $(RM) -r $(DEMO_DESTDIR)
0N/A
0N/A# This should not be needed, but some versions of GNU amke have a bug that
0N/A# sometimes deleted these files for some strange and unknown reason
0N/A# (GNU make version 3.78.1 has the problem, GNU make version 3.80 doesn't?)
0N/A.PRECIOUS: $(DEMO_FULL_SOURCES) $(DEMO_BUILD_SRCZIP) $(DEMO_SOURCE_ZIP)
0N/A
0N/A# List phony targets
0N/A.PHONY: all build clean clobber demo_info \
0N/A sources bundles
0N/A