ast_check_raii.m4 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. dnl check RAII requirements
  2. dnl
  3. dnl gcc / llvm-gcc: -fnested-functions
  4. dnl clang : -fblocks / -fblocks and -lBlocksRuntime"
  5. AC_DEFUN([AST_CHECK_RAII], [
  6. AC_MSG_CHECKING([for RAII support])
  7. AST_C_COMPILER_FAMILY=""
  8. AC_LINK_IFELSE(
  9. [AC_LANG_PROGRAM([], [
  10. int main() {
  11. #if defined(__clang__)
  12. choke
  13. #endif
  14. return 0;
  15. }
  16. ])
  17. ],[
  18. dnl Nested functions required for RAII implementation
  19. AC_MSG_CHECKING(for gcc -fnested-functions)
  20. AC_COMPILE_IFELSE(
  21. dnl Prototype needed due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36774
  22. [
  23. AC_LANG_PROGRAM([], [auto void foo(void); void foo(void) {}])
  24. ],[
  25. AST_NESTED_FUNCTIONS=""
  26. AC_MSG_RESULT(no)
  27. ],[
  28. AST_NESTED_FUNCTIONS="-fnested-functions"
  29. AC_MSG_RESULT(yes)
  30. ]
  31. )
  32. AC_SUBST(AST_NESTED_FUNCTIONS)
  33. AST_C_COMPILER_FAMILY="gcc"
  34. ],[
  35. AC_MSG_CHECKING(for clang -fblocks)
  36. if test "`echo 'int main(){return ^{return 42;}();}' | ${CC} -o /dev/null -fblocks -x c - 2>&1`" = ""; then
  37. AST_CLANG_BLOCKS_LIBS=""
  38. AST_CLANG_BLOCKS="-Wno-unknown-warning-option -fblocks"
  39. AC_MSG_RESULT(yes)
  40. elif test "`echo 'int main(){return ^{return 42;}();}' | ${CC} -o /dev/null -fblocks -x c -lBlocksRuntime - 2>&1`" = ""; then
  41. AST_CLANG_BLOCKS_LIBS="-lBlocksRuntime"
  42. AST_CLANG_BLOCKS="-fblocks"
  43. AC_MSG_RESULT(yes)
  44. else
  45. AC_MSG_ERROR([BlocksRuntime is required for clang, please install libblocksruntime])
  46. fi
  47. AC_SUBST(AST_CLANG_BLOCKS_LIBS)
  48. AC_SUBST(AST_CLANG_BLOCKS)
  49. AST_C_COMPILER_FAMILY="clang"
  50. ]
  51. )
  52. if test -z "${AST_C_COMPILER_FAMILY}"; then
  53. AC_MSG_ERROR([Compiler ${CC} not supported. Mminimum required gcc-4.3 / llvm-gcc-4.3 / clang-3.3 + libblocksruntime-dev])
  54. fi
  55. AC_SUBST(AST_C_COMPILER_FAMILY)
  56. ])