#
# 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.
#

##########################
# download config
##########################
# TODO need good version management
AXIS_TGZ=http://ftp.kddilabs.jp/infosystems/apache/ws/axis/1_4/axis-bin-1_4.tar.gz
IBATIS_ZIP=http://www.meisei-u.ac.jp/mirror/apache/dist/ibatis/binaries/ibatis.java/ibatis-2.3.0.677.zip
PGSQL_JDBC_URL=http://jdbc.postgresql.org/
PGSQL_JDBC_JAR_DIST=http://jdbc.postgresql.org/download/postgresql-8.1-411.jdbc3.jar
CODEC_URL=http://commons.apache.org/codec/
CODEC_ZIP=http://www.meisei-u.ac.jp/mirror/apache/dist/commons/codec/binaries/commons-codec-1.3.zip

IBATIS_JAR=/opt/ibatis-2.3.0.677/lib/ibatis-2.3.0.677.jar
LOG4J_JAR=/opt/axis-1_4/lib/log4j-1.2.8.jar
COMMONS_LOGGING_JAR=/opt/axis-1_4/lib/commons-logging-1.0.4.jar
CODEC_JAR=/opt/commons-codec-1.3/commons-codec-1.3.jar
PGSQL_JDBC_JAR=/opt/postgresql-jdbc/postgresql-8.1-411.jdbc3.jar
# RedHat
#PGJDBC_JAR=/usr/share/java/postgresql-jdbc.jar

usage:
	@echo "-------------------------- Normal built"
	@echo " sudo make setup-jars (get required jars)"
	@echo " make setup"
	@echo " make clean"
	@echo "------------------------------- for GCJ"
	@echo " make jpp"
	@echo "---------------------------------------"

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

all: setup

clean: clean-jpp
	rm -f *.jar

###############################
# Download required 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/ibatis-2.3.0.677.zip:
#/opt/ibatis-2.3.0.677: /tmp/ibatis-2.3.0.677.zip

/opt/ibatis-2.3.0.677: 
	cd /tmp; wget $(IBATIS_ZIP)
	mkdir -p /opt/ibatis-2.3.0.677
	cd /opt/ibatis-2.3.0.677; unzip /tmp/ibatis-2.3.0.677.zip

setup-ibatis: /opt/ibatis-2.3.0.677
	@echo "iBatis LIBs :  /opt/ibatis-2.3.0.677/lib"

$(PGSQL_JDBC_JAR):
	mkdir -p /opt/postgresql-jdbc
	cd /opt/postgresql-jdbc; wget $(PGSQL_JDBC_JAR_DIST)

setup-pgsql-jdbc: $(PGSQL_JDBC_JAR)
	@echo "PostgreSQL JDBC LIBs :  /opt/postgresql-jdbc/"
	
#/tmp/commons-codec-1.3.zip:
#/opt/commons-codec-1.3/commons-codec-1.3.jar: /tmp/commons-codec-1.3.zip

/opt/commons-codec-1.3/commons-codec-1.3.jar:
	cd /tmp; wget $(CODEC_ZIP)
	cd /opt/; unzip /tmp/commons-codec-1.3.zip
	# update the date for make
	touch /opt/commons-codec-1.3/commons-codec-1.3.jar 

setup-codec: /opt/commons-codec-1.3/commons-codec-1.3.jar
	@echo "CODEC LIBs :  /opt/commons-codec-1.3/"

setup-jars: setup-axis setup-ibatis setup-codec setup-pgsql-jdbc

##############################
# JARs
##############################

commons-logging.jar:
	ln -sf $(COMMONS_LOGGING_JAR) $@

log4j.jar:
	ln -sf $(LOG4J_JAR)  $@

ibatis.jar: 
	ln -sf $(IBATIS_JAR) $@

commons-codec.jar: 
	ln -sf $(CODEC_JAR) $@

# Redhat
#postgresql-jdbc.jar:
#	ln -s $(PGJDBC_JAR) $@

postgresql-jdbc.jar:
	#wget $(PGSQL_JDBC_JAR) -O $@
	ln -sf $(PGSQL_JDBC_JAR) $@

setup: log4j.jar ibatis.jar commons-logging.jar postgresql-jdbc.jar commons-codec.jar

#####################################
# GCJ For Client 
#####################################
# 2007-12-11 Munetoh 
#  AXIS did not work with GCJ, thus just create the so of core and base64

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

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


clean-jpp:
	rm -f *.so
	rm -f *.db

# EOF