# 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

BLINKENLIB=../BlinkenLibJava/BlinkenLib.jar
JFLEXIPIX=../JFlexiPix/JFlexiPix.jar

VERSION_MAJOR=1
VERSION_MINOR=4
VERSION_REVISION=1

JAVAC=javac
JAR=jar
KEYTOOL=keytool
JARSIGNER=jarsigner
KEYPASS=BlinkenLightsInteractiveMovieProgram
JAVA=java
P=org/blinkenarea/Blimp
IMG=$(P)/images

CLASSPATH=.:$(BLINKENLIB):$(JFLEXIPIX)
CLASS_FILES=$(P)/BlinkenFileFilter.class $(P)/BlinkenFrameDisplay.class \
            $(P)/BlinkenFrameDisplayListener.class $(P)/BlinkenFrameDisplayInterceptor.class \
            $(P)/BlinkenFrameEditor.class $(P)/BlinkenFrameEditorListener.class \
            $(P)/Blimp.class $(P)/Version.class

IMAGE_FILES=$(IMG)/ColorPicker.png $(IMG)/Dot.png $(IMG)/Line.png \
            $(IMG)/Rectangle.png $(IMG)/FilledRectangle.png \
            $(IMG)/Circle.png $(IMG)/FilledCircle.png \
            $(IMG)/Copy.png $(IMG)/Paste.png \
            $(IMG)/Invert.png $(IMG)/MirrorHor.png $(IMG)/RollLeft.png \
            $(IMG)/Rotate90.png $(IMG)/MirrorVer.png $(IMG)/RollRight.png \
            $(IMG)/Rotate180.png $(IMG)/MirrorDiag.png $(IMG)/RollUp.png \
            $(IMG)/Rotate270.png $(IMG)/MirrorDiag2.png $(IMG)/RollDown.png \
            $(IMG)/Undo.png $(IMG)/Redo.png \
            $(IMG)/InsertFrame.png $(IMG)/DuplicateFrame.png $(IMG)/DeleteFrame.png

.phony: all clean jar run

all: jar

clean:
	rm -f $(P)/Version.java $(CLASS_FILES) BlinkenLib.jar Blimp.jar

jar: Blimp.jar

run: Blimp.jar
	$(JAVA) -jar $<

$(P)/Version.java: Makefile
	echo "package org.blinkenarea.Blimp;" >$@
	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) $<

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

Blimp.jar: Blimp.mf Blimp.keystore $(CLASS_FILES) $(IMAGE_FILES)
	rm -rf tmp
	mkdir tmp
	for FILE in $(CLASS_FILES) $(IMAGE_FILES); \
	  do \
	    mkdir -p tmp/$$(dirname $$FILE) || exit; \
	    cp $$FILE tmp/$$FILE || exit; \
	  done
	for JAR in $(filter %.jar,$(subst :, ,$(CLASSPATH))); \
	  do \
	    cd tmp; $(JAR) xf ../$$JAR || exit; \
	    rm -rf META-INF; \
	  done
	cd tmp; $(JAR) cmf ../Blimp.mf ../Blimp.jar .
	rm -rf tmp
	$(JARSIGNER) -keystore Blimp.keystore -storepass $(KEYPASS) Blimp.jar Blimp