sim: build: remove various obsolete generation dep variables
[binutils-gdb.git] / sim / common / Make-common.in
1 # Makefile fragment for common parts of all simulators.
2 # Copyright 1997-2022 Free Software Foundation, Inc.
3 # Contributed by Cygnus Support.
4
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.
9 #
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.
14 #
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/>.
17
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".
21 #
22 # The target Makefile should look like:
23 #
24 #># Copyright blah blah
25 #>
26 #>## COMMON_PRE_CONFIG_FRAG
27 #>
28 #># Any overrides necessary for the SIM_FOO config vars.
29 #>SIM_FOO = ...
30 #>
31 #>## COMMON_POST_CONFIG_FRAG
32 #>
33 #># Rules to build target specific .o's.
34
35 ## COMMON_PRE_CONFIG_FRAG
36
37 srcdir = @abs_srcdir@
38 VPATH = $(srcdir):$(srccom)
39 srccom = $(srcdir)/../common
40 srcroot = $(srcdir)/../..
41 srcsim = $(srcdir)/..
42
43 @SIM_COMMON_BUILD_FALSE@config.status = config.status
44 @SIM_COMMON_BUILD_TRUE@config.status = ../config.status
45
46 # Settings from top-level configure.
47 include ../arch-subdir.mk
48
49 include $(srcroot)/gdb/silent-rules.mk
50
51 ifeq ($(V),0)
52 ECHO_STAMP = @echo " GEN "
53 ECHO_IGEN = @echo " IGEN $(<F)";
54 else
55 ECHO_STAMP = @:
56 endif
57
58 # Helper code from gnulib.
59 GNULIB_PARENT_DIR = ../..
60 include $(GNULIB_PARENT_DIR)/gnulib/Makefile.gnulib.inc
61
62 prefix = @prefix@
63 exec_prefix = @exec_prefix@
64
65 bindir = @bindir@
66
67 libdir = @libdir@
68 tooldir = $(libdir)/$(target_alias)
69
70 datadir = @datadir@
71 datarootdir = @datarootdir@
72 mandir = @mandir@
73 man1dir = $(mandir)/man1
74 infodir = @infodir@
75 includedir = @includedir@
76
77 # This can be referenced by the gettext configuration code.
78 top_builddir = ..
79
80 SHELL = @SHELL@
81
82 SIM_BITSIZE = @sim_bitsize@
83 SIM_FLOAT = @sim_float@
84 SIM_WARN_CFLAGS = $(WARN_CFLAGS)
85 SIM_WERROR_CFLAGS = $(WERROR_CFLAGS)
86
87 # Dependency tracking information.
88 depcomp = $(SHELL) $(srcroot)/depcomp
89
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)
95 POSTCOMPILE = @true
96
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)
101
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.
106
107 # List of object files, less common parts.
108 SIM_OBJS =
109 # List of extra dependencies.
110 # Generally this consists of simulator specific files included by sim-main.h.
111 SIM_EXTRA_DEPS =
112 # List of flags to always pass to $(CC).
113 SIM_EXTRA_CFLAGS =
114 # List of extra libraries to link with.
115 SIM_EXTRA_LIBS =
116 # List of main object files for `run'.
117 SIM_RUN_OBJS = nrun.o
118 # Dependency of `install' to install any extra files.
119 SIM_EXTRA_INSTALL =
120 # Dependency of `clean' to clean any extra files.
121 SIM_EXTRA_CLEAN =
122 # Likewise `distclean'
123 SIM_EXTRA_DISTCLEAN =
124
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.
133
134 SIM_COMMON_HW_OBJS = \
135 hw-alloc.o \
136 hw-base.o \
137 hw-device.o \
138 hw-events.o \
139 hw-handles.o \
140 hw-instances.o \
141 hw-ports.o \
142 hw-properties.o \
143 hw-tree.o \
144 sim-hw.o \
145
146 SIM_NEW_COMMON_OBJS = \
147 sim-arange.o \
148 sim-bits.o \
149 sim-close.o \
150 sim-command.o \
151 sim-config.o \
152 sim-core.o \
153 sim-cpu.o \
154 sim-endian.o \
155 sim-engine.o \
156 sim-events.o \
157 sim-fpu.o \
158 sim-hload.o \
159 sim-hrw.o \
160 sim-io.o \
161 sim-info.o \
162 sim-memopt.o \
163 sim-model.o \
164 sim-module.o \
165 sim-options.o \
166 sim-profile.o \
167 sim-reason.o \
168 sim-reg.o \
169 sim-signal.o \
170 sim-stop.o \
171 sim-syscall.o \
172 sim-trace.o \
173 sim-utils.o \
174 sim-watch.o \
175 \
176 $(SIM_HW_OBJS) \
177
178 ## End COMMON_PRE_CONFIG_FRAG
179
180 ## COMMON_POST_CONFIG_FRAG
181
182 CONFIG_CFLAGS = \
183 -DHAVE_CONFIG_H \
184 $(SIM_BITSIZE) \
185 $(SIM_FLOAT) \
186 $(SIM_HW_CFLAGS) \
187 $(SIM_INLINE) \
188 $(SIM_WARN_CFLAGS) \
189 $(SIM_WERROR_CFLAGS) \
190 $(SIM_HARDWARE)
191 CSEARCH = -I. -I$(srcdir) -I$(srccom) \
192 -I$(srcroot)/include \
193 -I../../bfd -I$(srcroot)/bfd \
194 -I$(srcroot)/opcodes \
195 -I../..
196 ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(INCGNU) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
197 BUILD_CFLAGS = $(CFLAGS_FOR_BUILD) $(CSEARCH)
198
199 COMMON_DEP_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS)
200
201 SIM_HW_DEVICES = cfi core pal glue $(SIM_EXTRA_HW_DEVICES)
202
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)
209
210 COMMON_OBJS_NAMES = \
211 callback.o \
212 portability.o \
213 sim-load.o \
214 syscall.o \
215 target-newlib-errno.o \
216 target-newlib-open.o \
217 target-newlib-signal.o \
218 target-newlib-syscall.o \
219 version.o
220 COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/%)
221
222 LIB_OBJS = modules.o $(COMMON_OBJS) $(SIM_OBJS)
223
224 COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS)
225 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
226
227 RUNTESTFLAGS =
228
229 all: libsim.a run$(EXEEXT)
230
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
235
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)
240
241 #
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
244 # simpler scheme.
245 #
246
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
255 else
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
259 # step.
260 override POSTCOMPILE =
261 endif
262
263 all_object_files = $(LIB_OBJS) $(SIM_RUN_OBJS)
264 generated_files = \
265 $(SIM_EXTRA_DEPS) \
266 hw-config.h \
267 modules.c
268
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.
272 ifdef .VARIABLES
273 $(all_object_files): | $(generated_files)
274 else
275 $(all_object_files) : $(generated_files)
276 endif
277
278 # Dependencies.
279 -include $(patsubst %.o, $(DEPDIR)/%.Po, $(all_object_files))
280
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
285 $(SILENCE) ( \
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 ; \
291 echo " NULL," ; \
292 echo "};" \
293 ) > tmp-hw.h
294 $(SILENCE) $(SHELL) $(srcroot)/move-if-change tmp-hw.h hw-config.h
295 $(SILENCE) touch $@
296
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)
301
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
309 @set -e; (\
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; \
317 echo '};'; \
318 echo 'const int sim_modules_detected_len = ARRAY_SIZE (sim_modules_detected);'; \
319 ) >$@.tmp
320 $(SILENCE) $(SHELL) $(srcroot)/move-if-change $@.tmp modules.c
321 $(SILENCE) rm -f $@.l-tmp $@.tmp
322 $(SILENCE) touch $@
323
324 # Support targets.
325
326 install: install-common $(SIM_EXTRA_INSTALL)
327
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"; \
336 n="lib$$n.a"; \
337 $(INSTALL_DATA) libsim.a $(DESTDIR)$(libdir)/$$n ; \
338 ( cd $(DESTDIR)$(libdir) ; $(RANLIB) $$n )
339
340 installdirs:
341 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(bindir)
342 $(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(libdir)
343
344 check:
345
346 html:
347 clean-html:
348 install-html:
349
350 info:
351 clean-info:
352 install-info:
353
354 pdf:
355 clean-pdf:
356 install-pdf:
357
358 .NOEXPORT:
359 MAKEOVERRIDES=
360
361 tags etags: TAGS
362
363 # Macros like EXTERN_SIM_CORE confuse tags.
364 # And the sim-n-foo.h files create functions that can't be found either.
365 TAGS: force
366 cd $(srcdir) && \
367 etags --regex '/^\([[:lower:]_]+\) (/\1/' --regex '/^\/[*] TAGS: .*/' \
368 *.[ch] ../common/*.[ch]
369
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
376
377 distclean maintainer-clean realclean: clean $(SIM_EXTRA_DISTCLEAN)
378 rm -f TAGS
379 rm -f Makefile config.cache config.log config.status
380
381 .c.o:
382 $(COMPILE) $<
383 $(POSTCOMPILE)
384
385 # Dummy target to force execution of dependent targets.
386 force:
387
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
392
393 @SIM_COMMON_BUILD_FALSE@config.status: configure
394 @SIM_COMMON_BUILD_FALSE@ $(ECHO_GEN) $(SHELL) ./config.status --recheck
395
396
397 # CGEN support
398
399 GUILE = `if [ -f ../../guile/libguile/guile ]; then echo ../../guile/libguile/guile; else echo guile ; fi`
400 CGEN = "$(GUILE) -l $(CGENDIR)/guile.scm -s"
401 CGENFLAGS = -v
402 CGEN_CPU_DIR = $(CGENDIR)/cpu
403
404 # Most ports use the files here instead of cgen/cpu.
405 CPU_DIR = $(srcroot)/cpu
406
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
412
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/
418 CGEN_CPU_SEM = /sem/
419 CGEN_CPU_SEMSW = /semsw/
420
421 CGEN_FLAGS_TO_PASS = \
422 CGEN='$(CGEN)' \
423 CGENFLAGS="$(CGENFLAGS)"
424
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.
427
428 cgen-arch: force
429 $(SHELL) $(srccom)/cgen.sh arch $(srcdir) \
430 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
431 $(arch) "$(FLAGS)" ignored "$(isa)" $(mach) ignored \
432 $(archfile) ignored
433
434 cgen-cpu: force
435 $(SHELL) $(srccom)/cgen.sh cpu $(srcdir) \
436 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
437 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
438 $(archfile) "$(EXTRAFILES)"
439
440 cgen-defs: force
441 $(SHELL) $(srccom)/cgen.sh defs $(srcdir) \
442 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
443 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
444 $(archfile) ignored
445
446 cgen-decode: force
447 $(SHELL) $(srccom)/cgen.sh decode $(srcdir) \
448 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
449 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
450 $(archfile) "$(EXTRAFILES)"
451
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)"
457
458 cgen-desc: force
459 $(SHELL) $(srccom)/cgen.sh desc $(srcdir) \
460 $(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
461 $(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
462 $(archfile) ignored $(opcfile)
463
464 ## End COMMON_POST_CONFIG_FRAG