]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sim: modules.c: move generation to top-level
authorMike Frysinger <vapier@gentoo.org>
Sun, 6 Nov 2022 09:56:39 +0000 (16:56 +0700)
committerMike Frysinger <vapier@gentoo.org>
Thu, 10 Nov 2022 18:44:16 +0000 (01:44 +0700)
In order to compile arch objects from the top-level, we need to
generate the modules.c file, so move that logic up to the top
level first.  The deps are a bit imperfect currently due to the
common/ files not being shared.  That'll improve as we share the
sources more.

sim/aarch64/local.mk
sim/common/Make-common.in
sim/common/local.mk

index bbcf5920723193f8b7545a546b06bf0beb149989..62095f7ce2cd0b5bdcfafdf0d61e57bbc18e7eaa 100644 (file)
@@ -47,6 +47,5 @@ $(%C%_libsim_a_OBJECTS) $(%C%_run_OBJECTS) $(%C%_libsim_a_LIBADD): | $(SIM_ALL_R
 %D%/%.o: common/%.c | $(SIM_ALL_RECURSIVE_DEPS)
        $(AM_V_CC)$(COMPILE) -c -o $@ $<
 
-# See sim_pre_argv_init and sim_module_install in sim-module.c for more details.
-#%D%/modules.c: %D%/stamp-modules ; @true
-#%D%/stamp-modules: Makefile $(%C%_libsim_a_SOURCES) ; $(DO_MODULES_C)
+%D%/modules.c: %D%/stamp-modules ; @true
+%D%/stamp-modules: Makefile $(%C%_libsim_a_SOURCES) ; $(GEN_MODULES_C)
index 1b32841f0bf3ff48d9760fef5e5e33efc851d597..96dd6deccc510dd9e5fa711dcfcf6489e40b8d5f 100644 (file)
@@ -196,9 +196,7 @@ override POSTCOMPILE =
 endif
 
 all_object_files = $(LIB_OBJS) $(SIM_RUN_OBJS)
-generated_files = \
-       $(SIM_EXTRA_DEPS) \
-       modules.c
+generated_files = $(SIM_EXTRA_DEPS)
 
 # Ensure that generated files are created early.  Use order-only
 # dependencies if available.  They require GNU make 3.80 or newer,
@@ -217,28 +215,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 $(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
-       @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:
@@ -274,7 +250,6 @@ TAGS: force
 mostlyclean clean: $(SIM_EXTRA_CLEAN)
        rm -f *.[oa] *~ core \
                run$(EXEEXT) libsim.a \
-               modules.c stamp-modules \
                tmp-mloop.hin tmp-mloop.h tmp-mloop.cin tmp-mloop.c
 
 distclean maintainer-clean realclean: clean $(SIM_EXTRA_DISTCLEAN)
index 29b1970865420f8dd54a004b64d1ff5037a827ea..07ca04b083ea97d0175ee14f26f1085cb842d631 100644 (file)
@@ -51,9 +51,6 @@ noinst_LIBRARIES += $(SIM_COMMON_LIB)
 CLEANFILES += \
        %D%/version.c %D%/version.c-stamp
 
-%/modules.c:
-       $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
-
 ##
 ## For subdirs.
 ##
@@ -133,6 +130,34 @@ 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.
+GEN_MODULES_C_SRCS = \
+       $(wildcard \
+               $(patsubst %.o,$(srcdir)/%.c,$($(@D)_libsim_a_OBJECTS) $($(@D)_libsim_a_LIBADD)) \
+               $(patsubst $(@D)/%.o,$(srcdir)/common/%.c,$($(@D)_libsim_a_LIBADD)))
+GEN_MODULES_C = \
+       $(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 $@
+GEN_MODULES_C_TARGETS = $(patsubst %,%/modules.c,$(SIM_SUBDIRS))
+MOSTLYCLEANFILES += $(GEN_MODULES_C_TARGETS) $(patsubst %,%/stamp-moules,$(SIM_SUBDIRS))
+SIM_ALL_RECURSIVE_DEPS += $(GEN_MODULES_C_TARGETS)
+
 LIBIBERTY_LIB = ../libiberty/libiberty.a
 BFD_LIB = ../bfd/libbfd.la
 OPCODES_LIB = ../opcodes/libopcodes.la