[1/3] sim: build: move install steps to the top-level

Message ID 20221105082727.32094-1-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
  We still have to maintain custom install rules due to how we rename
arch-specific files with an arch prefix in their name, but we can at
least unify the logic in the common dir.
---
 sim/Makefile.am           |  27 +++++++++
 sim/Makefile.in           | 113 ++++++++++++++++++++++++--------------
 sim/README-HACKING        |   2 -
 sim/common/Make-common.in |  19 +------
 sim/erc32/Makefile.in     |   6 --
 sim/erc32/local.mk        |   6 ++
 sim/ppc/Makefile.in       |  15 +----
 7 files changed, 107 insertions(+), 81 deletions(-)
  

Patch

diff --git a/sim/Makefile.am b/sim/Makefile.am
index 7ea013ac1965..523d8f8dec96 100644
--- a/sim/Makefile.am
+++ b/sim/Makefile.am
@@ -59,6 +59,10 @@  LINK_FOR_BUILD = $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@
 ## Deps to add to the all-recursive target.  These are built before descending
 ## into any subdirs.
 SIM_ALL_RECURSIVE_DEPS =
+## Deps to add to the install-data-local target.
+SIM_INSTALL_DATA_LOCAL_DEPS =
+## Deps to add to the install-exec-local target.
+SIM_INSTALL_EXEC_LOCAL_DEPS =
 
 # Generate target constants for newlib/libgloss from its source tree.
 # This file is shipped with distributions so we build in the source dir.
@@ -138,3 +142,26 @@  include v850/local.mk
 endif
 
 all-recursive: $(SIM_ALL_RECURSIVE_DEPS)
+
+install-data-local: installdirs $(SIM_INSTALL_DATA_LOCAL_DEPS)
+	$(AM_V_at)$(MKDIR_P) $(DESTDIR)$(libdir)
+	lib=`echo sim | sed '$(program_transform_name)'`; \
+	for d in $(SUBDIRS); do \
+		if [ -e $$d/run$(EXEEXT) ]; then \
+			n="$$lib"; \
+			[ "$(SIM_PRIMARY_TARGET)" = "$$d" ] || n="$$n-$$d"; \
+			n="lib$$n.a"; \
+			$(INSTALL_DATA) $$d/libsim.a $(DESTDIR)$(libdir)/$$n || exit 1; \
+		fi; \
+	done
+
+install-exec-local: installdirs $(SIM_INSTALL_EXEC_LOCAL_DEPS)
+	$(AM_V_at)$(MKDIR_P) $(DESTDIR)$(bindir)
+	run=`echo run | sed '$(program_transform_name)'`; \
+	for d in $(SUBDIRS); do \
+		if [ -e $$d/run$(EXEEXT) ]; then \
+			n="$$run"; \
+			[ "$(SIM_PRIMARY_TARGET)" = "$$d" ] || n="$$n-$$d"; \
+			$(INSTALL_PROGRAM) $$d/run$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT) || exit 1; \
+		fi; \
+	done
diff --git a/sim/README-HACKING b/sim/README-HACKING
index 38915bf3bb94..eddd7d51b305 100644
--- a/sim/README-HACKING
+++ b/sim/README-HACKING
@@ -71,8 +71,6 @@  SIM_EXTRA_DEPS =
 SIM_EXTRA_CFLAGS =
 # List of extra libraries to link with.
 SIM_EXTRA_LIBS =
-# Dependency of `install' to install any extra files.
-SIM_EXTRA_INSTALL =
 # Dependency of `clean' to clean any extra files.
 SIM_EXTRA_CLEAN =
 
diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index 18dcd36a72bb..bd50f052dae9 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -115,8 +115,6 @@  SIM_EXTRA_CFLAGS =
 SIM_EXTRA_LIBS =
 # List of main object files for `run'.
 SIM_RUN_OBJS = nrun.o
-# Dependency of `install' to install any extra files.
-SIM_EXTRA_INSTALL =
 # Dependency of `clean' to clean any extra files.
 SIM_EXTRA_CLEAN =
 # Likewise `distclean'
@@ -322,23 +320,8 @@  stamp-modules: Makefile $(SIM_OBJS:.o=.c)
 
 # Support targets.
 
-install: install-common $(SIM_EXTRA_INSTALL)
-
-install-common: installdirs
-	a=`basename "$$(pwd)"`; \
-	n=`echo run | sed '$(program_transform_name)'`; \
-	[ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
-	$(INSTALL_PROGRAM) run$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
-	n=`echo sim | sed '$(program_transform_name)'`; \
-	a=`basename "$$(pwd)"`; \
-	[ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
-	n="lib$$n.a"; \
-	$(INSTALL_DATA) libsim.a $(DESTDIR)$(libdir)/$$n ; \
-	( cd $(DESTDIR)$(libdir) ; $(RANLIB) $$n )
-
+install:
 installdirs:
-	$(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(bindir)
-	$(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(libdir)
 
 check:
 
diff --git a/sim/erc32/Makefile.in b/sim/erc32/Makefile.in
index 7dd5102bccbf..eef81d9dcd6e 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_INSTALL = install-sis
 SIM_EXTRA_CLEAN = clean-sis
 
 # UARTS run at about 115200 baud (simulator time). Add -DFAST_UART to
@@ -39,10 +38,5 @@  sis$(EXEEXT): run$(EXEEXT)
 	$(SILENCE) rm -f $@
 	$(ECHO_GEN) ln $< $@ 2>/dev/null || $(LN_S) $< $@ 2>/dev/null || cp -p $< $@
 
-# Copy the files into directories where they will be run.
-install-sis: installdirs
-	n=`echo sis | sed '$(program_transform_name)'`; \
-	$(INSTALL_PROGRAM) sis$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
-
 clean-sis:
 	rm -f sis
diff --git a/sim/erc32/local.mk b/sim/erc32/local.mk
index cf88a71f86ab..3b858a671d80 100644
--- a/sim/erc32/local.mk
+++ b/sim/erc32/local.mk
@@ -17,3 +17,9 @@ 
 
 %C%docdir = $(docdir)/%C%
 %C%doc_DATA = %D%/README.erc32 %D%/README.gdb %D%/README.sis
+
+SIM_INSTALL_EXEC_LOCAL_DEPS += sim-%D-install-exec-local
+sim-%D-install-exec-local: installdirs
+	$(AM_V_at)$(MKDIR_P) $(DESTDIR)$(bindir)
+	n=`echo sis | sed '$(program_transform_name)'`; \
+	$(INSTALL_PROGRAM) %D%/sis$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
diff --git a/sim/ppc/Makefile.in b/sim/ppc/Makefile.in
index 72dc479d1912..4fe4fd9597c0 100644
--- a/sim/ppc/Makefile.in
+++ b/sim/ppc/Makefile.in
@@ -843,18 +843,5 @@  pdf:
 clean-pdf:
 install-pdf:
 
-install: installdirs
-	a=`basename "$$(pwd)"`; \
-	n=`echo run | sed '$(program_transform_name)'`; \
-	[ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
-	$(INSTALL_PROGRAM) run$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
-
-install-strip: installdirs
-	a=`basename "$$(pwd)"`; \
-	n=`echo run | sed '$(program_transform_name)'`; \
-	[ "$(SIM_PRIMARY_TARGET)" = "$$a" ] || n="$$n-$$a"; \
-	$(INSTALL_PROGRAM) run$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
-	$(STRIP) $(DESTDIR)$(bindir)/$$n$(EXEEXT)
-
+install:
 installdirs:
-	$(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(bindir)