Last active
December 14, 2015 05:59
-
-
Save jinnko/5039183 to your computer and use it in GitHub Desktop.
Opscode Chef recipe to build hiphop-php from source on Debian 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: php-hiphop | |
# Recipe:: install_from_source | |
# | |
# Copyright 2011, FiveCool Consulting Ltd. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
include_recipe "apt::repo_wheezy" | |
# Note that order of libattr1, libacl1 and libarchive12 is important, and also requires specific vers | |
#, 'multiarch-support/wheezy', | |
pkgs = [ | |
'git-core', 'libmysqlclient-dev', 'libxml2-dev', 'libmcrypt-dev', 'libicu-dev', 'openssl', 'build-essential', 'libcap-dev', 'libgd2-xpm-dev', 'zlib1g-dev', 'libonig-dev', 'libpcre3-dev', 'autoconf', 'libtool', 'libcurl4-openssl-dev', 'wget', 'memcached', 'libreadline-dev', 'libncurses-dev', 'libmemcached-dev', 'libbz2-dev', 'libc-client2007e-dev', 'php5-mcrypt', 'php5-imagick', 'libgoogle-perftools-dev', 'libcloog-ppl0', 'libelf-dev', 'libunwind7-dev', 'subversion', | |
'libtbb2/wheezy#4.0+r233-1', 'libtbb-dev/wheezy#4.0+r233-1', | |
'libmpfr4/wheezy', 'libgomp1/wheezy', 'liblzma5/wheezy', 'libnettle4/wheezy', | |
'libattr1/wheezy#1:2.4.46-8', 'libacl1/wheezy#2.2.51-8', 'libarchive12/wheezy', | |
'libboost-thread1.49.0/wheezy', 'libboost-thread-dev/wheezy', 'libfontconfig1-dev/squeeze', 'pkg-config/wheezy', 'libdwarf-dev/wheezy#20120410-2', 'binutils-dev/wheezy', 'libboost-system1.49-dev/wheezy', 'libboost-program-options1.49-dev/wheezy', 'libboost-filesystem1.49-dev/wheezy', | |
'g++-4.7/wheezy', 'gcc-4.7/wheezy', 'libc6-dev/wheezy', 'libgcc1/wheezy', 'binutils/wheezy', 'libc6/wheezy', 'libc-dev-bin/wheezy', 'libc-bin/wheezy', 'libstdc++6-4.7-dev/wheezy', 'libstdc++6/wheezy', 'cmake/wheezy', 'g++/wheezy#4.7.2-1', 'cpp/wheezy#4.7.2-1', 'gcc/wheezy#4.7.2-1', 'make/wheezy', | |
] | |
pkgs.each do |pkg| | |
if pkg.include? '#' | |
pkg_name = pkg.gsub(/\/.+/, '') | |
file "/etc/apt/preferences.d/#{pkg_name}" do | |
content <<-EOH.gsub /^[[:space:]]+/, '' | |
Package: #{pkg_name} | |
Pin: version #{pkg.match(/#(.+)/)[1]} | |
Pin-Priority: 991 | |
EOH | |
end | |
end | |
end | |
# Activate the highest version of the compiler | |
bash "update-alternatives" do | |
code <<-EOH | |
for x in cpp gcc g++; do | |
if update-alternatives --display $x 2>/dev/null >/dev/null; then | |
update-alternatives --remove-all $x 2>/dev/null | |
fi | |
alternatives=( $(dpkg -l "${x}-*" | grep '^i' | grep -v base | awk '{print $2}' | sort -nr) ) | |
i=10 | |
for alt in ${alternatives[@]}; do | |
update-alternatives --install /usr/bin/$x $x /usr/bin/$alt $i | |
let i=$(( i + 10 )) | |
done | |
update-alternatives --set $x /usr/bin/${alternatives[0]} | |
done | |
EOH | |
action :run | |
end | |
# Install the pacakges | |
pkgs.each do |pkg| | |
package pkg.gsub(/\/.+/, '') do | |
action :upgrade | |
if pkg.include? '/wheezy' | |
options "-t wheezy" | |
end | |
if pkg.include? '#' | |
version pkg.match(/#(.+)/)[1] | |
end | |
end | |
end | |
############### | |
# HPHP | |
############### | |
build_path = "#{node[:php_hiphop][:build_path]}/src/hiphop-php" | |
directory build_path do | |
recursive true | |
action :create | |
end | |
bash "HPHP build: HPHP" do | |
cwd build_path | |
code <<-EOH | |
set -e | |
ionice -c3 nice -n 19 git submodule init | |
ionice -c3 nice -n 19 git submodule update | |
echo "DEBUG: HPHP_HOME=$HPHP_HOME" | |
echo "DEBUG: HPHP_LIB=$HPHP_LIB" | |
echo "DEBUG: CMAKE_LIBRARY_PATH=$CMAKE_LIBRARY_PATH" | |
echo "DEBUG: CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH" | |
ionice -c3 nice -n 19 cmake . | |
ionice -c3 nice -n 19 make -j #{node[:cpu][:core_count] + 1} | |
EOH | |
environment ({ | |
'CMAKE_PREFIX_PATH' => node[:php_hiphop][:build_path], | |
'HPHP_HOME' => build_path, | |
'HPHP_LIB' => "#{build_path}/bin", | |
'CMAKE_LIBRARY_PATH' => '/usr/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu' | |
}) | |
action :nothing | |
end | |
git "HPHP checkout" do | |
repository "git://github.com/facebook/hiphop-php.git" | |
destination build_path | |
#depth 3 | |
action :sync | |
notifies :run, "bash[HPHP build: HPHP]" | |
end | |
############### | |
# libevent | |
############### | |
build_path = "#{node[:php_hiphop][:build_path]}/src/libevent" | |
bash "HPHP build: libevent" do | |
cwd build_path | |
code <<-EOH | |
set -e | |
cat #{node[:php_hiphop][:build_path]}/src/hiphop-php/hphp/third_party/libevent-#{node[:php_hiphop][:deps][:libevent][:patch_version]}-changes.diff | patch -p1 | |
ionice -c3 nice -n 19 ./autogen.sh | |
ionice -c3 nice -n 19 ./configure --prefix=$CMAKE_PREFIX_PATH | |
ionice -c3 nice -n 19 make -j #{node[:cpu][:core_count] + 1} | |
ionice -c3 nice -n 19 make install | |
EOH | |
environment ({ 'CMAKE_PREFIX_PATH' => node[:php_hiphop][:build_path] }) | |
action :nothing | |
notifies :run, "bash[HPHP build: HPHP]" | |
end | |
git "HPHP dependency: libevent" do | |
repository "git://github.com/libevent/libevent.git" | |
reference node[:php_hiphop][:deps][:libevent][:reference] | |
destination build_path | |
#depth 3 | |
action :sync | |
notifies :run, "bash[HPHP build: libevent]", :immediately | |
end | |
############### | |
# Curl | |
############### | |
build_path = "#{node[:php_hiphop][:build_path]}/src/curl" | |
bash "HPHP build: curl" do | |
cwd build_path | |
code <<-EOH | |
set -e | |
ionice -c3 nice -n 19 ./buildconf | |
ionice -c3 nice -n 19 ./configure --prefix=$CMAKE_PREFIX_PATH | |
ionice -c3 nice -n 19 make -j #{node[:cpu][:core_count] + 1} | |
ionice -c3 nice -n 19 make install | |
EOH | |
environment ({ 'CMAKE_PREFIX_PATH' => node[:php_hiphop][:build_path] }) | |
action :nothing | |
notifies :run, "bash[HPHP build: HPHP]" | |
end | |
git "HPHP dependency: curl" do | |
repository "git://github.com/bagder/curl.git" | |
reference node[:php_hiphop][:deps][:curl][:reference] | |
destination build_path | |
#depth 3 | |
action :sync | |
notifies :run, "bash[HPHP build: curl]", :immediately | |
end | |
############### | |
# Google glog | |
############### | |
build_path = "#{node[:php_hiphop][:build_path]}/src/google-glog" | |
bash "HPHP build: google-glog" do | |
cwd build_path | |
code <<-EOH | |
set -e | |
ionice -c3 nice -n 19 ./configure --prefix=$CMAKE_PREFIX_PATH | |
ionice -c3 nice -n 19 make -j #{node[:cpu][:core_count] + 1} | |
ionice -c3 nice -n 19 make install | |
EOH | |
environment ({ 'CMAKE_PREFIX_PATH' => node[:php_hiphop][:build_path] }) | |
action :nothing | |
notifies :run, "bash[HPHP build: HPHP]" | |
end | |
subversion "HPHP dependency: google-glog" do | |
repository "http://google-glog.googlecode.com/svn/trunk/" | |
destination build_path | |
#depth 3 | |
action :sync | |
notifies :run, "bash[HPHP build: google-glog]", :immediately | |
end | |
############### | |
# JEMalloc | |
############### | |
jemalloc = "jemalloc-#{node[:php_hiphop][:deps][:jemalloc][:version]}" | |
jemalloc_filename = "#{jemalloc}.tar.bz2" | |
jemalloc_filepath = "#{node[:php_hiphop][:build_path]}/src/#{jemalloc_filename}" | |
jemalloc_buildpath = "#{node[:php_hiphop][:build_path]}/src/#{jemalloc}" | |
jemalloc_url = "http://www.canonware.com/download/jemalloc/#{jemalloc_filename}" | |
bash "HPHP compile dep: #{jemalloc}" do | |
cwd jemalloc_buildpath | |
code <<-EOH | |
set -e | |
ionice -c3 nice -n 19 ./configure --prefix=$CMAKE_PREFIX_PATH | |
ionice -c3 nice -n 19 make -j #{node[:cpu][:core_count] + 1} | |
ionice -c3 nice -n 19 make install | |
EOH | |
action :nothing | |
notifies :run, "bash[HPHP build: HPHP]" | |
end | |
execute "HPHP unzip dep: #{jemalloc}" do | |
cwd "#{node[:php_hiphop][:build_path]}/src/" | |
command "tar jxf #{jemalloc_filename}" | |
action :nothing | |
notifies :run, "bash[HPHP compile dep: #{jemalloc}]", :immediately | |
end | |
remote_file "HPHP download dep: #{jemalloc_filename}" do | |
source jemalloc_url | |
path jemalloc_filepath | |
mode 0644 | |
action :nothing | |
notifies :run, "execute[HPHP unzip dep: #{jemalloc}]", :immediately | |
end | |
http_request "HEAD #{jemalloc_url}" do | |
#Chef::Log.info "Check #{jemalloc_url}" | |
message "" | |
url jemalloc_url | |
action :head | |
if ::File.exists?(jemalloc_filepath) | |
headers "If-Modified-Since" => ::File.mtime(jemalloc_filepath).httpdate | |
end | |
notifies :create, "remote_file[HPHP download dep: #{jemalloc_filename}]", :immediately | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment