#
# The Initial Developer of the Original Code is International
# Business Machines Corporation. Portions created by IBM
# Corporation are Copyright (C) 2007,2009 International Business
# Machines Corporation. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the Common Public License as published by
# IBM Corporation; either version 1 of the License, or (at your option)
# any later version.
#
# 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
# Common Public License for more details.
#
# You should have received a copy of the Common Public License
# along with this program; if not, a copy can be viewed at
# http://www.opensource.org/licenses/cpl1.0.php.
#

PKGNAME=jOpenPTS
VERSION=0.2.4

ifndef INSTDIR
  INSTDIR=/usr/lib/jopenpts
endif

RPMDIR=$(HOME)/rpmbuild

TMP=/home/$(USER)/sandbox

ANT=ant

usage:
	@echo "-------------------------- Setup jars"
	@echo " make eclipse-setup-fedora"
	@echo " make eclipse-setup-ubuntu"
	@echo "-------------------------- Normal built"
	@echo " make all"
	@echo " make install"
	@echo " make clean"
	@echo "------------------------------- for RPM"
	@echo " make rpmbuild-ba"
	@echo "------------------------------- for DEB"
	@echo " make dpkg-buildpackage"
	@echo "---------------------------------------"

############################
# Normal
############################

all:
	$(ANT) compile

runtests:
	$(ANT) runtests

install:
	mkdir -p $(DESTDIR)/usr/bin
	install -m 0755 jopenpts  $(DESTDIR)/usr/bin/
	install -m 0755 jopenpts-gui  $(DESTDIR)/usr/bin/
	mkdir -p $(DESTDIR)/usr/share/applications/
	install -m 0755 dist/jopenpts.desktop  $(DESTDIR)/usr/share/applications/


doc:
	$(ANT) javadocs

clean:
	ant clean
	#make -C lib clean
	rm -rf aot-compile-rpm 
	rm -f *.list

#########################################
# RPM
#########################################

../$(PKGNAME)-$(VERSION):
	ln -s $(PWD) ../$(PKGNAME)-$(VERSION)

rpmbuild-ba: ../$(PKGNAME)-$(VERSION)
	rm -f  $(RPMDIR)/SOURCES/$(PKGNAME)-$(VERSION).tar.gz 
	make clean
	cd ..; tar --exclude=.git --exclude=bin --exclude=.project -zcvf $(RPMDIR)/SOURCES/$(PKGNAME)-$(VERSION).tar.gz $(PKGNAME)-$(VERSION)/*
	cd ..; rpmbuild -ba $(PKGNAME)-$(VERSION)/dist/$(PKGNAME).spec

###########################
# Debian package
###########################

debian:
	ln -s dist/deb/debian debian

dpkg-buildpackage: debian
	chmod +x debian/rules
	-dpkg-buildpackage -tc -b

#########################################
# Setup for Eclipse
#########################################
lib:
	mkdir -p lib

eclipse-setup-fedora: lib
	ln -sf /usr/share/java/log4j.jar ./lib/log4j.jar
	ln -sf /usr/share/java/jakarta-commons-codec.jar ./lib/commons-codec.jar
	ln -sf /usr/share/java/jakarta-commons-logging.jar ./lib/commons-logging.jar
	ln -sf /usr/share/java/jakarta-commons-daemon.jar ./lib/commons-daemon.jar
	ln -sf /usr/share/java/jsch.jar ./lib/jsch.jar

eclipse-setup-fedora15: lib
	ln -sf /usr/share/java/log4j.jar ./lib/log4j.jar
	ln -sf /usr/share/java/commons-codec.jar ./lib/commons-codec.jar
	ln -sf /usr/share/java/commons-logging.jar ./lib/commons-logging.jar
	ln -sf /usr/share/java/jsch.jar ./lib/jsch.jar
	
eclipse-setup-ubuntu: lib
	ln -sf /usr/share/java/log4j-1.2.jar ./lib/log4j.jar
	ln -sf /usr/share/java/commons-codec.jar ./lib/commons-codec.jar
	ln -sf /usr/share/java/commons-logging.jar ./lib/commons-logging.jar
	ln -sf /usr/share/java/commons-daemon.jar ./lib/commons-daemon.jar

# EOF
