config.m4 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. PHP_ARG_WITH(v8js, for V8 Javascript Engine,
  2. [ --with-v8js Include V8 JavaScript Engine])
  3. if test "$PHP_V8JS" != "no"; then
  4. SEARCH_PATH="/usr/local /usr"
  5. SEARCH_FOR="include/v8.h"
  6. if test -r $PHP_V8JS/$SEARCH_FOR; then
  7. case $host_os in
  8. darwin* )
  9. # MacOS does not support --rpath
  10. ;;
  11. * )
  12. LDFLAGS="$LDFLAGS -Wl,--rpath=$PHP_V8JS/$PHP_LIBDIR"
  13. ;;
  14. esac
  15. V8_DIR=$PHP_V8JS
  16. else
  17. AC_MSG_CHECKING([for V8 files in default path])
  18. for i in $SEARCH_PATH ; do
  19. if test -r $i/$SEARCH_FOR; then
  20. V8_DIR=$i
  21. AC_MSG_RESULT(found in $i)
  22. fi
  23. done
  24. fi
  25. if test -z "$V8_DIR"; then
  26. AC_MSG_RESULT([not found])
  27. AC_MSG_ERROR([Please reinstall the v8 distribution])
  28. fi
  29. PHP_ADD_INCLUDE($V8_DIR/include)
  30. PHP_ADD_LIBRARY_WITH_PATH(v8, $V8_DIR/$PHP_LIBDIR, V8JS_SHARED_LIBADD)
  31. PHP_SUBST(V8JS_SHARED_LIBADD)
  32. PHP_REQUIRE_CXX()
  33. AC_CACHE_CHECK(for C standard version, ac_cv_v8_cstd, [
  34. ac_cv_v8_cstd="c++11"
  35. old_CPPFLAGS=$CPPFLAGS
  36. AC_LANG_PUSH([C++])
  37. CPPFLAGS="-std="$ac_cv_v8_cstd
  38. AC_TRY_RUN([int main() { return 0; }],[],[ac_cv_v8_cstd="c++0x"],[])
  39. AC_LANG_POP([C++])
  40. CPPFLAGS=$old_CPPFLAGS
  41. ]);
  42. AC_CACHE_CHECK(how to allow c++11 narrowing, ac_cv_v8_narrowing, [
  43. ac_cv_v8_narrowing=""
  44. old_CXXFLAGS=$CXXFLAGS
  45. AC_LANG_PUSH([C++])
  46. CXXFLAGS="-std="$ac_cv_v8_cstd
  47. AC_TRY_RUN([int main() {
  48. struct { unsigned int x; } foo = {-1};
  49. (void) foo;
  50. return 0;
  51. }], [ ac_cv_v8_narrowing="" ], [
  52. CXXFLAGS="-Wno-c++11-narrowing -std="$ac_cv_v8_cstd
  53. AC_TRY_RUN([int main() {
  54. struct { unsigned int x; } foo = {-1};
  55. (void) foo;
  56. return 0;
  57. }], [ ac_cv_v8_narrowing="-Wno-c++11-narrowing" ], [
  58. CXXFLAGS="-Wno-narrowing -std="$ac_cv_v8_cstd
  59. AC_TRY_RUN([int main() {
  60. struct { unsigned int x; } foo = {-1};
  61. (void) foo;
  62. return 0;
  63. }], [ ac_cv_v8_narrowing="-Wno-narrowing" ], [
  64. AC_MSG_ERROR([cannot compile with narrowing])
  65. ], [])
  66. ], [])
  67. ], [])
  68. AC_LANG_POP([C++])
  69. CXXFLAGS=$old_CXXFLAGS
  70. ]);
  71. old_LIBS=$LIBS
  72. old_LDFLAGS=$LDFLAGS
  73. old_CPPFLAGS=$CPPFLAGS
  74. case $host_os in
  75. darwin* )
  76. # MacOS does not support --rpath
  77. LDFLAGS="-L$V8_DIR/$PHP_LIBDIR"
  78. ;;
  79. * )
  80. LDFLAGS="-Wl,--rpath=$V8_DIR/$PHP_LIBDIR -L$V8_DIR/$PHP_LIBDIR"
  81. ;;
  82. esac
  83. LIBS=-lv8
  84. CPPFLAGS="-I$V8_DIR/include -std=$ac_cv_v8_cstd"
  85. AC_LANG_SAVE
  86. AC_LANG_CPLUSPLUS
  87. AC_CACHE_CHECK(for V8 version, ac_cv_v8_version, [
  88. AC_TRY_RUN([#include <v8.h>
  89. #include <iostream>
  90. #include <fstream>
  91. using namespace std;
  92. int main ()
  93. {
  94. ofstream testfile ("conftestval");
  95. if (testfile.is_open()) {
  96. testfile << v8::V8::GetVersion();
  97. testfile << "\n";
  98. testfile.close();
  99. return 0;
  100. }
  101. return 1;
  102. }], [ac_cv_v8_version=`cat ./conftestval|awk '{print $1}'`], [ac_cv_v8_version=NONE], [ac_cv_v8_version=NONE])
  103. ])
  104. if test "$ac_cv_v8_version" != "NONE"; then
  105. ac_IFS=$IFS
  106. IFS=.
  107. set $ac_cv_v8_version
  108. IFS=$ac_IFS
  109. V8_API_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
  110. if test "$V8_API_VERSION" -lt 4006076 ; then
  111. AC_MSG_ERROR([libv8 must be version 4.6.76 or greater])
  112. fi
  113. AC_DEFINE_UNQUOTED([PHP_V8_API_VERSION], $V8_API_VERSION, [ ])
  114. AC_DEFINE_UNQUOTED([PHP_V8_VERSION], "$ac_cv_v8_version", [ ])
  115. else
  116. AC_MSG_ERROR([could not determine libv8 version])
  117. fi
  118. PHP_ADD_INCLUDE($V8_DIR)
  119. LDFLAGS_libplatform=""
  120. for static_link_extra_file in libv8_libplatform.a libv8_libbase.a; do
  121. AC_MSG_CHECKING([for $static_link_extra_file])
  122. static_link_dir=""
  123. if test -r $V8_DIR/$PHP_LIBDIR/$static_link_extra_file; then
  124. static_link_dir=$V8_DIR/$PHP_LIBDIR
  125. AC_MSG_RESULT(found in $V8_DIR/$PHP_LIBDIR)
  126. fi
  127. if test -z "$static_link_dir"; then
  128. AC_MSG_RESULT([not found])
  129. else
  130. LDFLAGS_libplatform="$LDFLAGS_libplatform $static_link_dir/$static_link_extra_file"
  131. fi
  132. done
  133. # modify flags for (possibly) succeeding V8 startup check
  134. CPPFLAGS="$CPPFLAGS -I$V8_DIR"
  135. LIBS="$LIBS $LDFLAGS_libplatform"
  136. dnl building for v8 4.4.10 or later, which requires us to
  137. dnl provide startup data, if V8 wasn't compiled with snapshot=off.
  138. AC_MSG_CHECKING([whether V8 requires startup data])
  139. AC_TRY_RUN([
  140. #include <v8.h>
  141. #include <libplatform/libplatform.h>
  142. #include <stdlib.h>
  143. #include <string.h>
  144. class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
  145. public:
  146. virtual void* Allocate(size_t length) {
  147. void* data = AllocateUninitialized(length);
  148. return data == NULL ? data : memset(data, 0, length);
  149. }
  150. virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
  151. virtual void Free(void* data, size_t) { free(data); }
  152. };
  153. int main ()
  154. {
  155. v8::Platform *v8_platform = v8::platform::CreateDefaultPlatform();
  156. v8::V8::InitializePlatform(v8_platform);
  157. v8::V8::Initialize();
  158. static ArrayBufferAllocator array_buffer_allocator;
  159. v8::Isolate::CreateParams create_params;
  160. create_params.array_buffer_allocator = &array_buffer_allocator;
  161. v8::Isolate::New(create_params);
  162. return 0;
  163. }
  164. ], [
  165. AC_MSG_RESULT([no])
  166. ], [
  167. AC_MSG_RESULT([yes])
  168. AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])
  169. SEARCH_PATH="$V8_DIR/$PHP_LIBDIR $V8_DIR/share/v8"
  170. AC_MSG_CHECKING([for natives_blob.bin])
  171. SEARCH_FOR="natives_blob.bin"
  172. for i in $SEARCH_PATH ; do
  173. if test -r $i/$SEARCH_FOR; then
  174. AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
  175. AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
  176. native_blob_found=1
  177. fi
  178. done
  179. if test -z "$native_blob_found"; then
  180. AC_MSG_RESULT([not found])
  181. AC_MSG_ERROR([Please provide V8 native blob as needed])
  182. fi
  183. AC_MSG_CHECKING([for snapshot_blob.bin])
  184. SEARCH_FOR="snapshot_blob.bin"
  185. for i in $SEARCH_PATH ; do
  186. if test -r $i/$SEARCH_FOR; then
  187. AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
  188. AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
  189. snapshot_blob_found=1
  190. fi
  191. done
  192. if test -z "$snapshot_blob_found"; then
  193. AC_MSG_RESULT([not found])
  194. AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
  195. fi
  196. ])
  197. AC_LANG_RESTORE
  198. LIBS=$old_LIBS
  199. LDFLAGS="$old_LDFLAGS $LDFLAGS_libplatform"
  200. CPPFLAGS=$old_CPPFLAGS
  201. PHP_NEW_EXTENSION(v8js, [ \
  202. v8js_array_access.cc \
  203. v8js.cc \
  204. v8js_class.cc \
  205. v8js_commonjs.cc \
  206. v8js_convert.cc \
  207. v8js_exceptions.cc \
  208. v8js_generator_export.cc \
  209. v8js_methods.cc \
  210. v8js_object_export.cc \
  211. v8js_timer.cc \
  212. v8js_v8.cc \
  213. v8js_v8object_class.cc \
  214. v8js_variables.cc \
  215. ], $ext_shared, , "$ac_cv_v8_narrowing -std="$ac_cv_v8_cstd)
  216. PHP_ADD_MAKEFILE_FRAGMENT
  217. fi
  218. dnl Local variables:
  219. dnl tab-width: 4
  220. dnl c-basic-offset: 4
  221. dnl End:
  222. dnl vim600: noet sw=4 ts=4 fdm=marker
  223. dnl vim<600: noet sw=4 ts=4