config.m4 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. AC_LANG_RESTORE
  119. LIBS=$old_LIBS
  120. LDFLAGS=$old_LDFLAGS
  121. CPPFLAGS=$old_CPPFLAGS
  122. if test "$V8_API_VERSION" -ge 3029036 ; then
  123. dnl building for v8 3.29.36 or later, which requires us to
  124. dnl initialize and provide a platform; hence we need to
  125. dnl link in libplatform to make our life easier.
  126. PHP_ADD_INCLUDE($V8_DIR)
  127. case $host_os in
  128. darwin* )
  129. static_link_extra="libv8_libplatform.a libv8_libbase.a"
  130. ;;
  131. * )
  132. static_link_extra="libv8_libplatform.a"
  133. ;;
  134. esac
  135. for static_link_extra_file in $static_link_extra; do
  136. AC_MSG_CHECKING([for $static_link_extra_file])
  137. for i in $PHP_V8JS $SEARCH_PATH ; do
  138. if test -r $i/lib64/$static_link_extra_file; then
  139. static_link_dir=$i/lib64
  140. AC_MSG_RESULT(found in $i)
  141. fi
  142. if test -r $i/lib/$static_link_extra_file; then
  143. static_link_dir=$i/lib
  144. AC_MSG_RESULT(found in $i)
  145. fi
  146. done
  147. if test -z "$static_link_dir"; then
  148. AC_MSG_RESULT([not found])
  149. AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
  150. fi
  151. LDFLAGS="$LDFLAGS $static_link_dir/$static_link_extra_file"
  152. done
  153. fi
  154. PHP_NEW_EXTENSION(v8js, [ \
  155. v8js_array_access.cc \
  156. v8js.cc \
  157. v8js_class.cc \
  158. v8js_commonjs.cc \
  159. v8js_convert.cc \
  160. v8js_exceptions.cc \
  161. v8js_methods.cc \
  162. v8js_object_export.cc \
  163. v8js_timer.cc \
  164. v8js_v8.cc \
  165. v8js_v8object_class.cc \
  166. v8js_variables.cc \
  167. ], $ext_shared, , "$ac_cv_v8_narrowing -std="$ac_cv_v8_cstd)
  168. PHP_ADD_MAKEFILE_FRAGMENT
  169. fi