xref: /netbsd-src/external/gpl3/gdb.old/dist/sim/common/Make-common.in (revision f8cf1a9151c7af1cb0bd8b09c13c66bca599c027)
1# Makefile fragment for common parts of all simulators.
2# Copyright 1997-2023 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
37srcdir = @abs_srcdir@
38VPATH = $(srcdir):$(srccom)
39srccom = $(srcdir)/../common
40srcroot = $(srcdir)/../..
41srcsim = $(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.
47include ../arch-subdir.mk
48
49include $(srcroot)/gdb/silent-rules.mk
50
51ifeq ($(V),0)
52ECHO_STAMP = @echo "  GEN   "
53ECHO_IGEN  = @echo "  IGEN   $(<F)";
54else
55ECHO_STAMP = @:
56endif
57
58# Helper code from gnulib.
59GNULIB_PARENT_DIR = ../..
60include $(GNULIB_PARENT_DIR)/gnulib/Makefile.gnulib.inc
61
62# This can be referenced by the gettext configuration code.
63top_builddir = ..
64
65SHELL = @SHELL@
66
67SIM_BITSIZE = @sim_bitsize@
68SIM_FLOAT = @sim_float@
69SIM_WARN_CFLAGS = $(WARN_CFLAGS)
70SIM_WERROR_CFLAGS = $(WERROR_CFLAGS)
71
72# Dependency tracking information.
73depcomp = $(SHELL) $(srcroot)/depcomp
74
75# Note that these are overridden by GNU make-specific code below if
76# GNU make is used.  The overrides implement dependency tracking.
77COMPILE.pre = $(CC) $(C_DIALECT)
78COMPILE.post = -c -o $@
79COMPILE = $(ECHO_CC) $(COMPILE.pre) $(ALL_CFLAGS) $(COMPILE.post)
80POSTCOMPILE = @true
81
82# igen leaks memory, and therefore makes AddressSanitizer unhappy.  Disable
83# leak detection while running it.
84IGEN = ../igen/igen$(EXEEXT)
85IGEN_RUN = ASAN_OPTIONS=detect_leaks=0 $(IGEN)
86
87# Each simulator's Makefile.in defines one or more of these variables
88# to override our settings as necessary.  There is no need to define these
89# in the simulator's Makefile.in if one is using the default value.  In fact
90# it's preferable not to.
91
92# List of object files, less common parts.
93SIM_OBJS =
94# List of extra dependencies.
95# Generally this consists of simulator specific files included by sim-main.h.
96SIM_EXTRA_DEPS =
97# List of flags to always pass to $(CC).
98SIM_EXTRA_CFLAGS =
99# List of extra libraries to link with.
100SIM_EXTRA_LIBS =
101# List of main object files for `run'.
102SIM_RUN_OBJS = nrun.o
103# Dependency of `clean' to clean any extra files.
104SIM_EXTRA_CLEAN =
105# Likewise `distclean'
106SIM_EXTRA_DISTCLEAN =
107
108# Every time a new general purpose source file was added every target's
109# Makefile.in needed to be updated to include the file in SIM_OBJS.
110# This doesn't scale.
111# This variable specifies all the generic stuff common to the newer simulators.
112# Things like sim-reason.o can't go here as the cpu may provide its own
113# (though hopefully in time that won't be so).  Things like sim-bits.o can go
114# here.  Some files are used by all simulators (e.g. callback.o).
115# Those files are specified in LIB_OBJS below.
116
117SIM_COMMON_HW_OBJS = \
118	hw-alloc.o \
119	hw-base.o \
120	hw-device.o \
121	hw-events.o \
122	hw-handles.o \
123	hw-instances.o \
124	hw-ports.o \
125	hw-properties.o \
126	hw-tree.o \
127	sim-hw.o \
128
129SIM_NEW_COMMON_OBJS = \
130	sim-arange.o \
131	sim-bits.o \
132	sim-close.o \
133	sim-command.o \
134	sim-config.o \
135	sim-core.o \
136	sim-cpu.o \
137	sim-endian.o \
138	sim-engine.o \
139	sim-events.o \
140	sim-fpu.o \
141	sim-hload.o \
142	sim-hrw.o \
143	sim-io.o \
144	sim-info.o \
145	sim-memopt.o \
146	sim-model.o \
147	sim-module.o \
148	sim-options.o \
149	sim-profile.o \
150	sim-reason.o \
151	sim-reg.o \
152	sim-signal.o \
153	sim-stop.o \
154	sim-syscall.o \
155	sim-trace.o \
156	sim-utils.o \
157	sim-watch.o \
158	\
159	$(SIM_HW_OBJS) \
160
161## End COMMON_PRE_CONFIG_FRAG
162
163## COMMON_POST_CONFIG_FRAG
164
165CONFIG_CFLAGS = \
166	-DHAVE_CONFIG_H \
167	$(SIM_BITSIZE) \
168	$(SIM_FLOAT) \
169	$(SIM_HW_CFLAGS) \
170	$(SIM_INLINE) \
171	$(SIM_WARN_CFLAGS) \
172	$(SIM_WERROR_CFLAGS)
173CSEARCH = -I. -I$(srcdir) -I$(srccom) \
174  -I$(srcroot)/include \
175  -I../../bfd -I$(srcroot)/bfd \
176  -I$(srcroot)/opcodes \
177  -I../..
178ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(INCGNU) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
179BUILD_CFLAGS = $(CFLAGS_FOR_BUILD) $(CSEARCH)
180
181COMMON_DEP_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS)
182
183SIM_HW_DEVICES = cfi core pal glue $(SIM_EXTRA_HW_DEVICES)
184
185LIBIBERTY_LIB = ../../libiberty/libiberty.a
186BFD_LIB = ../../bfd/libbfd.la
187OPCODES_LIB = ../../opcodes/libopcodes.la
188LIBDEPS = $(BFD_LIB) $(OPCODES_LIB) $(LIBIBERTY_LIB)
189EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBIBERTY_LIB) \
190	$(COMMON_LIBS) $(SIM_EXTRA_LIBS) $(LIBGNU) $(LIBGNU_EXTRA_LIBS)
191
192COMMON_OBJS_NAMES = \
193	callback.o \
194	portability.o \
195	sim-load.o \
196	syscall.o \
197	target-newlib-errno.o \
198	target-newlib-open.o \
199	target-newlib-signal.o \
200	target-newlib-syscall.o \
201	version.o
202COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/%)
203
204LIB_OBJS = modules.o $(COMMON_OBJS) $(SIM_OBJS)
205
206COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS)
207LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
208
209RUNTESTFLAGS =
210
211all: libsim.a $(SIM_RUN_OBJS)
212
213libsim.a: $(LIB_OBJS)
214	$(SILENCE) rm -f libsim.a
215	$(ECHO_AR) $(AR) $(AR_FLAGS) libsim.a $(LIB_OBJS)
216	$(ECHO_RANLIB) $(RANLIB) libsim.a
217
218#
219# Dependency tracking.  Most of this is conditional on GNU Make being
220# found by configure; if GNU Make is not found, we fall back to a
221# simpler scheme.
222#
223
224ifeq ($(DEPMODE),depmode=gcc3)
225# Note that we put the dependencies into a .Tpo file, then move them
226# into place if the compile succeeds.  We need this because gcc does
227# not atomically write the dependency output file.
228override COMPILE.post = -c -o $@ -MT $@ -MMD -MP \
229	-MF $(DEPDIR)/$(basename $(@F)).Tpo
230override POSTCOMPILE = @mv $(DEPDIR)/$(basename $(@F)).Tpo \
231	$(DEPDIR)/$(basename $(@F)).Po
232else
233override COMPILE.pre = source='$<' object='$@' libtool=no \
234	DEPDIR=$(DEPDIR) $(DEPMODE) $(depcomp) $(CC)
235# depcomp handles atomicity for us, so we don't need a postcompile
236# step.
237override POSTCOMPILE =
238endif
239
240all_object_files = $(LIB_OBJS) $(SIM_RUN_OBJS)
241generated_files = \
242	$(SIM_EXTRA_DEPS) \
243	hw-config.h \
244	modules.c
245
246# Ensure that generated files are created early.  Use order-only
247# dependencies if available.  They require GNU make 3.80 or newer,
248# and the .VARIABLES variable was introduced at the same time.
249ifdef .VARIABLES
250$(all_object_files): | $(generated_files)
251else
252$(all_object_files) : $(generated_files)
253endif
254
255# Dependencies.
256-include $(patsubst %.o, $(DEPDIR)/%.Po, $(all_object_files))
257
258# FIXME This is one very simple-minded way of generating the file hw-config.h
259hw-config.h: stamp-hw ; @true
260stamp-hw: Makefile.in $(srccom)/Make-common.in $(config.status) Makefile
261	$(ECHO_STAMP) hw-config.h
262	$(SILENCE) ( \
263	sim_hw="$(SIM_HW_DEVICES)" ; \
264	echo "/* generated by Makefile */" ; \
265	printf "extern const struct hw_descriptor dv_%s_descriptor[];\n" $$sim_hw ; \
266	echo "const struct hw_descriptor * const hw_descriptors[] = {" ; \
267	printf "  dv_%s_descriptor,\n" $$sim_hw ; \
268	echo "  NULL," ; \
269	echo "};" \
270	) > tmp-hw.h
271	$(SILENCE) $(SHELL) $(srcroot)/move-if-change tmp-hw.h hw-config.h
272	$(SILENCE) touch $@
273
274test-hw-events: $(srccom)/hw-events.c libsim.a
275	$(ECHO_CCLD) $(LIBTOOL) $(AM_V_lt) --tag=CC --mode=link \
276		$(CC) $(ALL_CFLAGS) -DMAIN -o test-hw-events$(EXEEXT) \
277		$(srccom)/hw-events.c libsim.a $(EXTRA_LIBS)
278
279# See sim_pre_argv_init and sim_module_install in sim-module.c for more details.
280modules.c: stamp-modules ; @true
281stamp-modules: Makefile $(SIM_OBJS:.o=.c)
282	$(ECHO_STAMP) modules.c
283	$(SILENCE) LANG=C ; export LANG ; \
284	LC_ALL=C ; export LC_ALL ; \
285	sed -n -e '/^sim_install_/{s/^\(sim_install_[a-z_0-9A-Z]*\).*/\1/;p}' $^ | sort >$@.l-tmp
286	@set -e; (\
287	echo '/* Do not modify this file.  */'; \
288	echo '/* It is created automatically by the Makefile.  */'; \
289	echo '#include "libiberty.h"'; \
290	echo '#include "sim-module.h"'; \
291	sed -e 's:\(.*\):extern MODULE_INIT_FN \1;:' $@.l-tmp; \
292	echo 'MODULE_INSTALL_FN * const sim_modules_detected[] = {'; \
293	sed -e 's:\(.*\):  \1,:' $@.l-tmp; \
294	echo '};'; \
295	echo 'const int sim_modules_detected_len = ARRAY_SIZE (sim_modules_detected);'; \
296	) >$@.tmp
297	$(SILENCE) $(SHELL) $(srcroot)/move-if-change $@.tmp modules.c
298	$(SILENCE) rm -f $@.l-tmp $@.tmp
299	$(SILENCE) touch $@
300
301# Support targets.
302
303install:
304installdirs:
305uninstall:
306
307check:
308
309html:
310clean-html:
311install-html:
312
313info:
314clean-info:
315install-info:
316
317pdf:
318clean-pdf:
319install-pdf:
320
321.NOEXPORT:
322MAKEOVERRIDES=
323
324tags etags: TAGS
325
326# Macros like EXTERN_SIM_CORE confuse tags.
327# And the sim-n-foo.h files create functions that can't be found either.
328TAGS: force
329	cd $(srcdir) && \
330	etags --regex '/^\([[:lower:]_]+\) (/\1/' --regex '/^\/[*] TAGS: .*/' \
331		*.[ch] ../common/*.[ch]
332
333mostlyclean clean: $(SIM_EXTRA_CLEAN)
334	rm -f *.[oa] *~ core \
335		run$(EXEEXT) libsim.a \
336		hw-config.h stamp-hw \
337		modules.c stamp-modules \
338		tmp-mloop.hin tmp-mloop.h tmp-mloop.cin tmp-mloop.c
339
340distclean maintainer-clean realclean: clean $(SIM_EXTRA_DISTCLEAN)
341	rm -f TAGS
342	rm -f Makefile config.cache config.log config.status
343
344.c.o:
345	$(COMPILE) $<
346	$(POSTCOMPILE)
347
348# Dummy target to force execution of dependent targets.
349force:
350
351Makefile: Makefile.in $(srccom)/Make-common.in $(config.status)
352@SIM_COMMON_BUILD_FALSE@	$(ECHO_GEN) CONFIG_HEADERS= $(SHELL) ./config.status
353@SIM_COMMON_BUILD_TRUE@	$(ECHO_GEN) pwd=`pwd` && subdir=`basename "$$pwd"` && cd .. && \
354@SIM_COMMON_BUILD_TRUE@		$(SHELL) ./config.status Make-common.sim $$subdir/Makefile.sim $$subdir/Makefile
355
356@SIM_COMMON_BUILD_FALSE@config.status: configure
357@SIM_COMMON_BUILD_FALSE@	$(ECHO_GEN) $(SHELL) ./config.status --recheck
358
359
360# CGEN support
361
362GUILE = `if [ -f ../../guile/libguile/guile ]; then echo ../../guile/libguile/guile; else echo guile ; fi`
363CGEN = "$(GUILE) -l $(CGENDIR)/guile.scm -s"
364CGENFLAGS = -v
365CGEN_CPU_DIR = $(CGENDIR)/cpu
366
367# Most ports use the files here instead of cgen/cpu.
368CPU_DIR = $(srcroot)/cpu
369
370CGEN_READ_SCM = $(CGENDIR)/sim.scm
371CGEN_ARCH_SCM = $(CGENDIR)/sim-arch.scm
372CGEN_CPU_SCM = $(CGENDIR)/sim-cpu.scm $(CGENDIR)/sim-model.scm
373CGEN_DECODE_SCM = $(CGENDIR)/sim-decode.scm
374CGEN_DESC_SCM = $(CGENDIR)/desc.scm $(CGENDIR)/desc-cpu.scm
375
376# Various choices for which cpu specific files to generate.
377# These are passed to cgen.sh in the "extrafiles" argument.
378CGEN_CPU_EXTR = /extr/
379CGEN_CPU_READ = /read/
380CGEN_CPU_WRITE = /write/
381CGEN_CPU_SEM = /sem/
382CGEN_CPU_SEMSW = /semsw/
383
384CGEN_FLAGS_TO_PASS = \
385	CGEN='$(CGEN)' \
386	CGENFLAGS="$(CGENFLAGS)"
387
388# We store the generated files in the source directory until we decide to
389# ship a Scheme interpreter with gdb/binutils.  Maybe we never will.
390
391cgen-arch: force
392	$(SHELL) $(srccom)/cgen.sh arch $(srcdir) \
393		$(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
394		$(arch) "$(FLAGS)" ignored "$(isa)" $(mach) ignored \
395		$(archfile) ignored
396
397cgen-cpu: force
398	$(SHELL) $(srccom)/cgen.sh cpu $(srcdir) \
399		$(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
400		$(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
401		$(archfile) "$(EXTRAFILES)"
402
403cgen-defs: force
404	$(SHELL) $(srccom)/cgen.sh defs $(srcdir) \
405		$(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
406		$(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
407		$(archfile) ignored
408
409cgen-decode: force
410	$(SHELL) $(srccom)/cgen.sh decode $(srcdir) \
411		$(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
412		$(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
413		$(archfile) "$(EXTRAFILES)"
414
415cgen-cpu-decode: force
416	$(SHELL) $(srccom)/cgen.sh cpu-decode $(srcdir) \
417		$(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
418		$(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
419		$(archfile) "$(EXTRAFILES)"
420
421cgen-desc: force
422	$(SHELL) $(srccom)/cgen.sh desc $(srcdir) \
423		$(CGEN) $(CGENDIR) "$(CGENFLAGS)" \
424		$(arch) "$(FLAGS)" $(cpu) "$(isa)" $(mach) "$(SUFFIX)" \
425		$(archfile) ignored $(opcfile)
426
427## End COMMON_POST_CONFIG_FRAG
428