#
# Copyright (c) 1996, 2019, 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.
#

#---------------------------------------------------------------------
#
# Copy resources (*.properties) into classes directory from source tree

$(CLASSDIR)/%.properties: $(JAVADIR)/%.properties
	$(RM) -f $@
	if [ ! -d $(@D) ] ; then $(MKDIR) -p $(@D) ; fi
	$(CP) $(@:$(CLASSDIR)/%=$(JAVADIR)/%) $@

$(CLASSDIR)/%.gif: $(JAVADIR)/%.gif
	$(RM) -f $@
	if [ ! -d $(@D) ] ; then $(MKDIR) -p $(@D) ; fi
	$(CP) $(@:$(CLASSDIR)/%=$(JAVADIR)/%) $@

$(CLASSDIR)/%.png: $(JAVADIR)/%.png
	$(RM) -f $@
	if [ ! -d $(@D) ] ; then $(MKDIR) -p $(@D) ; fi
	$(CP) $(@:$(CLASSDIR)/%=$(JAVADIR)/%) $@

#---------------------------------------------------------------------

$(CLASSDIR) $(BUILDDIR) $(BUILDDIR)/testClasses $(BUILDDIR)/testWork $(BUILDDIR)/testReport:
	$(MKDIR) -p $@

#----------------------------------------------------------------------
#
# Build a JAR file containing the contents of any classes/* files
# listed in the FILES.JAR.%

# default copyright; override as necessary
JAR_COPYRIGHT = -C $(TOPDIR) COPYRIGHT

$(IMAGES_DIR)/%.jar: pkgsToFiles.sh
	$(RM) $@ $(@:$(IMAGES_DIR)/%.jar=$(BUILDDIR)/jarData/%) 
	$(MKDIR) -p $(@D)
	$(MKDIR) -p $(@:$(IMAGES_DIR)/%.jar=$(BUILDDIR)/jarData/%)
	( if [ -n "$(JAR_MAINCLASS)" ]; then echo "Main-class: $(JAR_MAINCLASS)" ; fi ; \
	  if [ -n "$(JAR_CLASSPATH)" ]; then echo "Class-Path: $(JAR_CLASSPATH)" ; fi ; \
	  echo "$(@F:%.jar=%)-Name: $(@F:%.jar=%)" ; \
	  if [ -n "$(BUILD_VERSION_STRING)" ]; then echo "$(@F:%.jar=%)-VersionString: $(BUILD_VERSION_STRING)" ; fi ; \
	  echo "$(@F:%.jar=%)-Version: $(BUILD_VERSION)" ; \
	  echo "$(@F:%.jar=%)-Milestone: $(BUILD_MILESTONE)" ; \
	  echo "$(@F:%.jar=%)-Build: $(BUILD_NUMBER)" ; \
	  echo "$(@F:%.jar=%)-BuildJavaVersion: `$(JDKJAVA) -fullversion 2>&1 | awk '{print $$NF}'  | \
		sed -e 's|^"\(.*\)"$$|Java(TM) 2 SDK, Version \1|'`" ; \
	  echo "$(@F:%.jar=%)-BuildDate: `/bin/date +'%B %d, %Y'`" ; \
	) \
		> $(@:$(IMAGES_DIR)/%.jar=$(BUILDDIR)/jarData/%/manifest.txt)
	sh pkgsToFiles.sh $(CLASSDIR) $($(@F:%.jar=PKGS.JAR.%)) > $(@:$(IMAGES_DIR)/%.jar=$(BUILDDIR)/jarData/%/includes.txt)
	$(JAR) -cmf $(@:$(IMAGES_DIR)/%.jar=$(BUILDDIR)/jarData/%/manifest.txt) $@ \
	    $(JAR_COPYRIGHT) \
	    @$(@:$(IMAGES_DIR)/%.jar=$(BUILDDIR)/jarData/%/includes.txt) \
	    $(patsubst $(CLASSDIR)/%,-C $(CLASSDIR) %,$(sort $(FILES.JAR.$(@F:%.jar=%)))) \
	    $(JAR_EXTRAS)
	$(CHMOD) a-w $@

#----------------------------------------------------------------------
#
# Build zips with verbose names

%-$(VERBOSE_ZIP_SUFFIX).zip: %.zip 
	$(CP) $(@:%-$(VERBOSE_ZIP_SUFFIX).zip=%.zip) $@

%-$(NEW_VERBOSE_ZIP_SUFFIX).zip: %.zip
	$(RM) $@
	$(LN) $(@:%-$(NEW_VERBOSE_ZIP_SUFFIX).zip=%.zip) $@

#----------------------------------------------------------------------
#
# cancel implicit rules

%: %.o
%: %.obj
%: %.dll
%: %.c
%: %.cc
%: %.cpp
%: %.C
%: %.p
%: %.f
%: %.s
%: %.F
%: %.r
%: %.S
%: %.mod
%: %.sh



