[PATCH 3/3] sim: use build-gnulib with build-time tools [PR sim/30882]

Mike Frysinger vapier@gentoo.org
Sun Oct 15 17:17:28 GMT 2023


Some of our build-time tools are fairly complicated and require some
POSIX APIs that the build system doesn't provide.  Leverage the new
build-gnulib tree to provide fallback implementations automatically.
---
 sim/Makefile.am          |  4 ++++
 sim/Makefile.in          | 33 ++++++++++++++++++++++-----------
 sim/cr16/gencode.c       |  2 +-
 sim/cr16/local.mk        |  2 +-
 sim/d10v/gencode.c       |  3 +++
 sim/d10v/local.mk        |  2 +-
 sim/igen/filter.c        |  2 ++
 sim/igen/filter_host.c   |  3 +++
 sim/igen/gen-engine.c    |  3 +++
 sim/igen/gen-icache.c    |  3 +++
 sim/igen/gen-idecode.c   |  2 ++
 sim/igen/gen-itable.c    |  3 ++-
 sim/igen/gen-model.c     |  2 ++
 sim/igen/gen-semantics.c |  3 ++-
 sim/igen/gen-support.c   |  2 ++
 sim/igen/gen.c           |  2 ++
 sim/igen/igen.c          |  3 +++
 sim/igen/ld-cache.c      |  3 ++-
 sim/igen/ld-decode.c     |  4 +++-
 sim/igen/ld-insn.c       |  2 ++
 sim/igen/lf.c            |  2 ++
 sim/igen/local.mk        |  2 +-
 sim/igen/misc.c          |  3 ++-
 sim/igen/table.c         |  3 ++-
 sim/m32c/local.mk        |  1 +
 sim/m32c/opc2c.c         |  2 +-
 sim/m68hc11/gencode.c    |  2 +-
 sim/m68hc11/local.mk     |  1 +
 sim/sh/gencode.c         |  3 +++
 sim/sh/local.mk          |  1 +
 30 files changed, 80 insertions(+), 23 deletions(-)

diff --git a/sim/Makefile.am b/sim/Makefile.am
index 3693eb18d496..6cd85c7df957 100644
--- a/sim/Makefile.am
+++ b/sim/Makefile.am
@@ -20,6 +20,7 @@ ACLOCAL_AMFLAGS = -Im4 -I.. -I../config
 
 GNULIB_PARENT_DIR = ..
 @am__include@ @am__quote@$(GNULIB_PARENT_DIR)/gnulib/Makefile.gnulib.inc@am__quote@
+@am__include@ @am__quote@$(GNULIB_PARENT_DIR)/build-$(build)/gnulib/Makefile.gnulib.inc@am__quote@
 
 srccom = $(srcdir)/common
 srcroot = $(srcdir)/..
@@ -64,11 +65,14 @@ AM_CPPFLAGS = \
 	$(AM_CPPFLAGS_$(subst -,_,$(@D)_$(@F)))
 
 AM_CPPFLAGS_FOR_BUILD = \
+	$(BUILD_INCGNU) \
+	-I../build-$(build) \
 	-I$(srcroot)/include \
 	$(SIM_HW_CFLAGS) \
 	$(SIM_INLINE)
 COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(AM_CPPFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD)
 LINK_FOR_BUILD = $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@
+LIBS_FOR_BUILD = $(BUILD_LIBGNU) $(BUILD_LIBGNU_EXTRA_LIBS)
 
 ## Deps to add to the all-recursive target.  These are built before descending
 ## into any subdirs.
diff --git a/sim/cr16/gencode.c b/sim/cr16/gencode.c
index b0bb67b63c0b..dbe1b9e1423e 100644
--- a/sim/cr16/gencode.c
+++ b/sim/cr16/gencode.c
@@ -18,7 +18,7 @@
    along with this program. If not, see <http://www.gnu.org/licenses/>.  */
 
 /* This must come before any other includes.  */
-#include "defs.h"
+#include "gnulib/config.h"
 
 #include <stdio.h>
 #include <ctype.h>
diff --git a/sim/cr16/local.mk b/sim/cr16/local.mk
index 10533a467333..9eb464f58351 100644
--- a/sim/cr16/local.mk
+++ b/sim/cr16/local.mk
@@ -55,7 +55,7 @@ BUILT_SOURCES += %D%/simops.h
 %D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_gencode_SOURCES = %D%/gencode.c
-%C%_gencode_LDADD = %D%/cr16-opc.o
+%C%_gencode_LDADD = %D%/cr16-opc.o $(LIBS_FOR_BUILD)
 
 # These rules are copied from automake, but tweaked to use FOR_BUILD variables.
 %D%/gencode$(EXEEXT): $(%C%_gencode_OBJECTS) $(%C%_gencode_DEPENDENCIES) %D%/$(am__dirstamp)
diff --git a/sim/d10v/gencode.c b/sim/d10v/gencode.c
index 3a37bac62563..42d655d39845 100644
--- a/sim/d10v/gencode.c
+++ b/sim/d10v/gencode.c
@@ -1,3 +1,6 @@
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
+
 #include <stdio.h>
 #include <ctype.h>
 #include <limits.h>
diff --git a/sim/d10v/local.mk b/sim/d10v/local.mk
index a65635e81ede..0a9aa8fe5d5d 100644
--- a/sim/d10v/local.mk
+++ b/sim/d10v/local.mk
@@ -56,7 +56,7 @@ BUILT_SOURCES += %D%/simops.h
 %D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_gencode_SOURCES = %D%/gencode.c
-%C%_gencode_LDADD = %D%/d10v-opc.o
+%C%_gencode_LDADD = %D%/d10v-opc.o $(LIBS_FOR_BUILD)
 
 # These rules are copied from automake, but tweaked to use FOR_BUILD variables.
 %D%/gencode$(EXEEXT): $(%C%_gencode_OBJECTS) $(%C%_gencode_DEPENDENCIES) %D%/$(am__dirstamp)
diff --git a/sim/igen/filter.c b/sim/igen/filter.c
index 71b5482635d0..2e9ae7900a28 100644
--- a/sim/igen/filter.c
+++ b/sim/igen/filter.c
@@ -19,6 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include <stdio.h>
 #include <string.h>
diff --git a/sim/igen/filter_host.c b/sim/igen/filter_host.c
index ce5aa4b7f959..526d6a452e08 100644
--- a/sim/igen/filter_host.c
+++ b/sim/igen/filter_host.c
@@ -19,6 +19,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
+
 #include "filter_host.h"
 
 /* Shorten traces by eliminating the directory component to filenames.  */
diff --git a/sim/igen/gen-engine.c b/sim/igen/gen-engine.c
index 29eb33310230..83d4292797df 100644
--- a/sim/igen/gen-engine.c
+++ b/sim/igen/gen-engine.c
@@ -19,6 +19,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
+
 #include "misc.h"
 #include "lf.h"
 #include "table.h"
diff --git a/sim/igen/gen-icache.c b/sim/igen/gen-icache.c
index 366ba9307d0b..aa0cd6685fe2 100644
--- a/sim/igen/gen-icache.c
+++ b/sim/igen/gen-icache.c
@@ -19,6 +19,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
+
 #include <stdlib.h>
 
 #include "misc.h"
diff --git a/sim/igen/gen-idecode.c b/sim/igen/gen-idecode.c
index 0059c1c2ee10..d6be10be86b2 100644
--- a/sim/igen/gen-idecode.c
+++ b/sim/igen/gen-idecode.c
@@ -19,6 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include "misc.h"
 #include "lf.h"
diff --git a/sim/igen/gen-itable.c b/sim/igen/gen-itable.c
index bea06e861e20..c13307bcab3f 100644
--- a/sim/igen/gen-itable.c
+++ b/sim/igen/gen-itable.c
@@ -19,7 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include "misc.h"
 #include "lf.h"
diff --git a/sim/igen/gen-model.c b/sim/igen/gen-model.c
index 31f56bc45f30..3731a2eec61a 100644
--- a/sim/igen/gen-model.c
+++ b/sim/igen/gen-model.c
@@ -19,6 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include "misc.h"
 #include "lf.h"
diff --git a/sim/igen/gen-semantics.c b/sim/igen/gen-semantics.c
index 54d83d61eccd..24a3fdbad87a 100644
--- a/sim/igen/gen-semantics.c
+++ b/sim/igen/gen-semantics.c
@@ -19,7 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include "misc.h"
 #include "lf.h"
diff --git a/sim/igen/gen-support.c b/sim/igen/gen-support.c
index 63b29324c4b1..78ace2084fc8 100644
--- a/sim/igen/gen-support.c
+++ b/sim/igen/gen-support.c
@@ -19,6 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include "misc.h"
 #include "lf.h"
diff --git a/sim/igen/gen.c b/sim/igen/gen.c
index 2176b603fc59..ac4ca6b01d62 100644
--- a/sim/igen/gen.c
+++ b/sim/igen/gen.c
@@ -19,6 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include "misc.h"
 #include "lf.h"
diff --git a/sim/igen/igen.c b/sim/igen/igen.c
index b9919a9d80c1..eaf69b9982f7 100644
--- a/sim/igen/igen.c
+++ b/sim/igen/igen.c
@@ -19,6 +19,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
+
 #include <getopt.h>
 #include <stdlib.h>
 
diff --git a/sim/igen/ld-cache.c b/sim/igen/ld-cache.c
index 3c00f3443b7d..b5f5b9ded855 100644
--- a/sim/igen/ld-cache.c
+++ b/sim/igen/ld-cache.c
@@ -19,7 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include "misc.h"
 #include "lf.h"
diff --git a/sim/igen/ld-decode.c b/sim/igen/ld-decode.c
index 6edd7c8ec3d6..ad0e64f58c7f 100644
--- a/sim/igen/ld-decode.c
+++ b/sim/igen/ld-decode.c
@@ -19,9 +19,11 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-
 /* load the opcode stat structure */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
+
 #include "misc.h"
 #include "lf.h"
 #include "table.h"
diff --git a/sim/igen/ld-insn.c b/sim/igen/ld-insn.c
index af639df7c0ae..fa5b46bcf15c 100644
--- a/sim/igen/ld-insn.c
+++ b/sim/igen/ld-insn.c
@@ -19,6 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include "misc.h"
 #include "lf.h"
diff --git a/sim/igen/lf.c b/sim/igen/lf.c
index 46b1f6b59ec9..e664fbc46278 100644
--- a/sim/igen/lf.c
+++ b/sim/igen/lf.c
@@ -19,6 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include <stdbool.h>
 #include <stdio.h>
diff --git a/sim/igen/local.mk b/sim/igen/local.mk
index 75b9cebd8f7b..bfc754b29338 100644
--- a/sim/igen/local.mk
+++ b/sim/igen/local.mk
@@ -47,7 +47,7 @@ EXTRA_LIBRARIES += %D%/libigen.a
 	%D%/gen.c
 
 %C%_igen_SOURCES = %D%/igen.c
-%C%_igen_LDADD = %D%/libigen.a
+%C%_igen_LDADD = %D%/libigen.a $(LIBS_FOR_BUILD)
 
 # These rules are copied from automake, but tweaked to use FOR_BUILD variables.
 igen/libigen.a: $(igen_libigen_a_OBJECTS) $(igen_libigen_a_DEPENDENCIES) $(EXTRA_igen_libigen_a_DEPENDENCIES) igen/$(am__dirstamp)
diff --git a/sim/igen/misc.c b/sim/igen/misc.c
index a083f6d1bbd2..5e90107cf9df 100644
--- a/sim/igen/misc.c
+++ b/sim/igen/misc.c
@@ -19,7 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include <stdio.h>
 #include <stdarg.h>
diff --git a/sim/igen/table.c b/sim/igen/table.c
index fdca9cb32554..d5c7068bce11 100644
--- a/sim/igen/table.c
+++ b/sim/igen/table.c
@@ -19,7 +19,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
diff --git a/sim/m32c/local.mk b/sim/m32c/local.mk
index 39620b5ce2f2..f8efd074b9bc 100644
--- a/sim/m32c/local.mk
+++ b/sim/m32c/local.mk
@@ -61,6 +61,7 @@ noinst_PROGRAMS += %D%/run
 %D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_opc2c_SOURCES = %D%/opc2c.c
+%C%_opc2c_LDADD = $(LIBS_FOR_BUILD)
 
 # These rules are copied from automake, but tweaked to use FOR_BUILD variables.
 %D%/opc2c$(EXEEXT): $(%C%_opc2c_OBJECTS) $(%C%_opc2c_DEPENDENCIES) %D%/$(am__dirstamp)
diff --git a/sim/m32c/opc2c.c b/sim/m32c/opc2c.c
index da4da1c2a97f..e8a089eac596 100644
--- a/sim/m32c/opc2c.c
+++ b/sim/m32c/opc2c.c
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* This must come before any other includes.  */
-#include "defs.h"
+#include "gnulib/config.h"
 
 #include <stdio.h>
 #include <string.h>
diff --git a/sim/m68hc11/gencode.c b/sim/m68hc11/gencode.c
index 4e507701b9d0..4862a6dd7a73 100644
--- a/sim/m68hc11/gencode.c
+++ b/sim/m68hc11/gencode.c
@@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* This must come before any other includes.  */
-#include "defs.h"
+#include "gnulib/config.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/m68hc11/local.mk b/sim/m68hc11/local.mk
index 36c503e3bd88..1ec60d701ff0 100644
--- a/sim/m68hc11/local.mk
+++ b/sim/m68hc11/local.mk
@@ -71,6 +71,7 @@ noinst_PROGRAMS += %D%/run
 %D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_gencode_SOURCES = %D%/gencode.c
+%C%_gencode_LDADD = $(LIBS_FOR_BUILD)
 
 # These rules are copied from automake, but tweaked to use FOR_BUILD variables.
 %D%/gencode$(EXEEXT): $(%C%_gencode_OBJECTS) $(%C%_gencode_DEPENDENCIES) %D%/$(am__dirstamp)
diff --git a/sim/sh/gencode.c b/sim/sh/gencode.c
index 5eb7caf25893..e989afbf169e 100644
--- a/sim/sh/gencode.c
+++ b/sim/sh/gencode.c
@@ -30,6 +30,9 @@
 
 */
 
+/* This must come before any other includes.  */
+#include "gnulib/config.h"
+
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/sh/local.mk b/sim/sh/local.mk
index 6cbd3a7f1581..0d8a28a9db46 100644
--- a/sim/sh/local.mk
+++ b/sim/sh/local.mk
@@ -57,6 +57,7 @@ BUILT_SOURCES += \
 %D%/modules.c: | $(%C%_BUILD_OUTPUTS)
 
 %C%_gencode_SOURCES = %D%/gencode.c
+%C%_gencode_LDADD = $(LIBS_FOR_BUILD)
 
 # These rules are copied from automake, but tweaked to use FOR_BUILD variables.
 %D%/gencode$(EXEEXT): $(%C%_gencode_OBJECTS) $(%C%_gencode_DEPENDENCIES) %D%/$(am__dirstamp)
-- 
2.42.0



More information about the Gdb-patches mailing list