]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m4/sim_ac_common.m4
bfbde3fe1bf95e33dc5efe835d60f305d41ef74c
[thirdparty/binutils-gdb.git] / sim / m4 / sim_ac_common.m4
1 dnl Copyright (C) 1997-2021 Free Software Foundation, Inc.
2 dnl
3 dnl This program is free software; you can redistribute it and/or modify
4 dnl it under the terms of the GNU General Public License as published by
5 dnl the Free Software Foundation; either version 3 of the License, or
6 dnl (at your option) any later version.
7 dnl
8 dnl This program is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 dnl GNU General Public License for more details.
12 dnl
13 dnl You should have received a copy of the GNU General Public License
14 dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
15 dnl
16 dnl SIM_AC_COMMON invokes AC macros used by all simulators and by the common
17 dnl directory. It is intended to be invoked before any target specific stuff.
18 dnl SIM_AC_OUTPUT is a cover function to AC_OUTPUT to generate the Makefile.
19 dnl It is intended to be invoked last.
20 dnl
21 dnl See README-HACKING for more details.
22 AC_DEFUN([SIM_AC_COMMON],
23 [
24 AC_REQUIRE([AC_PROG_CC])
25 AC_CONFIG_HEADERS([config.h:config.in])
26 AC_CANONICAL_SYSTEM
27 AC_USE_SYSTEM_EXTENSIONS
28 AC_C_BIGENDIAN
29 AC_ARG_PROGRAM
30 AC_PROG_INSTALL
31
32 # Put a plausible default for CC_FOR_BUILD in Makefile.
33 if test -z "$CC_FOR_BUILD"; then
34 if test "x$cross_compiling" = "xno"; then
35 CC_FOR_BUILD='$(CC)'
36 else
37 CC_FOR_BUILD=gcc
38 fi
39 fi
40 AC_SUBST(CC_FOR_BUILD)
41
42 AC_SUBST(CFLAGS)
43 AR=${AR-ar}
44 AC_SUBST(AR)
45 AC_PROG_RANLIB
46
47 # Require C11 or newer. Autoconf-2.70 provides ac_cv_prog_cc_c11 when using
48 # AC_PROG_CC, but we're still using Autoconf-2.69, and the newest it understands
49 # is C99. So handle it ourselves.
50 m4_version_prereq([2.70], [AC_MSG_ERROR([clean this up!])], [:])
51 C_DIALECT=
52 AC_MSG_CHECKING([whether C11 is supported by default])
53 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
54 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
55 # error "C11 support not found"
56 #endif
57 ])], [AC_MSG_RESULT([yes])], [
58 AC_MSG_RESULT([no])
59 AC_MSG_CHECKING([for -std=c11 support])
60 ac_save_CC="$CC"
61 CC="$CC -std=c11"
62 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
63 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
64 # error "C11 support not found"
65 #endif
66 ])], [
67 AC_MSG_RESULT([yes])
68 CC="$ac_save_CC"
69 C_DIALECT="-std=c11"
70 ], [AC_MSG_ERROR([C11 is required])])])
71 AC_SUBST(C_DIALECT)
72
73 # Some of the common include files depend on bfd.h, and bfd.h checks
74 # that config.h is included first by testing that the PACKAGE macro
75 # is defined.
76 PACKAGE=sim
77 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package. ])
78 AC_SUBST(PACKAGE)
79
80 # Dependency checking.
81 ZW_CREATE_DEPDIR
82 ZW_PROG_COMPILER_DEPENDENCIES([CC])
83
84 # Check for the 'make' the user wants to use.
85 AC_CHECK_PROGS(MAKE, make)
86 MAKE_IS_GNU=
87 case "`$MAKE --version 2>&1 | sed 1q`" in
88 *GNU*)
89 MAKE_IS_GNU=yes
90 ;;
91 esac
92 AM_CONDITIONAL(GMAKE, test "$MAKE_IS_GNU" = yes)
93
94 dnl We don't use gettext, but bfd does. So we do the appropriate checks
95 dnl to see if there are intl libraries we should link against.
96 ALL_LINGUAS=
97 ZW_GNU_GETTEXT_SISTER_DIR(../../intl)
98
99 # Check for common headers.
100 # NB: You can assume C11 headers exist.
101 AC_CHECK_HEADERS(unistd.h)
102 AC_CHECK_HEADERS(sys/time.h sys/times.h sys/resource.h sys/mman.h)
103 AC_CHECK_HEADERS(fcntl.h fpu_control.h)
104 AC_CHECK_HEADERS(dlfcn.h sys/stat.h)
105 AC_CHECK_FUNCS(getrusage time sigaction __setfpucw)
106 AC_CHECK_FUNCS(mmap munmap lstat truncate ftruncate posix_fallocate)
107 AC_CHECK_MEMBERS([[struct stat.st_dev], [struct stat.st_ino],
108 [struct stat.st_mode], [struct stat.st_nlink], [struct stat.st_uid],
109 [struct stat.st_gid], [struct stat.st_rdev], [struct stat.st_size],
110 [struct stat.st_blksize], [struct stat.st_blocks], [struct stat.st_atime],
111 [struct stat.st_mtime], [struct stat.st_ctime]], [], [],
112 [[#ifdef HAVE_SYS_TYPES_H
113 #include <sys/types.h>
114 #endif
115 #ifdef HAVE_SYS_STAT_H
116 #include <sys/stat.h>
117 #endif]])
118 AC_CHECK_TYPES(socklen_t, [], [],
119 [#include <sys/types.h>
120 #include <sys/socket.h>
121 ])
122
123 # Check for socket libraries
124 AC_CHECK_LIB(socket, bind)
125 AC_CHECK_LIB(nsl, gethostbyname)
126
127 # BFD conditionally uses zlib, so we must link it in if libbfd does, by
128 # using the same condition.
129 AM_ZLIB
130
131 # BFD uses libdl when when plugins enabled.
132 AC_PLUGINS
133 AM_CONDITIONAL(PLUGINS, test "$plugins" = yes)
134 LT_INIT([dlopen])
135 AC_SUBST(lt_cv_dlopen_libs)
136
137 dnl Standard (and optional) simulator options.
138 dnl Eventually all simulators will support these.
139 dnl Do not add any here that cannot be supported by all simulators.
140 dnl Do not add similar but different options to a particular simulator,
141 dnl all shall eventually behave the same way.
142
143
144 dnl We don't use automake, but we still want to support
145 dnl --enable-maintainer-mode.
146 AM_MAINTAINER_MODE
147
148
149 dnl --enable-sim-debug is for developers of the simulator
150 dnl the allowable values are work-in-progress
151 AC_MSG_CHECKING([for sim debug setting])
152 sim_debug="0"
153 AC_ARG_ENABLE(sim-debug,
154 [AS_HELP_STRING([--enable-sim-debug=opts],
155 [Enable debugging flags (for developers of the sim itself)])],
156 [case "${enableval}" in
157 yes) sim_debug="7";;
158 no) sim_debug="0";;
159 *) sim_debug="($enableval)";;
160 esac])dnl
161 if test "$sim_debug" != "0"; then
162 AC_DEFINE_UNQUOTED([DEBUG], [$sim_debug], [Sim debug setting])
163 fi
164 AC_DEFINE_UNQUOTED([WITH_DEBUG], [$sim_debug], [Sim debug setting])
165 AC_MSG_RESULT($sim_debug)
166
167
168 dnl --enable-sim-stdio is for users of the simulator
169 dnl It determines if IO from the program is routed through STDIO (buffered)
170 AC_MSG_CHECKING([for sim stdio debug behavior])
171 sim_stdio="0"
172 AC_ARG_ENABLE(sim-stdio,
173 [AS_HELP_STRING([--enable-sim-stdio],
174 [Specify whether to use stdio for console input/output])],
175 [case "${enableval}" in
176 yes) sim_stdio="DO_USE_STDIO";;
177 no) sim_stdio="DONT_USE_STDIO";;
178 *) AC_MSG_ERROR([Unknown value $enableval passed to --enable-sim-stdio]);;
179 esac])dnl
180 AC_DEFINE_UNQUOTED([WITH_STDIO], [$sim_stdio], [How to route I/O])
181 AC_MSG_RESULT($sim_stdio)
182
183
184 dnl --enable-sim-trace is for users of the simulator
185 dnl The argument is either a bitmask of things to enable [exactly what is
186 dnl up to the simulator], or is a comma separated list of names of tracing
187 dnl elements to enable. The latter is only supported on simulators that
188 dnl use WITH_TRACE. Default to all tracing but internal debug.
189 AC_MSG_CHECKING([for sim trace settings])
190 sim_trace="~TRACE_debug"
191 AC_ARG_ENABLE(sim-trace,
192 [AS_HELP_STRING([--enable-sim-trace=opts],
193 [Enable tracing of simulated programs])],
194 [case "${enableval}" in
195 yes) sim_trace="-1";;
196 no) sim_trace="0";;
197 [[-0-9]]*)
198 sim_trace="'(${enableval})'";;
199 [[[:lower:]]]*)
200 sim_trace=""
201 for x in `echo "$enableval" | sed -e "s/,/ /g"`; do
202 if test x"$sim_trace" = x; then
203 sim_trace="(TRACE_$x"
204 else
205 sim_trace="${sim_trace}|TRACE_$x"
206 fi
207 done
208 sim_trace="$sim_trace)" ;;
209 esac])dnl
210 AC_DEFINE_UNQUOTED([WITH_TRACE], [$sim_trace], [Sim trace settings])
211 AC_MSG_RESULT($sim_trace)
212
213
214 dnl --enable-sim-profile
215 dnl The argument is either a bitmask of things to enable [exactly what is
216 dnl up to the simulator], or is a comma separated list of names of profiling
217 dnl elements to enable. The latter is only supported on simulators that
218 dnl use WITH_PROFILE.
219 AC_MSG_CHECKING([for sim profile settings])
220 profile="1"
221 sim_profile="-1"
222 AC_ARG_ENABLE(sim-profile,
223 [AS_HELP_STRING([--enable-sim-profile=opts], [Enable profiling flags])],
224 [case "${enableval}" in
225 yes) profile="1" sim_profile="-1";;
226 no) profile="0" sim_profile="0";;
227 [[-0-9]]*)
228 profile="(${enableval})" sim_profile="(${enableval})";;
229 [[a-z]]*)
230 profile="1"
231 sim_profile=""
232 for x in `echo "$enableval" | sed -e "s/,/ /g"`; do
233 if test x"$sim_profile" = x; then
234 sim_profile="(PROFILE_$x"
235 else
236 sim_profile="${sim_profile}|PROFILE_$x"
237 fi
238 done
239 sim_profile="$sim_profile)" ;;
240 esac])dnl
241 AC_DEFINE_UNQUOTED([PROFILE], [$profile], [Sim profile settings])
242 AC_DEFINE_UNQUOTED([WITH_PROFILE], [$sim_profile], [Sim profile settings])
243 AC_MSG_RESULT($sim_profile)
244
245
246 SIM_AC_OPTION_ASSERT
247 SIM_AC_OPTION_ENVIRONMENT
248 SIM_AC_OPTION_INLINE
249
250 ACX_PKGVERSION([SIM])
251 ACX_BUGURL([https://www.gnu.org/software/gdb/bugs/])
252 AC_DEFINE_UNQUOTED([PKGVERSION], ["$PKGVERSION"], [Additional package description])
253 AC_DEFINE_UNQUOTED([REPORT_BUGS_TO], ["$REPORT_BUGS_TO"], [Bug reporting address])
254
255 dnl Types used by common code
256 AC_TYPE_SIGNAL
257
258 dnl Detect exe extension
259 AC_EXEEXT
260 ]) dnl End of SIM_AC_COMMON