2012-04-27 16:26:15 +00:00
|
|
|
PHP_ARG_WITH(v8js, for V8 Javascript Engine,
|
|
|
|
[ --with-v8js Include V8 JavaScript Engine])
|
|
|
|
|
|
|
|
if test "$PHP_V8JS" != "no"; then
|
|
|
|
SEARCH_PATH="/usr/local /usr"
|
2013-10-01 22:05:36 +00:00
|
|
|
SEARCH_FOR="include/v8.h"
|
2012-04-27 16:26:15 +00:00
|
|
|
|
|
|
|
if test -r $PHP_V8JS/$SEARCH_FOR; then
|
2015-03-08 23:06:01 +00:00
|
|
|
case $host_os in
|
|
|
|
darwin* )
|
|
|
|
# MacOS does not support --rpath
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
LDFLAGS="$LDFLAGS -Wl,--rpath=$PHP_V8JS/$PHP_LIBDIR"
|
|
|
|
;;
|
|
|
|
esac
|
2012-04-27 16:26:15 +00:00
|
|
|
V8_DIR=$PHP_V8JS
|
|
|
|
else
|
|
|
|
AC_MSG_CHECKING([for V8 files in default path])
|
|
|
|
for i in $SEARCH_PATH ; do
|
|
|
|
if test -r $i/$SEARCH_FOR; then
|
|
|
|
V8_DIR=$i
|
|
|
|
AC_MSG_RESULT(found in $i)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test -z "$V8_DIR"; then
|
|
|
|
AC_MSG_RESULT([not found])
|
|
|
|
AC_MSG_ERROR([Please reinstall the v8 distribution])
|
|
|
|
fi
|
|
|
|
|
|
|
|
PHP_ADD_INCLUDE($V8_DIR/include)
|
|
|
|
PHP_ADD_LIBRARY_WITH_PATH(v8, $V8_DIR/$PHP_LIBDIR, V8JS_SHARED_LIBADD)
|
|
|
|
PHP_SUBST(V8JS_SHARED_LIBADD)
|
|
|
|
PHP_REQUIRE_CXX()
|
|
|
|
|
2015-03-10 13:16:37 +00:00
|
|
|
|
|
|
|
AC_CACHE_CHECK(for C standard version, ac_cv_v8_cstd, [
|
|
|
|
ac_cv_v8_cstd="c++11"
|
|
|
|
old_CPPFLAGS=$CPPFLAGS
|
|
|
|
AC_LANG_PUSH([C++])
|
|
|
|
CPPFLAGS="-std="$ac_cv_v8_cstd
|
|
|
|
AC_TRY_RUN([int main() { return 0; }],[],[ac_cv_v8_cstd="c++0x"],[])
|
|
|
|
AC_LANG_POP([C++])
|
|
|
|
CPPFLAGS=$old_CPPFLAGS
|
|
|
|
]);
|
|
|
|
|
2015-10-18 16:03:04 +00:00
|
|
|
AC_CACHE_CHECK(how to allow c++11 narrowing, ac_cv_v8_narrowing, [
|
2015-07-25 19:36:34 +00:00
|
|
|
ac_cv_v8_narrowing=""
|
|
|
|
old_CXXFLAGS=$CXXFLAGS
|
|
|
|
AC_LANG_PUSH([C++])
|
2015-10-18 16:03:04 +00:00
|
|
|
CXXFLAGS="-std="$ac_cv_v8_cstd
|
|
|
|
AC_TRY_RUN([int main() {
|
|
|
|
struct { unsigned int x; } foo = {-1};
|
|
|
|
(void) foo;
|
|
|
|
return 0;
|
|
|
|
}], [ ac_cv_v8_narrowing="" ], [
|
|
|
|
CXXFLAGS="-Wno-c++11-narrowing -std="$ac_cv_v8_cstd
|
|
|
|
AC_TRY_RUN([int main() {
|
|
|
|
struct { unsigned int x; } foo = {-1};
|
|
|
|
(void) foo;
|
|
|
|
return 0;
|
|
|
|
}], [ ac_cv_v8_narrowing="-Wno-c++11-narrowing" ], [
|
|
|
|
CXXFLAGS="-Wno-narrowing -std="$ac_cv_v8_cstd
|
|
|
|
AC_TRY_RUN([int main() {
|
|
|
|
struct { unsigned int x; } foo = {-1};
|
|
|
|
(void) foo;
|
|
|
|
return 0;
|
|
|
|
}], [ ac_cv_v8_narrowing="-Wno-narrowing" ], [
|
|
|
|
AC_MSG_ERROR([cannot compile with narrowing])
|
|
|
|
], [])
|
|
|
|
], [])
|
|
|
|
], [])
|
2015-07-25 19:36:34 +00:00
|
|
|
AC_LANG_POP([C++])
|
|
|
|
CXXFLAGS=$old_CXXFLAGS
|
|
|
|
]);
|
|
|
|
|
2015-03-10 13:16:37 +00:00
|
|
|
|
2013-10-12 18:44:15 +00:00
|
|
|
old_LIBS=$LIBS
|
|
|
|
old_LDFLAGS=$LDFLAGS
|
|
|
|
old_CPPFLAGS=$CPPFLAGS
|
2015-03-08 23:06:01 +00:00
|
|
|
|
|
|
|
case $host_os in
|
|
|
|
darwin* )
|
|
|
|
# MacOS does not support --rpath
|
|
|
|
LDFLAGS="-L$V8_DIR/$PHP_LIBDIR"
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
LDFLAGS="-Wl,--rpath=$V8_DIR/$PHP_LIBDIR -L$V8_DIR/$PHP_LIBDIR"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-10-12 18:44:15 +00:00
|
|
|
LIBS=-lv8
|
2015-03-10 13:16:37 +00:00
|
|
|
CPPFLAGS="-I$V8_DIR/include -std=$ac_cv_v8_cstd"
|
2013-10-12 18:44:15 +00:00
|
|
|
AC_LANG_SAVE
|
|
|
|
AC_LANG_CPLUSPLUS
|
|
|
|
|
2012-04-27 16:26:15 +00:00
|
|
|
AC_CACHE_CHECK(for V8 version, ac_cv_v8_version, [
|
|
|
|
AC_TRY_RUN([#include <v8.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
ofstream testfile ("conftestval");
|
|
|
|
if (testfile.is_open()) {
|
|
|
|
testfile << v8::V8::GetVersion();
|
|
|
|
testfile << "\n";
|
|
|
|
testfile.close();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2012-06-07 18:29:12 +00:00
|
|
|
}], [ac_cv_v8_version=`cat ./conftestval|awk '{print $1}'`], [ac_cv_v8_version=NONE], [ac_cv_v8_version=NONE])
|
2012-04-27 16:26:15 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
if test "$ac_cv_v8_version" != "NONE"; then
|
|
|
|
ac_IFS=$IFS
|
|
|
|
IFS=.
|
|
|
|
set $ac_cv_v8_version
|
|
|
|
IFS=$ac_IFS
|
|
|
|
V8_API_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
|
2015-03-11 14:00:01 +00:00
|
|
|
if test "$V8_API_VERSION" -lt 3024006 ; then
|
|
|
|
AC_MSG_ERROR([libv8 must be version 3.24.6 or greater])
|
2013-09-28 06:48:59 +00:00
|
|
|
fi
|
2012-04-27 16:26:15 +00:00
|
|
|
AC_DEFINE_UNQUOTED([PHP_V8_API_VERSION], $V8_API_VERSION, [ ])
|
|
|
|
AC_DEFINE_UNQUOTED([PHP_V8_VERSION], "$ac_cv_v8_version", [ ])
|
2013-10-03 21:59:27 +00:00
|
|
|
else
|
|
|
|
AC_MSG_ERROR([could not determine libv8 version])
|
2012-04-27 16:26:15 +00:00
|
|
|
fi
|
2013-10-12 05:07:34 +00:00
|
|
|
|
2014-09-16 22:45:24 +00:00
|
|
|
if test "$V8_API_VERSION" -ge 3029036 ; then
|
|
|
|
dnl building for v8 3.29.36 or later, which requires us to
|
|
|
|
dnl initialize and provide a platform; hence we need to
|
|
|
|
dnl link in libplatform to make our life easier.
|
|
|
|
PHP_ADD_INCLUDE($V8_DIR)
|
|
|
|
|
2015-03-09 11:48:03 +00:00
|
|
|
case $host_os in
|
|
|
|
darwin* )
|
|
|
|
static_link_extra="libv8_libplatform.a libv8_libbase.a"
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
static_link_extra="libv8_libplatform.a"
|
|
|
|
;;
|
|
|
|
esac
|
2014-09-16 22:45:24 +00:00
|
|
|
|
2016-03-23 09:24:50 +00:00
|
|
|
LDFLAGS_libplatform=""
|
2015-03-09 11:48:03 +00:00
|
|
|
for static_link_extra_file in $static_link_extra; do
|
|
|
|
AC_MSG_CHECKING([for $static_link_extra_file])
|
2014-09-16 22:45:24 +00:00
|
|
|
|
2015-03-09 11:48:03 +00:00
|
|
|
for i in $PHP_V8JS $SEARCH_PATH ; do
|
2015-08-12 15:26:23 +00:00
|
|
|
if test -r $i/lib64/$static_link_extra_file; then
|
|
|
|
static_link_dir=$i/lib64
|
|
|
|
AC_MSG_RESULT(found in $i)
|
|
|
|
fi
|
2015-03-09 11:48:03 +00:00
|
|
|
if test -r $i/lib/$static_link_extra_file; then
|
2015-08-12 15:26:23 +00:00
|
|
|
static_link_dir=$i/lib
|
2015-03-09 11:48:03 +00:00
|
|
|
AC_MSG_RESULT(found in $i)
|
|
|
|
fi
|
|
|
|
done
|
2014-09-16 22:45:24 +00:00
|
|
|
|
2015-03-09 11:48:03 +00:00
|
|
|
if test -z "$static_link_dir"; then
|
|
|
|
AC_MSG_RESULT([not found])
|
|
|
|
AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
|
|
|
|
fi
|
|
|
|
|
2016-03-23 09:24:50 +00:00
|
|
|
LDFLAGS_libplatform="$LDFLAGS_libplatform $static_link_dir/$static_link_extra_file"
|
2015-03-09 11:48:03 +00:00
|
|
|
done
|
2016-02-28 18:52:46 +00:00
|
|
|
|
|
|
|
# modify flags for (possibly) succeeding V8 startup check
|
|
|
|
CPPFLAGS="$CPPFLAGS -I$V8_DIR"
|
|
|
|
LIBS="$LIBS $LDFLAGS_libplatform"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test "$V8_API_VERSION" -ge 4004010 ; then
|
|
|
|
dnl building for v8 4.4.10 or later, which requires us to
|
|
|
|
dnl provide startup data, if V8 wasn't compiled with snapshot=off.
|
|
|
|
AC_MSG_CHECKING([whether V8 requires startup data])
|
|
|
|
AC_TRY_RUN([
|
|
|
|
#include <v8.h>
|
|
|
|
#include <libplatform/libplatform.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#if PHP_V8_API_VERSION >= 4004010
|
|
|
|
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
|
|
|
|
public:
|
|
|
|
virtual void* Allocate(size_t length) {
|
|
|
|
void* data = AllocateUninitialized(length);
|
|
|
|
return data == NULL ? data : memset(data, 0, length);
|
|
|
|
}
|
|
|
|
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
|
|
|
|
virtual void Free(void* data, size_t) { free(data); }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
v8::Platform *v8_platform = v8::platform::CreateDefaultPlatform();
|
|
|
|
v8::V8::InitializePlatform(v8_platform);
|
|
|
|
v8::V8::Initialize();
|
|
|
|
|
|
|
|
#if PHP_V8_API_VERSION >= 4004044
|
|
|
|
static ArrayBufferAllocator array_buffer_allocator;
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = &array_buffer_allocator;
|
|
|
|
|
|
|
|
v8::Isolate::New(create_params);
|
|
|
|
#else /* PHP_V8_API_VERSION < 4004044 */
|
|
|
|
v8::Isolate::New();
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
], [
|
|
|
|
AC_MSG_RESULT([no])
|
|
|
|
], [
|
|
|
|
AC_MSG_RESULT([yes])
|
|
|
|
AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])
|
|
|
|
|
2016-03-05 15:58:55 +00:00
|
|
|
SEARCH_PATH="$V8_DIR/lib $V8_DIR/share/v8"
|
2016-02-28 18:52:46 +00:00
|
|
|
|
|
|
|
AC_MSG_CHECKING([for natives_blob.bin])
|
|
|
|
SEARCH_FOR="natives_blob.bin"
|
|
|
|
|
|
|
|
for i in $SEARCH_PATH ; do
|
|
|
|
if test -r $i/$SEARCH_FOR; then
|
|
|
|
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
|
|
|
|
AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
|
|
|
|
native_blob_found=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if test -z "$native_blob_found"; then
|
|
|
|
AC_MSG_RESULT([not found])
|
|
|
|
AC_MSG_ERROR([Please provide V8 native blob as needed])
|
|
|
|
fi
|
|
|
|
|
|
|
|
AC_MSG_CHECKING([for snapshot_blob.bin])
|
|
|
|
SEARCH_FOR="snapshot_blob.bin"
|
|
|
|
|
|
|
|
for i in $SEARCH_PATH ; do
|
|
|
|
if test -r $i/$SEARCH_FOR; then
|
|
|
|
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
|
|
|
|
AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
|
|
|
|
snapshot_blob_found=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if test -z "$snapshot_blob_found"; then
|
|
|
|
AC_MSG_RESULT([not found])
|
|
|
|
AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
|
|
|
|
fi
|
|
|
|
])
|
2014-09-16 22:45:24 +00:00
|
|
|
fi
|
2013-10-12 18:44:15 +00:00
|
|
|
|
2016-02-28 18:52:46 +00:00
|
|
|
AC_LANG_RESTORE
|
|
|
|
LIBS=$old_LIBS
|
|
|
|
LDFLAGS="$old_LDFLAGS $LDFLAGS_libplatform"
|
|
|
|
CPPFLAGS=$old_CPPFLAGS
|
|
|
|
|
|
|
|
|
2014-12-12 22:59:28 +00:00
|
|
|
PHP_NEW_EXTENSION(v8js, [ \
|
|
|
|
v8js_array_access.cc \
|
|
|
|
v8js.cc \
|
|
|
|
v8js_class.cc \
|
|
|
|
v8js_commonjs.cc \
|
|
|
|
v8js_convert.cc \
|
|
|
|
v8js_exceptions.cc \
|
|
|
|
v8js_methods.cc \
|
|
|
|
v8js_object_export.cc \
|
|
|
|
v8js_timer.cc \
|
|
|
|
v8js_v8.cc \
|
|
|
|
v8js_v8object_class.cc \
|
|
|
|
v8js_variables.cc \
|
2015-07-25 19:36:34 +00:00
|
|
|
], $ext_shared, , "$ac_cv_v8_narrowing -std="$ac_cv_v8_cstd)
|
2012-04-27 16:26:15 +00:00
|
|
|
|
|
|
|
PHP_ADD_MAKEFILE_FRAGMENT
|
|
|
|
fi
|