]>
Commit | Line | Data |
---|---|---|
36230329 NS |
1 | # Nathan's Common Config -*- mode:autoconf -*- |
2 | # Copyright (C) 2020 Nathan Sidwell, nathan@acm.org | |
3 | # License: Apache v2.0 | |
4 | ||
5 | AC_DEFUN([NMS_NOT_IN_SOURCE], | |
6 | [if test -e configure ; then | |
7 | AC_MSG_ERROR([Do not build in the source tree. Reasons]) | |
8 | fi]) | |
9 | ||
10 | # thanks to Zack Weinberg for fixing this! | |
11 | AC_DEFUN([NMS_TOOLS], | |
12 | [AC_SUBST([tools], []) | |
13 | AC_ARG_WITH([tools], | |
14 | AS_HELP_STRING([--with-tools=DIR],[tool directory]), | |
15 | [AS_CASE([$withval], | |
16 | [yes], [AC_MSG_ERROR([--with-tools requires an argument])], | |
17 | [no], [:], | |
18 | [tools="${withval%/bin}"])]) | |
19 | ||
20 | if test -n "$tools" ; then | |
21 | if test -d "$tools/bin"; then | |
22 | PATH="$tools/bin:$PATH" | |
23 | AC_MSG_NOTICE([Using tools in $tools]) | |
24 | else | |
25 | AC_MSG_ERROR([tool location does not exist]) | |
26 | fi | |
27 | fi]) | |
28 | ||
29 | AC_DEFUN([NMS_TOOL_DIRS], | |
30 | [if test "$tools" && test -d "$tools/include" ; then | |
31 | CXX+=" -I$tools/include" | |
32 | fi | |
33 | if test "$tools" && test -d "$tools/lib" ; then | |
34 | toollib="$tools/lib" | |
35 | if os=$(CXX -print-multi-os-directory 2>/dev/null) ; then | |
36 | toollib+="/${os}" | |
37 | fi | |
e48456f5 NS |
38 | ## VAR+=... is not dashing |
39 | LDFLAGS="$LDFLAGS -L $toollib" | |
36230329 NS |
40 | unset toollib |
41 | fi]) | |
42 | ||
43 | AC_DEFUN([NMS_NUM_CPUS], | |
44 | [AC_MSG_CHECKING([number of CPUs]) | |
45 | AS_CASE([$build], | |
46 | [*-*-darwin*], [NUM_CPUS=$(sysctl -n hw.ncpu 2>/dev/null)], | |
47 | [NUM_CPUS=$(grep -c '^processor' /proc/cpuinfo 2>/dev/null)]) | |
48 | test "$NUM_CPUS" = 0 && NUM_CPUS= | |
49 | AC_MSG_RESULT([${NUM_CPUS:-unknown}]) | |
50 | test "$NUM_CPUS" = 1 && NUM_CPUS= | |
51 | AC_SUBST(NUM_CPUS)]) | |
52 | ||
53 | AC_DEFUN([NMS_MAINTAINER_MODE], | |
54 | [AC_ARG_ENABLE([maintainer-mode], | |
55 | AS_HELP_STRING([--enable-maintainer-mode], | |
56 | [enable maintainer mode. Add rules to rebuild configurey bits]),, | |
57 | [enable_maintainer_mode=no]) | |
58 | AS_CASE([$enable_maintainer_mode], | |
59 | [yes], [maintainer_mode=yes], | |
60 | [no], [maintainer=no], | |
61 | [AC_MSG_ERROR([unknown maintainer mode $enable_maintainer_mode])]) | |
62 | AC_MSG_CHECKING([maintainer-mode]) | |
63 | AC_MSG_RESULT([$maintainer_mode]) | |
64 | test "$maintainer_mode" = yes && MAINTAINER=yes | |
65 | AC_SUBST(MAINTAINER)]) | |
66 | ||
67 | AC_DEFUN([NMS_CXX_COMPILER], | |
68 | [AC_ARG_WITH([compiler], | |
69 | AS_HELP_STRING([--with-compiler=NAME],[which compiler to use]), | |
70 | AC_MSG_CHECKING([C++ compiler]) | |
71 | if test "$withval" = "yes" ; then | |
72 | AC_MSG_ERROR([NAME not specified]) | |
73 | elif test "$withval" = "no" ; then | |
74 | AC_MSG_ERROR([Gonna need a C++ compiler!]) | |
75 | else | |
76 | CXX="${withval}" | |
77 | AC_MSG_RESULT([$CXX]) | |
78 | fi)]) | |
79 | ||
80 | AC_DEFUN([NMS_CXX_11], | |
81 | [AC_MSG_CHECKING([whether $CXX is for C++11]) | |
82 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ | |
83 | [#if __cplusplus != 201103 | |
84 | #error "C++11 is required" | |
85 | #endif | |
86 | ]])], | |
87 | [AC_MSG_RESULT([yes])], | |
88 | [CXX_ORIG="$CXX" | |
89 | CXX+=" -std=c++11" | |
90 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ | |
91 | [#if __cplusplus != 201103 | |
92 | #error "C++11 is required" | |
93 | #endif | |
94 | ]])], | |
95 | AC_MSG_RESULT([adding -std=c++11]), | |
96 | [CXX="$CXX_ORIG" | |
97 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ | |
98 | [#if __cplusplus > 201103 | |
99 | #error "C++11 is required" | |
100 | #endif | |
101 | ]])], | |
102 | AC_MSG_RESULT([> C++11]), | |
103 | AC_MSG_RESULT([no]) | |
104 | AC_MSG_ERROR([C++11 is required])])) | |
105 | unset CXX_ORIG])]) | |
106 | ||
107 | AC_DEFUN([NMS_CXX_20], | |
108 | [AC_MSG_CHECKING([whether $CXX is for C++20]) | |
109 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ | |
110 | [#if __cplusplus <= 201703 | |
111 | #error "C++20 is required" | |
112 | #endif | |
113 | ]])], | |
114 | [AC_MSG_RESULT([yes])], | |
115 | [CXX+=" -std=c++20" | |
116 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ | |
117 | [#if __cplusplus <= 201703 | |
118 | #error "C++20 is required" | |
119 | #endif | |
120 | ]])], | |
121 | AC_MSG_RESULT([adding -std=c++20]), | |
122 | AC_MSG_RESULT([no]) | |
123 | AC_MSG_ERROR([C++20 is required])])) | |
124 | ||
125 | AC_MSG_CHECKING([whether C++20 support is sufficiently advanced]) | |
126 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | |
127 | #include <version> | |
128 | // There doesn't seem to be a feature macro for __VA_OPT__ :( | |
129 | #define VARIADIC(X,...) X __VA_OPT__((__VA_ARGS__)) | |
130 | #define X(Y,Z) 1 | |
131 | int ary[VARIADIC(X,Y,Z)]; | |
132 | #if __cpp_constinit < 201907 | |
133 | #error "C++20 constinit required" | |
134 | cpp_constinit is __cpp_constinit | |
135 | #endif | |
136 | #if __cpp_if_constexpr < 201606 | |
137 | #error "C++20 constexpr required" | |
138 | cpp_constexpr is __cpp_if_constexpr | |
139 | #endif | |
140 | #if __cpp_concepts < 201907 | |
141 | #error "C++20 concepts required" | |
142 | cpp_concepts is __cpp_concepts | |
143 | #endif | |
144 | #if __cpp_structured_bindings < 201606 | |
145 | #error "C++20 structured bindings required" | |
146 | cpp_structured_bindings is __cpp_structured_bindings | |
147 | #endif | |
148 | #if __cpp_lib_int_pow2 < 202002 | |
149 | #error "std::has_single_bit required" | |
150 | cpp_lib_int_pow2 is __cpp_lib_int_pow2 | |
151 | #endif | |
152 | ]])], | |
153 | AC_MSG_RESULT([yes 🙂]), | |
154 | AC_MSG_RESULT([no 🙁]) | |
155 | AC_MSG_ERROR([C++20 support is too immature]))]) | |
156 | ||
157 | AC_DEFUN([NMS_ENABLE_EXCEPTIONS], | |
158 | [AC_ARG_ENABLE([exceptions], | |
159 | AS_HELP_STRING([--enable-exceptions], | |
160 | [enable exceptions & rtti]),, | |
161 | [enable_exceptions="no"]) | |
162 | AS_CASE([$enable_exceptions], | |
163 | [yes], [nms_exceptions=yes], | |
164 | [no], [nms_exceptions=no], | |
165 | [AC_MSG_ERROR([unknown exceptions $enable_exceptions])]) | |
166 | AC_MSG_CHECKING([exceptions]) | |
167 | AC_MSG_RESULT([$nms_exceptions]) | |
168 | if test "$nms_exceptions" != no ; then | |
169 | EXCEPTIONS=yes | |
170 | fi | |
171 | AC_SUBST(EXCEPTIONS)]) | |
172 | ||
173 | AC_DEFUN([NMS_LINK_OPT], | |
174 | [AC_MSG_CHECKING([adding $1 to linker]) | |
175 | ORIG_LDFLAGS="$LDFLAGS" | |
176 | LDFLAGS+=" $1" | |
177 | AC_LINK_IFELSE([AC_LANG_PROGRAM([])], | |
178 | [AC_MSG_RESULT([ok])], | |
179 | [LDFLAGS="$ORIG_LDFLAGS" | |
180 | AC_MSG_RESULT([no])]) | |
181 | unset ORIG_LDFLAGS]) | |
182 | ||
183 | AC_DEFUN([NMS_BUGURL], | |
184 | [AC_MSG_CHECKING([bugurl]) | |
185 | AC_ARG_WITH(bugurl, | |
186 | AS_HELP_STRING([--with-bugurl=URL],[where to report bugs]), | |
187 | AS_CASE(["$withval"], | |
188 | [yes], [AC_MSG_ERROR([--with-bugurl requires an argument])], | |
189 | [no], [BUGURL=""], | |
190 | [BUGURL="${withval}"]), | |
191 | [BUGURL="${PACKAGE_BUGREPORT}"]) | |
192 | AC_MSG_RESULT($BUGURL) | |
193 | AC_DEFINE_UNQUOTED(BUGURL,"$BUGURL",[Bug reporting location])]) | |
194 | ||
195 | AC_DEFUN([NMS_DISTRIBUTION], | |
196 | [AC_ARG_ENABLE([distribution], | |
197 | AS_HELP_STRING([--enable-distribution], | |
198 | [enable distribution. Inhibit components that prevent distribution]),, | |
199 | [enable_distribution="no"]) | |
200 | AS_CASE([$enable_distribution], | |
201 | [yes], [nms_distribution=yes], | |
202 | [no], [nms_distribution=no], | |
203 | [AC_MSG_ERROR([unknown distribution $enable_distribution])]) | |
204 | AC_MSG_CHECKING([distribution]) | |
205 | AC_MSG_RESULT([$nms_distribution])]) | |
206 | ||
207 | AC_DEFUN([NMS_ENABLE_CHECKING], | |
208 | [AC_ARG_ENABLE([checking], | |
209 | AS_HELP_STRING([--enable-checking], | |
210 | [enable run-time checking]),, | |
211 | [enable_checking="yes"]) | |
212 | AS_CASE([$enable_checking], | |
213 | [yes|all|yes,*], [nms_checking=yes], | |
214 | [no|none|release], [nms_checking=], | |
215 | [AC_MSG_ERROR([unknown check "$enable_checking"])]) | |
216 | AC_MSG_CHECKING([checking]) | |
217 | AC_MSG_RESULT([${nms_checking:-no}]) | |
218 | if test "$nms_checking" = yes ; then | |
219 | AC_DEFINE_UNQUOTED([NMS_CHECKING], [0${nms_checking:+1}], [Enable checking]) | |
220 | fi]) | |
221 | ||
222 | AC_DEFUN([NMS_WITH_BINUTILS], | |
223 | [AC_MSG_CHECKING([binutils]) | |
224 | AC_ARG_WITH(bfd, | |
225 | AS_HELP_STRING([--with-bfd=DIR], [location of libbfd]), | |
226 | if test "$withval" = "yes" ; then | |
227 | AC_MSG_ERROR([DIR not specified]) | |
228 | elif test "$withval" = "no" ; then | |
229 | AC_MSG_RESULT(installed) | |
230 | else | |
231 | AC_MSG_RESULT(${withval}) | |
232 | CPPFLAGS+=" -I${withval}/include" | |
233 | LDFLAGS+=" -L${withval}/lib" | |
234 | fi, | |
235 | AC_MSG_RESULT(installed))]) | |
236 | ||
237 | AC_DEFUN([NMS_ENABLE_BACKTRACE], | |
238 | [AC_REQUIRE([NMS_DISTRIBUTION]) | |
239 | AC_ARG_ENABLE([backtrace], | |
240 | AS_HELP_STRING([--enable-backtrace],[provide backtrace on fatality.]),, | |
241 | [enable_backtrace="maybe"]) | |
242 | if test "${enable_backtrace:-maybe}" != no ; then | |
243 | AC_CHECK_HEADERS(execinfo.h) | |
244 | AC_CHECK_FUNCS(backtrace) | |
245 | if test "$nms_distribution" = no ; then | |
246 | AC_DEFINE([HAVE_DECL_BASENAME], [1], [Needed for demangle.h]) | |
247 | # libiberty prevents distribution because of licensing | |
248 | AC_CHECK_HEADERS([demangle.h libiberty/demangle.h],[break]) | |
249 | # libbfd prevents distribution because of licensing | |
250 | AC_CHECK_HEADERS([bfd.h]) | |
251 | AC_SEARCH_LIBS([bfd_openr],[bfd],[LIBS+="-lz -liberty -ldl"],,[-lz -liberty -ldl]) | |
252 | fi | |
253 | if test "$ac_cv_func_backtrace" = yes ; then | |
254 | nms_backtrace=yes | |
255 | ldbacktrace=-rdynamic | |
256 | AC_DEFINE([NMS_BACKTRACE], [1], [Enable backtrace]) | |
257 | elif test "$enable_backtrace" = yes ; then | |
258 | AC_MSG_ERROR([Backtrace unavailable]) | |
259 | fi | |
260 | AC_SUBST([ldbacktrace]) | |
261 | fi | |
262 | AC_MSG_CHECKING([backtrace]) | |
263 | AC_MSG_RESULT([${nms_backtrace:-no}])]) | |
264 | ||
265 | AC_DEFUN([NMS_CONFIG_FILES], | |
266 | [CONFIG_FILES="Makefile $1" | |
267 | SUBDIRS="$2" | |
268 | for generated in config.h.in configure ; do | |
269 | if test $srcdir/configure.ac -nt $srcdir/$generated ; then | |
270 | touch $srcdir/$generated | |
271 | fi | |
272 | done | |
273 | for dir in . $SUBDIRS | |
274 | do | |
275 | CONFIG_FILES+=" $dir/Makesub" | |
276 | test -f ${srcdir}/$dir/tests/Makesub.in && CONFIG_FILES+=" $dir/tests/Makesub" | |
277 | done | |
278 | AC_CONFIG_FILES([$CONFIG_FILES]) | |
279 | AC_SUBST(configure_args,[$ac_configure_args]) | |
280 | AC_SUBST(SUBDIRS) | |
281 | AC_SUBST(CONFIG_FILES)]) |