#!/bin/sh
if [ $# != 2 ]
then
	echo "usage: setup PHP_directory SQL_relay_directory"
	exit
fi

#
# The following is a massive hack.  It tries to steal the
# mechanism for build a dynamic library from Perl's -V output
# If this script fails on this machine, try running 'perl -V'
# manually and pick out the setting for:
#   
#    cc, optimize, ccflags, ld, cccdlflags and lddlflags
#
# Replace the below definitions with the output you see.
#
if test ! -r "perl.out"; then
	perl -V > perl.out
fi

# if the greps and cuts don't do the job, set these manually
CC=`grep cc= perl.out | cut -d, -f1 | cut -d\' -f2`
OPT=`grep optimize= perl.out | cut -d, -f2 | cut -d\' -f2`
CCFLAGS=`grep ccflags perl.out | cut -d, -f1 | cut -d\' -f2`
LD=`grep ld= perl.out | cut -d, -f1 | cut -d\' -f2`
LFLAGS=`grep cccdlflags= perl.out | cut -d, -f1 | cut -d\' -f2`
CCDLFLAGS=`grep ccdlflags= perl.out | cut -d, -f4 | cut -d\' -f2 | sed "s, ,,"`
LDDLFLAGS=`grep lddlflags perl.out | cut -d, -f2 | cut -d\' -f2`
#--------


CC="$CC $OPT $CCFLAGS -I. -I$1 -I$1/Zend $LFLAGS"
LD="$LD $LDDLFLAGS $CCDLFLAGS"

sed "s,@CC@,$CC,
	 s,@LD@,$LD,
     s,@SR@,$2," <Makefile.tmpl >Makefile
