0b027fdc07821d69e2eff55bfe952db149dd3490
[external/binutils.git] / sim / common / acinclude.m4
1 # This file contains common code used by all simulators.
2 #
3 # SIM_AC_COMMON invokes AC macros used by all simulators and by the common
4 # directory.  It is intended to be invoked before any target specific stuff.
5 # SIM_AC_OUTPUT is a cover function to AC_OUTPUT to generate the Makefile.
6 # It is intended to be invoked last.
7 #
8 # The simulator's configure.ac should look like:
9 #
10 # dnl Process this file with autoconf to produce a configure script.
11 # AC_PREREQ(2.64)dnl
12 # AC_INIT(Makefile.in)
13 # sinclude(../common/aclocal.m4)
14 #
15 # SIM_AC_COMMON
16 #
17 # ... target specific stuff ...
18 #
19 # SIM_AC_OUTPUT
20
21 # Include global overrides and fixes for Autoconf.
22 m4_include(../../config/override.m4)
23 sinclude([../../config/zlib.m4])
24 m4_include([../../config/plugins.m4])
25 m4_include([../../libtool.m4])
26 m4_include([../../ltoptions.m4])
27 m4_include([../../ltsugar.m4])
28 m4_include([../../ltversion.m4])
29 m4_include([../../lt~obsolete.m4])
30 sinclude([../../config/depstand.m4])
31
32 AC_DEFUN([SIM_AC_COMMON],
33 [
34 AC_REQUIRE([AC_PROG_CC])
35 # autoconf.info says this should be called right after AC_INIT.
36 AC_CONFIG_HEADER(ifelse([$1],,config.h,[$1]):config.in)
37 AC_CANONICAL_SYSTEM
38 AC_USE_SYSTEM_EXTENSIONS
39 AC_C_BIGENDIAN
40 AC_ARG_PROGRAM
41 AC_PROG_INSTALL
42
43 # Put a plausible default for CC_FOR_BUILD in Makefile.
44 if test "x$cross_compiling" = "xno"; then
45   CC_FOR_BUILD='$(CC)'
46 else
47   CC_FOR_BUILD=gcc
48 fi
49 AC_SUBST(CC_FOR_BUILD)
50
51 AC_SUBST(CFLAGS)
52 AC_SUBST(HDEFINES)
53 AR=${AR-ar}
54 AC_SUBST(AR)
55 AC_PROG_RANLIB
56
57 # Some of the common include files depend on bfd.h, and bfd.h checks
58 # that config.h is included first by testing that the PACKAGE macro
59 # is defined.
60 PACKAGE=sim
61 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package. ])
62 AC_SUBST(PACKAGE)
63
64 # Dependency checking.
65 ZW_CREATE_DEPDIR
66 ZW_PROG_COMPILER_DEPENDENCIES([CC])
67
68 # Check for the 'make' the user wants to use.
69 AC_CHECK_PROGS(MAKE, make)
70 MAKE_IS_GNU=
71 case "`$MAKE --version 2>&1 | sed 1q`" in
72   *GNU*)
73     MAKE_IS_GNU=yes
74     ;;
75 esac
76 AM_CONDITIONAL(GMAKE, test "$MAKE_IS_GNU" = yes)
77
78 dnl We don't use gettext, but bfd does.  So we do the appropriate checks
79 dnl to see if there are intl libraries we should link against.
80 ALL_LINGUAS=
81 ZW_GNU_GETTEXT_SISTER_DIR(../../intl)
82
83 # Check for common headers.
84 # FIXME: Seems to me this can cause problems for i386-windows hosts.
85 # At one point there were hardcoded AC_DEFINE's if ${host} = i386-*-windows*.
86 AC_CHECK_HEADERS(stdlib.h string.h strings.h unistd.h time.h)
87 AC_CHECK_HEADERS(sys/time.h sys/times.h sys/resource.h sys/mman.h)
88 AC_CHECK_HEADERS(fcntl.h fpu_control.h)
89 AC_CHECK_HEADERS(dlfcn.h errno.h sys/stat.h)
90 AC_CHECK_FUNCS(getrusage time sigaction __setfpucw)
91 AC_CHECK_FUNCS(mmap munmap lstat truncate ftruncate posix_fallocate)
92 AC_CHECK_MEMBERS([[struct stat.st_dev], [struct stat.st_ino],
93 [struct stat.st_mode], [struct stat.st_nlink], [struct stat.st_uid],
94 [struct stat.st_gid], [struct stat.st_rdev], [struct stat.st_size],
95 [struct stat.st_blksize], [struct stat.st_blocks], [struct stat.st_atime],
96 [struct stat.st_mtime], [struct stat.st_ctime]], [], [],
97 [[#ifdef HAVE_SYS_TYPES_H
98 #include <sys/types.h>
99 #endif
100 #ifdef HAVE_SYS_STAT_H
101 #include <sys/stat.h>
102 #endif]])
103 AC_CHECK_TYPES(socklen_t, [], [],
104 [#include <sys/types.h>
105 #include <sys/socket.h>
106 ])
107
108 # Check for socket libraries
109 AC_CHECK_LIB(socket, bind)
110 AC_CHECK_LIB(nsl, gethostbyname)
111
112 # BFD conditionally uses zlib, so we must link it in if libbfd does, by
113 # using the same condition.
114 AM_ZLIB
115
116 # BFD uses libdl when when plugins enabled.
117 AC_PLUGINS
118 AM_CONDITIONAL(PLUGINS, test "$plugins" = yes)
119 LT_INIT([dlopen])
120 AC_SUBST(lt_cv_dlopen_libs)
121
122 . ${srcdir}/../../bfd/configure.host
123
124 dnl Standard (and optional) simulator options.
125 dnl Eventually all simulators will support these.
126 dnl Do not add any here that cannot be supported by all simulators.
127 dnl Do not add similar but different options to a particular simulator,
128 dnl all shall eventually behave the same way.
129
130
131 dnl We don't use automake, but we still want to support
132 dnl --enable-maintainer-mode.
133 AM_MAINTAINER_MODE
134
135
136 dnl --enable-sim-debug is for developers of the simulator
137 dnl the allowable values are work-in-progress
138 AC_ARG_ENABLE(sim-debug,
139 [AS_HELP_STRING([--enable-sim-debug=opts],
140                 [Enable debugging flags (for developers of the sim itself)])],
141 [case "${enableval}" in
142   yes) sim_debug="-DDEBUG=7 -DWITH_DEBUG=7";;
143   no)  sim_debug="-DDEBUG=0 -DWITH_DEBUG=0";;
144   *)   sim_debug="-DDEBUG='(${enableval})' -DWITH_DEBUG='(${enableval})'";;
145 esac
146 if test x"$silent" != x"yes" && test x"$sim_debug" != x""; then
147   echo "Setting sim debug = $sim_debug" 6>&1
148 fi],[sim_debug=""])dnl
149 AC_SUBST(sim_debug)
150
151
152 dnl --enable-sim-stdio is for users of the simulator
153 dnl It determines if IO from the program is routed through STDIO (buffered)
154 AC_ARG_ENABLE(sim-stdio,
155 [AS_HELP_STRING([--enable-sim-stdio],
156                 [Specify whether to use stdio for console input/output])],
157 [case "${enableval}" in
158   yes)  sim_stdio="-DWITH_STDIO=DO_USE_STDIO";;
159   no)   sim_stdio="-DWITH_STDIO=DONT_USE_STDIO";;
160   *)    AC_MSG_ERROR("Unknown value $enableval passed to --enable-sim-stdio"); sim_stdio="";;
161 esac
162 if test x"$silent" != x"yes" && test x"$sim_stdio" != x""; then
163   echo "Setting stdio flags = $sim_stdio" 6>&1
164 fi],[sim_stdio=""])dnl
165 AC_SUBST(sim_stdio)
166
167
168 dnl --enable-sim-trace is for users of the simulator
169 dnl The argument is either a bitmask of things to enable [exactly what is
170 dnl up to the simulator], or is a comma separated list of names of tracing
171 dnl elements to enable.  The latter is only supported on simulators that
172 dnl use WITH_TRACE.
173 AC_ARG_ENABLE(sim-trace,
174 [AS_HELP_STRING([--enable-sim-trace=opts],
175                 [Enable tracing of simulated programs])],
176 [case "${enableval}" in
177   yes)  sim_trace="-DWITH_TRACE=-1";;
178   no)   sim_trace="-DWITH_TRACE=0";;
179   [[-0-9]]*)
180         sim_trace="-DWITH_TRACE='(${enableval})'";;
181   [[[:lower:]]]*)
182         sim_trace=""
183         for x in `echo "$enableval" | sed -e "s/,/ /g"`; do
184           if test x"$sim_trace" = x; then
185             sim_trace="-DWITH_TRACE='(TRACE_$x"
186           else
187             sim_trace="${sim_trace}|TRACE_$x"
188           fi
189         done
190         sim_trace="$sim_trace)'" ;;
191 esac
192 if test x"$silent" != x"yes" && test x"$sim_trace" != x""; then
193   echo "Setting sim trace = $sim_trace" 6>&1
194 fi],[sim_trace=""])dnl
195 AC_SUBST(sim_trace)
196
197
198 dnl --enable-sim-profile
199 dnl The argument is either a bitmask of things to enable [exactly what is
200 dnl up to the simulator], or is a comma separated list of names of profiling
201 dnl elements to enable.  The latter is only supported on simulators that
202 dnl use WITH_PROFILE.
203 AC_ARG_ENABLE(sim-profile,
204 [AS_HELP_STRING([--enable-sim-profile=opts], [Enable profiling flags])],
205 [case "${enableval}" in
206   yes)  sim_profile="-DPROFILE=1 -DWITH_PROFILE=-1";;
207   no)   sim_profile="-DPROFILE=0 -DWITH_PROFILE=0";;
208   [[-0-9]]*)
209         sim_profile="-DPROFILE='(${enableval})' -DWITH_PROFILE='(${enableval})'";;
210   [[a-z]]*)
211         sim_profile=""
212         for x in `echo "$enableval" | sed -e "s/,/ /g"`; do
213           if test x"$sim_profile" = x; then
214             sim_profile="-DWITH_PROFILE='(PROFILE_$x"
215           else
216             sim_profile="${sim_profile}|PROFILE_$x"
217           fi
218         done
219         sim_profile="$sim_profile)'" ;;
220 esac
221 if test x"$silent" != x"yes" && test x"$sim_profile" != x""; then
222   echo "Setting sim profile = $sim_profile" 6>&1
223 fi],[sim_profile="-DPROFILE=1 -DWITH_PROFILE=-1"])dnl
224 AC_SUBST(sim_profile)
225
226 SIM_AC_OPTION_INLINE
227
228 ACX_PKGVERSION([SIM])
229 ACX_BUGURL([http://www.gnu.org/software/gdb/bugs/])
230 AC_DEFINE_UNQUOTED([PKGVERSION], ["$PKGVERSION"], [Additional package description])
231 AC_DEFINE_UNQUOTED([REPORT_BUGS_TO], ["$REPORT_BUGS_TO"], [Bug reporting address])
232
233 dnl Types used by common code
234 AC_TYPE_SIGNAL
235
236 dnl Detect exe extension
237 AC_EXEEXT
238
239 dnl These are available to append to as desired.
240 sim_link_files=
241 sim_link_links=
242
243 # targ-vals.def points to the libc macro description file.
244 case "${target}" in
245 *-*-*) TARG_VALS_DEF=../common/nltvals.def ;;
246 esac
247 sim_link_files="${sim_link_files} ${TARG_VALS_DEF}"
248 sim_link_links="${sim_link_links} targ-vals.def"
249
250 ]) dnl End of SIM_AC_COMMON
251
252
253 dnl Additional SIM options that can (optionally) be configured
254 dnl For optional simulator options, a macro SIM_AC_OPTION_* is defined.
255 dnl Simulators that wish to use the relevant option specify the macro
256 dnl in the simulator specific configure.ac file between the SIM_AC_COMMON
257 dnl and SIM_AC_OUTPUT lines.
258
259
260 dnl Specify the running environment.
261 dnl If the simulator invokes this in its configure.ac then without this option
262 dnl the default is the user environment and all are runtime selectable.
263 dnl If the simulator doesn't invoke this, only the user environment is
264 dnl supported.
265 dnl ??? Until there is demonstrable value in doing something more complicated,
266 dnl let's not.
267 AC_DEFUN([SIM_AC_OPTION_ENVIRONMENT],
268 [
269 AC_ARG_ENABLE(sim-environment,
270 [AS_HELP_STRING([--enable-sim-environment=environment],
271                 [Specify mixed, user, virtual or operating environment])],
272 [case "${enableval}" in
273   all | ALL)             sim_environment="-DWITH_ENVIRONMENT=ALL_ENVIRONMENT";;
274   user | USER)           sim_environment="-DWITH_ENVIRONMENT=USER_ENVIRONMENT";;
275   virtual | VIRTUAL)     sim_environment="-DWITH_ENVIRONMENT=VIRTUAL_ENVIRONMENT";;
276   operating | OPERATING) sim_environment="-DWITH_ENVIRONMENT=OPERATING_ENVIRONMENT";;
277   *)   AC_MSG_ERROR("Unknown value $enableval passed to --enable-sim-environment");
278        sim_environment="";;
279 esac
280 if test x"$silent" != x"yes" && test x"$sim_environment" != x""; then
281   echo "Setting sim environment = $sim_environment" 6>&1
282 fi],
283 [sim_environment="-DWITH_ENVIRONMENT=ALL_ENVIRONMENT"])dnl
284 ])
285 AC_SUBST(sim_environment)
286
287
288 dnl Specify the alignment restrictions of the target architecture.
289 dnl Without this option all possible alignment restrictions are accommodated.
290 dnl arg[1] is hardwired target alignment
291 dnl arg[2] is default target alignment
292 AC_DEFUN([SIM_AC_OPTION_ALIGNMENT],
293 wire_alignment="[$1]"
294 default_alignment="[$2]"
295 [
296 AC_ARG_ENABLE(sim-alignment,
297 [AS_HELP_STRING([--enable-sim-alignment=align],
298                 [Specify strict, nonstrict or forced alignment of memory accesses])],
299 [case "${enableval}" in
300   strict | STRICT)       sim_alignment="-DWITH_ALIGNMENT=STRICT_ALIGNMENT";;
301   nonstrict | NONSTRICT) sim_alignment="-DWITH_ALIGNMENT=NONSTRICT_ALIGNMENT";;
302   forced | FORCED)       sim_alignment="-DWITH_ALIGNMENT=FORCED_ALIGNMENT";;
303   yes) if test x"$wire_alignment" != x; then
304          sim_alignment="-DWITH_ALIGNMENT=${wire_alignment}"
305        else
306          if test x"$default_alignment" != x; then
307            sim_alignment="-DWITH_ALIGNMENT=${default_alignment}"
308          else
309            echo "No hard-wired alignment for target $target" 1>&6
310            sim_alignment="-DWITH_ALIGNMENT=0"
311          fi
312        fi;;
313   no)  if test x"$default_alignment" != x; then
314          sim_alignment="-DWITH_DEFAULT_ALIGNMENT=${default_alignment}"
315        else
316          if test x"$wire_alignment" != x; then
317            sim_alignment="-DWITH_DEFAULT_ALIGNMENT=${wire_alignment}"
318          else
319            echo "No default alignment for target $target" 1>&6
320            sim_alignment="-DWITH_DEFAULT_ALIGNMENT=0"
321          fi
322        fi;;
323   *)   AC_MSG_ERROR("Unknown value $enableval passed to --enable-sim-alignment"); sim_alignment="";;
324 esac
325 if test x"$silent" != x"yes" && test x"$sim_alignment" != x""; then
326   echo "Setting alignment flags = $sim_alignment" 6>&1
327 fi],
328 [if test x"$default_alignment" != x; then
329   sim_alignment="-DWITH_DEFAULT_ALIGNMENT=${default_alignment}"
330 else
331   if test x"$wire_alignment" != x; then
332     sim_alignment="-DWITH_ALIGNMENT=${wire_alignment}"
333   else
334     sim_alignment=
335   fi
336 fi])dnl
337 ])dnl
338 AC_SUBST(sim_alignment)
339
340
341 dnl Conditionally compile in assertion statements.
342 AC_DEFUN([SIM_AC_OPTION_ASSERT],
343 [
344 AC_ARG_ENABLE(sim-assert,
345 [AS_HELP_STRING([--enable-sim-assert],
346                 [Specify whether to perform random assertions])],
347 [case "${enableval}" in
348   yes)  sim_assert="-DWITH_ASSERT=1";;
349   no)   sim_assert="-DWITH_ASSERT=0";;
350   *)    AC_MSG_ERROR("--enable-sim-assert does not take a value"); sim_assert="";;
351 esac
352 if test x"$silent" != x"yes" && test x"$sim_assert" != x""; then
353   echo "Setting assert flags = $sim_assert" 6>&1
354 fi],[sim_assert=""])dnl
355 ])
356 AC_SUBST(sim_assert)
357
358
359
360 dnl --enable-sim-bitsize is for developers of the simulator
361 dnl It specifies the number of BITS in the target.
362 dnl arg[1] is the number of bits in a word
363 dnl arg[2] is the number assigned to the most significant bit
364 dnl arg[3] is the number of bits in an address
365 dnl arg[4] is the number of bits in an OpenFirmware cell.
366 dnl FIXME: this information should be obtained from bfd/archure
367 AC_DEFUN([SIM_AC_OPTION_BITSIZE],
368 wire_word_bitsize="[$1]"
369 wire_word_msb="[$2]"
370 wire_address_bitsize="[$3]"
371 wire_cell_bitsize="[$4]"
372 [AC_ARG_ENABLE(sim-bitsize,
373 [AS_HELP_STRING([--enable-sim-bitsize=N], [Specify target bitsize (32 or 64)])],
374 [sim_bitsize=
375 case "${enableval}" in
376   64,63 | 64,63,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=63";;
377   32,31 | 32,31,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=31";;
378   64,0 | 64,0,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0";;
379   32,0 | 64,0,* ) sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0";;
380   32) if test x"$wire_word_msb" != x -a x"$wire_word_msb" != x0; then
381         sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=31"
382       else
383         sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=0"
384       fi ;;
385   64) if test x"$wire_word_msb" != x -a x"$wire_word_msb" != x0; then
386         sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=63"
387       else
388         sim_bitsize="-DWITH_TARGET_WORD_BITSIZE=64 -DWITH_TARGET_WORD_MSB=0"
389       fi ;;
390   *)  AC_MSG_ERROR("--enable-sim-bitsize was given $enableval.  Expected 32 or 64") ;;
391 esac
392 # address bitsize
393 tmp=`echo "${enableval}" | sed -e "s/^[[0-9]]*,*[[0-9]]*,*//"`
394 case x"${tmp}" in
395   x ) ;;
396   x32 | x32,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_ADDRESS_BITSIZE=32" ;;
397   x64 | x64,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_ADDRESS_BITSIZE=64" ;;
398   * ) AC_MSG_ERROR("--enable-sim-bitsize was given address size $enableval.  Expected 32 or 64") ;;
399 esac
400 # cell bitsize
401 tmp=`echo "${enableval}" | sed -e "s/^[[0-9]]*,*[[0-9*]]*,*[[0-9]]*,*//"`
402 case x"${tmp}" in
403   x ) ;;
404   x32 | x32,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_CELL_BITSIZE=32" ;;
405   x64 | x64,* ) sim_bitsize="${sim_bitsize} -DWITH_TARGET_CELL_BITSIZE=64" ;;
406   * ) AC_MSG_ERROR("--enable-sim-bitsize was given cell size $enableval.  Expected 32 or 64") ;;
407 esac
408 if test x"$silent" != x"yes" && test x"$sim_bitsize" != x""; then
409   echo "Setting bitsize flags = $sim_bitsize" 6>&1
410 fi],
411 [sim_bitsize=""
412 if test x"$wire_word_bitsize" != x; then
413   sim_bitsize="$sim_bitsize -DWITH_TARGET_WORD_BITSIZE=$wire_word_bitsize"
414 fi
415 if test x"$wire_word_msb" != x; then
416   sim_bitsize="$sim_bitsize -DWITH_TARGET_WORD_MSB=$wire_word_msb"
417 fi
418 if test x"$wire_address_bitsize" != x; then
419   sim_bitsize="$sim_bitsize -DWITH_TARGET_ADDRESS_BITSIZE=$wire_address_bitsize"
420 fi
421 if test x"$wire_cell_bitsize" != x; then
422   sim_bitsize="$sim_bitsize -DWITH_TARGET_CELL_BITSIZE=$wire_cell_bitsize"
423 fi])dnl
424 ])
425 AC_SUBST(sim_bitsize)
426
427
428
429 dnl --enable-sim-endian={yes,no,big,little} is for simulators
430 dnl that support both big and little endian targets.
431 dnl arg[1] is hardwired target endianness.
432 dnl arg[2] is default target endianness.
433 AC_DEFUN([SIM_AC_OPTION_ENDIAN],
434 [
435 wire_endian="[$1]"
436 default_endian="[$2]"
437 AC_ARG_ENABLE(sim-endian,
438 [AS_HELP_STRING([--enable-sim-endian=endian],
439                 [Specify target byte endian orientation])],
440 [case "${enableval}" in
441   b*|B*) sim_endian="-DWITH_TARGET_BYTE_ORDER=BFD_ENDIAN_BIG";;
442   l*|L*) sim_endian="-DWITH_TARGET_BYTE_ORDER=BFD_ENDIAN_LITTLE";;
443   yes)   if test x"$wire_endian" != x; then
444            sim_endian="-DWITH_TARGET_BYTE_ORDER=BFD_ENDIAN_${wire_endian}"
445          else
446           if test x"$default_endian" != x; then
447              sim_endian="-DWITH_TARGET_BYTE_ORDER=BFD_ENDIAN_${default_endian}"
448            else
449              echo "No hard-wired endian for target $target" 1>&6
450              sim_endian="-DWITH_TARGET_BYTE_ORDER=BFD_ENDIAN_UNKNOWN"
451            fi
452          fi;;
453   no)    if test x"$default_endian" != x; then
454            sim_endian="-DWITH_DEFAULT_TARGET_BYTE_ORDER=BFD_ENDIAN_${default_endian}"
455          else
456            if test x"$wire_endian" != x; then
457              sim_endian="-DWITH_DEFAULT_TARGET_BYTE_ORDER=BFD_ENDIAN_${wire_endian}"
458            else
459              echo "No default endian for target $target" 1>&6
460              sim_endian="-DWITH_DEFAULT_TARGET_BYTE_ORDER=BFD_ENDIAN_UNKNOWN"
461            fi
462          fi;;
463   *)     AC_MSG_ERROR("Unknown value $enableval for --enable-sim-endian"); sim_endian="";;
464 esac
465 if test x"$silent" != x"yes" && test x"$sim_endian" != x""; then
466   echo "Setting endian flags = $sim_endian" 6>&1
467 fi],
468 [if test x"$default_endian" != x; then
469   sim_endian="-DWITH_DEFAULT_TARGET_BYTE_ORDER=BFD_ENDIAN_${default_endian}"
470 else
471   if test x"$wire_endian" != x; then
472     sim_endian="-DWITH_TARGET_BYTE_ORDER=BFD_ENDIAN_${wire_endian}"
473   else
474     sim_endian=
475   fi
476 fi])dnl
477 ])
478 AC_SUBST(sim_endian)
479
480
481 dnl --enable-sim-float is for developers of the simulator
482 dnl It specifies the presence of hardware floating point
483 dnl And optionally the bitsize of the floating point register.
484 dnl arg[1] specifies the presence (or absence) of floating point hardware
485 dnl arg[2] specifies the number of bits in a floating point register
486 AC_DEFUN([SIM_AC_OPTION_FLOAT],
487 [
488 default_sim_float="[$1]"
489 default_sim_float_bitsize="[$2]"
490 AC_ARG_ENABLE(sim-float,
491 [AS_HELP_STRING([--enable-sim-float],
492                 [Specify that the target processor has floating point hardware])],
493 [case "${enableval}" in
494   yes | hard)   sim_float="-DWITH_FLOATING_POINT=HARD_FLOATING_POINT";;
495   no | soft)    sim_float="-DWITH_FLOATING_POINT=SOFT_FLOATING_POINT";;
496   32)           sim_float="-DWITH_FLOATING_POINT=HARD_FLOATING_POINT -DWITH_TARGET_FLOATING_POINT_BITSIZE=32";;
497   64)           sim_float="-DWITH_FLOATING_POINT=HARD_FLOATING_POINT -DWITH_TARGET_FLOATING_POINT_BITSIZE=64";;
498   *)            AC_MSG_ERROR("Unknown value $enableval passed to --enable-sim-float"); sim_float="";;
499 esac
500 if test x"$silent" != x"yes" && test x"$sim_float" != x""; then
501   echo "Setting float flags = $sim_float" 6>&1
502 fi],[
503 sim_float=
504 if test x"${default_sim_float}" != x""; then
505   sim_float="-DWITH_FLOATING_POINT=${default_sim_float}"
506 fi
507 if test x"${default_sim_float_bitsize}" != x""; then
508   sim_float="$sim_float -DWITH_TARGET_FLOATING_POINT_BITSIZE=${default_sim_float_bitsize}"
509 fi
510 ])dnl
511 ])
512 AC_SUBST(sim_float)
513
514
515 dnl The argument is the default cache size if none is specified.
516 AC_DEFUN([SIM_AC_OPTION_SCACHE],
517 [
518 default_sim_scache="ifelse([$1],,0,[$1])"
519 AC_ARG_ENABLE(sim-scache,
520 [AS_HELP_STRING([--enable-sim-scache=size],
521                 [Specify simulator execution cache size])],
522 [case "${enableval}" in
523   yes)  sim_scache="-DWITH_SCACHE=${default_sim_scache}";;
524   no)   sim_scache="-DWITH_SCACHE=0" ;;
525   [[0-9]]*) sim_scache="-DWITH_SCACHE=${enableval}";;
526   *)    AC_MSG_ERROR("Bad value $enableval passed to --enable-sim-scache");
527         sim_scache="";;
528 esac
529 if test x"$silent" != x"yes" && test x"$sim_scache" != x""; then
530   echo "Setting scache size = $sim_scache" 6>&1
531 fi],[sim_scache="-DWITH_SCACHE=${default_sim_scache}"])
532 ])
533 AC_SUBST(sim_scache)
534
535
536 dnl The argument is the default model if none is specified.
537 AC_DEFUN([SIM_AC_OPTION_DEFAULT_MODEL],
538 [
539 default_sim_default_model="ifelse([$1],,0,[$1])"
540 AC_ARG_ENABLE(sim-default-model,
541 [AS_HELP_STRING([--enable-sim-default-model=model],
542                 [Specify default model to simulate])],
543 [case "${enableval}" in
544   yes|no) AC_MSG_ERROR("Missing argument to --enable-sim-default-model");;
545   *)    sim_default_model="-DWITH_DEFAULT_MODEL='\"${enableval}\"'";;
546 esac
547 if test x"$silent" != x"yes" && test x"$sim_default_model" != x""; then
548   echo "Setting default model = $sim_default_model" 6>&1
549 fi],[sim_default_model="-DWITH_DEFAULT_MODEL='\"${default_sim_default_model}\"'"])
550 ])
551 AC_SUBST(sim_default_model)
552
553
554 dnl --enable-sim-hardware is for users of the simulator
555 dnl arg[1] Enable sim-hw by default? ("yes" or "no")
556 dnl arg[2] is a space separated list of devices that override the defaults
557 dnl arg[3] is a space separated list of extra target specific devices.
558 AC_DEFUN([SIM_AC_OPTION_HARDWARE],
559 [
560 if test "[$2]"; then
561   hardware="[$2]"
562 else
563   hardware="cfi core pal glue"
564 fi
565 hardware="$hardware [$3]"
566
567 sim_hw_cflags="-DWITH_HW=1"
568 sim_hw="$hardware"
569 sim_hw_objs="\$(SIM_COMMON_HW_OBJS) `echo $sim_hw | sed -e 's/\([[^ ]][[^ ]]*\)/dv-\1.o/g'`"
570
571 AC_ARG_ENABLE(sim-hardware,
572   [AS_HELP_STRING([--enable-sim-hardware=LIST],
573                   [Specify the hardware to be included in the build.])],
574   ,[enable_sim_hardware="[$1]"])
575 case ${enable_sim_hardware} in
576   yes|no) ;;
577   ,*) hardware="${hardware} `echo ${enableval} | sed -e 's/,/ /'`";;
578   *,) hardware="`echo ${enableval} | sed -e 's/,/ /'` ${hardware}";;
579   *)  hardware="`echo ${enableval} | sed -e 's/,/ /'`"'';;
580 esac
581
582 if test "$enable_sim_hardware" = no; then
583   sim_hw_objs=
584   sim_hw_cflags="-DWITH_HW=0"
585   sim_hw=
586 else
587   sim_hw_cflags="-DWITH_HW=1"
588   # remove duplicates
589   sim_hw=""
590   sim_hw_objs="\$(SIM_COMMON_HW_OBJS)"
591   for i in $hardware ; do
592     case " $sim_hw " in
593       *" $i "*) ;;
594       *) sim_hw="$sim_hw $i" ; sim_hw_objs="$sim_hw_objs dv-$i.o";;
595     esac
596   done
597   # mingw does not support sockser
598   case ${host} in
599     *mingw*) ;;
600     *) # TODO: We don't add dv-sockser to sim_hw as it is not a "real" device
601        # that you instatiate.  Instead, other code will call into it directly.
602        # At some point, we should convert it over.
603        sim_hw_objs="$sim_hw_objs dv-sockser.o"
604        AC_DEFINE_UNQUOTED(
605          [HAVE_DV_SOCKSER], 1, [Define if dv-sockser is usable.])
606        ;;
607   esac
608   if test x"$silent" != x"yes"; then
609     echo "Setting hardware to $sim_hw_cflags, $sim_hw, $sim_hw_objs"
610   fi
611   dnl Some devices require extra libraries.
612   case " $hardware " in
613     *" cfi "*) AC_CHECK_LIB(m, log2);;
614   esac
615 fi
616 ])
617 AC_SUBST(sim_hw_cflags)
618 AC_SUBST(sim_hw_objs)
619 AC_SUBST(sim_hw)
620
621
622 dnl --enable-sim-inline is for users that wish to ramp up the simulator's
623 dnl performance by inlining functions.
624 dnl Default sims to no inlining.
625 AC_DEFUN([SIM_AC_OPTION_INLINE],
626 [
627 sim_inline="-DDEFAULT_INLINE=m4_ifblank([$1],[0],[$1])"
628 AC_ARG_ENABLE(sim-inline,
629 [AS_HELP_STRING([--enable-sim-inline=inlines],
630                 [Specify which functions should be inlined])],
631 [sim_inline=""
632 case "$enableval" in
633   no)           sim_inline="-DDEFAULT_INLINE=0";;
634   0)            sim_inline="-DDEFAULT_INLINE=0";;
635   yes | 2)      sim_inline="-DDEFAULT_INLINE=ALL_C_INLINE";;
636   1)            sim_inline="-DDEFAULT_INLINE=INLINE_LOCALS";;
637   *) for x in `echo "$enableval" | sed -e "s/,/ /g"`; do
638        new_flag=""
639        case "$x" in
640          *_INLINE=*)    new_flag="-D$x";;
641          *=*)           new_flag=`echo "$x" | sed -e "s/=/_INLINE=/" -e "s/^/-D/"`;;
642          *_INLINE)      new_flag="-D$x=ALL_C_INLINE";;
643          *)             new_flag="-D$x""_INLINE=ALL_C_INLINE";;
644        esac
645        if test x"$sim_inline" = x""; then
646          sim_inline="$new_flag"
647        else
648          sim_inline="$sim_inline $new_flag"
649        fi
650      done;;
651 esac
652 if test x"$silent" != x"yes" && test x"$sim_inline" != x""; then
653   echo "Setting inline flags = $sim_inline" 6>&1
654 fi])dnl
655 ])
656 AC_SUBST(sim_inline)
657
658
659 AC_DEFUN([SIM_AC_OPTION_PACKAGES],
660 [
661 AC_ARG_ENABLE(sim-packages,
662 [AS_HELP_STRING([--enable-sim-packages=list],
663                 [Specify the packages to be included in the build])],
664 [packages=disklabel
665 case "${enableval}" in
666   yes)  ;;
667   no)   AC_MSG_ERROR("List of packages must be specified for --enable-sim-packages"); packages="";;
668   ,*)   packages="${packages}${enableval}";;
669   *,)   packages="${enableval}${packages}";;
670   *)    packages="${enableval}"'';;
671 esac
672 sim_pk_src=`echo $packages | sed -e 's/,/.c pk_/g' -e 's/^/pk_/' -e 's/$/.c/'`
673 sim_pk_obj=`echo $sim_pk_src | sed -e 's/\.c/.o/g'`
674 if test x"$silent" != x"yes" && test x"$packages" != x""; then
675   echo "Setting packages to $sim_pk_src, $sim_pk_obj"
676 fi],[packages=disklabel
677 sim_pk_src=`echo $packages | sed -e 's/,/.c pk_/g' -e 's/^/pk_/' -e 's/$/.c/'`
678 sim_pk_obj=`echo $sim_pk_src | sed -e 's/\.c/.o/g'`
679 if test x"$silent" != x"yes"; then
680   echo "Setting packages to $sim_pk_src, $sim_pk_obj"
681 fi])dnl
682 ])
683 AC_SUBST(sim_packages)
684
685
686 AC_DEFUN([SIM_AC_OPTION_RESERVED_BITS],
687 [
688 default_sim_reserved_bits="ifelse([$1],,1,[$1])"
689 AC_ARG_ENABLE(sim-reserved-bits,
690 [AS_HELP_STRING([--enable-sim-reserved-bits],
691                 [Specify whether to check reserved bits in instruction])],
692 [case "${enableval}" in
693   yes)  sim_reserved_bits="-DWITH_RESERVED_BITS=1";;
694   no)   sim_reserved_bits="-DWITH_RESERVED_BITS=0";;
695   *)    AC_MSG_ERROR("--enable-sim-reserved-bits does not take a value"); sim_reserved_bits="";;
696 esac
697 if test x"$silent" != x"yes" && test x"$sim_reserved_bits" != x""; then
698   echo "Setting reserved flags = $sim_reserved_bits" 6>&1
699 fi],[sim_reserved_bits="-DWITH_RESERVED_BITS=${default_sim_reserved_bits}"])dnl
700 ])
701 AC_SUBST(sim_reserved_bits)
702
703
704 AC_DEFUN([SIM_AC_OPTION_SMP],
705 [
706 default_sim_smp="ifelse([$1],,5,[$1])"
707 AC_ARG_ENABLE(sim-smp,
708 [AS_HELP_STRING([--enable-sim-smp=n],
709                 [Specify number of processors to configure for (default ${default_sim_smp})])],
710 [case "${enableval}" in
711   yes)  sim_smp="-DWITH_SMP=5" ; sim_igen_smp="-N 5";;
712   no)   sim_smp="-DWITH_SMP=0" ; sim_igen_smp="-N 0";;
713   *)    sim_smp="-DWITH_SMP=$enableval" ; sim_igen_smp="-N $enableval";;
714 esac
715 if test x"$silent" != x"yes" && test x"$sim_smp" != x""; then
716   echo "Setting smp flags = $sim_smp" 6>&1
717 fi],[sim_smp="-DWITH_SMP=${default_sim_smp}" ; sim_igen_smp="-N ${default_sim_smp}"
718 if test x"$silent" != x"yes"; then
719   echo "Setting smp flags = $sim_smp" 6>&1
720 fi])dnl
721 ])
722 AC_SUBST(sim_smp)
723
724
725 AC_DEFUN([SIM_AC_OPTION_XOR_ENDIAN],
726 [
727 default_sim_xor_endian="ifelse([$1],,8,[$1])"
728 AC_ARG_ENABLE(sim-xor-endian,
729 [AS_HELP_STRING([--enable-sim-xor-endian=n],
730                 [Specify number bytes involved in XOR bi-endian mode (default ${default_sim_xor_endian})])],
731 [case "${enableval}" in
732   yes)  sim_xor_endian="-DWITH_XOR_ENDIAN=8";;
733   no)   sim_xor_endian="-DWITH_XOR_ENDIAN=0";;
734   *)    sim_xor_endian="-DWITH_XOR_ENDIAN=$enableval";;
735 esac
736 if test x"$silent" != x"yes" && test x"$sim_xor_endian" != x""; then
737   echo "Setting xor-endian flag = $sim_xor_endian" 6>&1
738 fi],[sim_xor_endian="-DWITH_XOR_ENDIAN=${default_sim_xor_endian}"])dnl
739 ])
740 AC_SUBST(sim_xor_endian)
741
742
743 dnl --enable-build-warnings is for developers of the simulator.
744 dnl it enables extra GCC specific warnings.
745 AC_DEFUN([SIM_AC_OPTION_WARNINGS],
746 [
747 AC_ARG_ENABLE(werror,
748   AS_HELP_STRING([--enable-werror], [treat compile warnings as errors]),
749   [case "${enableval}" in
750      yes | y) ERROR_ON_WARNING="yes" ;;
751      no | n)  ERROR_ON_WARNING="no" ;;
752      *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
753    esac])
754
755 # Enable -Werror by default when using gcc
756 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
757     ERROR_ON_WARNING=yes
758 fi
759
760 WERROR_CFLAGS=""
761 if test "${ERROR_ON_WARNING}" = yes ; then
762 # NOTE: Disabled in the sim dir due to most sims generating warnings.
763 #    WERROR_CFLAGS="-Werror"
764      true
765 fi
766
767 build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith \
768 -Wpointer-sign \
769 -Wno-unused -Wunused-value -Wunused-function \
770 -Wno-switch -Wno-char-subscripts -Wmissing-prototypes
771 -Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type \
772 -Wold-style-declaration -Wold-style-definition"
773
774 # Enable -Wno-format by default when using gcc on mingw since many
775 # GCC versions complain about %I64.
776 case "${host}" in
777   *-*-mingw32*) build_warnings="$build_warnings -Wno-format" ;;
778   *) build_warnings="$build_warnings -Wformat-nonliteral" ;;
779 esac
780
781 AC_ARG_ENABLE(build-warnings,
782 AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
783 [case "${enableval}" in
784   yes)  ;;
785   no)   build_warnings="-w";;
786   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
787         build_warnings="${build_warnings} ${t}";;
788   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
789         build_warnings="${t} ${build_warnings}";;
790   *)    build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
791 esac
792 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
793   echo "Setting compiler warning flags = $build_warnings" 6>&1
794 fi])dnl
795 AC_ARG_ENABLE(sim-build-warnings,
796 AS_HELP_STRING([--enable-sim-build-warnings], [enable SIM specific build-time compiler warnings if gcc is used]),
797 [case "${enableval}" in
798   yes)  ;;
799   no)   build_warnings="-w";;
800   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
801         build_warnings="${build_warnings} ${t}";;
802   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
803         build_warnings="${t} ${build_warnings}";;
804   *)    build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
805 esac
806 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
807   echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
808 fi])dnl
809 WARN_CFLAGS=""
810 if test "x${build_warnings}" != x -a "x$GCC" = xyes
811 then
812     AC_MSG_CHECKING(compiler warning flags)
813     # Separate out the -Werror flag as some files just cannot be
814     # compiled with it enabled.
815     for w in ${build_warnings}; do
816         case $w in
817         -Werr*) WERROR_CFLAGS=-Werror ;;
818         *) # Check that GCC accepts it
819             saved_CFLAGS="$CFLAGS"
820             CFLAGS="$CFLAGS $w"
821             AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
822             CFLAGS="$saved_CFLAGS"
823         esac
824     done
825     AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
826 fi
827 ])
828 AC_SUBST(WARN_CFLAGS)
829 AC_SUBST(WERROR_CFLAGS)
830
831
832 dnl Generate the Makefile in a target specific directory.
833 dnl Substitutions aren't performed on the file in AC_SUBST_FILE,
834 dnl so this is a cover macro to tuck the details away of how we cope.
835 dnl We cope by having autoconf generate two files and then merge them into
836 dnl one afterwards.  The two pieces of the common fragment are inserted into
837 dnl the target's fragment at the appropriate points.
838
839 AC_DEFUN([SIM_AC_OUTPUT],
840 [
841 AC_LINK_FILES($sim_link_files, $sim_link_links)
842 dnl Make @cgen_breaks@ non-null only if the sim uses CGEN.
843 cgen_breaks=""
844 if grep CGEN_MAINT $srcdir/Makefile.in >/dev/null; then
845 cgen_breaks="break cgen_rtx_error";
846 fi
847 AC_SUBST(cgen_breaks)
848 AC_CONFIG_FILES(Makefile.sim:Makefile.in)
849 AC_CONFIG_FILES(Make-common.sim:../common/Make-common.in)
850 AC_CONFIG_FILES(.gdbinit:../common/gdbinit.in)
851 AC_CONFIG_COMMANDS([Makefile],
852 [echo "Merging Makefile.sim+Make-common.sim into Makefile ..."
853  rm -f Makesim1.tmp Makesim2.tmp Makefile
854  sed -n -e '/^## COMMON_PRE_/,/^## End COMMON_PRE_/ p' <Make-common.sim >Makesim1.tmp
855  sed -n -e '/^## COMMON_POST_/,/^## End COMMON_POST_/ p' <Make-common.sim >Makesim2.tmp
856  sed -e '/^## COMMON_PRE_/ r Makesim1.tmp' \
857         -e '/^## COMMON_POST_/ r Makesim2.tmp' \
858         <Makefile.sim >Makefile
859  rm -f Makefile.sim Make-common.sim Makesim1.tmp Makesim2.tmp
860 ])
861 AC_CONFIG_COMMANDS([stamp-h], [echo > stamp-h])
862 AC_OUTPUT
863 ])
864
865 sinclude(../../config/gettext-sister.m4)
866 sinclude(../../config/acx.m4)
867
868 dnl --enable-cgen-maint support
869 AC_DEFUN([SIM_AC_OPTION_CGEN_MAINT],
870 [
871 cgen_maint=no
872 dnl Default is to use one in build tree.
873 cgen=guile
874 cgendir='$(srcdir)/../../cgen'
875 dnl Having --enable-maintainer-mode take arguments is another way to go.
876 dnl ??? One can argue --with is more appropriate if one wants to specify
877 dnl a directory name, but what we're doing here is an enable/disable kind
878 dnl of thing and specifying both --enable and --with is klunky.
879 dnl If you reeely want this to be --with, go ahead and change it.
880 AC_ARG_ENABLE(cgen-maint,
881 [AS_HELP_STRING([--enable-cgen-maint[=DIR]], [build cgen generated files])],
882 [case "${enableval}" in
883   yes)  cgen_maint=yes ;;
884   no)   cgen_maint=no ;;
885   *)
886         # argument is cgen install directory (not implemented yet).
887         # Having a `share' directory might be more appropriate for the .scm,
888         # .cpu, etc. files.
889         cgendir=${cgen_maint}/lib/cgen
890         cgen=guile
891         ;;
892 esac])dnl
893 dnl AM_CONDITIONAL(CGEN_MAINT, test x${cgen_maint} != xno)
894 if test x${cgen_maint} != xno ; then
895   CGEN_MAINT=''
896 else
897   CGEN_MAINT='#'
898 fi
899 AC_SUBST(CGEN_MAINT)
900 AC_SUBST(cgendir)
901 AC_SUBST(cgen)
902 ])