# JFlexiPix - Java implementation of FlexiPix output library
#
# Copyright 2010-2011 Stefan Schuermans <stefan blinkenarea org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
#
# This program 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 for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# BlinkenLightsInteractiveMovieProgram
# Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
# Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
# a blinkenarea.org project

VERSION_MAJOR=0
VERSION_MINOR=1
VERSION_REVISION=0

JAVAC=javac
JAR=jar
KEYTOOL=keytool
JARSIGNER=jarsigner
KEYPASS=JFlexiPix
JAVA=java
PKG_PATH=org/blinkenarea/JFlexiPix
PKG_PATH_EX=$(PKG_PATH)/examples

CLASSES=AddrParser Config Constants Display Distri \
        Mapping MessageIf MsgType Pixel PixelParser Version
CLASSES_EX=Blink Fade Msg
CLASS_FILES=$(addprefix $(PKG_PATH)/,$(addsuffix .class,$(CLASSES)))
CLASS_FILES_EX=$(addprefix $(PKG_PATH_EX)/,$(addsuffix .class,$(CLASSES_EX)))
CONFIG_EX=$(PKG_PATH_EX)/config/single8x8.flp

CLASSPATH=.

.PHONY: all clean jar blink fade
.SUFFIXES:
.SECONDARY:

all: jar $(CLASS_FILES_EX)

clean:
	rm -f $(PKG_PATH)/Version.java
	rm -f $(CLASS_FILES)
	rm -f JFlexiPix.jar
	rm -f $(CLASS_FILES_EX)

jar: JFlexiPix.jar

blink: $(PKG_PATH_EX)/Blink.class
	$(JAVA) -classpath . $(subst /,.,$(basename $<)) $(CONFIG_EX)

fade: $(PKG_PATH_EX)/Fade.class
	$(JAVA) -classpath . $(subst /,.,$(basename $<)) $(CONFIG_EX)

$(CLASS_FILES_EX): $(CLASS_FILES)

$(PKG_PATH)/Version.java: Makefile
	echo "package org.blinkenarea.JFlexiPix;" >$@
	echo "public class Version {" >>$@
	echo "  public static int Major = $(VERSION_MAJOR);" >>$@
	echo "  public static int Minor = $(VERSION_MINOR);" >>$@
	echo "  public static int Revision = $(VERSION_REVISION);" >>$@
	echo "}" >>$@

%.class: %.java
	$(JAVAC) -classpath $(CLASSPATH) $<

JFlexiPix.keystore:
	$(KEYTOOL) -genkey -alias JFlexiPix -dname CN=JFlexiPix,O=blinkenarea,C=org -keypass $(KEYPASS) -keystore $@ -storepass $(KEYPASS) -validity 3652

JFlexiPix.jar: JFlexiPix.keystore $(CLASS_FILES)
	$(JAR) cf $@ $(CLASS_FILES)
	$(JARSIGNER) -keystore $< -storepass $(KEYPASS) $@ JFlexiPix