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