[3/3] sim: run: move linking into top-level

Message ID 20221105082727.32094-3-vapier@gentoo.org
State Committed
Headers
Series [1/3] sim: build: move install steps to the top-level |

Commit Message

Mike Frysinger Nov. 5, 2022, 8:27 a.m. UTC
  Automake will run each subdir individually before moving on to the next
one.  This means that the linking phase, a single threaded process, will
not run in parallel with anything else.  When we have to link ~32 ports,
that's 32 link steps that don't take advantage of parallel systems.  On
my really old 4-core system, this cuts a multi-target build from ~60 sec
to ~30 sec.  We eventually want to move all compile+link steps to this
common dir anyways, so might as well move linking now for a nice speedup.

We use noinst_PROGRAMS instead of bin_PROGRAMS because we're taking care
of the install ourselves rather than letting automake process it.
---
 sim/Makefile.am              |  50 ++
 sim/Makefile.in              | 939 +++++++++++++++++++++++++++++++----
 sim/aarch64/local.mk         |  25 +
 sim/arm/local.mk             |   9 +
 sim/avr/local.mk             |  24 +
 sim/bfin/local.mk            |  25 +
 sim/bpf/local.mk             |   8 +
 sim/common/Make-common.in    |   7 +-
 sim/common/local.mk          |  19 +-
 sim/configure                |  18 +-
 sim/configure.ac             |   1 +
 sim/cr16/local.mk            |   8 +
 sim/cris/local.mk            |   8 +
 sim/d10v/local.mk            |   8 +
 sim/erc32/Makefile.in        |   9 -
 sim/erc32/local.mk           |  17 +
 sim/example-synacor/local.mk |  25 +
 sim/frv/local.mk             |   8 +
 sim/ft32/local.mk            |  25 +
 sim/h8300/local.mk           |  25 +
 sim/iq2000/local.mk          |   8 +
 sim/lm32/local.mk            |   8 +
 sim/m32c/local.mk            |  12 +
 sim/m32r/local.mk            |   8 +
 sim/m68hc11/local.mk         |   8 +
 sim/mcore/local.mk           |  25 +
 sim/microblaze/local.mk      |  25 +
 sim/mips/local.mk            |  25 +
 sim/mn10300/local.mk         |   8 +
 sim/moxie/local.mk           |  18 +-
 sim/msp430/local.mk          |  25 +
 sim/or1k/local.mk            |   8 +
 sim/ppc/Makefile.in          |  16 +-
 sim/ppc/local.mk             |  15 +
 sim/pru/local.mk             |  25 +
 sim/riscv/local.mk           |  25 +
 sim/rl78/local.mk            |  29 ++
 sim/rx/local.mk              |  13 +
 sim/sh/local.mk              |   8 +
 sim/v850/local.mk            |   8 +
 40 files changed, 1449 insertions(+), 126 deletions(-)
 create mode 100644 sim/aarch64/local.mk
 create mode 100644 sim/avr/local.mk
 create mode 100644 sim/bfin/local.mk
 create mode 100644 sim/example-synacor/local.mk
 create mode 100644 sim/ft32/local.mk
 create mode 100644 sim/h8300/local.mk
 create mode 100644 sim/mcore/local.mk
 create mode 100644 sim/microblaze/local.mk
 create mode 100644 sim/mips/local.mk
 create mode 100644 sim/msp430/local.mk
 create mode 100644 sim/pru/local.mk
 create mode 100644 sim/riscv/local.mk
 create mode 100644 sim/rl78/local.mk
  

Patch

diff --git a/sim/Makefile.am b/sim/Makefile.am
index 4e4068a3539f..64847bc7abb3 100644
--- a/sim/Makefile.am
+++ b/sim/Makefile.am
@@ -33,6 +33,7 @@  AM_MAKEFLAGS = SIM_PRIMARY_TARGET=$(SIM_PRIMARY_TARGET)
 ## be used consistently in local.mk files we include below.
 pkginclude_HEADERS =
 check_PROGRAMS =
+noinst_PROGRAMS =
 noinst_LIBRARIES =
 EXTRA_PROGRAMS =
 
@@ -85,9 +86,19 @@  include igen/local.mk
 endif
 include testsuite/local.mk
 
+## Arch includes must come after common/local.mk.
+if SIM_ENABLE_ARCH_aarch64
+include aarch64/local.mk
+endif
 if SIM_ENABLE_ARCH_arm
 include arm/local.mk
 endif
+if SIM_ENABLE_ARCH_avr
+include avr/local.mk
+endif
+if SIM_ENABLE_ARCH_bfin
+include bfin/local.mk
+endif
 if SIM_ENABLE_ARCH_bpf
 include bpf/local.mk
 endif
@@ -103,9 +114,18 @@  endif
 if SIM_ENABLE_ARCH_erc32
 include erc32/local.mk
 endif
+if SIM_ENABLE_ARCH_examples
+include example-synacor/local.mk
+endif
 if SIM_ENABLE_ARCH_frv
 include frv/local.mk
 endif
+if SIM_ENABLE_ARCH_ft32
+include ft32/local.mk
+endif
+if SIM_ENABLE_ARCH_h8300
+include h8300/local.mk
+endif
 if SIM_ENABLE_ARCH_iq2000
 include iq2000/local.mk
 endif
@@ -121,18 +141,39 @@  endif
 if SIM_ENABLE_ARCH_m68hc11
 include m68hc11/local.mk
 endif
+if SIM_ENABLE_ARCH_mcore
+include mcore/local.mk
+endif
+if SIM_ENABLE_ARCH_microblaze
+include microblaze/local.mk
+endif
+if SIM_ENABLE_ARCH_mips
+include mips/local.mk
+endif
 if SIM_ENABLE_ARCH_mn10300
 include mn10300/local.mk
 endif
 if SIM_ENABLE_ARCH_moxie
 include moxie/local.mk
 endif
+if SIM_ENABLE_ARCH_msp430
+include msp430/local.mk
+endif
 if SIM_ENABLE_ARCH_or1k
 include or1k/local.mk
 endif
 if SIM_ENABLE_ARCH_ppc
 include ppc/local.mk
 endif
+if SIM_ENABLE_ARCH_pru
+include pru/local.mk
+endif
+if SIM_ENABLE_ARCH_riscv
+include riscv/local.mk
+endif
+if SIM_ENABLE_ARCH_rl78
+include rl78/local.mk
+endif
 if SIM_ENABLE_ARCH_rx
 include rx/local.mk
 endif
@@ -143,6 +184,15 @@  if SIM_ENABLE_ARCH_v850
 include v850/local.mk
 endif
 
+## Helper targets for running make from the top-level when some subdirs still
+## have Makefiles in subdirs.
+
+%/libsim.a: | $(SIM_ALL_RECURSIVE_DEPS)
+	$(MAKE) -C $(@D) $(@F)
+
+%/nrun.o: common/nrun.c | %/libsim.a $(SIM_ALL_RECURSIVE_DEPS)
+	$(MAKE) -C $(@D) $(@F)
+
 all-recursive: $(SIM_ALL_RECURSIVE_DEPS)
 
 install-data-local: installdirs $(SIM_INSTALL_DATA_LOCAL_DEPS)
diff --git a/sim/aarch64/local.mk b/sim/aarch64/local.mk
new file mode 100644
index 000000000000..7e5a53797d24
--- /dev/null
+++ b/sim/aarch64/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 2015-2022 Free Software Foundation, Inc.
+## Contributed by Red Hat.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/arm/local.mk b/sim/arm/local.mk
index 84dfbdfa5367..99790c6e4e42 100644
--- a/sim/arm/local.mk
+++ b/sim/arm/local.mk
@@ -1,6 +1,7 @@ 
 ## See sim/Makefile.am
 ##
 ## Copyright (C) 1995-2022 Free Software Foundation, Inc.
+## Written by Cygnus Support.
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -15,5 +16,13 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%docdir = $(docdir)/%C%
 %C%doc_DATA = %D%/README
diff --git a/sim/avr/local.mk b/sim/avr/local.mk
new file mode 100644
index 000000000000..7da400616a09
--- /dev/null
+++ b/sim/avr/local.mk
@@ -0,0 +1,24 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 2009-2022 Free Software Foundation, Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/bfin/local.mk b/sim/bfin/local.mk
new file mode 100644
index 000000000000..f61c917d7121
--- /dev/null
+++ b/sim/bfin/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 2005-2022 Free Software Foundation, Inc.
+## Written by Analog Devices, Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/bpf/local.mk b/sim/bpf/local.mk
index 9b096baf3adf..b855db359691 100644
--- a/sim/bpf/local.mk
+++ b/sim/bpf/local.mk
@@ -15,6 +15,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILD_OUTPUTS = \
 	%D%/eng-le.h \
 	%D%/mloop-le.c \
diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index 290fa2c171d9..66f5f724f55b 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -223,18 +223,13 @@  LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@
 
 RUNTESTFLAGS =
 
-all: libsim.a run$(EXEEXT)
+all: libsim.a $(SIM_RUN_OBJS)
 
 libsim.a: $(LIB_OBJS)
 	$(SILENCE) rm -f libsim.a
 	$(ECHO_AR) $(AR) $(AR_FLAGS) libsim.a $(LIB_OBJS)
 	$(ECHO_RANLIB) $(RANLIB) libsim.a
 
-run$(EXEEXT): $(SIM_RUN_OBJS) libsim.a $(LIBDEPS)
-	$(ECHO_CCLD) $(LIBTOOL) $(AM_V_lt) --tag=CC --mode=link \
-	  $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o run$(EXEEXT) \
-	  $(SIM_RUN_OBJS) libsim.a $(EXTRA_LIBS)
-
 #
 # Dependency tracking.  Most of this is conditional on GNU Make being
 # found by configure; if GNU Make is not found, we fall back to a
diff --git a/sim/common/local.mk b/sim/common/local.mk
index 5afae9141e54..fb03bb966e03 100644
--- a/sim/common/local.mk
+++ b/sim/common/local.mk
@@ -30,7 +30,8 @@  SIM_ALL_RECURSIVE_DEPS += \
 
 ## NB: libcommon.a isn't used directly by ports.  We need a target for common
 ## objects to be a part of, and ports use the individual objects directly.
-noinst_LIBRARIES += %D%/libcommon.a
+SIM_COMMON_LIB = %D%/libcommon.a
+noinst_LIBRARIES += $(SIM_COMMON_LIB)
 %C%_libcommon_a_SOURCES = \
 	%D%/callback.c \
 	%D%/portability.c \
@@ -50,3 +51,19 @@  noinst_LIBRARIES += %D%/libcommon.a
 
 CLEANFILES += \
 	%D%/version.c %D%/version.c-stamp
+
+#
+# For subdirs.
+#
+
+LIBIBERTY_LIB = ../libiberty/libiberty.a
+BFD_LIB = ../bfd/libbfd.la
+OPCODES_LIB = ../opcodes/libopcodes.la
+
+SIM_COMMON_LIBS = \
+	$(SIM_COMMON_LIB) \
+	$(BFD_LIB) \
+	$(OPCODES_LIB) \
+	$(LIBIBERTY_LIB) \
+	$(LIBGNU) \
+	$(LIBGNU_EXTRA_LIBS)
diff --git a/sim/configure.ac b/sim/configure.ac
index 30479aebc491..135aa2198cfd 100644
--- a/sim/configure.ac
+++ b/sim/configure.ac
@@ -156,6 +156,7 @@  if test "${enable_sim}" != no; then
     SIM_AC_TOOLCHAIN_FOR_TARGET(example-synacor)
     SIM_BUILD_TARGET([example-synacor])
   fi
+  AM_CONDITIONAL([SIM_ENABLE_ARCH_examples], [test "${enable_example_sims}" = "yes"])
 fi
 AM_CONDITIONAL([SIM_ENABLE_IGEN], [test "$sim_igen" = "yes"])
 AM_CONDITIONAL([ENABLE_SIM], [test -n "$SIM_SUBDIRS"])
diff --git a/sim/cr16/local.mk b/sim/cr16/local.mk
index f84a618889c4..a318bd4199b8 100644
--- a/sim/cr16/local.mk
+++ b/sim/cr16/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILD_OUTPUTS = \
 	%D%/gencode$(EXEEXT) \
 	%D%/simops.h \
diff --git a/sim/cris/local.mk b/sim/cris/local.mk
index 62a3f8e80abf..0a3423c33897 100644
--- a/sim/cris/local.mk
+++ b/sim/cris/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 ## rvdummy is just used for testing -- it runs on the same host as `run`.
 ## It does nothing if --enable-sim-hardware isn't active.
 %C%_rvdummy_SOURCES = %D%/rvdummy.c
diff --git a/sim/d10v/local.mk b/sim/d10v/local.mk
index f72bc145c906..4edd2e90d286 100644
--- a/sim/d10v/local.mk
+++ b/sim/d10v/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILD_OUTPUTS = \
 	%D%/gencode$(EXEEXT) \
 	%D%/simops.h \
diff --git a/sim/erc32/Makefile.in b/sim/erc32/Makefile.in
index eef81d9dcd6e..6675fceccf3d 100644
--- a/sim/erc32/Makefile.in
+++ b/sim/erc32/Makefile.in
@@ -24,7 +24,6 @@  SIM_OBJS = exec.o erc32.o func.o help.o float.o interf.o
 SIM_RUN_OBJS = sis.o
 SIM_EXTRA_CFLAGS = $(READLINE_CFLAGS)
 SIM_EXTRA_LIBS = $(READLINE_LIB) $(TERMCAP_LIB)
-SIM_EXTRA_CLEAN = clean-sis
 
 # UARTS run at about 115200 baud (simulator time). Add -DFAST_UART to
 # CFLAGS if faster (infinite) UART speed is desired. Might affect the
@@ -32,11 +31,3 @@  SIM_EXTRA_CLEAN = clean-sis
 SIM_EXTRA_CFLAGS += -DFAST_UART -I$(srcroot)
 
 ## COMMON_POST_CONFIG_FRAG
-
-all: sis$(EXEEXT)
-sis$(EXEEXT): run$(EXEEXT)
-	$(SILENCE) rm -f $@
-	$(ECHO_GEN) ln $< $@ 2>/dev/null || $(LN_S) $< $@ 2>/dev/null || cp -p $< $@
-
-clean-sis:
-	rm -f sis
diff --git a/sim/erc32/local.mk b/sim/erc32/local.mk
index 36baeb96614c..d73bc5b4bfef 100644
--- a/sim/erc32/local.mk
+++ b/sim/erc32/local.mk
@@ -1,6 +1,8 @@ 
 ## See sim/Makefile.am
 ##
 ## Copyright (C) 1993-2022 Free Software Foundation, Inc.
+## Written by Cygnus Support
+## Modified by J.Gaisler ESA/ESTEC
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -15,6 +17,21 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/sis.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS) $(READLINE_LIB) $(TERMCAP_LIB)
+
+%D%/sis$(EXEEXT): %D%/run$(EXEEXT)
+	$(AM_V_GEN)ln $< $@ 2>/dev/null || $(LN_S) $< $@ 2>/dev/null || cp -p $< $@
+
+## Helper targets for running make from the top-level due to run's sis.o.
+%D%/%.o: %D%/%.c | %D%/libsim.a $(SIM_ALL_RECURSIVE_DEPS)
+	$(MAKE) -C $(@D) $(@F)
+
+noinst_PROGRAMS += %D%/run %D%/sis
+
 %C%docdir = $(docdir)/%C%
 %C%doc_DATA = %D%/README.erc32 %D%/README.gdb %D%/README.sis
 
diff --git a/sim/example-synacor/local.mk b/sim/example-synacor/local.mk
new file mode 100644
index 000000000000..20cdc53215e4
--- /dev/null
+++ b/sim/example-synacor/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 2005-2022 Free Software Foundation, Inc.
+## Written by Mike Frysinger <vapier@gentoo.org>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/frv/local.mk b/sim/frv/local.mk
index 687fb4a86667..e08a488a91df 100644
--- a/sim/frv/local.mk
+++ b/sim/frv/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%docdir = $(docdir)/%C%
 %C%doc_DATA = %D%/README
 
diff --git a/sim/ft32/local.mk b/sim/ft32/local.mk
new file mode 100644
index 000000000000..cacf9f2b7c26
--- /dev/null
+++ b/sim/ft32/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 2008-2022 Free Software Foundation, Inc.
+## Written by FTDI
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/h8300/local.mk b/sim/h8300/local.mk
new file mode 100644
index 000000000000..ae29197283a7
--- /dev/null
+++ b/sim/h8300/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 1990-2022 Free Software Foundation, Inc.
+## Written by Cygnus Support.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/iq2000/local.mk b/sim/iq2000/local.mk
index cf9195a4cffe..b9a4ada3badc 100644
--- a/sim/iq2000/local.mk
+++ b/sim/iq2000/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILD_OUTPUTS = \
 	%D%/eng.h \
 	%D%/mloop.c \
diff --git a/sim/lm32/local.mk b/sim/lm32/local.mk
index bb6c7ad248ae..7add85ac98b7 100644
--- a/sim/lm32/local.mk
+++ b/sim/lm32/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILD_OUTPUTS = \
 	%D%/eng.h \
 	%D%/mloop.c \
diff --git a/sim/m32c/local.mk b/sim/m32c/local.mk
index 3ec947ad037a..efdf110e6309 100644
--- a/sim/m32c/local.mk
+++ b/sim/m32c/local.mk
@@ -16,6 +16,18 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/main.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
+## Helper targets for running make from the top-level due to run's main.o.
+%D%/%.o: %D%/%.c | %D%/libsim.a $(SIM_ALL_RECURSIVE_DEPS)
+	$(MAKE) -C $(@D) $(@F)
+
 %C%_BUILD_OUTPUTS = \
 	%D%/opc2c$(EXEEXT) \
 	%D%/m32c.c \
diff --git a/sim/m32r/local.mk b/sim/m32r/local.mk
index 4158c8b57db5..51d9d3413d6c 100644
--- a/sim/m32r/local.mk
+++ b/sim/m32r/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILD_OUTPUTS = \
 	%D%/eng.h \
 	%D%/mloop.c \
diff --git a/sim/m68hc11/local.mk b/sim/m68hc11/local.mk
index 838a089516eb..3cc980bf036a 100644
--- a/sim/m68hc11/local.mk
+++ b/sim/m68hc11/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILD_OUTPUTS = \
 	%D%/gencode$(EXEEXT) \
 	%D%/m68hc11int.c \
diff --git a/sim/mcore/local.mk b/sim/mcore/local.mk
new file mode 100644
index 000000000000..01a66bd1d680
--- /dev/null
+++ b/sim/mcore/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 1990-2022 Free Software Foundation, Inc.
+## Written by Cygnus Solutions.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/microblaze/local.mk b/sim/microblaze/local.mk
new file mode 100644
index 000000000000..01a66bd1d680
--- /dev/null
+++ b/sim/microblaze/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 1990-2022 Free Software Foundation, Inc.
+## Written by Cygnus Solutions.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/mips/local.mk b/sim/mips/local.mk
new file mode 100644
index 000000000000..8e266e77b36f
--- /dev/null
+++ b/sim/mips/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 1995-2022 Free Software Foundation, Inc.
+## Written by Cygnus Support.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/mn10300/local.mk b/sim/mn10300/local.mk
index a51813c275c1..08a3d4dedc47 100644
--- a/sim/mn10300/local.mk
+++ b/sim/mn10300/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILT_SRC_FROM_IGEN = \
 	%D%/icache.h \
 	%D%/icache.c \
diff --git a/sim/moxie/local.mk b/sim/moxie/local.mk
index 600d2640beca..3b5c4c25c268 100644
--- a/sim/moxie/local.mk
+++ b/sim/moxie/local.mk
@@ -1,6 +1,7 @@ 
 ## See sim/Makefile.am
 ##
-## Copyright (C) 1993-2022 Free Software Foundation, Inc.
+## Copyright (C) 2008-2022 Free Software Foundation, Inc.
+## Written by Anthony Green
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -15,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 dtbdir = $(datadir)/gdb/dtb
 
 dtb_DATA = %D%/moxie-gdb.dtb
@@ -30,10 +39,3 @@  dtb_DATA = %D%/moxie-gdb.dtb
 	  echo "tree compiler tool (dtc) is missing.  Install the tool to "; \
 	  echo "update the device tree blob."; \
 	fi
-
-# Rule to create the .dirstamp file (on which moxie-gdb.dtb depends)
-# as automake fails to automatically create this rule for _DATA items.
-%D%/$(am__dirstamp):
-	@$(MKDIR_P) %D%
-	@: >%D%/$(am__dirstamp)
-DISTCLEANFILES += %D%/$(am__dirstamp)
diff --git a/sim/msp430/local.mk b/sim/msp430/local.mk
new file mode 100644
index 000000000000..58557e17f025
--- /dev/null
+++ b/sim/msp430/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 2012-2022 Free Software Foundation, Inc.
+## Written by Red Hat Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/or1k/local.mk b/sim/or1k/local.mk
index 122f78305711..cea1c6e28955 100644
--- a/sim/or1k/local.mk
+++ b/sim/or1k/local.mk
@@ -15,6 +15,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%docdir = $(docdir)/%C%
 %C%doc_DATA = %D%/README
 
diff --git a/sim/ppc/Makefile.in b/sim/ppc/Makefile.in
index d7b9df0819f4..cb1a25b4b5e9 100644
--- a/sim/ppc/Makefile.in
+++ b/sim/ppc/Makefile.in
@@ -37,10 +37,6 @@  include ../arch-subdir.mk
 prefix = @prefix@
 exec_prefix = @exec_prefix@
 
-bindir = @bindir@
-libdir = @libdir@
-tooldir = $(libdir)/$(target_alias)
-
 datarootdir = @datarootdir@
 datadir = @datadir@
 mandir = @mandir@
@@ -135,7 +131,7 @@  BFD_LIB		= ../../bfd/libbfd.la
 
 TARGETLIB	= libsim.a
 
-all:	run$(EXEEXT) $(TARGETLIB) $(GDB_OBJ)
+all:	main.o $(TARGETLIB) $(GDB_OBJ)
 
 .c.o:
 	$(ECHO_CC) $(CC) -c $(STD_CFLAGS) $<
@@ -518,14 +514,6 @@  PACKAGE_SRC = pk_disklabel.c
 PACKAGE_OBJ = $(PACKAGE_SRC:.c=.o)
 
 
-psim$(EXEEXT): $(TARGETLIB) main.o $(LIBIBERTY_LIB) $(BFD_LIB)
-	$(ECHO_CCLD) $(LIBTOOL) $(AM_V_lt) --tag=CC --mode=link \
-	  $(CC) $(CFLAGS) $(LDFLAGS) -o psim$(EXEEXT) main.o $(TARGETLIB) $(BFD_LIB) $(LIBIBERTY_LIB) $(LIBS)
-
-run$(EXEEXT): psim$(EXEEXT)
-	$(SILENCE) rm -f $@
-	$(ECHO_GEN) ln $< $@ 2>/dev/null || $(LN_S) $< $@ 2>/dev/null || cp -p $< $@
-
 $(TARGETLIB): tmp-igen tmp-dgen tmp-hw tmp-defines $(LIB_OBJ) $(GDB_OBJ)
 	$(ECHO_AR) $(AR) $(AR_FLAGS) $(TARGETLIB) $(LIB_OBJ) $(GDB_OBJ)
 	$(ECHO_RANLIB) $(RANLIB) $(TARGETLIB)
@@ -811,7 +799,7 @@  TAGS: $(BUILT_SRC)
 	etags $(srcdir)/*.h $(srcdir)/*.c $(BUILT_SRC)
 
 clean mostlyclean:
-	rm -f tmp-* *.[oasi] core psim$(EXEEXT) run$(EXEEXT) igen dgen $(BUILT_SRC_WO_CONFIG)
+	rm -f tmp-* *.[oasi] core igen dgen $(BUILT_SRC_WO_CONFIG)
 
 distclean realclean: clean
 	rm -f TAGS Makefile config.cache config.status config.h defines.h stamp-h config.log
diff --git a/sim/ppc/local.mk b/sim/ppc/local.mk
index 03e54fbe083e..19a8a89ba47c 100644
--- a/sim/ppc/local.mk
+++ b/sim/ppc/local.mk
@@ -15,5 +15,20 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/main.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+%D%/psim$(EXEEXT): %D%/run$(EXEEXT)
+	$(AM_V_GEN)ln $< $@ 2>/dev/null || $(LN_S) $< $@ 2>/dev/null || cp -p $< $@
+
+## Helper targets for running make from the top-level due to run's sis.o.
+%D%/%.o: %D%/%.c | %D%/libsim.a $(SIM_ALL_RECURSIVE_DEPS)
+	$(MAKE) -C $(@D) $(@F)
+
+noinst_PROGRAMS += %D%/run %D%/psim
+
 %C%docdir = $(docdir)/%C%
 %C%doc_DATA = %D%/BUGS %D%/INSTALL %D%/README %D%/RUN
diff --git a/sim/pru/local.mk b/sim/pru/local.mk
new file mode 100644
index 000000000000..f83a6d9c700e
--- /dev/null
+++ b/sim/pru/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 1990-2022 Free Software Foundation, Inc.
+## Written by Dimitar Dimitrov <dimitar@dinux.eu>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/riscv/local.mk b/sim/riscv/local.mk
new file mode 100644
index 000000000000..11fdceca332a
--- /dev/null
+++ b/sim/riscv/local.mk
@@ -0,0 +1,25 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 2005-2022 Free Software Foundation, Inc.
+## Written by Mike Frysinger.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
diff --git a/sim/rl78/local.mk b/sim/rl78/local.mk
new file mode 100644
index 000000000000..132fa3abccbd
--- /dev/null
+++ b/sim/rl78/local.mk
@@ -0,0 +1,29 @@ 
+## See sim/Makefile.am
+##
+## Copyright (C) 2008-2022 Free Software Foundation, Inc.
+## Contributed by Red Hat, Inc.
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/main.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
+## Helper targets for running make from the top-level due to run's main.o.
+%D%/%.o: %D%/%.c | %D%/libsim.a $(SIM_ALL_RECURSIVE_DEPS)
+	$(MAKE) -C $(@D) $(@F)
diff --git a/sim/rx/local.mk b/sim/rx/local.mk
index 6f2dc7eee793..119a0f7ccf8d 100644
--- a/sim/rx/local.mk
+++ b/sim/rx/local.mk
@@ -1,6 +1,7 @@ 
 ## See sim/Makefile.am
 ##
 ## Copyright (C) 2008-2022 Free Software Foundation, Inc.
+## Contributed by Red Hat, Inc.
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -15,5 +16,17 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/main.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
+## Helper targets for running make from the top-level due to run's main.o.
+%D%/%.o: %D%/%.c | %D%/libsim.a $(SIM_ALL_RECURSIVE_DEPS)
+	$(MAKE) -C $(@D) $(@F)
+
 %C%docdir = $(docdir)/%C%
 %C%doc_DATA = %D%/README.txt
diff --git a/sim/sh/local.mk b/sim/sh/local.mk
index 5e97e543c72e..34be7b223e77 100644
--- a/sim/sh/local.mk
+++ b/sim/sh/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILD_OUTPUTS = \
 	%D%/gencode$(EXEEXT) \
 	%D%/code.c \
diff --git a/sim/v850/local.mk b/sim/v850/local.mk
index 028eda36f800..367ca6ef1f4a 100644
--- a/sim/v850/local.mk
+++ b/sim/v850/local.mk
@@ -16,6 +16,14 @@ 
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+%C%_run_SOURCES =
+%C%_run_LDADD = \
+	%D%/nrun.o \
+	%D%/libsim.a \
+	$(SIM_COMMON_LIBS)
+
+noinst_PROGRAMS += %D%/run
+
 %C%_BUILT_SRC_FROM_IGEN = \
 	%D%/icache.h \
 	%D%/icache.c \