1 # Makefile fragment for common parts of all simulators.
2 # Copyright 1997-2021 Free Software Foundation, Inc.
3 # Contributed by Cygnus Support.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # This Makefile fragment consists of two separate parts.
19 # They are merged into the final Makefile at points denoted by
20 # "## COMMON_PRE_CONFIG_FRAG" and "## COMMON_POST_CONFIG_FRAG".
22 # The target Makefile should look like:
24 #># Copyright blah blah
26 #>## COMMON_PRE_CONFIG_FRAG
28 #># Any overrides necessary for the SIM_FOO config vars.
31 #>## COMMON_POST_CONFIG_FRAG
33 #># Rules to build target specific .o's.
35 ## COMMON_PRE_CONFIG_FRAG
37 VPATH = @srcdir@:$(srccom)
39 srccom = $(srcdir)/../common
40 srcroot = $(srcdir)/../..
43 include $(srcroot)/gdb/silent-rules.mk
45 # Helper code from gnulib.
46 GNULIB_PARENT_DIR = ../..
47 include $(GNULIB_PARENT_DIR)/gnulib/Makefile.gnulib.inc
49 # Settings from top-level configure.
50 include ../arch-subdir.mk
53 exec_prefix = @exec_prefix@
58 tooldir = $(libdir)/$(target_alias)
61 datarootdir = @datarootdir@
63 man1dir = $(mandir)/man1
65 includedir = @includedir@
67 # This can be referenced by the gettext configuration code.
72 SIM_BITSIZE = @sim_bitsize@
73 SIM_DEFAULT_MODEL = @sim_default_model@
74 SIM_FLOAT = @sim_float@
75 SIM_HW_CFLAGS = @sim_hw_cflags@
76 SIM_HW_OBJS = @sim_hw_objs@
78 SIM_RESERVED_BITS = @sim_reserved_bits@
79 SIM_SCACHE = @sim_scache@
80 SIM_WARN_CFLAGS = $(WARN_CFLAGS)
81 SIM_WERROR_CFLAGS = $(WERROR_CFLAGS)
83 # Dependency tracking information.
84 depcomp = $(SHELL) $(srcroot)/depcomp
86 # Note that these are overridden by GNU make-specific code below if
87 # GNU make is used. The overrides implement dependency tracking.
88 COMPILE.pre = $(CC) $(C_DIALECT)
89 COMPILE.post = -c -o $@
90 COMPILE = $(ECHO_CC) $(COMPILE.pre) $(ALL_CFLAGS) $(COMPILE.post)
93 # igen leaks memory, and therefore makes AddressSanitizer unhappy. Disable
94 # leak detection while running it.
95 IGEN = ../igen/igen$(EXEEXT)
96 IGEN_RUN = ASAN_OPTIONS=detect_leaks=0 $(IGEN)
98 # Each simulator's Makefile.in defines one or more of these variables
99 # to override our settings as necessary. There is no need to define these
100 # in the simulator's Makefile.in if one is using the default value. In fact
101 # it's preferable not to.
103 # List of object files, less common parts.
105 # List of extra dependencies.
106 # Generally this consists of simulator specific files included by sim-main.h.
108 # List of flags to always pass to $(CC).
110 # List of extra libraries to link with.
112 # List of main object files for `run'.
113 SIM_RUN_OBJS = nrun.o
114 # Dependency of `install' to install any extra files.
116 # Dependency of `clean' to clean any extra files.
118 # Likewise `distclean'
119 SIM_EXTRA_DISTCLEAN =
121 # Every time a new general purpose source file was added every target's
122 # Makefile.in needed to be updated to include the file in SIM_OBJS.
123 # This doesn't scale.
124 # This variable specifies all the generic stuff common to the newer simulators.
125 # Things like sim-reason.o can't go here as the cpu may provide its own
126 # (though hopefully in time that won't be so). Things like sim-bits.o can go
127 # here. Some files are used by all simulators (e.g. callback.o).
128 # Those files are specified in LIB_OBJS below.
130 SIM_COMMON_HW_OBJS = \
142 SIM_NEW_COMMON_OBJS = \
174 # cgen-sim.h and the headers it includes
176 $(srccom)/cgen-sim.h \
177 $(srccom)/cgen-defs.h \
178 $(srccom)/cgen-scache.h \
179 $(srccom)/cgen-fpu.h \
180 $(srccom)/cgen-par.h \
181 $(srccom)/cgen-cpu.h \
182 $(srccom)/cgen-trace.h \
185 # Add this to SIM_EXTRA_DEPS.
186 CGEN_INCLUDE_DEPS = \
188 $(srccom)/cgen-engine.h \
189 $(srccom)/cgen-types.h \
190 $(srcdir)/../../include/opcode/cgen.h
192 ## End COMMON_PRE_CONFIG_FRAG
194 ## COMMON_POST_CONFIG_FRAG
198 $(SIM_DEFAULT_MODEL) \
203 $(SIM_RESERVED_BITS) \
206 $(SIM_WERROR_CFLAGS) \
208 CSEARCH = -I. -I$(srcdir) -I../common -I$(srccom) \
209 -I../../include -I$(srcroot)/include \
210 -I../../bfd -I$(srcroot)/bfd \
211 -I../../opcodes -I$(srcroot)/opcodes \
214 ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(INCGNU) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
215 BUILD_CFLAGS = $(CFLAGS_FOR_BUILD) $(CSEARCH)
217 COMMON_DEP_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS)
219 ZLIB = $(zlibdir) -lz
220 LIBIBERTY_LIB = ../../libiberty/libiberty.a
221 BFD_LIB = ../../bfd/libbfd.a
222 OPCODES_LIB = ../../opcodes/libopcodes.a
223 CONFIG_LIBS = $(COMMON_LIBS) @LIBS@ $(ZLIB)
224 LIBDEPS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL_DEP) $(LIBIBERTY_LIB)
225 EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \
226 $(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL) $(LIBGNU) $(LIBGNU_EXTRA_LIBS)
228 COMMON_OBJS_NAMES = \
232 COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/common_libcommon_a-%)
234 LIB_OBJS = callback.o modules.o syscall.o targ-map.o $(COMMON_OBJS) $(SIM_OBJS)
236 COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS)
237 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
241 callback_h = $(srcroot)/include/sim/callback.h
242 remote_sim_h = $(srcroot)/include/sim/sim.h
244 all: libsim.a run$(EXEEXT) .gdbinit
246 libsim.a: $(LIB_OBJS)
248 $(ECHO_AR) $(AR) $(AR_FLAGS) libsim.a $(LIB_OBJS)
249 $(ECHO_RANLIB) $(RANLIB) libsim.a
251 run$(EXEEXT): $(SIM_RUN_OBJS) libsim.a $(LIBDEPS)
252 $(ECHO_CCLD) $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o run$(EXEEXT) \
253 $(SIM_RUN_OBJS) libsim.a $(EXTRA_LIBS)
255 # FIXME: Ideally, callback.o and friends live in a library outside of
256 # both the gdb and simulator source trees (e.g. devo/remote. Not
257 # devo/libremote because this directory would contain more than just
260 gentmap.o: Makefile $(srccom)/gentmap.c $(srccom)/nltvals.def
261 $(ECHO_CC) $(COMPILE_FOR_BUILD) -o $@ -c $(srccom)/gentmap.c $(NL_TARGET)
264 $(ECHO_CC) $(LINK_FOR_BUILD) $<
266 targ-vals.h targ-map.c: stamp-tvals
268 rm -f tmp-tvals.h tmp-tmap.c
269 ./gentmap -h >tmp-tvals.h
270 $(SHELL) $(srcroot)/move-if-change tmp-tvals.h targ-vals.h
271 ./gentmap -c >tmp-tmap.c
272 $(SHELL) $(srcroot)/move-if-change tmp-tmap.c targ-map.c
276 # Rules for building sim-* components. Triggered by listing the corresponding
277 # .o file in the list of simulator targets.
296 # Exported version of sim_main_headers.
300 sim-alu_h = $(srccom)/sim-alu.h
301 sim-arange_h = $(srccom)/sim-arange.h
302 sim-assert_h = $(srccom)/sim-assert.h
303 sim-base_h = $(srccom)/sim-base.h \
315 sim-basics_h = $(srccom)/sim-basics.h \
325 sim-bits_h = $(srccom)/sim-bits.h \
327 sim-config_h = $(srccom)/sim-config.h
328 sim-core_h = $(srccom)/sim-core.h
329 sim-cpu_h = $(srccom)/sim-cpu.h
330 sim-endian_h = $(srccom)/sim-endian.h \
331 $(srccom)/sim-endian.c
332 sim-engine_h = $(srccom)/sim-engine.h
333 sim-events_h = $(srccom)/sim-events.h
334 sim-fpu_h = $(srccom)/sim-fpu.h
335 sim-hw_h = $(srccom)/sim-hw.h
336 sim-inline_h = $(srccom)/sim-inline.h
337 sim-io_h = $(srccom)/sim-io.h
338 sim-memopt_h = $(srccom)/sim-memopt.h
339 sim-model_h = $(srccom)/sim-model.h
340 sim-module_h = $(srccom)/sim-module.h
341 sim-n-bits_h = $(srccom)/sim-n-bits.h
342 sim-n-core_h = $(srccom)/sim-n-core.h
343 sim-n-endian_h = $(srccom)/sim-n-endian.h
344 sim-options_h = $(srccom)/sim-options.h
345 sim-profile_h = $(srccom)/sim-profile.h
346 sim-signal_h = $(srccom)/sim-signal.h
347 sim-trace_h = $(srccom)/sim-trace.h
348 sim-types_h = $(srccom)/sim-types.h
349 sim-utils_h = $(srccom)/sim-utils.h
350 sim-watch_h = $(srccom)/sim-watch.h
352 hw-alloc_h = $(srccom)/hw-alloc.h
353 hw-base_h = $(srccom)/hw-base.h
354 hw-device_h = $(srccom)/hw-device.h
355 hw-events_h = $(srccom)/hw-events.h
356 hw-handles_h = $(srccom)/hw-handles.h
357 hw-instances_h = $(srccom)/hw-instances.h
358 hw-ports_h = $(srccom)/hw-ports.h
359 hw-properties_h = $(srccom)/hw-properties.h
360 hw-tree_h = $(srccom)/hw-tree.h
363 $(srccom)/hw-main.h \
374 # Dependency tracking. Most of this is conditional on GNU Make being
375 # found by configure; if GNU Make is not found, we fall back to a
379 ifeq ($(DEPMODE),depmode=gcc3)
380 # Note that we put the dependencies into a .Tpo file, then move them
381 # into place if the compile succeeds. We need this because gcc does
382 # not atomically write the dependency output file.
383 override COMPILE.post = -c -o $@ -MT $@ -MMD -MP \
384 -MF $(DEPDIR)/$(basename $(@F)).Tpo
385 override POSTCOMPILE = @mv $(DEPDIR)/$(basename $(@F)).Tpo \
386 $(DEPDIR)/$(basename $(@F)).Po
388 override COMPILE.pre = source='$<' object='$@' libtool=no \
389 DEPDIR=$(DEPDIR) $(DEPMODE) $(depcomp) $(CC)
390 # depcomp handles atomicity for us, so we don't need a postcompile
392 override POSTCOMPILE =
395 all_object_files = $(LIB_OBJS) $(SIM_RUN_OBJS)
403 # Ensure that generated files are created early. Use order-only
404 # dependencies if available. They require GNU make 3.80 or newer,
405 # and the .VARIABLES variable was introduced at the same time.
407 $(all_object_files): | $(generated_files)
409 $(all_object_files) : $(generated_files)
413 -include $(patsubst %.o, $(DEPDIR)/%.Po, $(all_object_files))
415 # FIXME This is one very simple-minded way of generating the file hw-config.h
416 hw-config.h: stamp-hw ; @true
417 stamp-hw: Makefile.in $(srccom)/Make-common.in config.status Makefile
419 echo "/* generated by Makefile */" > tmp-hw.h
420 sim_hw="$(SIM_HW)"; \
421 for hw in $$sim_hw ; do \
422 echo "extern const struct hw_descriptor dv_$${hw}_descriptor[];" ; \
424 echo "const struct hw_descriptor *hw_descriptors[] = {" >> tmp-hw.h
425 sim_hw="$(SIM_HW)"; \
426 for hw in $$sim_hw ; do \
427 echo " dv_$${hw}_descriptor," ; \
429 echo " NULL," >> tmp-hw.h
430 echo "};" >> tmp-hw.h
431 $(SHELL) $(srcroot)/move-if-change tmp-hw.h hw-config.h
432 @echo stamp > stamp-hw
434 test-hw-events: $(srccom)/hw-events.c libsim.a
435 $(CC) $(ALL_CFLAGS) -DMAIN -o test-hw-events$(EXEEXT) \
436 $(srccom)/hw-events.c libsim.a $(EXTRA_LIBS)
438 # See sim_pre_argv_init and sim_module_install in sim-module.c for more details.
439 modules.c: stamp-modules ; @true
440 stamp-modules: Makefile $(SIM_OBJS:.o=.c)
442 @LANG=C ; export LANG ; \
443 LC_ALL=C ; export LC_ALL ; \
444 sed -n -e '/^sim_install_/{s/^\(sim_install_[a-z_0-9A-Z]*\).*/\1/;p}' $^ | sort >$@.l-tmp
446 echo '/* Do not modify this file. */'; \
447 echo '/* It is created automatically by the Makefile. */'; \
448 echo '#include "libiberty.h"'; \
449 echo '#include "sim-module.h"'; \
450 sed -e 's:\(.*\):extern __attribute__((__weak__)) MODULE_INIT_FN \1;:' $@.l-tmp; \
451 echo 'MODULE_INSTALL_FN * const sim_modules_detected[] = {'; \
452 sed -e 's:\(.*\): \1,:' $@.l-tmp; \
454 echo 'const int sim_modules_detected_len = ARRAY_SIZE (sim_modules_detected);'; \
456 $(SHELL) $(srcroot)/move-if-change $@.tmp modules.c
457 @rm -f $@.l-tmp $@.tmp
462 # For use in Makefile.in for cpu-specific files.
463 CGEN_MAIN_CPU_DEPS = \
465 $(srccom)/cgen-ops.h \
470 install: install-common $(SIM_EXTRA_INSTALL)
472 install-common: installdirs
473 a=`basename "$$(pwd)"`; \
474 n=`echo run | sed '$(program_transform_name)'`; \
475 [ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
476 $(INSTALL_PROGRAM) run$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
477 n="$(target_alias)-sim"; \
478 a=`basename "$$(pwd)"`; \
479 [ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
481 $(INSTALL_DATA) libsim.a $(DESTDIR)$(libdir)/$$n ; \
482 ( cd $(DESTDIR)$(libdir) ; $(RANLIB) $$n )
485 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(bindir)
486 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(libdir)
507 # Macros like EXTERN_SIM_CORE confuse tags.
508 # And the sim-n-foo.h files create functions that can't be found either.
511 etags --regex '/^\([[:lower:]_]+\) (/\1/' --regex '/^\/[*] TAGS: .*/' \
512 *.[ch] ../common/*.[ch]
514 mostlyclean clean: $(SIM_EXTRA_CLEAN)
516 rm -f run$(EXEEXT) libsim.a
517 rm -f hw-config.h stamp-hw
518 rm -f modules.c stamp-modules
519 rm -f gentmap targ-map.c targ-vals.h stamp-tvals
520 rm -f tmp-mloop.hin tmp-mloop.h tmp-mloop.cin tmp-mloop.c
522 distclean maintainer-clean realclean: clean $(SIM_EXTRA_DISTCLEAN)
524 rm -f Makefile config.cache config.log config.status .gdbinit
530 # Dummy target to force execution of dependent targets.
533 Makefile: Makefile.in $(srccom)/Make-common.in config.status
534 CONFIG_HEADERS= $(SHELL) ./config.status
536 config.status: configure
537 $(SHELL) ./config.status --recheck
539 .gdbinit: # config.status $(srccom)/gdbinit.in
540 CONFIG_FILES=$@:../common/gdbinit.in CONFIG_HEADERS= $(SHELL) ./config.status
546 CGEN = "`if [ -f ../../guile/libguile/guile ]; then echo ../../guile/libguile/guile; else echo guile ; fi` -l $(CGENDIR)/guile.scm -s"
548 CGEN_CPU_DIR = $(CGENDIR)/cpu
550 # Most ports use the files here instead of cgen/cpu.
551 CPU_DIR = $(srcroot)/cpu
553 CGEN_READ_SCM = $(CGENDIR)/sim.scm
554 CGEN_ARCH_SCM = $(CGENDIR)/sim-arch.scm
555 CGEN_CPU_SCM = $(CGENDIR)/sim-cpu.scm $(CGENDIR)/sim-model.scm
556 CGEN_DECODE_SCM = $(CGENDIR)/sim-decode.scm
557 CGEN_DESC_SCM = $(CGENDIR)/desc.scm $(CGENDIR)/desc-cpu.scm
559 # Various choices for which cpu specific files to generate.
560 # These are passed to cgen.sh in the "extrafiles" argument.
561 CGEN_CPU_EXTR = /extr/
562 CGEN_CPU_READ = /read/
563 CGEN_CPU_WRITE = /write/
565 CGEN_CPU_SEMSW = /semsw/
567 CGEN_FLAGS_TO_PASS = \
569 CGENFLAGS="$(CGENFLAGS)"
571 # We store the generated files in the source directory until we decide to
572 # ship a Scheme interpreter with gdb/binutils. Maybe we never will.
575 $(SHELL) $(srccom)/cgen.sh arch $(srcdir) \
576 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
577 $(arch) "$(FLAGS)" ignored "$(isa)" $(mach) ignored \
581 $(SHELL) $(srccom)/cgen.sh cpu $(srcdir) \
582 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
583 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
584 $(archfile) "$(EXTRAFILES)"
587 $(SHELL) $(srccom)/cgen.sh defs $(srcdir) \
588 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
589 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
593 $(SHELL) $(srccom)/cgen.sh decode $(srcdir) \
594 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
595 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
596 $(archfile) "$(EXTRAFILES)"
598 cgen-cpu-decode: force
599 $(SHELL) $(srccom)/cgen.sh cpu-decode $(srcdir) \
600 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
601 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
602 $(archfile) "$(EXTRAFILES)"
605 $(SHELL) $(srccom)/cgen.sh desc $(srcdir) \
606 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
607 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
608 $(archfile) ignored $(opcfile)
610 ## End COMMON_POST_CONFIG_FRAG