xref: /trueos/lib/libdispatch/m4/blocks.m4 (revision bf5f91cb28c5878845eb00fbf329c042f6c643c9)
1AC_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#
6AC_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# Detect compiler support for Blocks; perhaps someday -fblocks won't be
15# required, in which case we'll need to change this.
16#
17AC_CACHE_CHECK([for C Blocks support], [dispatch_cv_cblocks], [
18  saveCFLAGS="$CFLAGS"
19  CFLAGS="$CFLAGS -fblocks"
20  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[(void)^{int i; i = 0; }();])], [
21    CFLAGS="$saveCFLAGS"
22    dispatch_cv_cblocks="-fblocks"
23  ], [
24    CFLAGS="$saveCFLAGS"
25    dispatch_cv_cblocks="no"
26  ])
27])
28
29AS_IF([test "x$dispatch_cv_cblocks" != "xno"], [
30    CBLOCKS_FLAGS="$dispatch_cv_cblocks"
31
32    #
33    # It may be necessary to directly link the Blocks runtime on some
34    # systems, so give it a try if we can't link a C program that uses
35    # Blocks.  We will want to remove this at somepoint, as really -fblocks
36    # should force that linkage already.
37    #
38    saveCFLAGS="$CFLAGS"
39    CFLAGS="$CFLAGS -fblocks -O0"
40    AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
41    AC_TRY_LINK([], [
42	^{ int j; j=0; }();
43    ], [
44	AC_MSG_RESULT([no]);
45    ], [
46      saveLIBS="$LIBS"
47      LIBS="$LIBS -lBlocksRuntime"
48      AC_TRY_LINK([], [
49	^{ int k; k=0; }();
50      ], [
51	AC_MSG_RESULT([-lBlocksRuntime])
52      ], [
53	AC_MSG_ERROR([can't find Blocks runtime])
54      ])
55    ])
56    CFLAGS="$saveCFLAGS"
57    have_cblocks=true
58], [
59    CBLOCKS_FLAGS=""
60    have_cblocks=false
61])
62AM_CONDITIONAL(HAVE_CBLOCKS, $have_cblocks)
63AC_SUBST([CBLOCKS_FLAGS])
64
65#
66# Because a different C++ compiler may be specified than C compiler, we have
67# to do it again for C++.
68#
69AC_LANG_PUSH([C++])
70AC_CACHE_CHECK([for C++ Blocks support], [dispatch_cv_cxxblocks], [
71  saveCXXFLAGS="$CXXFLAGS"
72  CXXFLAGS="$CXXFLAGS -fblocks"
73  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[(void)^{int i; i = 0; }();])], [
74    CXXFLAGS="$saveCXXFLAGS"
75    dispatch_cv_cxxblocks="-fblocks"
76  ], [
77    CXXFLAGS="$saveCXXFLAGS"
78    dispatch_cv_cxxblocks="no"
79  ])
80])
81
82AS_IF([test "x$dispatch_cv_cxxblocks" != "xno"], [
83    CXXBLOCKS_FLAGS="$dispatch_cv_cxxblocks"
84
85    saveCXXFLAGS="$CXXFLAGS"
86    CXXFLAGS="$CXXFLAGS -fblocks -O0"
87    AC_MSG_CHECKING([whether additional libraries are required for the Blocks runtime])
88    AC_TRY_LINK([], [
89	^{ int j; j=0; }();
90    ], [
91	AC_MSG_RESULT([no]);
92    ], [
93      saveLIBS="$LIBS"
94      LIBS="$LIBS -lBlocksRuntime"
95      AC_TRY_LINK([], [
96	^{ int k; k=0; }();
97      ], [
98	AC_MSG_RESULT([-lBlocksRuntime])
99      ], [
100	AC_MSG_ERROR([can't find Blocks runtime])
101      ])
102    ])
103    CXXFLAGS="$saveCXXFLAGS"
104    have_cxxblocks=true
105], [
106    CXXBLOCKS_FLAGS=""
107    have_cxxblocks=false
108])
109AC_LANG_POP([C++])
110AM_CONDITIONAL(HAVE_CXXBLOCKS, $have_cxxblocks)
111AC_SUBST([CXXBLOCKS_FLAGS])
112])
113