1## See sim/Makefile.am
2##
3## Copyright (C) 1994-2024 Free Software Foundation, Inc.
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
18AM_CPPFLAGS_%C% = \
19          -DHAVE_COMMON_FPU \
20          $(sim_ppc_smp) \
21          $(sim_ppc_xor_endian) \
22          $(sim_ppc_bitsize) \
23          $(sim_ppc_timebase) \
24          $(sim_ppc_float) \
25          $(sim_ppc_monitor) \
26          $(sim_ppc_model) $(sim_ppc_default_model) $(sim_ppc_model_issue) \
27          $(sim_ppc_switch)
28AM_CPPFLAGS_%C%_options.o = '-DOPCODE_RULES="$(IGEN_OPCODE_RULES)"' '-DIGEN_FLAGS="$(ppc_IGEN_FLAGS)"'
29
30%C%_libsim_a_SOURCES = \
31          $(common_libcommon_a_SOURCES)
32%C%_libsim_a_LIBADD = \
33          %D%/debug.o \
34          %D%/bits.o \
35          %D%/sim-endian.o \
36          %D%/os_emul.o \
37          %D%/emul_generic.o \
38          %D%/emul_bugapi.o \
39          %D%/emul_chirp.o \
40          %D%/emul_netbsd.o \
41          %D%/emul_unix.o \
42          %D%/registers.o \
43          %D%/vm.o \
44          %D%/corefile.o \
45          %D%/model.o \
46          %D%/spreg.o \
47          %D%/cpu.o \
48          %D%/interrupts.o \
49          %D%/events.o \
50          %D%/cap.o \
51          %D%/device.o \
52          %D%/tree.o \
53          %D%/device_table.o \
54          %D%/itable.o \
55          %D%/mon.o \
56          %D%/icache.o \
57          %D%/semantics.o \
58          %D%/idecode.o \
59          %D%/support.o \
60          %D%/sim-fpu.o \
61          %D%/psim.o \
62          %D%/pk_disklabel.o \
63          $(patsubst %,%D%/%,$(sim_ppc_hw_obj)) \
64          %D%/options.o \
65          %D%/gdb-sim.o \
66          %D%/sim_calls.o
67
68noinst_LIBRARIES += %D%/libsim.a
69
70%D%/%.o: common/%.c ; $(SIM_COMPILE)
71-@am__include@ %D%/$(DEPDIR)/*.Po
72
73%C%_run_SOURCES = \
74          %D%/main.c
75%C%_run_LDADD = \
76          %D%/libsim.a \
77          $(SIM_COMMON_LIBS)
78
79noinst_PROGRAMS += %D%/run
80
81%D%/defines.h: %D%/stamp-defines ; @true
82%D%/stamp-defines: config.h Makefile
83          $(AM_V_GEN)$(SED) -n -e '/^#define HAVE_.*1$$/{ s/ 1$$/",/; s/.* HAVE_/"HAVE_/; p }' < config.h > %D%/defines.hin
84          $(AM_V_at)$(SHELL) $(srcroot)/move-if-change %D%/defines.hin %D%/defines.h
85          $(AM_V_at)touch $@
86
87BUILT_SOURCES += %D%/defines.h
88MOSTLYCLEANFILES += %D%/defines.h %D%/stamp-defines
89
90%D%/spreg.c: @MAINT@ %D%/ppc-spr-table %D%/spreg-gen.py %D%/$(am__dirstamp)
91          $(AM_V_GEN)$(srcdir)/%D%/spreg-gen.py --source $@.tmp
92          $(AM_V_at)$(SHELL) $(srcroot)/move-if-change $@.tmp $(srcdir)/%D%/spreg.c
93          $(AM_V_at)touch $(srcdir)/%D%/spreg.c
94
95%D%/spreg.h: @MAINT@ %D%/ppc-spr-table %D%/spreg-gen.py %D%/$(am__dirstamp)
96          $(AM_V_GEN)$(srcdir)/%D%/spreg-gen.py --header $@.tmp
97          $(AM_V_at)$(SHELL) $(srcroot)/move-if-change $@.tmp $(srcdir)/%D%/spreg.h
98          $(AM_V_at)touch $(srcdir)/%D%/spreg.h
99
100EXTRA_LIBRARIES += %D%/libigen.a
101%C%_libigen_a_SOURCES = \
102          %D%/table.c \
103          %D%/lf-ppc.c \
104          %D%/dumpf.c \
105          %D%/ld-decode.c \
106          %D%/ld-cache.c \
107          %D%/filter-ppc.c \
108          %D%/ld-insn.c \
109          %D%/gen-model.c \
110          %D%/gen-itable.c \
111          %D%/gen-icache.c \
112          %D%/gen-semantics.c \
113          %D%/gen-idecode.c \
114          %D%/gen-support.c
115%C%_libigen_a_LIBADD = \
116          igen/filter.o \
117          igen/filter_host.o \
118          igen/lf.o \
119          igen/misc.o
120
121%C%_igen_SOURCES = %D%/igen.c
122%C%_igen_LDADD = %D%/libigen.a
123
124# igen leaks memory, and therefore makes AddressSanitizer unhappy.  Disable
125# leak detection while running it.
126PPC_IGEN = %D%/igen$(EXEEXT)
127PPC_IGEN_RUN = ASAN_OPTIONS=detect_leaks=0 $(PPC_IGEN) $(%C%_IGEN_FLAGS)
128
129%C%_IGEN_FLAGS = \
130          @sim_ppc_decode_mechanism@ \
131          @sim_ppc_dup@ \
132          @sim_ppc_jump@ \
133          @sim_ppc_filter@ \
134          @sim_ppc_icache@ \
135          @sim_ppc_igen_smp@ \
136          @sim_ppc_line_nr@
137
138## List all generated headers to help Automake dependency tracking.
139BUILT_SOURCES += \
140          %D%/icache.h \
141          %D%/idecode.h \
142          %D%/semantics.h \
143          %D%/model.h \
144          %D%/support.h \
145          %D%/itable.h
146%C%_BUILT_SRC_FROM_IGEN = \
147          %D%/icache.h \
148          %D%/icache.c \
149          %D%/idecode.h \
150          %D%/idecode.c \
151          %D%/semantics.h \
152          %D%/semantics.c \
153          %D%/model.h \
154          %D%/model.c \
155          %D%/support.h \
156          %D%/support.c \
157          %D%/itable.h \
158          %D%/itable.c
159%C%_BUILD_OUTPUTS = \
160          $(%C%_BUILT_SRC_FROM_IGEN) \
161          %D%/stamp-igen
162
163$(%C%_BUILT_SRC_FROM_IGEN): %D%/stamp-igen
164
165%C%_IGEN_OPCODE_RULES = %D%/@sim_ppc_opcode@
166%D%/stamp-igen: %D%/powerpc.igen %D%/altivec.igen %D%/e500.igen $(%C%_IGEN_OPCODE_RULES) $(PPC_IGEN)
167          $(AM_V_GEN)$(PPC_IGEN_RUN) \
168                    -o $(srcdir)/$(%C%_IGEN_OPCODE_RULES) \
169                    -I $(srcdir)/%D% -i $(srcdir)/%D%/powerpc.igen \
170                    -n icache.h    -hc %D%/icache.h \
171                    -n icache.c    -c  %D%/icache.c \
172                    -n semantics.h -hs %D%/semantics.h \
173                    -n semantics.c -s  %D%/semantics.c \
174                    -n idecode.h   -hd %D%/idecode.h \
175                    -n idecode.c   -d  %D%/idecode.c \
176                    -n itable.h    -ht %D%/itable.h \
177                    -n itable.c    -t  %D%/itable.c \
178                    -n model.h     -hm %D%/model.h \
179                    -n model.c     -m  %D%/model.c \
180                    -n support.h   -hf %D%/support.h \
181                    -n support.c   -f  %D%/support.c
182          $(AM_V_at)touch $@
183
184MOSTLYCLEANFILES += $(%C%_BUILD_OUTPUTS)
185
186## These rules are copied from automake, but tweaked to use FOR_BUILD variables.
187%D%/libigen.a: $(%C%_libigen_a_OBJECTS) $(%C%_libigen_a_DEPENDENCIES) $(EXTRA_%C%_libigen_a_DEPENDENCIES) %D%/$(am__dirstamp)
188          $(AM_V_at)-rm -f $@
189          $(AM_V_AR)$(AR_FOR_BUILD) $(ARFLAGS) $@ $(%C%_libigen_a_OBJECTS) $(%C%_libigen_a_LIBADD)
190          $(AM_V_at)$(RANLIB_FOR_BUILD) $@
191
192## igen is a build-time only tool.  Override the default rules for it.
193%D%/igen$(EXEEXT): $(%C%_igen_OBJECTS) $(%C%_igen_DEPENDENCIES) %D%/$(am__dirstamp)
194          $(AM_V_CCLD)$(LINK_FOR_BUILD) $(%C%_igen_OBJECTS) $(%C%_igen_LDADD)
195
196$(%C%_libigen_a_OBJECTS) $(%C%_igen_OBJECTS): %D%/%.o: %D%/%.c
197          $(AM_V_CC)$(COMPILE_FOR_BUILD) -I$(srcdir)/igen -I$(srcdir)/%D% -c $< -o $@
198
199## Build some of the files in standalone mode for developers of igen itself.
200%D%/%-main.o: %D%/%.c
201          $(AM_V_CC)$(COMPILE_FOR_BUILD) -DMAIN -c $< -o $@
202
203%C%_ld_cache_SOURCES =
204%C%_ld_cache_LDADD = %D%/ld-cache-main.o %D%/libigen.a
205
206%C%_ld_decode_SOURCES =
207%C%_ld_decode_LDADD = %D%/ld-decode-main.o %D%/libigen.a
208
209%C%_ld_insn_SOURCES =
210%C%_ld_insn_LDADD = %D%/ld-insn-main.o %D%/libigen.a
211
212%C%_IGEN_TOOLS = \
213          $(PPC_IGEN) \
214          %D%/ld-cache \
215          %D%/ld-decode \
216          %D%/ld-insn
217EXTRA_PROGRAMS += $(%C%_IGEN_TOOLS)
218MOSTLYCLEANFILES += $(%C%_IGEN_TOOLS) %D%/libigen.a
219
220IGEN_OPCODE_RULES = @sim_ppc_opcode@
221
222## Real hardware.
223## NB: The first for loop is to remove duplicates.
224%C%_HW_SRC = $(sim_ppc_hw_src:%=%D%/%)
225%D%/hw.c %D%/hw.h: %D%/stamp-hw ; @true
226%D%/stamp-hw: Makefile $(%C%_HW_SRC) $(srcroot)/move-if-change
227          $(AM_V_GEN)\
228          f=""; \
229          for i in $(%C%_HW_SRC) ; do \
230            case " $$f " in \
231              *" $$i "*) ;; \
232              *) f="$$f $$i" ;; \
233            esac ; \
234          done ; \
235          for hw in $$f ; do echo $$hw ; done \
236          | sed -e 's/^.*\(hw_.*\)\.c/\1/' \
237                    -e 's/^/extern const device_descriptor /' \
238                    -e 's/$$/_device_descriptor\[\];/' \
239                    > %D%/hw.hin; \
240          f=""; \
241          for i in $(%C%_HW_SRC) ; do \
242            case " $$f " in \
243              *" $$i "*) ;; \
244              *) f="$$f $$i" ;; \
245            esac ; \
246          done ; \
247          for hw in $$f ; do echo $$hw ; done \
248          | sed -e 's/^.*\(hw_.*\)\.c/\1/' \
249                    -e 's/^/    /' \
250                    -e 's/$$/_device_descriptor,/' \
251                    > %D%/hw.cin
252          $(AM_V_at)$(SHELL) $(srcroot)/move-if-change %D%/hw.hin %D%/hw.h
253          $(AM_V_at)$(SHELL) $(srcroot)/move-if-change %D%/hw.cin %D%/hw.c
254          $(AM_V_at)touch $@
255
256BUILT_SOURCES += \
257          %D%/hw.h
258%C%_BUILD_OUTPUTS += \
259          %D%/hw.c \
260          %D%/hw.h \
261          %D%/stamp-hw
262%D%/hw.c %D%/hw.h: %D%/stamp-igen
263
264## Real packages
265## NB: The first for loop is to remove duplicates.
266%C%_PACKAGE_SRC = %D%/pk_disklabel.c
267$(srcdir)/%D%/pk.h: @MAINT@ %D%/stamp-pk ; @true
268%D%/stamp-pk: $(srcdir)/%D%/local.mk $(%C%_PACKAGE_SRC) $(srcroot)/move-if-change
269          $(AM_V_GEN)echo "/* Generated file by local.mk; do not edit.  */" > %D%/pk.hin; \
270          f=""; \
271          for i in $(%C%_PACKAGE_SRC) ; do \
272            case " $$f " in \
273              *" $$i "*) ;; \
274              *) f="$$f $$i" ;; \
275            esac ; \
276          done ; \
277          for pk in $$f ; do echo $$pk ; done \
278          | sed -e 's/^.*pk_\(.*\)\.c/\1/' \
279                    -e 's/^/extern package_create_instance_callback pk_/' \
280                    -e 's/$$/_create_instance;/' \
281                    >> %D%/pk.hin
282          $(AM_V_at)$(SHELL) $(srcroot)/move-if-change %D%/pk.hin $(srcdir)/%D%/pk.h
283          $(AM_V_at)touch $@
284
285%C%_BUILD_OUTPUTS += %D%/stamp-pk
286
287%C%docdir = $(docdir)/%C%
288%C%doc_DATA = %D%/BUGS %D%/INSTALL %D%/README %D%/RUN
289