#!/bin/sh
#
BUILD_DIR=`dirname $0`
# Get coregrade_api root directory
cd ..
WORK_DIR=`pwd`
MAILSEND="$WORK_DIR/src/mailsend"
LIBCONFIG="$WORK_DIR/src/libconfig-1.3.1"
# Checking user
if [ "$USER" = "root" ]
then
    echo "Configuring as root"
    LIBCONFIG_PREFIX="/usr"
    echo "Building $LIBCONFIG ..."
    cd $LIBCONFIG
    #echo `pwd` $LIBCONFIG_PREFIX
    CFLAGS=-fPIC CXXFLAGS=-fPIC ./configure --prefix=$LIBCONFIG_PREFIX
    make
    make install
fi
mkdir $WORK_DIR/logs
chmod a+w $WORK_DIR/logs
mkdir $WORK_DIR/src/modules
# Building mailsend
cd $MAILSEND
make
# Configure extension
cd $WORK_DIR/src/

#####echo "Generating interswitch proxy..."
#####cd shared_tool/soap
#####wsdl2h -ninterswitch -Ninterswitch -qinterswitch -o QuickTellerService.h https://stageserv.interswitchng.com/uat_quicktellerservice/quickteller.svc?wsdl
#wsdl2h -o QuickTellerService.h https://stageserv.interswitchng.com/uat_quicktellerservice/quickteller.svc?wsdl
#####soapcpp2 -n -pinterswitch -qinterswitch -1 -C -i -I/usr/share/gsoap/import/ QuickTellerService.h
#soapcpp2 -C -i -I/usr/share/gsoap/import/ QuickTellerService.h
## copy C++
#cp soapC.cpp ../soapC.cc
#cp soapBasicHttpBinding_USCOREQuickTellerServiceProxy.cpp ../soapBasicHttpBinding_USCOREQuickTellerServiceProxy.cc
## copy headers
#cp soapH.h ../../include/
#cp soapBasicHttpBinding_USCOREQuickTellerServiceProxy.h ../../include/
#cp BasicHttpBinding_USCOREQuickTellerService.nsmap ../../include/
#cp soapStub.h ../../include/
# copy C++
#####cp interswitchC.cpp ../interswitchC.cc
#####cp interswitchBasicHttpBinding_USCOREQuickTellerServiceProxy.cpp ../interswitchBasicHttpBinding_USCOREQuickTellerServiceProxy.cc
# copy headers
#####cp interswitchH.h ../../include/
#####cp interswitchBasicHttpBinding_USCOREQuickTellerServiceProxy.h ../../include/
#####cp interswitch.nsmap ../../include/
#####cp interswitchStub.h ../../include/
#####cd ../..
echo "Generating paylid proxy..."
cd shared_tool/paylid
wsdl2h -npaylid -Npaylid -qpaylid -o PaylidService.h http://www.paylid.com/rsl/service.php?wsdl
soapcpp2 -n -ppaylid -qpaylid -1 -C -i -I/usr/share/gsoap/import/ PaylidService.h
# copy C++
cp paylidC.cpp ../paylidC.cc
cp paylidpaylidwsdlBindingProxy.cpp ../paylidpaylidwsdlBindingProxy.cc
# copy headers
cp paylidH.h ../../include/
cp paylidStub.h ../../include/
cp paylid.nsmap ../../include/
cp paylidpaylidwsdlBindingProxy.h ../../include/
cd ../..

# Generate extension
phpize
./configure --enable-coregrade_api
echo "done."
cd $BUILD_DIR
echo $BUILD_DIR
echo $WORK_DIR
echo $USER
