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