#!/bin/sh
#
BUILD_DIR=`dirname $0`
# Get jubabox_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/

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