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
38 VPATH = $(srcdir):$(srccom)
39 srccom = $(srcdir)/../common
40 srcroot = $(srcdir)/../..
43 @SIM_COMMON_BUILD_FALSE@config.status = config.status
44 @SIM_COMMON_BUILD_TRUE@config.status = ../config.status
46 include $(srcroot)/gdb/silent-rules.mk
48 # Helper code from gnulib.
49 GNULIB_PARENT_DIR = ../..
50 include $(GNULIB_PARENT_DIR)/gnulib/Makefile.gnulib.inc
52 # Settings from top-level configure.
53 include ../arch-subdir.mk
56 exec_prefix = @exec_prefix@
61 tooldir = $(libdir)/$(target_alias)
64 datarootdir = @datarootdir@
66 man1dir = $(mandir)/man1
68 includedir = @includedir@
70 # This can be referenced by the gettext configuration code.
75 SIM_BITSIZE = @sim_bitsize@
76 SIM_DEFAULT_MODEL = @sim_default_model@
77 SIM_FLOAT = @sim_float@
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 SIM_HW_DEVICES = cfi core pal glue $(SIM_EXTRA_HW_DEVICES)
221 ZLIB = $(zlibdir) -lz
222 LIBIBERTY_LIB = ../../libiberty/libiberty.a
223 BFD_LIB = ../../bfd/libbfd.a
224 OPCODES_LIB = ../../opcodes/libopcodes.a
225 CONFIG_LIBS = $(COMMON_LIBS) @LIBS@ $(ZLIB)
226 LIBDEPS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL_DEP) $(LIBIBERTY_LIB)
227 EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \
228 $(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL) $(LIBGNU) $(LIBGNU_EXTRA_LIBS)
230 COMMON_OBJS_NAMES = \
234 COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/common_libcommon_a-%)
236 LIB_OBJS = callback.o modules.o syscall.o targ-map.o $(COMMON_OBJS) $(SIM_OBJS)
238 COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS)
239 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
243 callback_h = $(srcroot)/include/sim/callback.h
244 remote_sim_h = $(srcroot)/include/sim/sim.h
246 all: libsim.a run$(EXEEXT) .gdbinit
248 libsim.a: $(LIB_OBJS)
250 $(ECHO_AR) $(AR) $(AR_FLAGS) libsim.a $(LIB_OBJS)
251 $(ECHO_RANLIB) $(RANLIB) libsim.a
253 run$(EXEEXT): $(SIM_RUN_OBJS) libsim.a $(LIBDEPS)
254 $(ECHO_CCLD) $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o run$(EXEEXT) \
255 $(SIM_RUN_OBJS) libsim.a $(EXTRA_LIBS)
257 # FIXME: Ideally, callback.o and friends live in a library outside of
258 # both the gdb and simulator source trees (e.g. devo/remote. Not
259 # devo/libremote because this directory would contain more than just
262 gentmap.o: Makefile $(srccom)/gentmap.c $(srccom)/nltvals.def
263 $(ECHO_CC) $(COMPILE_FOR_BUILD) -o $@ -c $(srccom)/gentmap.c $(NL_TARGET)
266 $(ECHO_CC) $(LINK_FOR_BUILD) $<
268 targ-vals.h targ-map.c: stamp-tvals
270 rm -f tmp-tvals.h tmp-tmap.c
271 ./gentmap -h >tmp-tvals.h
272 $(SHELL) $(srcroot)/move-if-change tmp-tvals.h targ-vals.h
273 ./gentmap -c >tmp-tmap.c
274 $(SHELL) $(srcroot)/move-if-change tmp-tmap.c targ-map.c
278 # Rules for building sim-* components. Triggered by listing the corresponding
279 # .o file in the list of simulator targets.
298 # Exported version of sim_main_headers.
302 sim-alu_h = $(srccom)/sim-alu.h
303 sim-arange_h = $(srccom)/sim-arange.h
304 sim-assert_h = $(srccom)/sim-assert.h
305 sim-base_h = $(srccom)/sim-base.h \
317 sim-basics_h = $(srccom)/sim-basics.h \
327 sim-bits_h = $(srccom)/sim-bits.h \
329 sim-config_h = $(srccom)/sim-config.h
330 sim-core_h = $(srccom)/sim-core.h
331 sim-cpu_h = $(srccom)/sim-cpu.h
332 sim-endian_h = $(srccom)/sim-endian.h \
333 $(srccom)/sim-endian.c
334 sim-engine_h = $(srccom)/sim-engine.h
335 sim-events_h = $(srccom)/sim-events.h
336 sim-fpu_h = $(srccom)/sim-fpu.h
337 sim-hw_h = $(srccom)/sim-hw.h
338 sim-inline_h = $(srccom)/sim-inline.h
339 sim-io_h = $(srccom)/sim-io.h
340 sim-memopt_h = $(srccom)/sim-memopt.h
341 sim-model_h = $(srccom)/sim-model.h
342 sim-module_h = $(srccom)/sim-module.h
343 sim-n-bits_h = $(srccom)/sim-n-bits.h
344 sim-n-core_h = $(srccom)/sim-n-core.h
345 sim-n-endian_h = $(srccom)/sim-n-endian.h
346 sim-options_h = $(srccom)/sim-options.h
347 sim-profile_h = $(srccom)/sim-profile.h
348 sim-signal_h = $(srccom)/sim-signal.h
349 sim-trace_h = $(srccom)/sim-trace.h
350 sim-types_h = $(srccom)/sim-types.h
351 sim-utils_h = $(srccom)/sim-utils.h
352 sim-watch_h = $(srccom)/sim-watch.h
354 hw-alloc_h = $(srccom)/hw-alloc.h
355 hw-base_h = $(srccom)/hw-base.h
356 hw-device_h = $(srccom)/hw-device.h
357 hw-events_h = $(srccom)/hw-events.h
358 hw-handles_h = $(srccom)/hw-handles.h
359 hw-instances_h = $(srccom)/hw-instances.h
360 hw-ports_h = $(srccom)/hw-ports.h
361 hw-properties_h = $(srccom)/hw-properties.h
362 hw-tree_h = $(srccom)/hw-tree.h
365 $(srccom)/hw-main.h \
376 # Dependency tracking. Most of this is conditional on GNU Make being
377 # found by configure; if GNU Make is not found, we fall back to a
381 ifeq ($(DEPMODE),depmode=gcc3)
382 # Note that we put the dependencies into a .Tpo file, then move them
383 # into place if the compile succeeds. We need this because gcc does
384 # not atomically write the dependency output file.
385 override COMPILE.post = -c -o $@ -MT $@ -MMD -MP \
386 -MF $(DEPDIR)/$(basename $(@F)).Tpo
387 override POSTCOMPILE = @mv $(DEPDIR)/$(basename $(@F)).Tpo \
388 $(DEPDIR)/$(basename $(@F)).Po
390 override COMPILE.pre = source='$<' object='$@' libtool=no \
391 DEPDIR=$(DEPDIR) $(DEPMODE) $(depcomp) $(CC)
392 # depcomp handles atomicity for us, so we don't need a postcompile
394 override POSTCOMPILE =
397 all_object_files = $(LIB_OBJS) $(SIM_RUN_OBJS)
405 # Ensure that generated files are created early. Use order-only
406 # dependencies if available. They require GNU make 3.80 or newer,
407 # and the .VARIABLES variable was introduced at the same time.
409 $(all_object_files): | $(generated_files)
411 $(all_object_files) : $(generated_files)
415 -include $(patsubst %.o, $(DEPDIR)/%.Po, $(all_object_files))
417 # FIXME This is one very simple-minded way of generating the file hw-config.h
418 hw-config.h: stamp-hw ; @true
419 stamp-hw: Makefile.in $(srccom)/Make-common.in $(config.status) Makefile
421 echo "/* generated by Makefile */" > tmp-hw.h
422 sim_hw="$(SIM_HW_DEVICES)"; \
423 for hw in $$sim_hw ; do \
424 echo "extern const struct hw_descriptor dv_$${hw}_descriptor[];" ; \
426 echo "const struct hw_descriptor *hw_descriptors[] = {" >> tmp-hw.h
427 sim_hw="$(SIM_HW_DEVICES)"; \
428 for hw in $$sim_hw ; do \
429 echo " dv_$${hw}_descriptor," ; \
431 echo " NULL," >> tmp-hw.h
432 echo "};" >> tmp-hw.h
433 $(SHELL) $(srcroot)/move-if-change tmp-hw.h hw-config.h
434 @echo stamp > stamp-hw
436 test-hw-events: $(srccom)/hw-events.c libsim.a
437 $(CC) $(ALL_CFLAGS) -DMAIN -o test-hw-events$(EXEEXT) \
438 $(srccom)/hw-events.c libsim.a $(EXTRA_LIBS)
440 # See sim_pre_argv_init and sim_module_install in sim-module.c for more details.
441 modules.c: stamp-modules ; @true
442 stamp-modules: Makefile $(SIM_OBJS:.o=.c)
444 @LANG=C ; export LANG ; \
445 LC_ALL=C ; export LC_ALL ; \
446 sed -n -e '/^sim_install_/{s/^\(sim_install_[a-z_0-9A-Z]*\).*/\1/;p}' $^ | sort >$@.l-tmp
448 echo '/* Do not modify this file. */'; \
449 echo '/* It is created automatically by the Makefile. */'; \
450 echo '#include "libiberty.h"'; \
451 echo '#include "sim-module.h"'; \
452 sed -e 's:\(.*\):extern __attribute__((__weak__)) MODULE_INIT_FN \1;:' $@.l-tmp; \
453 echo 'MODULE_INSTALL_FN * const sim_modules_detected[] = {'; \
454 sed -e 's:\(.*\): \1,:' $@.l-tmp; \
456 echo 'const int sim_modules_detected_len = ARRAY_SIZE (sim_modules_detected);'; \
458 $(SHELL) $(srcroot)/move-if-change $@.tmp modules.c
459 @rm -f $@.l-tmp $@.tmp
464 # For use in Makefile.in for cpu-specific files.
465 CGEN_MAIN_CPU_DEPS = \
467 $(srccom)/cgen-ops.h \
472 install: install-common $(SIM_EXTRA_INSTALL)
474 install-common: installdirs
475 a=`basename "$$(pwd)"`; \
476 n=`echo run | sed '$(program_transform_name)'`; \
477 [ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
478 $(INSTALL_PROGRAM) run$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
479 n="$(target_alias)-sim"; \
480 a=`basename "$$(pwd)"`; \
481 [ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
483 $(INSTALL_DATA) libsim.a $(DESTDIR)$(libdir)/$$n ; \
484 ( cd $(DESTDIR)$(libdir) ; $(RANLIB) $$n )
487 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(bindir)
488 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(libdir)
509 # Macros like EXTERN_SIM_CORE confuse tags.
510 # And the sim-n-foo.h files create functions that can't be found either.
513 etags --regex '/^\([[:lower:]_]+\) (/\1/' --regex '/^\/[*] TAGS: .*/' \
514 *.[ch] ../common/*.[ch]
516 mostlyclean clean: $(SIM_EXTRA_CLEAN)
518 rm -f run$(EXEEXT) libsim.a
519 rm -f hw-config.h stamp-hw
520 rm -f modules.c stamp-modules
521 rm -f gentmap targ-map.c targ-vals.h stamp-tvals
522 rm -f tmp-mloop.hin tmp-mloop.h tmp-mloop.cin tmp-mloop.c
524 distclean maintainer-clean realclean: clean $(SIM_EXTRA_DISTCLEAN)
526 rm -f Makefile config.cache config.log config.status .gdbinit
532 # Dummy target to force execution of dependent targets.
535 Makefile: Makefile.in $(srccom)/Make-common.in $(config.status)
536 @SIM_COMMON_BUILD_FALSE@ CONFIG_HEADERS= $(SHELL) ./config.status
537 @SIM_COMMON_BUILD_TRUE@ cd .. && $(SHELL) ./config.status $(arch)/Makefile
539 @SIM_COMMON_BUILD_FALSE@config.status: configure
540 @SIM_COMMON_BUILD_FALSE@ $(SHELL) ./config.status --recheck
542 .gdbinit: # config.status $(srccom)/gdbinit.in
543 @SIM_COMMON_BUILD_FALSE@ CONFIG_FILES=$@:../common/gdbinit.in CONFIG_HEADERS= $(SHELL) ./config.status
548 CGEN = "`if [ -f ../../guile/libguile/guile ]; then echo ../../guile/libguile/guile; else echo guile ; fi` -l $(CGENDIR)/guile.scm -s"
550 CGEN_CPU_DIR = $(CGENDIR)/cpu
552 # Most ports use the files here instead of cgen/cpu.
553 CPU_DIR = $(srcroot)/cpu
555 CGEN_READ_SCM = $(CGENDIR)/sim.scm
556 CGEN_ARCH_SCM = $(CGENDIR)/sim-arch.scm
557 CGEN_CPU_SCM = $(CGENDIR)/sim-cpu.scm $(CGENDIR)/sim-model.scm
558 CGEN_DECODE_SCM = $(CGENDIR)/sim-decode.scm
559 CGEN_DESC_SCM = $(CGENDIR)/desc.scm $(CGENDIR)/desc-cpu.scm
561 # Various choices for which cpu specific files to generate.
562 # These are passed to cgen.sh in the "extrafiles" argument.
563 CGEN_CPU_EXTR = /extr/
564 CGEN_CPU_READ = /read/
565 CGEN_CPU_WRITE = /write/
567 CGEN_CPU_SEMSW = /semsw/
569 CGEN_FLAGS_TO_PASS = \
571 CGENFLAGS="$(CGENFLAGS)"
573 # We store the generated files in the source directory until we decide to
574 # ship a Scheme interpreter with gdb/binutils. Maybe we never will.
577 $(SHELL) $(srccom)/cgen.sh arch $(srcdir) \
578 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
579 $(arch) "$(FLAGS)" ignored "$(isa)" $(mach) ignored \
583 $(SHELL) $(srccom)/cgen.sh cpu $(srcdir) \
584 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
585 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
586 $(archfile) "$(EXTRAFILES)"
589 $(SHELL) $(srccom)/cgen.sh defs $(srcdir) \
590 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
591 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
595 $(SHELL) $(srccom)/cgen.sh decode $(srcdir) \
596 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
597 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
598 $(archfile) "$(EXTRAFILES)"
600 cgen-cpu-decode: force
601 $(SHELL) $(srccom)/cgen.sh cpu-decode $(srcdir) \
602 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
603 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
604 $(archfile) "$(EXTRAFILES)"
607 $(SHELL) $(srccom)/cgen.sh desc $(srcdir) \
608 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
609 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
610 $(archfile) ignored $(opcfile)
612 ## End COMMON_POST_CONFIG_FRAG