#
# The Initial Developer of the Original Code is International
# Business Machines Corporation. Portions created by IBM
# Corporation are Copyright (C) 2007 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.
#

# AXIS
AXIS_TGZ=http://ftp.kddilabs.jp/infosystems/apache/ws/axis/1_4/axis-bin-1_4.tar.gz

# jTreemap
# 2007-12-11 Munetoh, the package on below links are somehow broken...
JTREEMAP_URL=http://jtreemap.sourceforge.net/
JTREEMAP_ZIP=http://jaist.dl.sourceforge.net/sourceforge/jtreemap/jtreemap-1.1.0.zip
#JTREEMAP_ZIP=http://nchc.dl.sourceforge.net/sourceforge/jtreemap/jtreemap-1.1.0.zip

#OPENPTS_JAR=../../openpts/lib/openpts5.jar
OPENPTS_JAR=/opt/OpenPlatformTrustServices/lib/openpts5.jar

AXIS_DIR=/opt/axis-1_4/
JTREEMAP_JAR=/opt/jtreemap-site-1.1.0/jtreemap-1.1.0.jar 

# get by openpts 
CODEC_JAR= /opt/commons-codec-1.3/commons-codec-1.3.jar


##############################
# normal?
##############################

all: setup

clean:
	rm -f *.jar
	rm -f *.jar.db
	rm -f *.jar.so
	rm -f *.o
	rm -f pts-cu
	rm -f pts-cu-swing
	rm -f pts-ca-swing
	rm -f pts-vt-swing

##############################
# Download JARs
##############################

#/tmp/axis-bin-1_4.tar.gz:
#/opt/axis-1_4 : /tmp/axis-bin-1_4.tar.gz

/opt/axis-1_4 : 
	cd /tmp; wget $(AXIS_TGZ)
	cd /opt/; tar xvfz  /tmp/axis-bin-1_4.tar.gz

setup-axis: /opt/axis-1_4
	@echo "AXIS LIBs :  /opt/axis-1_4/lib"

#/tmp/jtreemap-1.1.0.zip:
#/opt/jtreemap-site-1.1.0/jtreemap-1.1.0.jar: /tmp/jtreemap-1.1.0.zip

/opt/jtreemap-site-1.1.0/jtreemap-1.1.0.jar: 
	wget $(JTREEMAP_ZIP) -o /tmp/jtreemap-1.1.0.zip
	cd /opt/; unzip /tmp/jtreemap-1.1.0.zip
	touch $@

setup-jtreemap: /opt/jtreemap-site-1.1.0/jtreemap-1.1.0.jar
	@echo "jTreemap LIB : /opt//jtreemap-site-1.1.0 "


setup-jars: setup-axis setup-jtreemap

##############################
# setup JARs
##############################

openpts5.jar:
	ln -sf $(OPENPTS_JAR) $@
axis.jar:
	ln -sf $(AXIS_DIR)/lib/axis.jar  $@
axis-ant.jar:
	ln -sf $(AXIS_DIR)/lib/axis-ant.jar  $@
commons-discovery.jar:
	ln -sf $(AXIS_DIR)/lib/commons-discovery-0.2.jar  $@
commons-logging.jar:
	ln -sf $(AXIS_DIR)/lib/commons-logging-1.0.4.jar  $@
jaxrpc.jar:
	ln -sf $(AXIS_DIR)/lib/jaxrpc.jar  $@
log4j.jar:
	ln -sf $(AXIS_DIR)/lib/log4j-1.2.8.jar  $@
saaj.jar:
	ln -sf $(AXIS_DIR)/lib/saaj.jar  $@
wsdl4j.jar:
	ln -sf $(AXIS_DIR)/lib/wsdl4j-1.5.1.jar  $@
jtreemap.jar:
	ln -sf $(JTREEMAP_JAR) $@
	
commons-codec.jar: 
	ln -s $(CODEC_JAR) $@

#lib/ktreemap.jar:
#	wget http://nchc.dl.sourceforge.net/sourceforge/jtreemap/org.jense.ktreemap_1.0.0.jar -O $@	
#lib/jface.jar:
#	ln -s /opt/eclipse/plugins/org.eclipse.jface_3.2.1.M20060908-1000.jar $@

# 2007-12-10 Servlet
servlet-api.jar:
	ln -s /opt/apache-tomcat-5.5.25/common/lib/servlet-api.jar .
#
#
setup: openpts5.jar axis.jar axis-ant.jar commons-discovery.jar\
 commons-logging.jar jaxrpc.jar log4j.jar saaj.jar wsdl4j.jar jtreemap.jar commons-codec.jar
setup-servlet: servlet-api.jar

##########################
# SO
##########################


openpts5.jar.so: openpts5.jar
	gcj -shared -findirect-dispatch -fjni -fPIC -Wl,-symbolic -o $<.so $<
	gcj-dbtool -n $<.db
	gcj-dbtool -a $<.db $< $<.so

commons-codec.jar.so: commons-codec.jar
	gcj -shared -findirect-dispatch -fjni -fPIC -Wl,-symbolic -o $<.so $<
	gcj-dbtool -n $<.db
	gcj-dbtool -a $<.db $< $<.so

commons-logging.jar.so: commons-logging.jar
	gcj -shared -findirect-dispatch -fjni -fPIC -Wl,-symbolic -o $<.so $<
	gcj-dbtool -n $<.db
	gcj-dbtool -a $<.db $< $<.so

log4j.jar.so: log4j.jar 
	gcj -shared -findirect-dispatch -fjni -fPIC -Wl,-symbolic -o $<.so $<
	gcj-dbtool -n $<.db
	gcj-dbtool -a $<.db $< $<.so

jtreemap.jar.so: jtreemap.jar
	gcj -shared -findirect-dispatch -fjni -fPIC -Wl,-symbolic -o $<.so $<
	gcj-dbtool -n $<.db
	gcj-dbtool -a $<.db $< $<.so

#axis.jar.so: axis.jar
#	gcj -shared -findirect-dispatch -fjni -fPIC -Wl,-symbolic -o $<.so $<
#	gcj-dbtool -n $<.db
#	gcj-dbtool -a $<.db $< $<.so

so: openpts5.jar.so commons-codec.jar.so commons-logging.jar.so log4j.jar.so jtreemap.jar.so 

clean-so:
	rm -f openpts5.jar.so commons-codec.jar.so commons-logging.jar.so log4j.jar.so jtreemap.jar.so

###################################
# jpp - Build Native Commands
###################################
#SOP=./
SOP=/usr/lib/gcj/OpenPlatformTrustServices/
SOS=$(SOP)/openpts5.jar.so \
$(SOP)/commons-codec.jar.so \
$(SOP)/commons-logging.jar.so \
$(SOP)/log4j.jar.so \
$(SOP)/jtreemap.jar.so 
#$(SOP)/axis.jar.so

# work for java.util.ConcurrentModificationException???
#GCJFLAGS=-fhash-synchronization 
GCJFLAGS=-fhash-synchronization -O2

# ClientUser (cmdline)
pts-cu : openpts-tcdemo.jar $(SOS)
	gcj -findirect-dispatch -Wl,-Bsymbolic -fjni -fPIC openpts-tcdemo.jar $(CFLAGS) -o $@ --main=tcdemo.cmd.ClientUser -L. ${SOS}

# ClientUser (GUI,Swing)
pts-cu-swing : openpts-tcdemo.jar $(SOS)
	gcj -findirect-dispatch -Wl,-Bsymbolic -fjni -fPIC openpts-tcdemo.jar $(CFLAGS) -o $@ --main=tcdemo.swing.ClientUser -L. ${SOS}

# ClientAdmin (GUI,Swing)
pts-ca-swing :  openpts-tcdemo.jar $(SOS)
	gcj $(GCJFLAGS) -findirect-dispatch -Wl,-Bsymbolic -fjni -fPIC openpts-tcdemo.jar $(CFLAGS) -o $@ --main=tcdemo.swing.ClientAdmin -L. ${SOS}

# Vendor Tool (GUI,Swing)
pts-vt-swing : openpts-tcdemo.jar $(SOS)
	gcj -findirect-dispatch -Wl,-Bsymbolic -fjni -fPIC openpts-tcdemo.jar $(CFLAGS) -o $@ --main=tcdemo.swing.VendorTool -L. ${SOS}

jpp: pts-cu pts-cu-swing pts-ca-swing pts-vt-swing

clean-jpp:
	rm -f pts-cu pts-cu-swing pts-ca-swing pts-vt-swing

# EOF
