#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2003 Stefan Gybas <sgybas@debian.org>

#
# Example file for Java library packages that use the Ant build system
#

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/ant.mk

# Including this file gets us a simple patch system.  You can just
# drop patches in debian/patches, and they will be automatically
# applied and unapplied.
include /usr/share/cdbs/1/rules/simple-patchsys.mk

# The home directory of the Java Runtime Environment (JRE) or Java Development
# Kit (JDK). You can either set JAVA_HOME directly or set JAVA_HOME_DIRS to
# multilpe possbile home directories. The first existing directory from this
# list is used for JAVA_HOME. You can also override JAVACMD in case you don't
# want to use the default JAVA_HOME/bin/java.
JAVA_HOME = /usr/lib/kaffe

# Ant's home directory. Use /usr/share/ant1.5 for the libant1.5-java package
# in main. If you need optional Ant tasks, use /usr/share/ant and add
# $(ANT_HOME)/lib/ant-optional.jar to DEB_JARS below.
ANT_HOME := /usr/share/ant

# Additional JARs to add to the class path, either full path or just the
# basename for JARs in /usr/share/java. The ".jar" suffix may also be ommitted.
# ant.jar and $(JAVA_HOME)/lib/tools.jar are automatically added if they
# exist.
DEB_JARS :=

# Build compiler
DEB_ANT_COMPILER := jikes

# Property file for Ant, defaults to debian/ant.properties if it exists.
# You may define additional properties that are referenced from build.xml so
# you don't have to modify upstream's build.xml. Please note that command-line
# arguments in ANT_ARGS (see below) override the settings in build.xml and
# the property file.
#DEB_ANT_PROPERTYFILE := build.properties

# Defaults to build.xml (Ant's default) in the $(DEB_BUILDDIR) directory
#DEB_ANT_BUILDFILE := build.xml

# Additional options to pass to the Java virtual machine
#ANT_OPTS := -verify *

# Additional command-line arguments for Ant
#ANT_ARGS := -verbose

# This is crude, but I see no other way to work around dh_shlibdeps automatically 
# be called from debhelper.mk
# 
# Exclude everything from dh_* and then add options to be passed to dpkg-*

SWT_VER := 3042

# disabling awt and mozilla. Mozilla is picked up by dh_*, but awt 
# is currently not build.
DEB_DH_SHLIBDEPS_ARGS := -Xlibswt-mozilla-* -- -dDepends \
        debian/libswt3-gtk-java/usr/lib/jni/libswt-gtk-$(SWT_VER).so \
	debian/libswt3-gtk-java/usr/lib/jni/libswt-pi-gtk-$(SWT_VER).so \
	debian/libswt3-gtk-java/usr/lib/jni/libswt-atk-gtk-$(SWT_VER).so \
	-dSuggests \
	debian/libswt3-gtk-java/usr/lib/jni/libswt-gnome-gtk-$(SWT_VER).so
#	debian/libswt3-gtk-java/usr/lib/jni/libswt-mozilla-gtk-$(SWT_VER).so 
#	debian/libswt3-gtk-java/usr/lib/jni/libswt-awt-gtk-$(SWT_VER).so
	

# Targets to invoke for building, installing, testing and cleaning up.
# Building uses the default target from build.xml, installing and testing is
# only called if the corresponding variable is set. You can also specify
# multiple targets for each step.
DEB_ANT_BUILD_TARGET   := compile
DEB_ANT_INSTALL_TARGET := install
#DEB_ANT_TEST_TARGET    :=
#DEB_ANT_CLEAN_TARGET   := clean

install/libswt3-gtk-java::
	install -m 644 debian/libswt3-gtk.java debian/$(cdbs_curpkg)/usr/share/java-config/libswt3-gtk-java
	# They are alread installed there, but with wrong names...
	mv debian/$(cdbs_curpkg)/usr/share/java/swt.jar debian/$(cdbs_curpkg)/usr/share/java/swt3-gtk.jar
	mv debian/$(cdbs_curpkg)/usr/share/java/swt-pi.jar debian/$(cdbs_curpkg)/usr/share/java/swt3-pi-gtk.jar
	mv debian/$(cdbs_curpkg)/usr/share/java/swt-mozilla.jar debian/$(cdbs_curpkg)/usr/share/java/swt3-mozilla-gtk.jar
        # disabled for now...
	-rm debian/$(cdbs_curpkg)/usr/lib/jni/libswt-awt-gtk-*.so

update-source:
	echo $(JAVACMD)
	echo $(JAVA_HOME)
	# this breaks, if the plugin specify its own build.xml!
#	find plugins -name build.xml -exec rm \{\} \;
	bash debian/update.sh
	rm -f fetch*xml
	rm -f directory.txt
	# bug in eclipse: always wants a workspace...
	rm -rf workspace
	rm -rf debian/update/workspace

common-configure-arch:: debian/stamp-copy-all-together
	
debian/stamp-copy-all-together:
	cd plugins/org.eclipse.swt && mkdir -p bin && cp -r Eclipse\ SWT\ PI/gtk/library bin && \
	cp Eclipse\ SWT/common/library/* bin/library && cp Eclipse\ SWT\ Program/gnome/library/* bin/library && \
	cp Eclipse\ SWT\ Mozilla/common/library/* bin/library && \
	cp Eclipse\ SWT\ AWT/gtk/library/* bin/library
	
	touch debian/stamp-copy-all-together

	
common-build-arch:: common-configure-arch debian/stamp-arch-ant-call

# This involves a hack, as we can't pass the JAVA_HOME through ant without
# patching too much. So we first call the makefile and then the ant file, so 
# the ant make call doesn't do anything. This way we also fail on 
# build errors. :)
# 
# Disableing make_awt for now. Lets see when kaffe catches up...
debian/stamp-arch-ant-call:
	cd plugins/org.eclipse.swt/bin/library/ && \
	MOZILLA_HOME=/usr/include/mozilla \
	MOZILLA_LIBS_HOME=/usr/lib/mozilla sh build.sh make_swt make_atk make_gnome make_mozilla
	cd plugins/org.eclipse.swt/Eclipse\ SWT\ PI/gtk/library/ && \
	$(DEB_ANT_INVOKE) -buildfile make_gtk.xml -v
	touch debian/stamp-arch-ant-call

clean::
	rm -f compilelog.txt
	rm -rf plugins/org.eclipse.swt/bin
	rm -f debian/stamp-arch-ant-call
	rm -f debian/stamp-copy-all-together
	find plugins -name "*.so" -exec  rm -r "{}" \;

	
