]> git.saurik.com Git - apple/libdispatch.git/blob - m4/blocks.m4
libdispatch-913.30.4.tar.gz
[apple/libdispatch.git] / m4 / blocks.m4
1 AC_DEFUN([DISPATCH_C_BLOCKS], [
2 #
3 # Allow configure to be passed a path to the directory where it should look
4 # for the Blocks runtime library, if any.
5 #
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"]
11 )
12
13 #
14 # Configure argument to enable/disable using an embedded blocks runtime
15 #
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]])],,
19 [case $target_os in
20 linux*)
21 enable_embedded_blocks_runtime=yes
22 ;;
23 *)
24 enable_embedded_blocks_runtime=no
25 esac]
26 )
27
28 #
29 # Detect compiler support for Blocks; perhaps someday -fblocks won't be
30 # required, in which case we'll need to change this.
31 #
32 AC_CACHE_CHECK([for C Blocks support], [dispatch_cv_cblocks], [
33 saveCFLAGS="$CFLAGS"
34 CFLAGS="$CFLAGS -fblocks"
35 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[(void)^{int i; i = 0; }();])], [
36 CFLAGS="$saveCFLAGS"
37 dispatch_cv_cblocks="-fblocks"
38 ], [
39 CFLAGS="$saveCFLAGS"
40 dispatch_cv_cblocks="no"
41 ])
42 ])
43
44 AS_IF([test "x$dispatch_cv_cblocks" != "xno"], [
45 CBLOCKS_FLAGS="$dispatch_cv_cblocks"
46
47 AS_IF([test "x$enable_embedded_blocks_runtime" != "xyes"], [
48 #
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.
53 #
54 saveCFLAGS="$CFLAGS"
55 CFLAGS="$CFLAGS -fblocks -O0"
56 AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
57 AC_TRY_LINK([], [
58 ^{ int j; j=0; }();
59 ], [
60 AC_MSG_RESULT([no]);
61 ], [
62 saveLIBS="$LIBS"
63 LIBS="$LIBS -lBlocksRuntime"
64 AC_TRY_LINK([], [
65 ^{ int k; k=0; }();
66 ], [
67 AC_MSG_RESULT([-lBlocksRuntime])
68 ], [
69 AC_MSG_ERROR([can't find Blocks runtime])
70 ])
71 ])
72 ])
73 CFLAGS="$saveCFLAGS"
74 have_cblocks=true
75 ], [
76 CBLOCKS_FLAGS=""
77 have_cblocks=false
78 ])
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"])
82
83 #
84 # Because a different C++ compiler may be specified than C compiler, we have
85 # to do it again for C++.
86 #
87 AC_LANG_PUSH([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"
94 ], [
95 CXXFLAGS="$saveCXXFLAGS"
96 dispatch_cv_cxxblocks="no"
97 ])
98 ])
99
100 AS_IF([test "x$dispatch_cv_cxxblocks" != "xno"], [
101 CXXBLOCKS_FLAGS="$dispatch_cv_cxxblocks"
102
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])
107 AC_TRY_LINK([], [
108 ^{ int j; j=0; }();
109 ], [
110 AC_MSG_RESULT([no]);
111 ], [
112 saveLIBS="$LIBS"
113 LIBS="$LIBS -lBlocksRuntime"
114 AC_TRY_LINK([], [
115 ^{ int k; k=0; }();
116 ], [
117 AC_MSG_RESULT([-lBlocksRuntime])
118 ], [
119 AC_MSG_ERROR([can't find Blocks runtime])
120 ])
121 ])
122 ])
123 CXXFLAGS="$saveCXXFLAGS"
124 have_cxxblocks=true
125 ], [
126 CXXBLOCKS_FLAGS=""
127 have_cxxblocks=false
128 ])
129 AC_LANG_POP([C++])
130 AM_CONDITIONAL(HAVE_CXXBLOCKS, $have_cxxblocks)
131 AC_SUBST([CXXBLOCKS_FLAGS])
132 ])