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 # Helper code from gnulib.
44 GNULIB_PARENT_DIR = ../..
45 include $(GNULIB_PARENT_DIR)/gnulib/Makefile.gnulib.inc
48 exec_prefix = @exec_prefix@
50 host_alias = @host_alias@
51 target_alias = @target_alias@
52 program_transform_name = @program_transform_name@
56 tooldir = $(libdir)/$(target_alias)
59 datarootdir = @datarootdir@
61 man1dir = $(mandir)/man1
63 includedir = @includedir@
65 lt_cv_dlopen_libs = @lt_cv_dlopen_libs@
66 # This can be referenced by the gettext configuration code.
73 INSTALL_PROGRAM = @INSTALL_PROGRAM@
74 INSTALL_DATA = @INSTALL_DATA@
77 C_DIALECT = @C_DIALECT@
78 CC_FOR_BUILD = @CC_FOR_BUILD@
79 CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
85 SIM_BITSIZE = @sim_bitsize@
86 SIM_DEFAULT_MODEL = @sim_default_model@
87 SIM_ENDIAN = @sim_endian@
88 SIM_FLOAT = @sim_float@
89 SIM_HW_CFLAGS = @sim_hw_cflags@
90 SIM_HW_OBJS = @sim_hw_objs@
92 SIM_INLINE = @sim_inline@
93 SIM_RESERVED_BITS = @sim_reserved_bits@
94 SIM_SCACHE = @sim_scache@
95 WARN_CFLAGS = @WARN_CFLAGS@
96 WERROR_CFLAGS = @WERROR_CFLAGS@
97 SIM_WARN_CFLAGS = $(WARN_CFLAGS)
98 SIM_WERROR_CFLAGS = $(WERROR_CFLAGS)
105 # Dependency tracking information.
106 DEPMODE = @CCDEPMODE@
108 depcomp = $(SHELL) $(srcroot)/depcomp
110 # Note that these are overridden by GNU make-specific code below if
111 # GNU make is used. The overrides implement dependency tracking.
112 COMPILE.pre = $(CC) $(C_DIALECT)
113 COMPILE.post = -c -o $@
114 COMPILE = $(COMPILE.pre) $(ALL_CFLAGS) $(COMPILE.post)
117 # igen leaks memory, and therefore makes AddressSanitizer unhappy. Disable
118 # leak detection while running it.
119 IGEN = ../igen/igen$(EXEEXT)
120 IGEN_RUN = ASAN_OPTIONS=detect_leaks=0 $(IGEN)
122 # Each simulator's Makefile.in defines one or more of these variables
123 # to override our settings as necessary. There is no need to define these
124 # in the simulator's Makefile.in if one is using the default value. In fact
125 # it's preferable not to.
127 # List of object files, less common parts.
129 # List of extra dependencies.
130 # Generally this consists of simulator specific files included by sim-main.h.
132 # List of flags to always pass to $(CC).
134 # List of extra libraries to link with.
136 # List of main object files for `run'.
137 SIM_RUN_OBJS = nrun.o
138 # Dependency of `install' to install any extra files.
140 # Dependency of `clean' to clean any extra files.
142 # Likewise `distclean'
143 SIM_EXTRA_DISTCLEAN =
145 # Every time a new general purpose source file was added every target's
146 # Makefile.in needed to be updated to include the file in SIM_OBJS.
147 # This doesn't scale.
148 # This variable specifies all the generic stuff common to the newer simulators.
149 # Things like sim-reason.o can't go here as the cpu may provide its own
150 # (though hopefully in time that won't be so). Things like sim-bits.o can go
151 # here. Some files are used by all simulators (e.g. callback.o).
152 # Those files are specified in LIB_OBJS below.
154 SIM_COMMON_HW_OBJS = \
166 SIM_NEW_COMMON_OBJS = \
198 # cgen-sim.h and the headers it includes
200 $(srccom)/cgen-sim.h \
201 $(srccom)/cgen-defs.h \
202 $(srccom)/cgen-scache.h \
203 $(srccom)/cgen-fpu.h \
204 $(srccom)/cgen-par.h \
205 $(srccom)/cgen-cpu.h \
206 $(srccom)/cgen-trace.h \
209 # Add this to SIM_EXTRA_DEPS.
210 CGEN_INCLUDE_DEPS = \
212 $(srccom)/cgen-engine.h \
213 $(srccom)/cgen-types.h \
214 $(srcdir)/../../include/opcode/cgen.h
216 ## End COMMON_PRE_CONFIG_FRAG
218 ## COMMON_POST_CONFIG_FRAG
222 $(SIM_DEFAULT_MODEL) \
228 $(SIM_RESERVED_BITS) \
231 $(SIM_WERROR_CFLAGS) \
233 CSEARCH = -I. -I$(srcdir) -I../common -I$(srccom) \
234 -I../../include -I$(srcroot)/include \
235 -I../../bfd -I$(srcroot)/bfd \
236 -I../../opcodes -I$(srcroot)/opcodes \
239 ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(INCGNU) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
240 BUILD_CFLAGS = $(CFLAGS_FOR_BUILD) $(CSEARCH)
242 COMMON_DEP_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS)
245 LIBIBERTY_LIB = ../../libiberty/libiberty.a
246 BFD_LIB = ../../bfd/libbfd.a
247 @PLUGINS_TRUE@LIBDL = @lt_cv_dlopen_libs@
248 OPCODES_LIB = ../../opcodes/libopcodes.a
250 LIBINTL_DEP = @LIBINTL_DEP@
251 CONFIG_LIBS = @LIBS@ $(ZLIB)
252 LIBDEPS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL_DEP) $(LIBIBERTY_LIB)
253 EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \
254 $(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL) $(LIBGNU) $(LIBGNU_EXTRA_LIBS)
256 COMMON_OBJS_NAMES = \
260 COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/common_libcommon_a-%)
262 LIB_OBJS = callback.o modules.o syscall.o targ-map.o $(COMMON_OBJS) $(SIM_OBJS)
264 COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS)
265 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
269 callback_h = $(srcroot)/include/sim/callback.h
270 remote_sim_h = $(srcroot)/include/sim/sim.h
272 all: libsim.a run$(EXEEXT) .gdbinit
274 libsim.a: $(LIB_OBJS)
276 $(AR) $(AR_FLAGS) libsim.a $(LIB_OBJS)
279 run$(EXEEXT): $(SIM_RUN_OBJS) libsim.a $(LIBDEPS)
280 $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o run$(EXEEXT) \
281 $(SIM_RUN_OBJS) libsim.a $(EXTRA_LIBS)
283 # FIXME: Ideally, callback.o and friends live in a library outside of
284 # both the gdb and simulator source trees (e.g. devo/remote. Not
285 # devo/libremote because this directory would contain more than just
288 gentmap.o: Makefile $(srccom)/gentmap.c $(srccom)/nltvals.def
289 $(COMPILE_FOR_BUILD) -o $@ -c $(srccom)/gentmap.c $(NL_TARGET)
294 targ-vals.h targ-map.c: stamp-tvals
296 rm -f tmp-tvals.h tmp-tmap.c
297 ./gentmap -h >tmp-tvals.h
298 $(SHELL) $(srcroot)/move-if-change tmp-tvals.h targ-vals.h
299 ./gentmap -c >tmp-tmap.c
300 $(SHELL) $(srcroot)/move-if-change tmp-tmap.c targ-map.c
304 # Rules for building sim-* components. Triggered by listing the corresponding
305 # .o file in the list of simulator targets.
324 # Exported version of sim_main_headers.
328 sim-alu_h = $(srccom)/sim-alu.h
329 sim-arange_h = $(srccom)/sim-arange.h
330 sim-assert_h = $(srccom)/sim-assert.h
331 sim-base_h = $(srccom)/sim-base.h \
343 sim-basics_h = $(srccom)/sim-basics.h \
353 sim-bits_h = $(srccom)/sim-bits.h \
355 sim-config_h = $(srccom)/sim-config.h
356 sim-core_h = $(srccom)/sim-core.h
357 sim-cpu_h = $(srccom)/sim-cpu.h
358 sim-endian_h = $(srccom)/sim-endian.h \
359 $(srccom)/sim-endian.c
360 sim-engine_h = $(srccom)/sim-engine.h
361 sim-events_h = $(srccom)/sim-events.h
362 sim-fpu_h = $(srccom)/sim-fpu.h
363 sim-hw_h = $(srccom)/sim-hw.h
364 sim-inline_h = $(srccom)/sim-inline.h
365 sim-io_h = $(srccom)/sim-io.h
366 sim-memopt_h = $(srccom)/sim-memopt.h
367 sim-model_h = $(srccom)/sim-model.h
368 sim-module_h = $(srccom)/sim-module.h
369 sim-n-bits_h = $(srccom)/sim-n-bits.h
370 sim-n-core_h = $(srccom)/sim-n-core.h
371 sim-n-endian_h = $(srccom)/sim-n-endian.h
372 sim-options_h = $(srccom)/sim-options.h
373 sim-profile_h = $(srccom)/sim-profile.h
374 sim-signal_h = $(srccom)/sim-signal.h
375 sim-trace_h = $(srccom)/sim-trace.h
376 sim-types_h = $(srccom)/sim-types.h
377 sim-utils_h = $(srccom)/sim-utils.h
378 sim-watch_h = $(srccom)/sim-watch.h
380 hw-alloc_h = $(srccom)/hw-alloc.h
381 hw-base_h = $(srccom)/hw-base.h
382 hw-device_h = $(srccom)/hw-device.h
383 hw-events_h = $(srccom)/hw-events.h
384 hw-handles_h = $(srccom)/hw-handles.h
385 hw-instances_h = $(srccom)/hw-instances.h
386 hw-ports_h = $(srccom)/hw-ports.h
387 hw-properties_h = $(srccom)/hw-properties.h
388 hw-tree_h = $(srccom)/hw-tree.h
391 $(srccom)/hw-main.h \
402 # Dependency tracking. Most of this is conditional on GNU Make being
403 # found by configure; if GNU Make is not found, we fall back to a
407 ifeq ($(DEPMODE),depmode=gcc3)
408 # Note that we put the dependencies into a .Tpo file, then move them
409 # into place if the compile succeeds. We need this because gcc does
410 # not atomically write the dependency output file.
411 override COMPILE.post = -c -o $@ -MT $@ -MMD -MP \
412 -MF $(DEPDIR)/$(basename $(@F)).Tpo
413 override POSTCOMPILE = @mv $(DEPDIR)/$(basename $(@F)).Tpo \
414 $(DEPDIR)/$(basename $(@F)).Po
416 override COMPILE.pre = source='$<' object='$@' libtool=no \
417 DEPDIR=$(DEPDIR) $(DEPMODE) $(depcomp) $(CC)
418 # depcomp handles atomicity for us, so we don't need a postcompile
420 override POSTCOMPILE =
423 all_object_files = $(LIB_OBJS) $(SIM_RUN_OBJS)
432 # Ensure that generated files are created early. Use order-only
433 # dependencies if available. They require GNU make 3.80 or newer,
434 # and the .VARIABLES variable was introduced at the same time.
436 $(all_object_files): | $(generated_files)
438 $(all_object_files) : $(generated_files)
442 -include $(patsubst %.o, $(DEPDIR)/%.Po, $(all_object_files))
444 # FIXME This is one very simple-minded way of generating the file hw-config.h
445 hw-config.h: stamp-hw ; @true
446 stamp-hw: Makefile.in $(srccom)/Make-common.in config.status Makefile
448 echo "/* generated by Makefile */" > tmp-hw.h
449 sim_hw="$(SIM_HW)"; \
450 for hw in $$sim_hw ; do \
451 echo "extern const struct hw_descriptor dv_$${hw}_descriptor[];" ; \
453 echo "const struct hw_descriptor *hw_descriptors[] = {" >> tmp-hw.h
454 sim_hw="$(SIM_HW)"; \
455 for hw in $$sim_hw ; do \
456 echo " dv_$${hw}_descriptor," ; \
458 echo " NULL," >> tmp-hw.h
459 echo "};" >> tmp-hw.h
460 $(SHELL) $(srcroot)/move-if-change tmp-hw.h hw-config.h
461 @echo stamp > stamp-hw
463 test-hw-events: $(srccom)/hw-events.c libsim.a
464 $(CC) $(ALL_CFLAGS) -DMAIN -o test-hw-events$(EXEEXT) \
465 $(srccom)/hw-events.c libsim.a $(EXTRA_LIBS)
467 # See sim_pre_argv_init and sim_module_install in sim-module.c for more details.
468 modules.c: Makefile $(SIM_OBJS:.o=.c)
470 @LANG=C ; export LANG ; \
471 LC_ALL=C ; export LC_ALL ; \
472 sed -n -e '/^sim_install_/{s/^\(sim_install_[a-z_0-9A-Z]*\).*/\1/;p}' $^ | sort >$@.l-tmp
474 echo '/* Do not modify this file. */'; \
475 echo '/* It is created automatically by the Makefile. */'; \
476 echo '#include "libiberty.h"'; \
477 echo '#include "sim-module.h"'; \
478 sed -e 's:\(.*\):extern __attribute__((__weak__)) MODULE_INIT_FN \1;:' $@.l-tmp; \
479 echo 'MODULE_INSTALL_FN * const sim_modules_detected[] = {'; \
480 sed -e 's:\(.*\): \1,:' $@.l-tmp; \
482 echo 'const int sim_modules_detected_len = ARRAY_SIZE (sim_modules_detected);'; \
484 $(SHELL) $(srcroot)/move-if-change $@.tmp $@
485 @rm -f $@.l-tmp $@.tmp
490 # For use in Makefile.in for cpu-specific files.
491 CGEN_MAIN_CPU_DEPS = \
493 $(srccom)/cgen-ops.h \
498 install: install-common $(SIM_EXTRA_INSTALL)
500 install-common: installdirs
501 a=`basename "$$(pwd)"`; \
502 n=`echo run | sed '$(program_transform_name)'`; \
503 [ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
504 $(INSTALL_PROGRAM) run$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
505 n="$(target_alias)-sim"; \
506 a=`basename "$$(pwd)"`; \
507 [ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
509 $(INSTALL_DATA) libsim.a $(DESTDIR)$(libdir)/$$n ; \
510 ( cd $(DESTDIR)$(libdir) ; $(RANLIB) $$n )
513 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(bindir)
514 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(libdir)
535 # Macros like EXTERN_SIM_CORE confuse tags.
536 # And the sim-n-foo.h files create functions that can't be found either.
539 etags --regex '/^\([[:lower:]_]+\) (/\1/' --regex '/^\/[*] TAGS: .*/' \
540 *.[ch] ../common/*.[ch]
542 mostlyclean clean: $(SIM_EXTRA_CLEAN)
544 rm -f run$(EXEEXT) libsim.a
545 rm -f hw-config.h stamp-hw
546 rm -f gentmap targ-map.c targ-vals.h stamp-tvals
547 if [ ! -f Make-common.in ] ; then \
548 rm -f $(BUILT_SRC_FROM_COMMON) ; \
550 rm -f tmp-mloop.hin tmp-mloop.h tmp-mloop.cin tmp-mloop.c
552 distclean maintainer-clean realclean: clean $(SIM_EXTRA_DISTCLEAN)
554 rm -f Makefile config.cache config.log config.status .gdbinit
555 rm -f config.h stamp-h
561 # Dummy target to force execution of dependent targets.
564 Makefile: Makefile.in $(srccom)/Make-common.in config.status
565 CONFIG_HEADERS= $(SHELL) ./config.status
567 config.status: configure
568 $(SHELL) ./config.status --recheck
570 config.h: stamp-h ; @true
571 stamp-h: config.in config.status
572 CONFIG_FILES= CONFIG_HEADERS=config.h:config.in $(SHELL) ./config.status
574 .gdbinit: # config.status $(srccom)/gdbinit.in
575 CONFIG_FILES=$@:../common/gdbinit.in CONFIG_HEADERS= $(SHELL) ./config.status
581 CGEN = "`if [ -f ../../guile/libguile/guile ]; then echo ../../guile/libguile/guile; else echo guile ; fi` -l $(CGENDIR)/guile.scm -s"
583 CGEN_CPU_DIR = $(CGENDIR)/cpu
585 # Most ports use the files here instead of cgen/cpu.
586 CPU_DIR = $(srcroot)/cpu
588 CGEN_READ_SCM = $(CGENDIR)/sim.scm
589 CGEN_ARCH_SCM = $(CGENDIR)/sim-arch.scm
590 CGEN_CPU_SCM = $(CGENDIR)/sim-cpu.scm $(CGENDIR)/sim-model.scm
591 CGEN_DECODE_SCM = $(CGENDIR)/sim-decode.scm
592 CGEN_DESC_SCM = $(CGENDIR)/desc.scm $(CGENDIR)/desc-cpu.scm
594 # Various choices for which cpu specific files to generate.
595 # These are passed to cgen.sh in the "extrafiles" argument.
596 CGEN_CPU_EXTR = /extr/
597 CGEN_CPU_READ = /read/
598 CGEN_CPU_WRITE = /write/
600 CGEN_CPU_SEMSW = /semsw/
602 CGEN_FLAGS_TO_PASS = \
604 CGENFLAGS="$(CGENFLAGS)"
606 # We store the generated files in the source directory until we decide to
607 # ship a Scheme interpreter with gdb/binutils. Maybe we never will.
610 $(SHELL) $(srccom)/cgen.sh arch $(srcdir) \
611 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
612 $(arch) "$(FLAGS)" ignored "$(isa)" $(mach) ignored \
616 $(SHELL) $(srccom)/cgen.sh cpu $(srcdir) \
617 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
618 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
619 $(archfile) "$(EXTRAFILES)"
622 $(SHELL) $(srccom)/cgen.sh defs $(srcdir) \
623 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
624 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
628 $(SHELL) $(srccom)/cgen.sh decode $(srcdir) \
629 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
630 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
631 $(archfile) "$(EXTRAFILES)"
633 cgen-cpu-decode: force
634 $(SHELL) $(srccom)/cgen.sh cpu-decode $(srcdir) \
635 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
636 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
637 $(archfile) "$(EXTRAFILES)"
640 $(SHELL) $(srccom)/cgen.sh desc $(srcdir) \
641 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
642 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
643 $(archfile) ignored $(opcfile)
645 ## End COMMON_POST_CONFIG_FRAG