Skip to content

Instantly share code, notes, and snippets.

@ircmaxell
Created July 8, 2012 16:58
Show Gist options
  • Save ircmaxell/3071768 to your computer and use it in GitHub Desktop.
Save ircmaxell/3071768 to your computer and use it in GitHub Desktop.
PHP Build Script
#!/bin/bash
function checkError {
if [ $1 -ne 0 ]; then
echo -e "Error in build step\n"
exit
fi
}
VERSION=$1
DEBUG=$2
ZTS=$3
THIRTYTWO=$4
POSTFIX=
EXTRA_FLAGS=
BUILDDIR="./php-src/"
BRANCH="master"
if (test ${VERSION:0:3} == "5.3"); then
export PHP_AUTOCONF="autoconf-2.13"
else
export PHP_AUTOCONF="autoconf"
fi
if (test "${DEBUG}" = "debug"); then
POSTFIX="$POSTFIX-debug"
EXTRA_FLAGS="$EXTRA_FLAGS --enable-debug"
fi
if (test "${ZTS}" = "zts"); then
EXTRA_FLAGS="$EXTRA_FLAGS --enable-maintainer-zts"
POSTFIX="$POSTFIX-zts"
fi
if (test "${THIRTYTWO}" = "32bit"); then
export CFLAGS="-m32"
POSTFIX="$POSTFIX-32bit"
fi
cd $BUILDDIR
make distclean
# remove any untracked files
git clean -f -d
# completely revert back to the repo status
git checkout .
if (test "${VERSION}" = "master"); then
BRANCH="master"
else
BRANCH=`echo "PHP-${VERSION}" | sed 's/dev//'`
fi
echo "Building ${VERSION}${POSTFIX} with ($EXTRA_FLAGS)"
# Switch to the requsted version
git checkout ${BRANCH}
# Make sure that it succeeded
checkError $?
# Fetch latest updates
git pull origin
# Make sure that it succeeded
checkError $?
# Start the build process
./buildconf --force
# Make sure that it succeeded
checkError $?
if (test "${THIRTYTWO}" = "32bit"); then
OPTIONS="--disable-all --enable-zip --with-zlib --with-bz2 --with-xsl --with-openssl"
else
OPTIONS="--enable-debug --disable-cgi --enable-zip --with-zlib --with-bz2 --with-xsl --with-openssl"
fi
# Generate the Makefile
./configure \
--prefix=/usr/local/php/${VERSION}${POSTFIX} ${EXTRA_FLAGS} ${OPTIONS}
# Make sure that it succeeded
checkError $?
# Compile
make -j 5
# Make sure that it succeeded
checkError $?
# Install away
make install
# Make sure that it succeeded
checkError $?
cat php.ini-development > /usr/local/php/${VERSION}${POSTFIX}/lib/php.ini
echo -e "\n\ninclude_path = '.:/usr/local/lib/php'\n" >> /usr/local/php/${VERSION}${POSTFIX}/lib/php.ini
echo -e "date.timezone = 'America/New_York'\n" >> /usr/local/php/${VERSION}${POSTFIX}/lib/php.ini
echo -e "phar.readonly = Off\n" >> /usr/local/php/${VERSION}${POSTFIX}/lib/php.ini
if (test "${version}" != "master"); then
cd ../xdebug-src
make clean
git pull origin
/usr/local/php/${VERSION}${POSTFIX}/bin/phpize
./configure --enable-xdebug --with-php-config=/usr/local/php/${VERSION}${POSTFIX}/bin/php-config
make -j5
mkdir -p /usr/local/php/${VERSION}${POSTFIX}/ext
cp modules/xdebug.so /usr/local/php/${VERSION}${POSTFIX}/ext/xdebug.so
echo -e "zend_extension=/usr/local/php/${VERSION}${POSTFIX}/ext/xdebug.so" >> /usr/local/php/${VERSION}${POSTFIX}/lib/php.ini
echo -e "\nxdebug.scream=1" >> /usr/local/php/${VERSION}${POSTFIX}/lib/php.ini
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment