1 AC_DEFUN([DISPATCH_C_BLOCKS], [
3 # Allow configure to be passed a path to the directory where it should look
4 # for the Blocks runtime library, if any.
6 AC_ARG_WITH([blocks-runtime],
7 [AS_HELP_STRING([--with-blocks-runtime],
8 [Specify path to the blocks runtime])],
9 [blocks_runtime=${withval}
10 LIBS="$LIBS -L$blocks_runtime"]
14 # Configure argument to enable/disable using an embedded blocks runtime
16 AC_ARG_ENABLE([embedded_blocks_runtime],
17 [AS_HELP_STRING([--enable-embedded-blocks-runtime],
18 [Embed blocks runtime in libdispatch [default=yes on Linux, default=no on all other platforms]])],,
21 enable_embedded_blocks_runtime=yes
24 enable_embedded_blocks_runtime=no
29 # Detect compiler support for Blocks; perhaps someday -fblocks won't be
30 # required, in which case we'll need to change this.
32 AC_CACHE_CHECK([for C Blocks support], [dispatch_cv_cblocks], [
34 CFLAGS="$CFLAGS -fblocks"
35 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[(void)^{int i; i = 0; }();])], [
37 dispatch_cv_cblocks="-fblocks"
40 dispatch_cv_cblocks="no"
44 AS_IF([test "x$dispatch_cv_cblocks" != "xno"], [
45 CBLOCKS_FLAGS="$dispatch_cv_cblocks"
47 AS_IF([test "x$enable_embedded_blocks_runtime" != "xyes"], [
49 # It may be necessary to directly link the Blocks runtime on some
50 # systems, so give it a try if we can't link a C program that uses
51 # Blocks. We will want to remove this at somepoint, as really -fblocks
52 # should force that linkage already.
55 CFLAGS="$CFLAGS -fblocks -O0"
56 AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
63 LIBS="$LIBS -lBlocksRuntime"
67 AC_MSG_RESULT([-lBlocksRuntime])
69 AC_MSG_ERROR([can't find Blocks runtime])
79 AM_CONDITIONAL(HAVE_CBLOCKS, $have_cblocks)
80 AC_SUBST([CBLOCKS_FLAGS])
81 AM_CONDITIONAL([BUILD_OWN_BLOCKS_RUNTIME], [test "x$enable_embedded_blocks_runtime" = "xyes"])
84 # Because a different C++ compiler may be specified than C compiler, we have
85 # to do it again for C++.
88 AC_CACHE_CHECK([for C++ Blocks support], [dispatch_cv_cxxblocks], [
89 saveCXXFLAGS="$CXXFLAGS"
90 CXXFLAGS="$CXXFLAGS -fblocks"
91 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[(void)^{int i; i = 0; }();])], [
92 CXXFLAGS="$saveCXXFLAGS"
93 dispatch_cv_cxxblocks="-fblocks"
95 CXXFLAGS="$saveCXXFLAGS"
96 dispatch_cv_cxxblocks="no"
100 AS_IF([test "x$dispatch_cv_cxxblocks" != "xno"], [
101 CXXBLOCKS_FLAGS="$dispatch_cv_cxxblocks"
103 AS_IF([test "x$enable_embedded_blocks_runtime" != "xyes"], [
104 saveCXXFLAGS="$CXXFLAGS"
105 CXXFLAGS="$CXXFLAGS -fblocks -O0"
106 AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
113 LIBS="$LIBS -lBlocksRuntime"
117 AC_MSG_RESULT([-lBlocksRuntime])
119 AC_MSG_ERROR([can't find Blocks runtime])
123 CXXFLAGS="$saveCXXFLAGS"
130 AM_CONDITIONAL(HAVE_CXXBLOCKS, $have_cxxblocks)
131 AC_SUBST([CXXBLOCKS_FLAGS])