You don't need to rebuild the entire php - just the bcmath extension.
Do the following :
. Download the amp source pkg
. Install autoconf from blastwave.org
. Run the following script :
SAVEPATH=$PATH
PATH=/opt/csw/bin:$PATH
INSTALLDIR=/opt/coolstack
$INSTALLDIR/php5/bin/phpize
make distclean
PATH=$SAVEPATH
./configure --with-prefix=$INSTALLDIR --enable-bcmath --with-php-config=$INSTALLDIR/php5/bin/php-config CFLAGS="-O3 -fPIC"
make
make install