[37/83] sim: modules.c: move generation to top-level

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

Commit Message

Mike Frysinger Jan. 3, 2023, 7:55 a.m. UTC
  Now that all arches create libsim.a from the top-level, we have full
access to their inputs, and can move the actual generation from the
subdir up to the top-level.  This avoids recursive makes and will
help simplify state passing between the two.
---
 sim/Makefile.in           | 28 ++++++++++++++++++++++++----
 sim/common/Make-common.in | 25 +------------------------
 sim/common/local.mk       | 28 ++++++++++++++++++++++++----
 3 files changed, 49 insertions(+), 32 deletions(-)
  

Patch

diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index f9f6ed1984c4..15242c612647 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -159,28 +159,6 @@  test-hw-events: $(srccom)/hw-events.c libsim.a
 		$(CC) $(ALL_CFLAGS) -DMAIN -o test-hw-events$(EXEEXT) \
 		$(srccom)/hw-events.c libsim.a $(EXTRA_LIBS)
 
-# See sim_pre_argv_init and sim_module_install in sim-module.c for more details.
-modules.c: stamp-modules ; @true
-stamp-modules: Makefile
-	$(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}' $^ $(GEN_MODULES_C_SRCS) | sort >$@.l-tmp
-	@set -e; (\
-	echo '/* Do not modify this file.  */'; \
-	echo '/* It is created automatically by the Makefile.  */'; \
-	echo '#include "libiberty.h"'; \
-	echo '#include "sim-module.h"'; \
-	sed -e 's:\(.*\):extern MODULE_INIT_FN \1;:' $@.l-tmp; \
-	echo 'MODULE_INSTALL_FN * const sim_modules_detected[] = {'; \
-	sed -e 's:\(.*\):  \1,:' $@.l-tmp; \
-	echo '};'; \
-	echo 'const int sim_modules_detected_len = ARRAY_SIZE (sim_modules_detected);'; \
-	) >$@.tmp
-	$(SILENCE) $(SHELL) $(srcroot)/move-if-change $@.tmp modules.c
-	$(SILENCE) rm -f $@.l-tmp $@.tmp
-	$(SILENCE) touch $@
-
 # Support targets.
 
 install:
@@ -214,8 +192,7 @@  TAGS: force
 		*.[ch] ../common/*.[ch]
 
 mostlyclean clean: $(SIM_EXTRA_CLEAN)
-	rm -f *.[oa] *~ core \
-		modules.c stamp-modules
+	rm -f *.[oa] *~ core
 
 distclean maintainer-clean realclean: clean
 	rm -f TAGS Makefile
diff --git a/sim/common/local.mk b/sim/common/local.mk
index 128b770dbe10..debb55da933b 100644
--- a/sim/common/local.mk
+++ b/sim/common/local.mk
@@ -135,10 +135,30 @@  SIM_ALL_RECURSIVE_DEPS += $(%C%_HW_CONFIG_H_TARGETS)
 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)
+		$(patsubst %,$(srcdir)/%,$($(am_arch_d)_libsim_a_SOURCES)) \
+		$(patsubst %.o,$(srcdir)/%.c,$($(am_arch_d)_libsim_a_OBJECTS) $($(am_arch_d)_libsim_a_LIBADD)) \
+		$(filter-out %.o,$(patsubst $(@D)/%.o,$(srcdir)/common/%.c,$($(am_arch_d)_libsim_a_LIBADD))))
+%/modules.c: %/stamp-modules ; @true
+%/stamp-modules: Makefile
+	$(AM_V_GEN)set -e; \
+	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}' $(GEN_MODULES_C_SRCS) | sort >$@.l-tmp; \
+	( \
+	echo '/* Do not modify this file.  */'; \
+	echo '/* It is created automatically by the Makefile.  */'; \
+	echo '#include "libiberty.h"'; \
+	echo '#include "sim-module.h"'; \
+	sed -e 's:\(.*\):extern MODULE_INIT_FN \1;:' $@.l-tmp; \
+	echo 'MODULE_INSTALL_FN * const sim_modules_detected[] = {'; \
+	sed -e 's:\(.*\):  \1,:' $@.l-tmp; \
+	echo '};'; \
+	echo 'const int sim_modules_detected_len = ARRAY_SIZE (sim_modules_detected);'; \
+	) >$@.tmp; \
+	$(SHELL) $(srcroot)/move-if-change $@.tmp $(@D)/modules.c; \
+	rm -f $@.l-tmp; \
+	touch $@
+.PRECIOUS: %/stamp-modules
 
 ## 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)))