Add half-hearted support for Clang, because its `blocks' are deficient.
[finally] / configure.ac
1 dnl -*-autoconf-*-
2 dnl
3 dnl Configuration script for `finally'
4 dnl
5 dnl (c) 2023 Mark Wooding
6 dnl
7
8 dnl----- Licensing notice ---------------------------------------------------
9 dnl
10 dnl This file is part of the `Finally' package.
11 dnl
12 dnl Finally is free software: you can redistribute it and/or modify it
13 dnl under the terms of the GNU Library General Public License as published
14 dnl by the Free Software Foundation; either version 2 of the License, or
15 dnl (at your option) any later version.
16 dnl
17 dnl Finally is distributed in the hope that it will be useful, but WITHOUT
18 dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 dnl FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 dnl License for more details.
21 dnl
22 dnl You should have received a copy of the GNU Library General Public
23 dnl License along with Finally. If not, write to the Free Software
24 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 dnl USA.
26
27 dnl--------------------------------------------------------------------------
28 dnl Initialization.
29
30 AC_INIT([finally], [0.9], [mdw@distorted.org.uk])
31 AC_CONFIG_SRCDIR([finally.h])
32 AC_CONFIG_AUX_DIR([config])
33 AC_CONFIG_MACRO_DIR([m4])
34 AM_INIT_AUTOMAKE([foreign])
35 AC_REQUIRE_AUX_FILE([tap-driver.sh])
36 AM_SILENT_RULES([yes])
37
38 dnl--------------------------------------------------------------------------
39 dnl C programming environment.
40
41 AC_PROG_CC
42 AM_PROG_CC_C_O
43 AC_SUBST(AM_CFLAGS)
44
45 case $GCC in
46 yes)
47 AM_CFLAGS="$AM_CFLAGS -std=c89 -pedantic -Wall -Wextra -Werror"
48 ;;
49 esac
50
51 dnl--------------------------------------------------------------------------
52 dnl C++ programming environment.
53
54 AC_PROG_CXX
55 AC_SUBST(AM_CXXFLAGS)
56
57 case $GXX in
58 yes)
59 AM_CXXFLAGS="$AM_CXXFLAGS -std=c++11 -pedantic -Wall -Wextra -Werror"
60 ;;
61 esac
62
63 AC_DEFUN([FINALLY_CXX14_PROGRAM], [AC_LANG_PROGRAM([], [
64 #if !defined(__cplusplus) || __cplusplus < 201103
65 choke me
66 #endif
67 ])])
68
69 AC_CACHE_CHECK([whether $CXX works at all], [finally_cv_cxx_works_p], [
70 AC_LANG_PUSH([C++])
71 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
72 [finally_cv_cxx_works_p=yes],
73 [finally_cv_cxx_works_p=no])
74 AC_LANG_POP([C++])])
75
76 case $finally_cv_cxx_works_p in
77 yes)
78 AC_CACHE_CHECK([whether $CC accepts \`-fexceptions'],
79 [finally_cv_gcc_fexceptions_p], [
80 AC_LANG_PUSH([C])
81 finally_test_original_CFLAGS=$CFLAGS
82 CFLAGS="$CFLAGS -fexceptions"
83 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
84 [finally_cv_gcc_fexceptions_p=yes],
85 [finally_cv_gcc_fexceptions_p=no])
86 CFLAGS=$finally_test_original_CFLAGS
87 AC_LANG_POP([C])])
88 ;;
89 no)
90 finally_cv_gcc_fexceptions_p=no
91 ;;
92 esac
93
94 case $finally_cv_cxx_works_p in
95 yes)
96 AC_CACHE_CHECK([whether $CXX supports C++11], [finally_cv_cxx14_p], [
97 AC_LANG_PUSH([C++])
98 AC_COMPILE_IFELSE([FINALLY_CXX14_PROGRAM],
99 [finally_cv_cxx14_p=yes],
100 [finally_cv_cxx14_p=no])
101 AC_LANG_POP([C++])])
102 ;;
103 *)
104 finally_cv_cxx14_p=no
105 CXX=\${CC}
106 ;;
107 esac
108
109 dnl--------------------------------------------------------------------------
110 dnl Other tools.
111
112 AC_CHECK_PROGS([autom4te])
113 AC_PROG_RANLIB
114
115 dnl--------------------------------------------------------------------------
116 dnl Test configuration.
117
118 finally_test_original_CFLAGS=$CFLAGS
119 CFLAGS="$CFLAGS $AM_CFLAGS"
120 case $finally_cv_gcc_fexceptions_p in
121 yes) CFLAGS="$CFLAGS -fexceptions" ;;
122 esac
123 FINALLY_CHECK
124 CFLAGS=$finally_test_original_CFLAGS
125 AM_CFLAGS="$AM_CFLAGS $FINALLY_CFLAGS"
126 AM_CONDITIONAL([C], [test $finally_flavour != NIL])
127 AM_CONDITIONAL([CXX], [test $finally_cv_cxx_works_p = yes])
128 AM_CONDITIONAL([CXX14], [test $finally_cv_cxx14_p = yes])
129
130 case $finally_flavour,$finally_cv_cxx14_p in
131 NIL,no)
132 AC_MSG_ERROR([no suitable C or C++ compiler found: not going to space today])
133 ;;
134 esac
135
136 case $finally_flavour,$finally_cv_gcc_fexceptions_p,$finally_cv_cxx_works_p in
137 NIL,*,no) finally_fexceptions_p=no ;;
138 *,yes,*) AM_CFLAGS="$AM_CFLAGS -fexceptions"; finally_fexceptions_p=yes ;;
139 *,yes) finally_fexceptions_p=yes ;;
140 esac
141 case $finally_fexceptions_p in
142 yes) AC_DEFINE([HAVE_FEXCEPTIONS], [1]) ;;
143 esac
144 AM_CONDITIONAL([FEXCEPTIONS], [test $finally_fexceptions_p = yes])
145
146 dnl--------------------------------------------------------------------------
147 dnl Output.
148
149 AC_CONFIG_FILES([Makefile])
150 AC_OUTPUT
151
152 dnl----- That's all, folks --------------------------------------------------