[5/5] sim: hw: move cfi & glue to common code

Message ID 20210620055519.22229-5-vapier@gentoo.org
State New
Headers show
Series
  • [1/5] sim: hw: rework configure option & device selection
Related show

Commit Message

Simon Marchi via Gdb-patches June 20, 2021, 5:55 a.m.
These don't depend on any arch state, so move them to the common
build code so we only build them once across all subdirs.
---
 sim/Makefile.in           | 61 +++++++++++++++++++++++++++++++--------
 sim/common/Make-common.in |  8 +++--
 sim/common/dv-cfi.c       |  2 +-
 sim/common/hw-base.h      |  2 ++
 sim/common/local.mk       |  6 ++++
 5 files changed, 63 insertions(+), 16 deletions(-)

-- 
2.31.1

Patch

diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index 4bf1e2e21e27..2701462ba096 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -216,7 +216,8 @@  BUILD_CFLAGS = $(CFLAGS_FOR_BUILD) $(CSEARCH)
 
 COMMON_DEP_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS)
 
-SIM_HW_DEVICES = cfi core pal glue $(SIM_EXTRA_HW_DEVICES)
+SIM_HW_DEVICES = core pal $(SIM_EXTRA_HW_DEVICES)
+SIM_HW_DEVICES_COMMON = cfi glue
 
 ZLIB = $(zlibdir) -lz
 LIBIBERTY_LIB = ../../libiberty/libiberty.a
@@ -228,6 +229,7 @@  EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \
 	$(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL) $(LIBGNU) $(LIBGNU_EXTRA_LIBS)
 
 COMMON_OBJS_NAMES = \
+	$(SIM_HW_DEVICES_COMMON:%=dv-%.o) \
 	portability.o \
 	sim-load.o \
 	version.o
@@ -419,12 +421,12 @@  hw-config.h: stamp-hw ; @true
 stamp-hw: Makefile.in $(srccom)/Make-common.in $(config.status) Makefile
 	rm -f tmp-hw.h
 	echo "/* generated by Makefile */" > tmp-hw.h
-	sim_hw="$(SIM_HW_DEVICES)"; \
+	sim_hw="$(SIM_HW_DEVICES) $(SIM_HW_DEVICES_COMMON)"; \
 	for hw in $$sim_hw ; do \
 	  echo "extern const struct hw_descriptor dv_$${hw}_descriptor[];" ; \
 	done >> tmp-hw.h
 	echo "const struct hw_descriptor *hw_descriptors[] = {" >> tmp-hw.h
-	sim_hw="$(SIM_HW_DEVICES)"; \
+	sim_hw="$(SIM_HW_DEVICES) $(SIM_HW_DEVICES_COMMON)"; \
 	for hw in $$sim_hw ; do \
 	  echo "  dv_$${hw}_descriptor," ; \
 	done >> tmp-hw.h
diff --git a/sim/common/dv-cfi.c b/sim/common/dv-cfi.c
index 02a2cedd558b..008a3904771b 100644
--- a/sim/common/dv-cfi.c
+++ b/sim/common/dv-cfi.c
@@ -34,10 +34,10 @@ 
 #include <sys/mman.h>
 #endif
 
-#include "sim-main.h"
 #include "hw-base.h"
 #include "hw-main.h"
 #include "dv-cfi.h"
+#include "libiberty.h"
 
 /* Flashes are simple state machines, so here we cover all the
    different states a device might be in at any particular time.  */
diff --git a/sim/common/hw-base.h b/sim/common/hw-base.h
index f1cf989357b7..6980834c6874 100644
--- a/sim/common/hw-base.h
+++ b/sim/common/hw-base.h
@@ -23,6 +23,8 @@ 
 #ifndef HW_BASE
 #define HW_BASE
 
+struct sim_state;
+
 /* Create a primative device */
 
 struct hw *hw_create
diff --git a/sim/common/local.mk b/sim/common/local.mk
index 25c7e5beb1f9..bc562c6e5e5e 100644
--- a/sim/common/local.mk
+++ b/sim/common/local.mk
@@ -38,6 +38,12 @@  noinst_LIBRARIES += %D%/libcommon.a
 	%D%/sim-load.c \
 	%D%/version.c
 
+if SIM_ENABLE_HW
+%C%_libcommon_a_SOURCES += \
+	%D%/dv-cfi.c \
+	%D%/dv-glue.c
+endif
+
 %D%/version.c: %D%/version.c-stamp ; @true
 %D%/version.c-stamp: $(srcroot)/gdb/version.in $(srcroot)/bfd/version.h $(srcdir)/%D%/create-version.sh
 	$(AM_V_GEN)$(SHELL) $(srcdir)/%D%/create-version.sh $(srcroot)/gdb $@.tmp