#!/bin/sh

PRE=/usr/local/xscale_be/bin/xscale_be-
CC=${PRE}gcc
CPP=${PRE}cpp
LD=${PRE}ld
AR=${PRE}ar
CXX=${PRE}c++
RANLIB=${PRE}ranlib
STRIP=${PRE}strip

BUILDDIR=`pwd`
LZODIR=$BUILDDIR/lzo-2.02
OPENVPNDIR=$BUILDDIR/openvpn-2.0.9
OPENVPNINSTALLDIR=$BUILDDIR/target_build

#### Building the LZO ###
cd $LZODIR
CPP=${CPP} CC=${CC} LD=${LD} AR=${AR} CXX=${CXX} RANLIB=${RANLIB} STRIP=${STRIP}  CFLAGS=-O2 ./configure --enable-shared --build=i686 --host=xscale-linux
make

### Building the OpenVPN ###
cd $OPENVPNDIR
CPP=${CPP} CC=${CC} LD=${LD} AR=${AR} CXX=${CXX} RANLIB=${RANLIB} STRIP=${STRIP} CFLAGS=-O2 ./configure --enable-shared --build=i686 --host=xscale-linux --with-lzo-lib=$LZODIR/src/.libs --with-lzo-headers=$LZODIR/include --with-ssl-lib=../../openssl/openssl-0.9.7e --with-ssl-headers=../../openssl/openssl-0.9.7e/include
make

# Build the auto-install package
#mkdir -p $OPENVPNINSTALLDIR/sbin
#cp -a $OPENVPNDIR/openvpn $OPENVPNINSTALLDIR/sbin/
#xscale_be-strip $OPENVPNINSTALLDIR/sbin/openvpn
#tar -cvf openvpn.tar $OPENVPNINSTALLDIR/*
#make
