JPDFXAPP_VERSION:=$(shell grep "private static final String appVersion" src/Jmakepdfx.java | sed "s/private\sstatic\sfinal\sString\sappVersion\s=//" | tr -d "\"\; ")
INNOSETUP=wine ~/.wine/drive_c/Program\ Files/Inno\ Setup\ 5/Compil32.exe


test	: app
	bin/jmakepdfx -debug

dist	: app inno-setup/jmakepdfx.iss
	mkdir -p dist/jmakepdfx
	mkdir -p dist/jmakepdfx/doc
	cp doc/jmakepdfx.pdf dist/jmakepdfx/doc
	cp doc/LICENSE dist/jmakepdfx/doc
	cp doc/jlfgr-license.txt dist/jmakepdfx/doc
	cp doc/README dist/jmakepdfx/doc
	cp CHANGES dist/jmakepdfx/doc
	rsync -r -L --exclude=\*.svn bin dist/jmakepdfx
	rsync -r -L --exclude=\*.svn lib dist/jmakepdfx
	$(INNOSETUP) /cc inno-setup/jmakepdfx.iss
	cd dist; zip -r jmakepdfx.zip jmakepdfx/
	rm -rf dist/jmakepdfx-src
	svn export file:///media/Repository/programming/java/jmakepdfx dist/jmakepdfx-src
	cd dist; zip -r jmakepdfx-src.zip jmakepdfx-src

ctan	: dist
	mkdir -p jmakepdfx
	cp doc/README jmakepdfx/
	cp doc/LICENSE jmakepdfx/
	cp doc/jmakepdfx.pdf jmakepdfx/
	cp dist/*.{zip,exe} jmakepdfx/
	zip -r jmakepdfx-dist.zip jmakepdfx/
	\rm -rf jmakepdfx/

app	: lib/jmakepdfx.jar lib/jh.jar \
	  lib/jlfgr-1_0.jar lib/icons \
	  bin/jmakepdfx lib/resources \
	  resources/helpsets/jmakepdfx-en/Map.jhm \
	  resources/LICENSE

resources/LICENSE	:
	cd resources; ln -s ../doc/LICENSE

resources/helpsets/jmakepdfx-en/Map.jhm	: doc/jmakepdfx.tex
				make -C doc helpset

lib/jmakepdfx.jar	: lib src/Manifest.txt \
		classes/com/dickimawbooks/jmakepdfx/Jmakepdfx.class 
	cd classes; \
	jar cmf ../src/Manifest.txt ../lib/jmakepdfx.jar \
	  com/dickimawbooks/jmakepdfx/*.class 

lib/resources	:
	cd lib; ln -s ../resources

lib/icons	:
	cd lib; ln -s ../images/icons

lib/jlfgr-1_0.jar	: 
	cd lib; ln -f -s /usr/share/java/jlfgr-1_0.jar

lib/jh.jar      : 
	cd lib; ln -f -s /usr/share/java/jh.jar

lib	:
	mkdir -p lib

lib/splash.png	:
	cd lib; ln -s ../images/splash.png

classes/com/dickimawbooks/jmakepdfx/Jmakepdfx.class	: classes/com/dickimawbooks/jmakepdfx \
	src/*.java \
	lib/jh.jar \
	lib/jlfgr-1_0.jar \
	lib/splash.png
	cd src; \
	javac -d ../classes \
	-Xlint:unchecked -Xlint:deprecation \
	-cp ../lib/jh.jar:../lib/jlfgr-1_0.jar \
	*.java

classes/com/dickimawbooks/jmakepdfx	:
	mkdir -p classes/com/dickimawbooks/jmakepdfx

inno-setup/jmakepdfx.iss : Makefile inno-setup/jmakepdfx-src.iss src/Jmakepdfx.java
	cat inno-setup/jmakepdfx-src.iss | sed "s/\"VERSION\"/\"$(JPDFXAPP_VERSION)\"/" > inno-setup/jmakepdfx.iss


clean	:
	\rm -f classes/com/dickimawbooks/jmakepdfx/*.class
	\rm -f -r tests/*/html-src
	\rm -f tests/*/*.{aux,log,out,toc,dvi}
	\rm -f tests/*/*/*.{aux,bbl,blg,log,out,dvi}

squeaky	:
	\rm -f lib/jmakepdfx.jar
	\rm -f inno-setup/jmakepdfx.iss
	make -C doc clean
