#
# Copyright (c) 2002, 2007, 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.
#

BUILDDIR = ../..
PACKAGE = sun.awt.X11
PRODUCT = sun

include $(BUILDDIR)/common/Defs.gmk

PACKAGE_DIR=sun/awt/X11
GEN_DIR=$(GENSRCDIR)/$(PACKAGE_DIR)

CLASSES_INIT += $(TEMPDIR)/.gen_icons

.PHONY: generated.clean

#
# Files
#
ifdef OPENJDK
    ICONS_PATH_PREFIX=$(PLATFORM_SRC)
else
    ICONS_PATH_PREFIX=$(CLOSED_SRC)/solaris
endif

ICONS = \
    $(ICONS_PATH_PREFIX)/classes/sun/awt/X11/java-icon16.png \
    $(ICONS_PATH_PREFIX)/classes/sun/awt/X11/java-icon24.png \
    $(ICONS_PATH_PREFIX)/classes/sun/awt/X11/java-icon32.png \
    $(ICONS_PATH_PREFIX)/classes/sun/awt/X11/java-icon48.png

FILES_java := $(shell \
        for i in $(ICONS); do \
            filename=`basename $$i`; \
            name=`$(ECHO) $$filename | $(TR) '\-.' '__'`;  \
            classname=$(PACKAGE_DIR)/XAWTIcon32_$$name.java; \
            $(ECHO) $$classname;  \
            classname=$(PACKAGE_DIR)/XAWTIcon64_$$name.java; \
            $(ECHO) $$classname;  \
        done \
    )

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

generated.clean:	
	$(RM) -r $(GEN_DIR)/*.java

TEMPDIR_CLASSES = $(TEMPDIR)/classes

$(TEMPDIR_CLASSES)/sun/awt/X11/ToBin.class: ToBin.java
	@$(prep-target)
	$(BOOT_JAVAC_CMD) -d $(TEMPDIR_CLASSES) $<

# Switch to the java we just built to avoid dylib (freetype) loading issue on crossing-compiling
BUILT_JAVA_CMD = $(OUTPUTDIR)/bin/java

$(TEMPDIR)/.gen_icons: generated.FORCE $(TEMPDIR_CLASSES)/sun/awt/X11/ToBin.class $(ICONS)
	$(prep-target)
	for i in $(ICONS); do \
            filename=`basename $$i`; \
	    name=`$(ECHO) $$filename | $(TR) '\-.' '__'`;  \
            classname=$(GEN_DIR)/XAWTIcon32_$$name.java; \
	    $(RM) $$classname; \
	    $(ECHO) "package sun.awt.X11;" >> $$classname ; \
	    $(ECHO) "public class XAWTIcon32_$$name {" >> $$classname; \
	    $(ECHO) "public static int[] $$name = { " >> $$classname;  \
	    $(CAT) $$i | \
	      $(BUILT_JAVA_CMD) -cp $(TEMPDIR_CLASSES)  \
		-Dawt.toolkit=sun.awt.motif.MToolkit \
		-Djava.awt.headless=true \
		sun.awt.X11.ToBin >> $$classname; \
	    $(ECHO) "}; }" >> $$classname;  \
            classname=$(GEN_DIR)/XAWTIcon64_$$name.java; \
	    $(RM) $$classname; \
	    $(ECHO) "package sun.awt.X11;" >> $$classname ; \
	    $(ECHO) "public class XAWTIcon64_$$name {" >> $$classname; \
	    $(ECHO) "public static long[] $$name = { " >> $$classname;  \
	    $(CAT) $$i | \
	      $(BUILT_JAVA_CMD) -cp $(TEMPDIR_CLASSES)  \
		-Dawt.toolkit=sun.awt.motif.MToolkit \
		-Djava.awt.headless=true \
		sun.awt.X11.ToBin >> $$classname; \
	    $(ECHO) "}; }" >> $$classname;  \
	done
	$(TOUCH) $@

clean clobber:: generated.clean

generated.FORCE:

.PHONY: generated.clean robot_child generated.FORCE
