# This file is a nasty piece of work I use for building SQLiteJDBC
# across multiple architectures. Best to ignore it.

include Makefile.common

afsdir 		:= /afs/hcoop.net/user/c/cr/crawshaw
repo   		:= $(afsdir)/repo/sqlitejdbc
files  		:= $(afsdir)/files/sqlitejdbc

default: dist/$(sqlitejdbc).jar dist/$(sqlitejdbc)-src.tgz dist/$(sqlitejdbc)-bin.tgz

release: dist/$(sqlitejdbc).jar dist/$(sqlitejdbc)-src.tgz dist/$(sqlitejdbc)-bin.tgz
	darcs push -a hcoop:$(repo)
	scp dist/$(sqlitejdbc)* hcoop:$(files)/

dist/$(sqlitejdbc).jar: build/mac-universal.lib build/win-x86.lib build/linux-x86.lib dist/$(sqlitejdbc)-pure.jar
	cp dist/$(sqlitejdbc)-pure.jar build/$(sqlitejdbc).jar
	(cd build; jar uf $(sqlitejdbc).jar *.lib)
	cp build/$(sqlitejdbc).jar $@
	rm build/$(sqlitejdbc).jar

dist/$(sqlitejdbc)-src.tgz:
	darcs dist -d $(sqlitejdbc)-src
	mv $(sqlitejdbc)-src.tar.gz $@

dist/$(sqlitejdbc)-bin.tgz: dist/$(sqlitejdbc).jar
	cp build/mac-universal.lib build/libsqlitejdbc.jnilib
	cp build/win-x86.lib build/sqlitejdbc.dll
	cp build/linux-x86.lib build/libsqlitejdbc.so
	$(MAKE) build/$(sqlitejdbc)-native.jar
	cd build; tar cfz ../$@ $(sqlitejdbc)-native.jar \
	    libsqlitejdbc.jnilib sqlitejdbc.dll libsqlitejdbc.so \

dist/$(sqlitejdbc)-pure.jar:
	darcs push -a debian:repo/sqlitejdbc
	ssh debian "cd repo/sqlitejdbc && make -f Makefile.nested test $@"
	scp debian:repo/sqlitejdbc/$@ $@

build/mac-universal.lib:
	@mkdir -p dist build/Darwin-universal
	$(MAKE) os=Darwin arch=ppc native
	$(MAKE) os=Darwin arch=i386 native
	lipo -create build/Darwin-ppc/$(Darwin_LIBNAME) \
	             build/Darwin-i386/$(Darwin_LIBNAME) \
	     -output $@

build/win-x86.lib:
	darcs push -a debian:repo/sqlitejdbc
	ssh debian "cd repo/sqlitejdbc && make os=Win arch=i586 native"
	scp debian:repo/sqlitejdbc/build/Win-i586/$(Win_LIBNAME) $@

build/linux-x86.lib:
	darcs push -a debian:repo/sqlitejdbc
	ssh debian "cd repo/sqlitejdbc && make arch=i386 test"
	scp debian:repo/sqlitejdbc/build/Default-i386/$(Default_LIBNAME) $@

