Skip to content

Instantly share code, notes, and snippets.

@satooshi
Created April 12, 2013 09:20
Show Gist options
  • Save satooshi/5370775 to your computer and use it in GitHub Desktop.
Save satooshi/5370775 to your computer and use it in GitHub Desktop.
php-build plugin for twig extension. put this script into /path/to/php-build/plugins.d/twig.sh
#!/usr/bin/env bash
# PHP.next Development releases depend on current XDebug development
# snapshots.
function install_twig_master {
local source_dir="$TMP/source/twig-master"
local cwd=$(pwd)
local revision=$1
if [ -d "$source_dir" ] && [ -d "$source_dir/.git" ]; then
log "Twig" "Updating Twig from Git Master"
cd "$source_dir"
git pull origin master > /dev/null
cd "$cwd"
else
log "Twig" "Fetching from Git Master"
git clone git://github.com/fabpot/Twig.git "$source_dir" > /dev/null
fi
if [ -n "$revision" ]; then
log "Twig" "Checkout specified revision: $revision"
cd "$source_dir"
git reset --hard $revision
cd "$cwd"
fi
_build_twig "$source_dir/ext/twig"
}
# On the contrary, for stable PHP versions we need a stable XDebug version
function install_twig {
local version=$1
local package_url="https://github.com/fabpot/Twig/archive/v$version.tar.gz"
if [ -z "$version" ]; then
echo "install_twig: No Version given." >&3
return 1
fi
log "Twig" "Downloading $package_url"
# We cache the tarballs for XDebug versions in `packages/`.
if [ ! -f "$TMP/packages/Twig-$version.tar.gz" ]; then
wget -q -O "$TMP/packages/Twig-$version.tar.gz" "$package_url"
fi
# Each tarball gets extracted to `source/xdebug-$version`.
if [ -d "$TMP/source/Twig-$version" ]; then
rm -rf "$TMP/source/Twig-$version"
fi
tar -xzf "$TMP/packages/Twig-$version.tar.gz" -C "$TMP/source"
[[ -f "$TMP/source/package.xml" ]] && rm "$TMP/source/package.xml"
[[ -f "$TMP/source/package2.xml" ]] && rm "$TMP/source/package2.xml"
_build_twig "$TMP/source/Twig-$version/ext/twig"
}
function _build_twig {
local source_dir="$1"
local cwd=$(pwd)
log "Twig" "Compiling in $source_dir"
cd "$source_dir"
{
$PREFIX/bin/phpize > /dev/null
"$(pwd)/configure" --with-php-config=$PREFIX/bin/php-config > /dev/null
make > /dev/null
make install > /dev/null
} >&4 2>&1
local twig_ini="$PREFIX/etc/conf.d/twig.ini"
# Zend extensions are not looked up in PHP's extension dir, so
# we need to find the absolute path for the extension_dir.
local extension_dir=$("$PREFIX/bin/php" -r "echo ini_get('extension_dir');")
if [ -z "$PHP_BUILD_XDEBUG_ENABLE" ]; then
PHP_BUILD_XDEBUG_ENABLE=yes
fi
if [ ! -f "$twig_ini" ]; then
log "Twig" "Installing Twig configuration in $twig_ini"
# Comment out the lines in the xdebug.ini when the env variable
# is set to something to "no"
local conf_line_prefix=
if [ "$PHP_BUILD_XDEBUG_ENABLE" == "off" ]; then
log "Twig" "Twig is commented out in $twig_ini. Remove the \";\" to enable it."
conf_line_prefix=";"
fi
echo "$conf_line_prefix extension=\"$extension_dir/twig.so\"" > $twig_ini
fi
log "Twig" "Cleaning up."
make clean > /dev/null
cd "$cwd" > /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment