config.m4 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 3024006 ; then
  111. AC_MSG_ERROR([libv8 must be version 3.24.6 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. if test "$V8_API_VERSION" -ge 3029036 ; then
  119. dnl building for v8 3.29.36 or later, which requires us to
  120. dnl initialize and provide a platform; hence we need to
  121. dnl link in libplatform to make our life easier.
  122. PHP_ADD_INCLUDE($V8_DIR)
  123. case $host_os in
  124. darwin* )
  125. static_link_extra="libv8_libplatform.a libv8_libbase.a"
  126. ;;
  127. * )
  128. static_link_extra="libv8_libplatform.a"
  129. ;;
  130. esac
  131. for static_link_extra_file in $static_link_extra; do
  132. AC_MSG_CHECKING([for $static_link_extra_file])
  133. for i in $PHP_V8JS $SEARCH_PATH ; do
  134. if test -r $i/lib64/$static_link_extra_file; then
  135. static_link_dir=$i/lib64
  136. AC_MSG_RESULT(found in $i)
  137. fi
  138. if test -r $i/lib/$static_link_extra_file; then
  139. static_link_dir=$i/lib
  140. AC_MSG_RESULT(found in $i)
  141. fi
  142. done
  143. if test -z "$static_link_dir"; then
  144. AC_MSG_RESULT([not found])
  145. AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
  146. fi
  147. LDFLAGS_libplatform="$static_link_dir/$static_link_extra_file"
  148. done
  149. # modify flags for (possibly) succeeding V8 startup check
  150. CPPFLAGS="$CPPFLAGS -I$V8_DIR"
  151. LIBS="$LIBS $LDFLAGS_libplatform"
  152. fi
  153. if test "$V8_API_VERSION" -ge 4004010 ; then
  154. dnl building for v8 4.4.10 or later, which requires us to
  155. dnl provide startup data, if V8 wasn't compiled with snapshot=off.
  156. AC_MSG_CHECKING([whether V8 requires startup data])
  157. AC_TRY_RUN([
  158. #include <v8.h>
  159. #include <libplatform/libplatform.h>
  160. #include <stdlib.h>
  161. #include <string.h>
  162. #if PHP_V8_API_VERSION >= 4004010
  163. class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
  164. public:
  165. virtual void* Allocate(size_t length) {
  166. void* data = AllocateUninitialized(length);
  167. return data == NULL ? data : memset(data, 0, length);
  168. }
  169. virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
  170. virtual void Free(void* data, size_t) { free(data); }
  171. };
  172. #endif
  173. int main ()
  174. {
  175. v8::Platform *v8_platform = v8::platform::CreateDefaultPlatform();
  176. v8::V8::InitializePlatform(v8_platform);
  177. v8::V8::Initialize();
  178. #if PHP_V8_API_VERSION >= 4004044
  179. static ArrayBufferAllocator array_buffer_allocator;
  180. v8::Isolate::CreateParams create_params;
  181. create_params.array_buffer_allocator = &array_buffer_allocator;
  182. v8::Isolate::New(create_params);
  183. #else /* PHP_V8_API_VERSION < 4004044 */
  184. v8::Isolate::New();
  185. #endif
  186. return 0;
  187. }
  188. ], [
  189. AC_MSG_RESULT([no])
  190. ], [
  191. AC_MSG_RESULT([yes])
  192. AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])
  193. SEARCH_PATH="$V8_DIR/lib $V8_DIR/share/v8"
  194. AC_MSG_CHECKING([for natives_blob.bin])
  195. SEARCH_FOR="natives_blob.bin"
  196. for i in $SEARCH_PATH ; do
  197. if test -r $i/$SEARCH_FOR; then
  198. AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
  199. AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
  200. native_blob_found=1
  201. fi
  202. done
  203. if test -z "$native_blob_found"; then
  204. AC_MSG_RESULT([not found])
  205. AC_MSG_ERROR([Please provide V8 native blob as needed])
  206. fi
  207. AC_MSG_CHECKING([for snapshot_blob.bin])
  208. SEARCH_FOR="snapshot_blob.bin"
  209. for i in $SEARCH_PATH ; do
  210. if test -r $i/$SEARCH_FOR; then
  211. AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
  212. AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
  213. snapshot_blob_found=1
  214. fi
  215. done
  216. if test -z "$snapshot_blob_found"; then
  217. AC_MSG_RESULT([not found])
  218. AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
  219. fi
  220. ])
  221. fi
  222. AC_LANG_RESTORE
  223. LIBS=$old_LIBS
  224. LDFLAGS="$old_LDFLAGS $LDFLAGS_libplatform"
  225. CPPFLAGS=$old_CPPFLAGS
  226. PHP_NEW_EXTENSION(v8js, [ \
  227. v8js_array_access.cc \
  228. v8js.cc \
  229. v8js_class.cc \
  230. v8js_commonjs.cc \
  231. v8js_convert.cc \
  232. v8js_exceptions.cc \
  233. v8js_generator_export.cc \
  234. v8js_methods.cc \
  235. v8js_object_export.cc \
  236. v8js_timer.cc \
  237. v8js_v8.cc \
  238. v8js_v8object_class.cc \
  239. v8js_variables.cc \
  240. ], $ext_shared, , "$ac_cv_v8_narrowing -std="$ac_cv_v8_cstd)
  241. PHP_ADD_MAKEFILE_FRAGMENT
  242. fi
  243. dnl Local variables:
  244. dnl tab-width: 4
  245. dnl c-basic-offset: 4
  246. dnl End:
  247. dnl vim600: noet sw=4 ts=4 fdm=marker
  248. dnl vim<600: noet sw=4 ts=4