+# NOTES:
+# - hphp/runtime/base/runtime-option.cpp evalJitDefault enables jit if /.hhvm-jit exists (yes, in filesystem root)
# TODO
-# - offline build (without git)
-Summary: HipHop for PHP transforms PHP source code into highly optimized C++
+# - system libevent2: https://github.com/facebook/hiphop-php/pull/421
+# - system libmbfl, system xhp, sqlite3
+%define githash 78394ee
+%define rel 3
+Summary: Virtual Machine, Runtime, and JIT for PHP
Name: hiphop-php
-Version: 0.1
-Release: 0.1
+Version: 2.1.0
+Release: 0.%{githash}.%{rel}
License: PHP 3.01
Group: Development/Languages
-# git clone git://github.com/facebook/hiphop-php.git
-# tar -cjf hiphop-php.tar.bz2 hiphop-php
-Source0: %{name}.tar.bz2
-# Source0-md5: fbeaba0785d6ae3a6f513576867fb5a6
+Source0: https://github.com/facebook/hiphop-php/archive/%{githash}/HPHP-%{version}.%{githash}.tar.gz
+# Source0-md5: 81742a0535a6bab906208d3756b206d1
+# need fb.changes.patch, which is available for 1.4 only
+Source1: http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
+# Source1-md5: a00e037e4d3f9e4fe9893e8a2d27918c
+Source2: get-source.sh
+Patch0: cmake-missing-library.patch
+Patch1: libevent14.patch
+Patch3: system-xhp.patch
+Patch4: system-libafdt.patch
+Patch5: system-folly.patch
+Patch6: boost-system-category.patch
URL: http://wiki.github.com/facebook/hiphop-php/
BuildRequires: binutils-devel
-BuildRequires: bison
-BuildRequires: boost-devel >= 1.37
-BuildRequires: cmake >= 2.6.4
-BuildRequires: curl-devel >= 7.20.1-2
+BuildRequires: bison >= 2.3
+BuildRequires: boost-devel >= 1.50
+BuildRequires: cmake >= 2.8.5
+BuildRequires: curl-devel >= 7.29.0
+BuildRequires: elfutils-devel
BuildRequires: expat-devel
-BuildRequires: flex
+BuildRequires: flex >= 2.5.35
+BuildRequires: gcc >= 6:4.6.0
BuildRequires: gd-devel
-BuildRequires: git-core
+BuildRequires: glog-devel >= 0.3.2
+BuildRequires: imap-devel >= 1:2007
+#BuildRequires: jemalloc-devel
+BuildRequires: libafdt-devel >= 0.1.0
BuildRequires: libcap-devel
-BuildRequires: libevent-devel >= 1.4.13-2
+BuildRequires: libdwarf-devel
+#BuildRequires: libevent-devel >= 1.4.14
BuildRequires: libicu-devel >= 4.2
#BuildRequires: libmbfl-devel
-BuildRequires: libmcrypt
-BuildRequires: libstdc++-devel >= 6:4.1
+BuildRequires: libmcrypt-devel
+BuildRequires: libmemcached-devel >= 1.0.4
+BuildRequires: libstdc++-devel >= 6:4.3
+BuildRequires: libunwind-devel
BuildRequires: libxml2-devel
BuildRequires: mysql-devel
BuildRequires: oniguruma-devel
BuildRequires: openssl-devel
BuildRequires: pcre-devel
+#BuildRequires: php-xhp-devel >= 1.3.9-6
BuildRequires: re2c >= 0.13.0
-BuildRequires: tbb-devel >= 2.2
+BuildRequires: readline-devel
+BuildRequires: rpmbuild(macros) >= 1.675
+BuildRequires: tbb-devel >= 4.0.6000
BuildRequires: zlib-devel
+Provides: php(apc)
+Provides: php(bcmath)
+Provides: php(ctype)
+Provides: php(curl)
+Provides: php(date)
+Provides: php(dom)
+Provides: php(exif)
+Provides: php(fb)
+Provides: php(filter)
+Provides: php(gd)
+Provides: php(hash)
+Provides: php(hotprofiler)
+Provides: php(iconv)
+Provides: php(icu_ucsdet)
+Provides: php(icu_uspoof)
+Provides: php(idn)
+Provides: php(imap)
+Provides: php(json)
+Provides: php(ldap)
+Provides: php(mbstring)
+Provides: php(mcrypt)
+Provides: php(memcache)
+Provides: php(memcached)
+Provides: php(mysql)
+Provides: php(openssl)
+Provides: php(pcntl)
+Provides: php(pcre)
+Provides: php(pdo)
+Provides: php(pdo_mysql)
+Provides: php(pdo_sqlite)
+Provides: php(phar)
+Provides: php(posix)
+Provides: php(reflection)
+Provides: php(server)
+Provides: php(session)
+Provides: php(simplexml)
+Provides: php(soap)
+Provides: php(sockets)
+Provides: php(spl)
+Provides: php(sqlite3)
+Provides: php(sysvmsg)
+Provides: php(sysvsem)
+Provides: php(sysvshm)
+Provides: php(thread)
+Provides: php(thrift_protocol)
+Provides: php(tokenizer)
+Provides: php(xhprof)
+Provides: php(xml)
+Provides: php(xmlreader)
+Provides: php(xmlwriter)
+Provides: php(zlib)
ExclusiveArch: %{x8664}
BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
%description
-HipHop transforms your PHP source code into highly optimized C++ and
-then compiles it with g++ to build binary files. You keep coding in
-simpler PHP, then HipHop executes your source code in a semantically
-equivalent manner and sacrifices some rarely used features - such as
-eval() - in exchange for improved performance.
+HipHop VM (HHVM) is a new open-source virtual machine designed for
+executing programs written in PHP. HHVM uses a just-in-time
+compilation approach to achieve superior performance while maintaining
+the flexibility that PHP developers are accustomed to. HipHop VM (and
+before it HPHPc) has realized > 5x increase in throughput for Facebook
+compared with Zend PHP 5.2.
-Facebook sees about a 50% reduction in CPU usage when serving equal
-amounts of Web traffic when compared to Apache and PHP. Facebook's API
-tier can serve twice the traffic using 30% less CPU.
-
-Keep up to date on HipHop development by joining the HipHop for PHP
-Discussion Group.
+HipHop is most commonly run as a standalone server, replacing both
+Apache and mod_php.
%prep
-%setup -qn %{name}
+%setup -qc -a1
+mv %{name}-%{githash}*/* .
+
+#%patch5 -p1
+%patch6 -p1
+
+ln -s libevent-1.4.*-stable libevent
+%{__patch} -d libevent -p1 < hphp/third_party/libevent-1.4.14.fb-changes.diff
+
+%if 0
+%patch0 -p1
+%patch1 -p1
+#%patch3 -p1
+%patch4 -p1
+
+
+#rm -rf src/third_party/libmbfl
+#sed -i -e '/add_subdirectory(third_party\/libmbfl)/d' src/CMakeLists.txt
+
+rm -rf src/third_party/xhp
+rm -rf src/third_party/libafdt
+%endif
%build
+# build libevent 1.4 with fb patches
+if [ ! -d libevent/.libs ]; then
+ cd libevent
+ # TODO: should use static linking, but then it fails to detect libraries due missing -lrt
+ %configure \
+ %{?0:--enable-static} \
+ %{?0:--disable-shared}
+ %{__make}
+ ln -s .libs lib
+ ln -s . include
+ cd ..
+fi
+
export HPHP_HOME=$(pwd)
export HPHP_LIB=$HPHP_HOME/bin
-git submodule init
-git submodule update
+# asm linking breaks on $CC containing spaces
+if [[ "%{__cc}" = *ccache* ]]; then
+ cat <<-'EOF' > $HPHP_LIB/gcc
+ #!/bin/sh
+ exec %{__cc} "$@"
+ EOF
+ chmod +x $HPHP_LIB/gcc
+ CC=$HPHP_LIB/gcc
+fi
-%cmake .
-%{__make}
+%if 0
+export LIBEVENT_PREFIX=$HPHP_HOME/libevent
-%{__sed} -i -e 's,/usr/local/bin/php,/usr/bin/php,g' src/crutch.php
+ -DLibEvent_LIB=$HPHP_HOME/libevent/libevent.so \
+ -DLibEvent_INCLUDE_PATHS=$HPHP_HOME/libevent \
+ -DLibEvent_LIB_PATHS=$HPHP_HOME/libevent/.libs \
+%endif
+
+%if 0
+# out of dir build broken (can't find it's tools)
+install -d build
+cd build
+%endif
+
+%cmake \
+ -DLIBEVENT_LIB=$HPHP_HOME/libevent/lib/libevent.so \
+ -DLIBEVENT_INCLUDE_DIR=$HPHP_HOME/libevent \
+ -DCMAKE_PREFIX_PATH=%{_prefix} \
+ -DSKIP_BUNDLED_XHP=ON \
+ -DUSE_JEMALLOC=OFF \
+ -DUSE_TCMALLOC=OFF \
+ ./
+
+# setup COMPILER_ID/HHVM_REPO_SCHEMA so it doesn't look it up from our package git repo
+# see hphp/util/generate-buildinfo.sh
+sha=$(echo %{name}-%{githash}*)
+export COMPILER_ID=HPHP-%{version}-%{release}-${sha#%{name}-}
+export HHVM_REPO_SCHEMA=$(date +%N_%s)
+
+%{__make}
%install
rm -rf $RPM_BUILD_ROOT
-cd $RPM_BUILD_ROOT
+%{__make} install \
+ HPHP_HOME=$(pwd) \
+ DESTDIR=$RPM_BUILD_ROOT
+
+install -d $RPM_BUILD_ROOT%{_datadir}/%{name}/hdf
+cp -p hphp/doc/mime.hdf $RPM_BUILD_ROOT%{_datadir}/%{name}/hdf/static.mime-types.hdf
+
+# install our libevent for now
+install -d $RPM_BUILD_ROOT%{_libdir}
+libtool --mode=install install -p libevent/libevent.la $RPM_BUILD_ROOT%{_libdir}
+%{__rm} $RPM_BUILD_ROOT%{_libdir}/libevent.{a,la,so}
%clean
rm -rf $RPM_BUILD_ROOT
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
%files
%defattr(644,root,root,755)
+%doc README.md hphp/NEWS
+%attr(755,root,root) %{_bindir}/hhvm
+%attr(755,root,root) %{_libdir}/libevent-1.4.so.*.*.*
+%ghost %{_libdir}/libevent-1.4.so.2
+
+%dir %{_datadir}/%{name}
+%dir %{_datadir}/%{name}/hdf
+%{_datadir}/%{name}/hdf/static.mime-types.hdf