#
# Copyright 1998-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.
#

#
# Makefile for building the Java 2D Demo
#

BUILDDIR = ../../..
DEMOS    = Java2Demo

# identify this as a demo/jfc/Java2D product - used to identify a
# unique name for OBJDIR
PRODUCT = demo/jfc/Java2D

include $(BUILDDIR)/common/Defs.gmk

#
# What do we compile?
#
DEMODST  = $(DEMODIR)/jfc/Java2D
DEMOSRC  = $(CLOSED_SRC)/share/demo/jfc/Java2D
include FILES.gmk

#
# Activate some hooks so Classes.gmk looks elsewhere for sources, and
# dumps classes where we want.
#
SOURCEPATH              = $(DEMOSRC)

# use "simple expansion" (GNU Make 6.2) for setting BOOTCLASSPATH 
# because CLASSBINDIR is changed a few lines down:
BOOTCLASSPATH           := $(CLASSBINDIR)

DEMOJAR			= $(DEMODST)/Java2Demo.jar
ALT_CLASSES_DISPOSITION = src docs $(DEMOJAR)
ALT_CLASSBINDIR         = $(TEMPDIR)/class
CLASSDESTDIR            = $(ALT_CLASSBINDIR)
CLASSBINDIR             = $(ALT_CLASSBINDIR)

#
# Rules.
#
include $(BUILDDIR)/common/Classes.gmk

build: src docs $(DEMOJAR)

#
# Sources.
#
SRCSRC = $(DEMOSRC)
SRCDST = $(DEMODST)/src
FILES_src = $(FILES_java:%.java=$(SRCDST)/%.java)

src: $(FILES_src) $(FILES_other)

$(SRCDST)/%.java: $(SRCSRC)/%.java
	$(install-file)

$(SRCDST)/%: $(DEMOSRC)/%
	$(install-file)

#
# Docs.
#
docs: $(DEMODST)/README.txt $(DEMODST)/Java2Demo.html

$(DEMODST)/README.txt: $(DEMOSRC)/README.txt
	$(install-file)

$(DEMODST)/Java2Demo.html: $(DEMOSRC)/Java2Demo.html
	$(install-file)

#
# Jar file.
#

#
# Since there is no easy way to exclude SCCS files from
# being 'jar'ed together while using -C flag,
# temporarily copy only resource files into separate directory
# and then use jar on it
#

define copy-resourcefiles-to-temp
$(MKDIR) $(TEMPDIR)/images
$(CP) $(DEMOSRC)/images/*.* $(TEMPDIR)/images
$(MKDIR) $(TEMPDIR)/fonts
$(CP) $(DEMOSRC)/fonts/*.* $(TEMPDIR)/fonts
endef

define remove-temp-resourcefiles
$(RM) -rf $(TEMPDIR)/images
$(RM) -rf $(TEMPDIR)/fonts
endef

jar: $(DEMODST)/Java2Demo.jar

$(DEMODST)/Java2Demo.jar: $(FILES_class) $(FILES_java:%.java=$(DEMOSRC)/%.java)
	$(ECHO) Main-Class: java2d.Java2Demo > $(TEMPDIR)/manifest
	$(copy-resourcefiles-to-temp)
	$(JAR) -cvfm $@ $(TEMPDIR)/manifest -C $(TEMPDIR)/class . \
		     -C $(TEMPDIR) images -C $(TEMPDIR) fonts \
			  $(JAR_JFLAGS)
	$(remove-temp-resourcefiles)
	$(RM) $(TEMPDIR)/manifest
	@$(java-vm-cleanup)
