1 # Makefile fragment for common parts of all simulators.
2 # Copyright 1997-2022 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 # Settings from top-level configure.
47 include ../arch-subdir.mk
49 include $(srcroot)/gdb/silent-rules.mk
52 ECHO_STAMP = @echo " GEN "
53 ECHO_IGEN = @echo " IGEN $(<F)";
58 # Helper code from gnulib.
59 GNULIB_PARENT_DIR = ../..
60 include $(GNULIB_PARENT_DIR)/gnulib/Makefile.gnulib.inc
63 exec_prefix = @exec_prefix@
68 tooldir = $(libdir)/$(target_alias)
71 datarootdir = @datarootdir@
73 man1dir = $(mandir)/man1
75 includedir = @includedir@
77 # This can be referenced by the gettext configuration code.
82 SIM_BITSIZE = @sim_bitsize@
83 SIM_FLOAT = @sim_float@
84 SIM_WARN_CFLAGS = $(WARN_CFLAGS)
85 SIM_WERROR_CFLAGS = $(WERROR_CFLAGS)
87 # Dependency tracking information.
88 depcomp = $(SHELL) $(srcroot)/depcomp
90 # Note that these are overridden by GNU make-specific code below if
91 # GNU make is used. The overrides implement dependency tracking.
92 COMPILE.pre = $(CC) $(C_DIALECT)
93 COMPILE.post = -c -o $@
94 COMPILE = $(ECHO_CC) $(COMPILE.pre) $(ALL_CFLAGS) $(COMPILE.post)
97 # igen leaks memory, and therefore makes AddressSanitizer unhappy. Disable
98 # leak detection while running it.
99 IGEN = ../igen/igen$(EXEEXT)
100 IGEN_RUN = ASAN_OPTIONS=detect_leaks=0 $(IGEN)
102 # Each simulator's Makefile.in defines one or more of these variables
103 # to override our settings as necessary. There is no need to define these
104 # in the simulator's Makefile.in if one is using the default value. In fact
105 # it's preferable not to.
107 # List of object files, less common parts.
109 # List of extra dependencies.
110 # Generally this consists of simulator specific files included by sim-main.h.
112 # List of flags to always pass to $(CC).
114 # List of extra libraries to link with.
116 # List of main object files for `run'.
117 SIM_RUN_OBJS = nrun.o
118 # Dependency of `install' to install any extra files.
120 # Dependency of `clean' to clean any extra files.
122 # Likewise `distclean'
123 SIM_EXTRA_DISTCLEAN =
125 # Every time a new general purpose source file was added every target's
126 # Makefile.in needed to be updated to include the file in SIM_OBJS.
127 # This doesn't scale.
128 # This variable specifies all the generic stuff common to the newer simulators.
129 # Things like sim-reason.o can't go here as the cpu may provide its own
130 # (though hopefully in time that won't be so). Things like sim-bits.o can go
131 # here. Some files are used by all simulators (e.g. callback.o).
132 # Those files are specified in LIB_OBJS below.
134 SIM_COMMON_HW_OBJS = \
146 SIM_NEW_COMMON_OBJS = \
178 ## End COMMON_PRE_CONFIG_FRAG
180 ## COMMON_POST_CONFIG_FRAG
189 $(SIM_WERROR_CFLAGS) \
191 CSEARCH = -I. -I$(srcdir) -I$(srccom) \
192 -I$(srcroot)/include \
193 -I../../bfd -I$(srcroot)/bfd \
194 -I$(srcroot)/opcodes \
196 ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(INCGNU) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
197 BUILD_CFLAGS = $(CFLAGS_FOR_BUILD) $(CSEARCH)
199 COMMON_DEP_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS)
201 SIM_HW_DEVICES = cfi core pal glue $(SIM_EXTRA_HW_DEVICES)
203 LIBIBERTY_LIB = ../../libiberty/libiberty.a
204 BFD_LIB = ../../bfd/libbfd.la
205 OPCODES_LIB = ../../opcodes/libopcodes.la
206 LIBDEPS = $(BFD_LIB) $(OPCODES_LIB) $(LIBIBERTY_LIB)
207 EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBIBERTY_LIB) \
208 $(COMMON_LIBS) $(SIM_EXTRA_LIBS) $(LIBGNU) $(LIBGNU_EXTRA_LIBS)
210 COMMON_OBJS_NAMES = \
215 target-newlib-errno.o \
216 target-newlib-open.o \
217 target-newlib-signal.o \
218 target-newlib-syscall.o \
220 COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/%)
222 LIB_OBJS = modules.o $(COMMON_OBJS) $(SIM_OBJS)
224 COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS)
225 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
229 all: libsim.a run$(EXEEXT)
231 libsim.a: $(LIB_OBJS)
232 $(SILENCE) rm -f libsim.a
233 $(ECHO_AR) $(AR) $(AR_FLAGS) libsim.a $(LIB_OBJS)
234 $(ECHO_RANLIB) $(RANLIB) libsim.a
236 run$(EXEEXT): $(SIM_RUN_OBJS) libsim.a $(LIBDEPS)
237 $(ECHO_CCLD) $(LIBTOOL) $(AM_V_lt) --tag=CC --mode=link \
238 $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o run$(EXEEXT) \
239 $(SIM_RUN_OBJS) libsim.a $(EXTRA_LIBS)
242 # Dependency tracking. Most of this is conditional on GNU Make being
243 # found by configure; if GNU Make is not found, we fall back to a
247 ifeq ($(DEPMODE),depmode=gcc3)
248 # Note that we put the dependencies into a .Tpo file, then move them
249 # into place if the compile succeeds. We need this because gcc does
250 # not atomically write the dependency output file.
251 override COMPILE.post = -c -o $@ -MT $@ -MMD -MP \
252 -MF $(DEPDIR)/$(basename $(@F)).Tpo
253 override POSTCOMPILE = @mv $(DEPDIR)/$(basename $(@F)).Tpo \
254 $(DEPDIR)/$(basename $(@F)).Po
256 override COMPILE.pre = source='$<' object='$@' libtool=no \
257 DEPDIR=$(DEPDIR) $(DEPMODE) $(depcomp) $(CC)
258 # depcomp handles atomicity for us, so we don't need a postcompile
260 override POSTCOMPILE =
263 all_object_files = $(LIB_OBJS) $(SIM_RUN_OBJS)
269 # Ensure that generated files are created early. Use order-only
270 # dependencies if available. They require GNU make 3.80 or newer,
271 # and the .VARIABLES variable was introduced at the same time.
273 $(all_object_files): | $(generated_files)
275 $(all_object_files) : $(generated_files)
279 -include $(patsubst %.o, $(DEPDIR)/%.Po, $(all_object_files))
281 # FIXME This is one very simple-minded way of generating the file hw-config.h
282 hw-config.h: stamp-hw ; @true
283 stamp-hw: Makefile.in $(srccom)/Make-common.in $(config.status) Makefile
284 $(ECHO_STAMP) hw-config.h
286 sim_hw="$(SIM_HW_DEVICES)" ; \
287 echo "/* generated by Makefile */" ; \
288 printf "extern const struct hw_descriptor dv_%s_descriptor[];\n" $$sim_hw ; \
289 echo "const struct hw_descriptor * const hw_descriptors[] = {" ; \
290 printf " dv_%s_descriptor,\n" $$sim_hw ; \
294 $(SILENCE) $(SHELL) $(srcroot)/move-if-change tmp-hw.h hw-config.h
297 test-hw-events: $(srccom)/hw-events.c libsim.a
298 $(ECHO_CCLD) $(LIBTOOL) $(AM_V_lt) --tag=CC --mode=link \
299 $(CC) $(ALL_CFLAGS) -DMAIN -o test-hw-events$(EXEEXT) \
300 $(srccom)/hw-events.c libsim.a $(EXTRA_LIBS)
302 # See sim_pre_argv_init and sim_module_install in sim-module.c for more details.
303 modules.c: stamp-modules ; @true
304 stamp-modules: Makefile $(SIM_OBJS:.o=.c)
305 $(ECHO_STAMP) modules.c
306 $(SILENCE) LANG=C ; export LANG ; \
307 LC_ALL=C ; export LC_ALL ; \
308 sed -n -e '/^sim_install_/{s/^\(sim_install_[a-z_0-9A-Z]*\).*/\1/;p}' $^ | sort >$@.l-tmp
310 echo '/* Do not modify this file. */'; \
311 echo '/* It is created automatically by the Makefile. */'; \
312 echo '#include "libiberty.h"'; \
313 echo '#include "sim-module.h"'; \
314 sed -e 's:\(.*\):extern MODULE_INIT_FN \1;:' $@.l-tmp; \
315 echo 'MODULE_INSTALL_FN * const sim_modules_detected[] = {'; \
316 sed -e 's:\(.*\): \1,:' $@.l-tmp; \
318 echo 'const int sim_modules_detected_len = ARRAY_SIZE (sim_modules_detected);'; \
320 $(SILENCE) $(SHELL) $(srcroot)/move-if-change $@.tmp modules.c
321 $(SILENCE) rm -f $@.l-tmp $@.tmp
326 install: install-common $(SIM_EXTRA_INSTALL)
328 install-common: installdirs
329 a=`basename "$$(pwd)"`; \
330 n=`echo run | sed '$(program_transform_name)'`; \
331 [ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
332 $(INSTALL_PROGRAM) run$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
333 n=`echo sim | sed '$(program_transform_name)'`; \
334 a=`basename "$$(pwd)"`; \
335 [ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
337 $(INSTALL_DATA) libsim.a $(DESTDIR)$(libdir)/$$n ; \
338 ( cd $(DESTDIR)$(libdir) ; $(RANLIB) $$n )
341 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(bindir)
342 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(libdir)
363 # Macros like EXTERN_SIM_CORE confuse tags.
364 # And the sim-n-foo.h files create functions that can't be found either.
367 etags --regex '/^\([[:lower:]_]+\) (/\1/' --regex '/^\/[*] TAGS: .*/' \
368 *.[ch] ../common/*.[ch]
370 mostlyclean clean: $(SIM_EXTRA_CLEAN)
371 rm -f *.[oa] *~ core \
372 run$(EXEEXT) libsim.a \
373 hw-config.h stamp-hw \
374 modules.c stamp-modules \
375 tmp-mloop.hin tmp-mloop.h tmp-mloop.cin tmp-mloop.c
377 distclean maintainer-clean realclean: clean $(SIM_EXTRA_DISTCLEAN)
379 rm -f Makefile config.cache config.log config.status
385 # Dummy target to force execution of dependent targets.
388 Makefile: Makefile.in $(srccom)/Make-common.in $(config.status)
389 @SIM_COMMON_BUILD_FALSE@ $(ECHO_GEN) CONFIG_HEADERS= $(SHELL) ./config.status
390 @SIM_COMMON_BUILD_TRUE@ $(ECHO_GEN) pwd=`pwd` && subdir=`basename "$$pwd"` && cd .. && \
391 @SIM_COMMON_BUILD_TRUE@ $(SHELL) ./config.status Make-common.sim $$subdir/Makefile.sim $$subdir/Makefile
393 @SIM_COMMON_BUILD_FALSE@config.status: configure
394 @SIM_COMMON_BUILD_FALSE@ $(ECHO_GEN) $(SHELL) ./config.status --recheck
399 GUILE = `if [ -f ../../guile/libguile/guile ]; then echo ../../guile/libguile/guile; else echo guile ; fi`
400 CGEN = "$(GUILE) -l $(CGENDIR)/guile.scm -s"
402 CGEN_CPU_DIR = $(CGENDIR)/cpu
404 # Most ports use the files here instead of cgen/cpu.
405 CPU_DIR = $(srcroot)/cpu
407 CGEN_READ_SCM = $(CGENDIR)/sim.scm
408 CGEN_ARCH_SCM = $(CGENDIR)/sim-arch.scm
409 CGEN_CPU_SCM = $(CGENDIR)/sim-cpu.scm $(CGENDIR)/sim-model.scm
410 CGEN_DECODE_SCM = $(CGENDIR)/sim-decode.scm
411 CGEN_DESC_SCM = $(CGENDIR)/desc.scm $(CGENDIR)/desc-cpu.scm
413 # Various choices for which cpu specific files to generate.
414 # These are passed to cgen.sh in the "extrafiles" argument.
415 CGEN_CPU_EXTR = /extr/
416 CGEN_CPU_READ = /read/
417 CGEN_CPU_WRITE = /write/
419 CGEN_CPU_SEMSW = /semsw/
421 CGEN_FLAGS_TO_PASS = \
423 CGENFLAGS="$(CGENFLAGS)"
425 # We store the generated files in the source directory until we decide to
426 # ship a Scheme interpreter with gdb/binutils. Maybe we never will.
429 $(SHELL) $(srccom)/cgen.sh arch $(srcdir) \
430 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
431 $(arch) "$(FLAGS)" ignored "$(isa)" $(mach) ignored \
435 $(SHELL) $(srccom)/cgen.sh cpu $(srcdir) \
436 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
437 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
438 $(archfile) "$(EXTRAFILES)"
441 $(SHELL) $(srccom)/cgen.sh defs $(srcdir) \
442 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
443 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
447 $(SHELL) $(srccom)/cgen.sh decode $(srcdir) \
448 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
449 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
450 $(archfile) "$(EXTRAFILES)"
452 cgen-cpu-decode: force
453 $(SHELL) $(srccom)/cgen.sh cpu-decode $(srcdir) \
454 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
455 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
456 $(archfile) "$(EXTRAFILES)"
459 $(SHELL) $(srccom)/cgen.sh desc $(srcdir) \
460 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
461 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
462 $(archfile) ignored $(opcfile)
464 ## End COMMON_POST_CONFIG_FRAG