[02/83] sim: modules: trigger generation from top-level

Message ID 20230103075605.13606-3-vapier@gentoo.org
State Committed
Headers
Series sim: merge subdir makefiles into top-level |

Commit Message

Mike Frysinger Jan. 3, 2023, 7:54 a.m. UTC
  Add rules for tracking generated subdir modules.c files.  This doesn't
actually generate the file from the top-level, but allows us to add
rules that need to be ordered wrt it.  Once those changes land, we can
rework this to actually generate from the top-level.

This currently builds off of the objects that go into the libsim.a as
we don't build those from the top-level either.  Once we migrate that
up, we can switch this to the source files directly.  It's a bit hacky
overall, but makes it easier to migrate things in smaller chunks, and
we aren't going to keep this logic long term.
---
 sim/Makefile.in           | 41 ++++++++++++++++++++++++++++++++-------
 sim/bpf/local.mk          |  1 +
 sim/common/Make-common.in |  5 ++---
 sim/common/local.mk       | 16 +++++++++++++++
 sim/cr16/local.mk         |  1 +
 sim/cris/local.mk         |  1 +
 sim/d10v/local.mk         |  1 +
 sim/frv/local.mk          |  1 +
 sim/iq2000/local.mk       |  1 +
 sim/lm32/local.mk         |  1 +
 sim/m32c/local.mk         |  1 +
 sim/m32r/local.mk         |  1 +
 sim/m68hc11/local.mk      |  1 +
 sim/mips/local.mk         |  1 +
 sim/mn10300/local.mk      |  1 +
 sim/or1k/local.mk         |  1 +
 sim/sh/local.mk           |  1 +
 sim/v850/local.mk         |  1 +
 18 files changed, 67 insertions(+), 10 deletions(-)
  

Patch

diff --git a/sim/bpf/local.mk b/sim/bpf/local.mk
index 4ba1f461303c..f86f3306a8a9 100644
--- a/sim/bpf/local.mk
+++ b/sim/bpf/local.mk
@@ -35,6 +35,7 @@  BUILT_SOURCES += \
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %D%/mloop-le.c %D%/eng-le.h: %D%/stamp-mloop-le ; @true
 %D%/stamp-mloop-le: $(srccom)/genmloop.sh %D%/mloop.in
diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index 35477d94bb8e..b56a49a0051f 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -186,8 +186,7 @@  endif
 
 all_object_files = $(LIB_OBJS) $(SIM_RUN_OBJS)
 generated_files = \
-	$(SIM_EXTRA_DEPS) \
-	modules.c
+	$(SIM_EXTRA_DEPS)
 
 # Ensure that generated files are created early.  Use order-only
 # dependencies if available.  They require GNU make 3.80 or newer,
@@ -212,7 +211,7 @@  stamp-modules: Makefile $(SIM_OBJS:.o=.c)
 	$(ECHO_STAMP) modules.c
 	$(SILENCE) LANG=C ; export LANG ; \
 	LC_ALL=C ; export LC_ALL ; \
-	sed -n -e '/^sim_install_/{s/^\(sim_install_[a-z_0-9A-Z]*\).*/\1/;p}' $^ | sort >$@.l-tmp
+	sed -n -e '/^sim_install_/{s/^\(sim_install_[a-z_0-9A-Z]*\).*/\1/;p}' $^ $(GEN_MODULES_C_SRCS) | sort >$@.l-tmp
 	@set -e; (\
 	echo '/* Do not modify this file.  */'; \
 	echo '/* It is created automatically by the Makefile.  */'; \
diff --git a/sim/common/local.mk b/sim/common/local.mk
index dd6ed5fec83c..128b770dbe10 100644
--- a/sim/common/local.mk
+++ b/sim/common/local.mk
@@ -130,6 +130,22 @@  endif
 MOSTLYCLEANFILES += $(%C%_HW_CONFIG_H_TARGETS) $(patsubst %,%/stamp-hw,$(SIM_ENABLED_ARCHES))
 SIM_ALL_RECURSIVE_DEPS += $(%C%_HW_CONFIG_H_TARGETS)
 
+## See sim_pre_argv_init and sim_module_install in sim-module.c for more details.
+## TODO: Switch this to xxx_SOURCES once projects build objects in local.mk.
+am_arch_d = $(subst -,_,$(@D))
+GEN_MODULES_C_SRCS = \
+	$(wildcard \
+		$(patsubst %.o,$(abs_srcdir)/%.c,$($(am_arch_d)_libsim_a_OBJECTS) $($(am_arch_d)_libsim_a_LIBADD)) \
+		$(filter-out %.o,$(patsubst $(@D)/%.o,$(abs_srcdir)/common/%.c,$($(am_arch_d)_libsim_a_LIBADD))))
+%/modules.c:
+	$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) GEN_MODULES_C_SRCS="$(GEN_MODULES_C_SRCS)" -C $(@D) $(@F)
+
+## NB: The ppc port doesn't currently utilize the modules API, so skip it.
+%C%_GEN_MODULES_C_TARGETS = $(patsubst %,%/modules.c,$(filter-out ppc,$(SIM_ENABLED_ARCHES)))
+MOSTLYCLEANFILES += $(%C%_GEN_MODULES_C_TARGETS) $(patsubst %,%/stamp-modules,$(SIM_ENABLED_ARCHES))
+## TODO: Drop this once each port's local.mk:libsim.a depends on it themself.
+SIM_ALL_RECURSIVE_DEPS += $(%C%_GEN_MODULES_C_TARGETS)
+
 LIBIBERTY_LIB = ../libiberty/libiberty.a
 BFD_LIB = ../bfd/libbfd.la
 OPCODES_LIB = ../opcodes/libopcodes.la
diff --git a/sim/cr16/local.mk b/sim/cr16/local.mk
index f5401f6d5f93..8e28cc356f58 100644
--- a/sim/cr16/local.mk
+++ b/sim/cr16/local.mk
@@ -32,6 +32,7 @@  BUILT_SOURCES += %D%/simops.h
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_gencode_SOURCES = %D%/gencode.c
 %C%_gencode_LDADD = %D%/cr16-opc.o
diff --git a/sim/cris/local.mk b/sim/cris/local.mk
index 0e56fefa960c..d55e7b84e25b 100644
--- a/sim/cris/local.mk
+++ b/sim/cris/local.mk
@@ -46,6 +46,7 @@  BUILT_SOURCES += \
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 ## FIXME: What is mono and what does "Use of `mono' is wip" mean (other
 ## than the apparent; some "mono" feature is work in progress)?
diff --git a/sim/d10v/local.mk b/sim/d10v/local.mk
index 38a3c9263d62..2556845ed1d1 100644
--- a/sim/d10v/local.mk
+++ b/sim/d10v/local.mk
@@ -32,6 +32,7 @@  BUILT_SOURCES += %D%/simops.h
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_gencode_SOURCES = %D%/gencode.c
 %C%_gencode_LDADD = %D%/d10v-opc.o
diff --git a/sim/frv/local.mk b/sim/frv/local.mk
index 11db636a7159..471b0adc6533 100644
--- a/sim/frv/local.mk
+++ b/sim/frv/local.mk
@@ -35,6 +35,7 @@  BUILT_SOURCES += %D%/eng.h
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 ## FIXME: Use of `mono' is wip.
 %D%/mloop.c %D%/eng.h: %D%/stamp-mloop ; @true
diff --git a/sim/iq2000/local.mk b/sim/iq2000/local.mk
index 881cf2c55dcd..4113b4bc2f39 100644
--- a/sim/iq2000/local.mk
+++ b/sim/iq2000/local.mk
@@ -32,6 +32,7 @@  BUILT_SOURCES += %D%/eng.h
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 ## FIXME: Use of `mono' is wip.
 %D%/mloop.c %D%/eng.h: %D%/stamp-mloop ; @true
diff --git a/sim/lm32/local.mk b/sim/lm32/local.mk
index 3f9606410d62..311de7df47e8 100644
--- a/sim/lm32/local.mk
+++ b/sim/lm32/local.mk
@@ -35,6 +35,7 @@  BUILT_SOURCES += %D%/eng.h
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 ## FIXME: Use of `mono' is wip.
 %D%/mloop.c %D%/eng.h: %D%/stamp-mloop ; @true
diff --git a/sim/m32c/local.mk b/sim/m32c/local.mk
index 1a542f186553..75909075a1e3 100644
--- a/sim/m32c/local.mk
+++ b/sim/m32c/local.mk
@@ -35,6 +35,7 @@  noinst_PROGRAMS += %D%/run
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_opc2c_SOURCES = %D%/opc2c.c
 
diff --git a/sim/m32r/local.mk b/sim/m32r/local.mk
index 4f9f2bc257dc..9814ae5c6c16 100644
--- a/sim/m32r/local.mk
+++ b/sim/m32r/local.mk
@@ -42,6 +42,7 @@  BUILT_SOURCES += \
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 ## FIXME: Use of `mono' is wip.
 %D%/mloop.c %D%/eng.h: %D%/stamp-mloop ; @true
diff --git a/sim/m68hc11/local.mk b/sim/m68hc11/local.mk
index 187bd389cefe..d2e04576a771 100644
--- a/sim/m68hc11/local.mk
+++ b/sim/m68hc11/local.mk
@@ -34,6 +34,7 @@  AM_MAKEFLAGS += %C%_SIM_EXTRA_HW_DEVICES="$(%C%_SIM_EXTRA_HW_DEVICES)"
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_gencode_SOURCES = %D%/gencode.c
 
diff --git a/sim/mips/local.mk b/sim/mips/local.mk
index 9db960ca4beb..5a7b12c29a1e 100644
--- a/sim/mips/local.mk
+++ b/sim/mips/local.mk
@@ -96,6 +96,7 @@  endif
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 $(%C%_BUILT_SRC_FROM_IGEN_ITABLE): %D%/stamp-igen-itable
 $(%C%_BUILT_SRC_FROM_GEN_MODE_SINGLE): %D%/stamp-gen-mode-single
diff --git a/sim/mn10300/local.mk b/sim/mn10300/local.mk
index afb1df75f2ef..d24e6b8d0405 100644
--- a/sim/mn10300/local.mk
+++ b/sim/mn10300/local.mk
@@ -58,6 +58,7 @@  BUILT_SOURCES += \
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 $(%C%_BUILT_SRC_FROM_IGEN): %D%/stamp-igen
 
diff --git a/sim/or1k/local.mk b/sim/or1k/local.mk
index ef8ae2a6abcb..7d999f6f3aa4 100644
--- a/sim/or1k/local.mk
+++ b/sim/or1k/local.mk
@@ -34,6 +34,7 @@  BUILT_SOURCES += %D%/eng.h
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 ## FIXME: Use of `mono' is wip.
 %D%/mloop.c %D%/eng.h: %D%/stamp-mloop ; @true
diff --git a/sim/sh/local.mk b/sim/sh/local.mk
index 8c2ce0da1499..c25ab536c681 100644
--- a/sim/sh/local.mk
+++ b/sim/sh/local.mk
@@ -36,6 +36,7 @@  BUILT_SOURCES += \
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_gencode_SOURCES = %D%/gencode.c
 
diff --git a/sim/v850/local.mk b/sim/v850/local.mk
index 4741e070a300..2c27d0c6d7ea 100644
--- a/sim/v850/local.mk
+++ b/sim/v850/local.mk
@@ -55,6 +55,7 @@  BUILT_SOURCES += \
 
 ## This makes sure build tools are available before building the arch-subdirs.
 SIM_ALL_RECURSIVE_DEPS += $(%C%_BUILD_OUTPUTS)
+%D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 $(%C%_BUILT_SRC_FROM_IGEN): %D%/stamp-igen