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