public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] sim: switch config.h usage to defs.h
@ 2021-05-07  4:00 Mike Frysinger
  2021-05-07  4:00 ` [PATCH 2/2] sim: leverage gnulib Mike Frysinger
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2021-05-07  4:00 UTC (permalink / raw)
  To: gdb-patches

The defs.h header will take care of including the various config.h
headers.  For now, it's just config.h, but we'll add more when we
integrate gnulib in.

This header should be used instead of config.h, and should be the
first include in every .c file.  We won't rely on the old behavior
where we expected files to include the port's sim-main.h which then
includes the common sim-basics.h which then includes config.h.  We
have a ton of code that includes things before sim-main.h, and it
sometimes needs to be that way.  Creating a dedicated header avoids
the ordering mess and implicit inclusion that shows up otherwise.
---
 sim/aarch64/cpustate.c         |  3 +++
 sim/aarch64/cpustate.h         |  1 -
 sim/aarch64/interp.c           |  4 +++-
 sim/aarch64/memory.c           |  4 +++-
 sim/aarch64/simulator.c        |  4 +++-
 sim/aarch64/simulator.h        |  1 -
 sim/arm/armcopro.c             |  3 +++
 sim/arm/armdefs.h              |  1 -
 sim/arm/armemu.c               |  3 +++
 sim/arm/arminit.c              |  3 +++
 sim/arm/armos.c                |  4 +++-
 sim/arm/armsupp.c              |  3 +++
 sim/arm/armvirt.c              |  3 +++
 sim/arm/iwmmxt.c               |  3 +++
 sim/arm/maverick.c             |  3 +++
 sim/arm/thumbemu.c             |  3 +++
 sim/arm/wrapper.c              |  4 +++-
 sim/avr/interp.c               |  3 ++-
 sim/bfin/bfin-sim.c            |  3 ++-
 sim/bfin/devices.c             |  3 ++-
 sim/bfin/dv-bfin_cec.c         |  3 ++-
 sim/bfin/dv-bfin_ctimer.c      |  3 ++-
 sim/bfin/dv-bfin_dma.c         |  3 ++-
 sim/bfin/dv-bfin_dmac.c        |  3 ++-
 sim/bfin/dv-bfin_ebiu_amc.c    |  3 ++-
 sim/bfin/dv-bfin_ebiu_ddrc.c   |  3 ++-
 sim/bfin/dv-bfin_ebiu_sdc.c    |  3 ++-
 sim/bfin/dv-bfin_emac.c        |  3 ++-
 sim/bfin/dv-bfin_eppi.c        |  3 ++-
 sim/bfin/dv-bfin_evt.c         |  3 ++-
 sim/bfin/dv-bfin_gpio.c        |  3 ++-
 sim/bfin/dv-bfin_gpio2.c       |  3 ++-
 sim/bfin/dv-bfin_gptimer.c     |  3 ++-
 sim/bfin/dv-bfin_jtag.c        |  3 ++-
 sim/bfin/dv-bfin_mmu.c         |  3 ++-
 sim/bfin/dv-bfin_nfc.c         |  3 ++-
 sim/bfin/dv-bfin_otp.c         |  3 ++-
 sim/bfin/dv-bfin_pfmon.c       |  3 ++-
 sim/bfin/dv-bfin_pint.c        |  3 ++-
 sim/bfin/dv-bfin_pll.c         |  3 ++-
 sim/bfin/dv-bfin_ppi.c         |  3 ++-
 sim/bfin/dv-bfin_rtc.c         |  3 ++-
 sim/bfin/dv-bfin_sic.c         |  3 ++-
 sim/bfin/dv-bfin_spi.c         |  3 ++-
 sim/bfin/dv-bfin_trace.c       |  3 ++-
 sim/bfin/dv-bfin_twi.c         |  3 ++-
 sim/bfin/dv-bfin_uart.c        |  3 ++-
 sim/bfin/dv-bfin_uart2.c       |  3 ++-
 sim/bfin/dv-bfin_wdog.c        |  3 ++-
 sim/bfin/dv-bfin_wp.c          |  3 ++-
 sim/bfin/dv-eth_phy.c          |  3 ++-
 sim/bfin/gui.c                 |  3 ++-
 sim/bfin/interp.c              |  3 ++-
 sim/bfin/machs.c               |  3 ++-
 sim/bpf/bpf-helpers.c          |  3 +++
 sim/bpf/bpf.c                  |  3 +++
 sim/bpf/sim-if.c               |  3 +++
 sim/bpf/traps.c                |  3 +++
 sim/common/callback.c          |  6 +++---
 sim/common/cgen-accfp.c        |  3 +++
 sim/common/cgen-fpu.c          |  3 +++
 sim/common/cgen-par.c          |  3 +++
 sim/common/cgen-run.c          |  3 +++
 sim/common/cgen-scache.c       |  3 +++
 sim/common/cgen-trace.c        |  4 +++-
 sim/common/cgen-utils.c        |  4 +++-
 sim/common/defs.h              | 30 ++++++++++++++++++++++++++++++
 sim/common/dv-cfi.c            |  3 ++-
 sim/common/dv-core.c           |  2 ++
 sim/common/dv-glue.c           |  2 ++
 sim/common/dv-pal.c            |  4 +++-
 sim/common/dv-sockser.c        |  4 +++-
 sim/common/genmloop.sh         |  3 +++
 sim/common/gentmap.c           |  2 +-
 sim/common/hw-alloc.c          |  2 ++
 sim/common/hw-base.c           |  2 ++
 sim/common/hw-device.c         |  2 ++
 sim/common/hw-events.c         |  2 ++
 sim/common/hw-handles.c        |  2 ++
 sim/common/hw-instances.c      |  2 ++
 sim/common/hw-ports.c          |  2 ++
 sim/common/hw-properties.c     |  3 +++
 sim/common/hw-tree.c           |  2 ++
 sim/common/nrun.c              |  4 +---
 sim/common/sim-abort.c         |  3 +++
 sim/common/sim-arange.c        |  3 +++
 sim/common/sim-basics.h        |  4 +---
 sim/common/sim-bits.c          |  3 +++
 sim/common/sim-close.c         |  3 +++
 sim/common/sim-command.c       |  3 +++
 sim/common/sim-config.c        |  2 ++
 sim/common/sim-core.c          |  3 +++
 sim/common/sim-cpu.c           |  3 +++
 sim/common/sim-endian.c        |  3 +++
 sim/common/sim-engine.c        |  3 +++
 sim/common/sim-events.c        |  3 +++
 sim/common/sim-fpu.c           |  3 +++
 sim/common/sim-hload.c         |  3 +++
 sim/common/sim-hrw.c           |  3 +++
 sim/common/sim-hw.c            |  3 +++
 sim/common/sim-info.c          |  3 +++
 sim/common/sim-inline.c        |  3 +++
 sim/common/sim-io.c            |  4 ++++
 sim/common/sim-load.c          |  6 +++---
 sim/common/sim-memopt.c        |  3 ++-
 sim/common/sim-model.c         |  3 +++
 sim/common/sim-module.c        |  4 +++-
 sim/common/sim-options.c       |  4 +++-
 sim/common/sim-profile.c       |  3 +++
 sim/common/sim-reason.c        |  3 +++
 sim/common/sim-reg.c           |  3 +++
 sim/common/sim-resume.c        |  3 +++
 sim/common/sim-run.c           |  3 +++
 sim/common/sim-signal.c        |  3 +++
 sim/common/sim-stop.c          |  3 +++
 sim/common/sim-syscall.c       |  3 ++-
 sim/common/sim-trace.c         |  3 +++
 sim/common/sim-utils.c         |  3 +++
 sim/common/sim-watch.c         |  4 +++-
 sim/common/syscall.c           |  6 +++---
 sim/cr16/cr16_sim.h            |  1 -
 sim/cr16/gencode.c             |  5 ++++-
 sim/cr16/interp.c              |  4 +++-
 sim/cr16/simops.c              |  4 ++--
 sim/cris/dv-cris.c             |  3 +++
 sim/cris/dv-cris_900000xx.c    |  3 +++
 sim/cris/dv-rv.c               |  2 ++
 sim/cris/rvdummy.c             |  5 ++---
 sim/cris/sim-if.c              |  4 +++-
 sim/cris/traps.c               |  3 +++
 sim/d10v/d10v_sim.h            |  1 -
 sim/d10v/gencode.c             |  1 -
 sim/d10v/interp.c              |  4 +++-
 sim/d10v/simops.c              |  3 ++-
 sim/erc32/erc32.c              |  4 +++-
 sim/erc32/exec.c               |  4 +++-
 sim/erc32/float.c              |  4 +++-
 sim/erc32/func.c               |  4 +++-
 sim/erc32/help.c               |  4 +++-
 sim/erc32/interf.c             |  4 +++-
 sim/erc32/sis.c                |  4 +++-
 sim/erc32/sis.h                |  1 -
 sim/example-synacor/interp.c   |  3 ++-
 sim/example-synacor/sim-main.c |  3 ++-
 sim/frv/sim-main.h             |  4 ----
 sim/ft32/interp.c              |  4 +++-
 sim/h8300/compile.c            |  4 +++-
 sim/h8300/sim-main.h           |  1 -
 sim/iq2000/iq2000.c            |  3 +++
 sim/iq2000/sim-if.c            |  3 +++
 sim/iq2000/sim-main.h          |  4 ----
 sim/m32c/gdb-if.c              |  4 +++-
 sim/m32c/int.c                 |  2 ++
 sim/m32c/load.c                |  4 +++-
 sim/m32c/main.c                |  3 ++-
 sim/m32c/mem.c                 |  3 ++-
 sim/m32c/misc.c                |  2 ++
 sim/m32c/opc2c.c               |  2 ++
 sim/m32c/reg.c                 |  2 ++
 sim/m32c/safe-fgets.c          |  2 ++
 sim/m32c/srcdest.c             |  2 ++
 sim/m32c/syscalls.c            |  4 +++-
 sim/m32c/trace.c               |  4 +++-
 sim/m32r/dv-m32r_cache.c       |  3 ++-
 sim/m32r/dv-m32r_uart.c        |  3 ++-
 sim/m32r/sim-if.c              |  3 +++
 sim/m32r/traps-linux.c         |  3 +++
 sim/m32r/traps.c               |  3 +++
 sim/m68hc11/dv-m68hc11.c       |  2 ++
 sim/m68hc11/dv-m68hc11eepr.c   |  2 ++
 sim/m68hc11/dv-m68hc11sio.c    |  2 ++
 sim/m68hc11/dv-m68hc11spi.c    |  2 ++
 sim/m68hc11/dv-m68hc11tim.c    |  2 ++
 sim/m68hc11/dv-nvram.c         |  2 ++
 sim/m68hc11/emulos.c           |  3 +++
 sim/m68hc11/gencode.c          |  3 +++
 sim/m68hc11/interp.c           |  3 +++
 sim/m68hc11/interrupts.c       |  3 +++
 sim/m68hc11/m68hc11_sim.c      |  3 +++
 sim/mcore/interp.c             |  4 +++-
 sim/microblaze/interp.c        |  4 +++-
 sim/mips/cp1.c                 |  3 +++
 sim/mips/dsp.c                 |  3 +++
 sim/mips/dv-tx3904cpu.c        |  2 ++
 sim/mips/dv-tx3904irc.c        |  2 ++
 sim/mips/dv-tx3904sio.c        |  2 ++
 sim/mips/dv-tx3904tmr.c        |  2 ++
 sim/mips/interp.c              |  7 +++----
 sim/mips/m16run.c              |  3 +++
 sim/mips/mdmx.c                |  3 +++
 sim/mips/micromipsrun.c        |  3 +++
 sim/mips/sim-main.c            |  3 +++
 sim/mn10300/dv-mn103cpu.c      |  2 ++
 sim/mn10300/dv-mn103int.c      |  2 ++
 sim/mn10300/dv-mn103iop.c      |  3 +++
 sim/mn10300/dv-mn103ser.c      |  3 +++
 sim/mn10300/dv-mn103tim.c      |  3 +++
 sim/mn10300/interp.c           |  4 +++-
 sim/mn10300/op_utils.c         |  3 +++
 sim/moxie/interp.c             |  4 +++-
 sim/msp430/msp430-sim.c        |  4 +++-
 sim/or1k/sim-if.c              |  3 +++
 sim/or1k/sim-main.h            |  2 --
 sim/or1k/traps.c               |  3 +++
 sim/ppc/Makefile.in            |  2 +-
 sim/ppc/basics.h               |  3 ++-
 sim/ppc/debug.c                |  4 +++-
 sim/ppc/defs.h                 | 26 ++++++++++++++++++++++++++
 sim/ppc/filter_filename.c      |  4 +++-
 sim/ppc/inline.c               |  4 +++-
 sim/ppc/sim-endian.c           |  4 +++-
 sim/ppc/words.h                |  5 ++---
 sim/pru/interp.c               |  4 +++-
 sim/pru/pru.h                  |  1 -
 sim/pru/sim-main.h             |  2 --
 sim/riscv/interp.c             |  3 ++-
 sim/riscv/machs.c              |  3 ++-
 sim/riscv/sim-main.c           |  3 ++-
 sim/rl78/cpu.c                 |  4 +++-
 sim/rl78/gdb-if.c              |  4 +++-
 sim/rl78/load.c                |  3 ++-
 sim/rl78/main.c                |  3 ++-
 sim/rl78/mem.c                 |  4 +++-
 sim/rl78/rl78.c                |  4 +++-
 sim/rl78/trace.c               |  3 ++-
 sim/rx/err.c                   |  3 +++
 sim/rx/fpu.c                   |  4 +++-
 sim/rx/gdb-if.c                |  4 +++-
 sim/rx/load.c                  |  3 ++-
 sim/rx/main.c                  |  3 ++-
 sim/rx/mem.c                   |  4 +++-
 sim/rx/misc.c                  |  3 ++-
 sim/rx/reg.c                   |  3 ++-
 sim/rx/rx.c                    |  4 +++-
 sim/rx/syscalls.c              |  3 ++-
 sim/rx/trace.c                 |  3 ++-
 sim/sh/interp.c                |  3 ++-
 sim/v850/interp.c              |  3 +++
 sim/v850/sim-main.h            |  1 -
 sim/v850/simops.c              |  3 +++
 240 files changed, 628 insertions(+), 159 deletions(-)
 create mode 100644 sim/common/defs.h
 create mode 100644 sim/ppc/defs.h

diff --git a/sim/aarch64/cpustate.c b/sim/aarch64/cpustate.c
index f6b93fbb1a85..6007d74872d1 100644
--- a/sim/aarch64/cpustate.c
+++ b/sim/aarch64/cpustate.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 "defs.h"
+
 #include <stdio.h>
 #include <math.h>
 
diff --git a/sim/aarch64/cpustate.h b/sim/aarch64/cpustate.h
index 00b62e1a6f5e..4eaa8d336296 100644
--- a/sim/aarch64/cpustate.h
+++ b/sim/aarch64/cpustate.h
@@ -22,7 +22,6 @@
 #ifndef _CPU_STATE_H
 #define _CPU_STATE_H
 
-#include "config.h"
 #include <sys/types.h>
 #include <stdint.h>
 #include <inttypes.h>
diff --git a/sim/aarch64/interp.c b/sim/aarch64/interp.c
index fae2b7a06bbd..229045aecef1 100644
--- a/sim/aarch64/interp.c
+++ b/sim/aarch64/interp.c
@@ -19,7 +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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <assert.h>
 #include <signal.h>
diff --git a/sim/aarch64/memory.c b/sim/aarch64/memory.c
index aa2f2e5fc22e..22caf617074d 100644
--- a/sim/aarch64/memory.c
+++ b/sim/aarch64/memory.c
@@ -19,7 +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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/aarch64/simulator.c b/sim/aarch64/simulator.c
index a8391212c064..be1c2987636a 100644
--- a/sim/aarch64/simulator.c
+++ b/sim/aarch64/simulator.c
@@ -19,7 +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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/sim/aarch64/simulator.h b/sim/aarch64/simulator.h
index f80e1f2eba81..5875c843e90b 100644
--- a/sim/aarch64/simulator.h
+++ b/sim/aarch64/simulator.h
@@ -22,7 +22,6 @@
 #ifndef _SIMULATOR_H
 #define _SIMULATOR_H
 
-#include "config.h"
 #include <sys/types.h>
 #include <setjmp.h>
 
diff --git a/sim/arm/armcopro.c b/sim/arm/armcopro.c
index 9227fc097acd..5cd33fb3ae53 100644
--- a/sim/arm/armcopro.c
+++ b/sim/arm/armcopro.c
@@ -14,6 +14,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 "defs.h"
+
 #include "armdefs.h"
 #include "armos.h"
 #include "armemu.h"
diff --git a/sim/arm/armdefs.h b/sim/arm/armdefs.h
index 68cf199db6b3..7df5d022942b 100644
--- a/sim/arm/armdefs.h
+++ b/sim/arm/armdefs.h
@@ -14,7 +14,6 @@
     You should have received a copy of the GNU General Public License
     along with this program; if not, see <http://www.gnu.org/licenses/>. */
 
-#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
diff --git a/sim/arm/armemu.c b/sim/arm/armemu.c
index f93ad0cee254..ab7454628ba0 100644
--- a/sim/arm/armemu.c
+++ b/sim/arm/armemu.c
@@ -15,6 +15,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 "defs.h"
+
 #include "armdefs.h"
 #include "armemu.h"
 #include "armos.h"
diff --git a/sim/arm/arminit.c b/sim/arm/arminit.c
index 3a626c84674e..bc5456f47b77 100644
--- a/sim/arm/arminit.c
+++ b/sim/arm/arminit.c
@@ -14,6 +14,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 "defs.h"
+
 #include <string.h>
 
 #include "armdefs.h"
diff --git a/sim/arm/armos.c b/sim/arm/armos.c
index 2ce7051a44ce..76706fefff33 100644
--- a/sim/arm/armos.c
+++ b/sim/arm/armos.c
@@ -21,7 +21,9 @@
    fun, and definign VAILDATE will define SWI 1 to enter SVC mode, and SWI
    0x11 to halt the emulator.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "ansidecl.h"
 #include "libiberty.h"
 
diff --git a/sim/arm/armsupp.c b/sim/arm/armsupp.c
index 11bb53c5b704..1a5eeaff1d65 100644
--- a/sim/arm/armsupp.c
+++ b/sim/arm/armsupp.c
@@ -14,6 +14,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 "defs.h"
+
 #include "armdefs.h"
 #include "armemu.h"
 #include "ansidecl.h"
diff --git a/sim/arm/armvirt.c b/sim/arm/armvirt.c
index 4f95ed838f68..ba01a652ebcc 100644
--- a/sim/arm/armvirt.c
+++ b/sim/arm/armvirt.c
@@ -22,6 +22,9 @@
    freed as they might be needed again. A single area of memory may be
    defined to generate aborts.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "armos.h"
 #include "armdefs.h"
 #include "ansidecl.h"
diff --git a/sim/arm/iwmmxt.c b/sim/arm/iwmmxt.c
index 8e818248645d..c71d06f4c6bf 100644
--- a/sim/arm/iwmmxt.c
+++ b/sim/arm/iwmmxt.c
@@ -15,6 +15,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 "defs.h"
+
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/sim/arm/maverick.c b/sim/arm/maverick.c
index 15041b63cc8c..fb62ccd8c8c4 100644
--- a/sim/arm/maverick.c
+++ b/sim/arm/maverick.c
@@ -15,6 +15,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 "defs.h"
+
 #include <assert.h>
 #include "armdefs.h"
 #include "ansidecl.h"
diff --git a/sim/arm/thumbemu.c b/sim/arm/thumbemu.c
index fa70d5bfcfbf..6915d23ec4cc 100644
--- a/sim/arm/thumbemu.c
+++ b/sim/arm/thumbemu.c
@@ -18,6 +18,9 @@
 instruction into its corresponding ARM instruction, and using the
 existing ARM simulator.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #ifndef MODET			/* required for the Thumb instruction support */
 #if 1
 #error "MODET needs to be defined for the Thumb world to work"
diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c
index 54a04f424284..f81024e8bc29 100644
--- a/sim/arm/wrapper.c
+++ b/sim/arm/wrapper.c
@@ -20,7 +20,9 @@
    run.c and gdb (when the simulator is linked with gdb).
    All simulator interaction should go through this file.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
diff --git a/sim/avr/interp.c b/sim/avr/interp.c
index c806f4c46eba..81c935223d42 100644
--- a/sim/avr/interp.c
+++ b/sim/avr/interp.c
@@ -17,7 +17,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <string.h>
 
diff --git a/sim/bfin/bfin-sim.c b/sim/bfin/bfin-sim.c
index 33bbc6e4963f..486fe4717ef5 100644
--- a/sim/bfin/bfin-sim.c
+++ b/sim/bfin/bfin-sim.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/bfin/devices.c b/sim/bfin/devices.c
index aadb9bcf1f46..97873f6f59ee 100644
--- a/sim/bfin/devices.c
+++ b/sim/bfin/devices.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "sim-hw.h"
diff --git a/sim/bfin/dv-bfin_cec.c b/sim/bfin/dv-bfin_cec.c
index 2236830d24d2..6179b16ad8a8 100644
--- a/sim/bfin/dv-bfin_cec.c
+++ b/sim/bfin/dv-bfin_cec.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_ctimer.c b/sim/bfin/dv-bfin_ctimer.c
index beb4a0e76f80..df62d9487e60 100644
--- a/sim/bfin/dv-bfin_ctimer.c
+++ b/sim/bfin/dv-bfin_ctimer.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_dma.c b/sim/bfin/dv-bfin_dma.c
index e3834d761433..d7dc541dd8ce 100644
--- a/sim/bfin/dv-bfin_dma.c
+++ b/sim/bfin/dv-bfin_dma.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdlib.h>
 
diff --git a/sim/bfin/dv-bfin_dmac.c b/sim/bfin/dv-bfin_dmac.c
index ae720cb8b61f..d5c608f4cd9d 100644
--- a/sim/bfin/dv-bfin_dmac.c
+++ b/sim/bfin/dv-bfin_dmac.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "sim-hw.h"
diff --git a/sim/bfin/dv-bfin_ebiu_amc.c b/sim/bfin/dv-bfin_ebiu_amc.c
index 67f557d29b22..29c4c4a5a9f9 100644
--- a/sim/bfin/dv-bfin_ebiu_amc.c
+++ b/sim/bfin/dv-bfin_ebiu_amc.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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_ebiu_ddrc.c b/sim/bfin/dv-bfin_ebiu_ddrc.c
index 4206c2537782..4160cb210e5d 100644
--- a/sim/bfin/dv-bfin_ebiu_ddrc.c
+++ b/sim/bfin/dv-bfin_ebiu_ddrc.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_ebiu_sdc.c b/sim/bfin/dv-bfin_ebiu_sdc.c
index d542f02c082c..4af04dcdac4d 100644
--- a/sim/bfin/dv-bfin_ebiu_sdc.c
+++ b/sim/bfin/dv-bfin_ebiu_sdc.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_emac.c b/sim/bfin/dv-bfin_emac.c
index 249aef6b9d3d..e5ceedbef514 100644
--- a/sim/bfin/dv-bfin_emac.c
+++ b/sim/bfin/dv-bfin_emac.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <errno.h>
 #include <fcntl.h>
diff --git a/sim/bfin/dv-bfin_eppi.c b/sim/bfin/dv-bfin_eppi.c
index ad36a943f208..169895d3dd4e 100644
--- a/sim/bfin/dv-bfin_eppi.c
+++ b/sim/bfin/dv-bfin_eppi.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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_evt.c b/sim/bfin/dv-bfin_evt.c
index c4cf691da924..e49f4804fe65 100644
--- a/sim/bfin/dv-bfin_evt.c
+++ b/sim/bfin/dv-bfin_evt.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_gpio.c b/sim/bfin/dv-bfin_gpio.c
index 2830aa3847f0..bbcc54f0fb54 100644
--- a/sim/bfin/dv-bfin_gpio.c
+++ b/sim/bfin/dv-bfin_gpio.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_gpio2.c b/sim/bfin/dv-bfin_gpio2.c
index 2933ad15b869..61c99802c136 100644
--- a/sim/bfin/dv-bfin_gpio2.c
+++ b/sim/bfin/dv-bfin_gpio2.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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_gptimer.c b/sim/bfin/dv-bfin_gptimer.c
index 8f2b476eeb62..3dfa2b58e910 100644
--- a/sim/bfin/dv-bfin_gptimer.c
+++ b/sim/bfin/dv-bfin_gptimer.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_jtag.c b/sim/bfin/dv-bfin_jtag.c
index d97b9eac822f..12629970cc88 100644
--- a/sim/bfin/dv-bfin_jtag.c
+++ b/sim/bfin/dv-bfin_jtag.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_mmu.c b/sim/bfin/dv-bfin_mmu.c
index cbaaaa2cae15..cadc9df552e9 100644
--- a/sim/bfin/dv-bfin_mmu.c
+++ b/sim/bfin/dv-bfin_mmu.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "sim-options.h"
diff --git a/sim/bfin/dv-bfin_nfc.c b/sim/bfin/dv-bfin_nfc.c
index a26cb1399035..80fe49da72ce 100644
--- a/sim/bfin/dv-bfin_nfc.c
+++ b/sim/bfin/dv-bfin_nfc.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_otp.c b/sim/bfin/dv-bfin_otp.c
index e11e04e96729..6cf1c8155c62 100644
--- a/sim/bfin/dv-bfin_otp.c
+++ b/sim/bfin/dv-bfin_otp.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_pfmon.c b/sim/bfin/dv-bfin_pfmon.c
index 2216c064569c..bffe67b18a06 100644
--- a/sim/bfin/dv-bfin_pfmon.c
+++ b/sim/bfin/dv-bfin_pfmon.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_pint.c b/sim/bfin/dv-bfin_pint.c
index 90b3190c025a..b4f4f40ab656 100644
--- a/sim/bfin/dv-bfin_pint.c
+++ b/sim/bfin/dv-bfin_pint.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_pll.c b/sim/bfin/dv-bfin_pll.c
index 5ba1a6afafcb..e2a5f5cd55c6 100644
--- a/sim/bfin/dv-bfin_pll.c
+++ b/sim/bfin/dv-bfin_pll.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "machs.h"
diff --git a/sim/bfin/dv-bfin_ppi.c b/sim/bfin/dv-bfin_ppi.c
index e319df91440d..a67dc5eecb0f 100644
--- a/sim/bfin/dv-bfin_ppi.c
+++ b/sim/bfin/dv-bfin_ppi.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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_rtc.c b/sim/bfin/dv-bfin_rtc.c
index 5486ac8287fe..06ae4249d6e2 100644
--- a/sim/bfin/dv-bfin_rtc.c
+++ b/sim/bfin/dv-bfin_rtc.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <time.h>
 #include "sim-main.h"
diff --git a/sim/bfin/dv-bfin_sic.c b/sim/bfin/dv-bfin_sic.c
index 94e55f21eea8..cc90a4cf22a2 100644
--- a/sim/bfin/dv-bfin_sic.c
+++ b/sim/bfin/dv-bfin_sic.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_spi.c b/sim/bfin/dv-bfin_spi.c
index 8fdd9dbc5149..c0869fcf77ca 100644
--- a/sim/bfin/dv-bfin_spi.c
+++ b/sim/bfin/dv-bfin_spi.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_trace.c b/sim/bfin/dv-bfin_trace.c
index ab8220f7a19d..56fad63cd3e7 100644
--- a/sim/bfin/dv-bfin_trace.c
+++ b/sim/bfin/dv-bfin_trace.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_twi.c b/sim/bfin/dv-bfin_twi.c
index 87794f538528..00b080f122c4 100644
--- a/sim/bfin/dv-bfin_twi.c
+++ b/sim/bfin/dv-bfin_twi.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_uart.c b/sim/bfin/dv-bfin_uart.c
index d01362175028..7aa843065b8b 100644
--- a/sim/bfin/dv-bfin_uart.c
+++ b/sim/bfin/dv-bfin_uart.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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "dv-sockser.h"
diff --git a/sim/bfin/dv-bfin_uart2.c b/sim/bfin/dv-bfin_uart2.c
index 2fd540164dc2..a7985889f87d 100644
--- a/sim/bfin/dv-bfin_uart2.c
+++ b/sim/bfin/dv-bfin_uart2.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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-bfin_wdog.c b/sim/bfin/dv-bfin_wdog.c
index 4be19aa64588..850ae0618df0 100644
--- a/sim/bfin/dv-bfin_wdog.c
+++ b/sim/bfin/dv-bfin_wdog.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "dv-sockser.h"
diff --git a/sim/bfin/dv-bfin_wp.c b/sim/bfin/dv-bfin_wp.c
index 28626a569f85..189c121d97a1 100644
--- a/sim/bfin/dv-bfin_wp.c
+++ b/sim/bfin/dv-bfin_wp.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/dv-eth_phy.c b/sim/bfin/dv-eth_phy.c
index 14aafee9192b..486054277c2f 100644
--- a/sim/bfin/dv-eth_phy.c
+++ b/sim/bfin/dv-eth_phy.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "devices.h"
diff --git a/sim/bfin/gui.c b/sim/bfin/gui.c
index 029a22ef3b5c..8e84d2dff961 100644
--- a/sim/bfin/gui.c
+++ b/sim/bfin/gui.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #ifdef HAVE_SDL
 # include <SDL.h>
diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c
index a4333daa44dd..4b7b111f7c72 100644
--- a/sim/bfin/interp.c
+++ b/sim/bfin/interp.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/bfin/machs.c b/sim/bfin/machs.c
index a2060e8d8986..e94af5d0f5b8 100644
--- a/sim/bfin/machs.c
+++ b/sim/bfin/machs.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdlib.h>
 
diff --git a/sim/bpf/bpf-helpers.c b/sim/bpf/bpf-helpers.c
index d7760d572668..c308812ab1cc 100644
--- a/sim/bpf/bpf-helpers.c
+++ b/sim/bpf/bpf-helpers.c
@@ -21,6 +21,9 @@
    implementation of the helpers, which can be customized by the
    user.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #define WANT_CPU_BPFBF
 #define WANT_CPU bpfbf
 
diff --git a/sim/bpf/bpf.c b/sim/bpf/bpf.c
index a0cc803da821..c626781adbf8 100644
--- a/sim/bpf/bpf.c
+++ b/sim/bpf/bpf.c
@@ -16,6 +16,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 "defs.h"
+
 #define WANT_CPU_BPFBF
 #define WANT_CPU bpfbf
 
diff --git a/sim/bpf/sim-if.c b/sim/bpf/sim-if.c
index c2c01fc547a0..185e96dd7b93 100644
--- a/sim/bpf/sim-if.c
+++ b/sim/bpf/sim-if.c
@@ -16,6 +16,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 "defs.h"
+
 #include <stdlib.h>
 
 #include "sim-main.h"
diff --git a/sim/bpf/traps.c b/sim/bpf/traps.c
index b58d17f04013..85da1cba02e6 100644
--- a/sim/bpf/traps.c
+++ b/sim/bpf/traps.c
@@ -16,6 +16,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 "defs.h"
+
 #define WANT_CPU bpfbf
 #define WANT_CPU_BPFBF
 
diff --git a/sim/common/callback.c b/sim/common/callback.c
index 55280abb04b9..e888dd4ca67e 100644
--- a/sim/common/callback.c
+++ b/sim/common/callback.c
@@ -20,9 +20,9 @@
 /* This file provides a standard way for targets to talk to the host OS
    level.  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "ansidecl.h"
 #include <stdarg.h>
 #include <stdio.h>
diff --git a/sim/common/cgen-accfp.c b/sim/common/cgen-accfp.c
index d6cd751e2b05..345cfe81eb28 100644
--- a/sim/common/cgen-accfp.c
+++ b/sim/common/cgen-accfp.c
@@ -11,6 +11,9 @@
    - proper rounding
 */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-fpu.h"
 
diff --git a/sim/common/cgen-fpu.c b/sim/common/cgen-fpu.c
index 3a8d5199bea5..1b035eae3432 100644
--- a/sim/common/cgen-fpu.c
+++ b/sim/common/cgen-fpu.c
@@ -1,6 +1,9 @@
 /* CGEN fpu support
    Copyright (C) 1999 Cygnus Solutions.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-fpu.h"
 
diff --git a/sim/common/cgen-par.c b/sim/common/cgen-par.c
index 4cf0388e16f4..b535edfdaec0 100644
--- a/sim/common/cgen-par.c
+++ b/sim/common/cgen-par.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include <stdlib.h>
 #include "cgen-mem.h"
diff --git a/sim/common/cgen-run.c b/sim/common/cgen-run.c
index 1458c4e5d154..443b62a0bbc3 100644
--- a/sim/common/cgen-run.c
+++ b/sim/common/cgen-run.c
@@ -33,6 +33,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    When the framework is more modular, this can be.
 */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/cgen-scache.c b/sim/common/cgen-scache.c
index 56df075f6804..f1c757148402 100644
--- a/sim/common/cgen-scache.c
+++ b/sim/common/cgen-scache.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #define SCACHE_DEFINE_INLINE
 
 #include "sim-main.h"
diff --git a/sim/common/cgen-trace.c b/sim/common/cgen-trace.c
index 649c37a61b1c..e55607de9fac 100644
--- a/sim/common/cgen-trace.c
+++ b/sim/common/cgen-trace.c
@@ -17,7 +17,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <errno.h>
 #include <stdlib.h>
 #include "dis-asm.h"
diff --git a/sim/common/cgen-utils.c b/sim/common/cgen-utils.c
index 3d7c2821eaa2..fd3deab6782e 100644
--- a/sim/common/cgen-utils.c
+++ b/sim/common/cgen-utils.c
@@ -17,7 +17,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "bfd.h"
 #include "sim-main.h"
 #include "dis-asm.h"
diff --git a/sim/common/defs.h b/sim/common/defs.h
new file mode 100644
index 000000000000..3a0737cb9b89
--- /dev/null
+++ b/sim/common/defs.h
@@ -0,0 +1,30 @@
+/* The configure generated header settings.
+
+   Copyright 2002-2021 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/>.  */
+
+/* This file should be included by every .c file before any other header.  */
+
+#ifndef DEFS_H
+#define DEFS_H
+
+#ifdef HAVE_CONFIG_H
+
+/* Include sim's various configure tests.  */
+#include "config.h"
+
+#endif
+
+#endif
diff --git a/sim/common/dv-cfi.c b/sim/common/dv-cfi.c
index b8652271752d..02a2cedd558b 100644
--- a/sim/common/dv-cfi.c
+++ b/sim/common/dv-cfi.c
@@ -22,7 +22,8 @@
 
 /* TODO: support vendor query tables.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <math.h>
 #include <errno.h>
diff --git a/sim/common/dv-core.c b/sim/common/dv-core.c
index be56aa462959..c596da45c985 100644
--- a/sim/common/dv-core.c
+++ b/sim/common/dv-core.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 "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/common/dv-glue.c b/sim/common/dv-glue.c
index 8bda32615780..7c8e1f877af2 100644
--- a/sim/common/dv-glue.c
+++ b/sim/common/dv-glue.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 "defs.h"
 
 #include "hw-main.h"
 
diff --git a/sim/common/dv-pal.c b/sim/common/dv-pal.c
index dd4ab4fb390f..c60f524ea8ea 100644
--- a/sim/common/dv-pal.c
+++ b/sim/common/dv-pal.c
@@ -19,7 +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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "hw-main.h"
 #include "sim-io.h"
diff --git a/sim/common/dv-sockser.c b/sim/common/dv-sockser.c
index 73c473b15c01..ef652f62f468 100644
--- a/sim/common/dv-sockser.c
+++ b/sim/common/dv-sockser.c
@@ -18,7 +18,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 /* FIXME: will obviously need to evolve.
    - connectionless sockets might be more appropriate.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 
 #include <string.h>
diff --git a/sim/common/genmloop.sh b/sim/common/genmloop.sh
index 460a26c31e56..fa4e7b90a516 100755
--- a/sim/common/genmloop.sh
+++ b/sim/common/genmloop.sh
@@ -301,6 +301,9 @@ exec 1>tmp-mloop-$$.cin
 cat << EOF
 /* This file is generated by the genmloop script.  DO NOT EDIT! */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 /* Enable switch() support in cgen headers.  */
 #define SEM_IN_SWITCH
 
diff --git a/sim/common/gentmap.c b/sim/common/gentmap.c
index a606fad0e4ff..acfaed3fd7e0 100644
--- a/sim/common/gentmap.c
+++ b/sim/common/gentmap.c
@@ -67,7 +67,7 @@ gen_targ_map_c (void)
   printf ("/* Target value mapping utilities needed by the simulator and gdb.  */\n");
   printf ("/* This file is machine generated by gentmap.c.  */\n\n");
 
-  printf ("#include \"config.h\"\n");
+  printf ("#include \"defs.h\"\n");
   printf ("#include <errno.h>\n");
   printf ("#include <fcntl.h>\n");
   printf ("#include \"ansidecl.h\"\n");
diff --git a/sim/common/hw-alloc.c b/sim/common/hw-alloc.c
index 141dc21167f3..a16666b931a0 100644
--- a/sim/common/hw-alloc.c
+++ b/sim/common/hw-alloc.c
@@ -17,6 +17,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "hw-main.h"
 #include "hw-base.h"
diff --git a/sim/common/hw-base.c b/sim/common/hw-base.c
index af8b18124896..af4cc50f1a4b 100644
--- a/sim/common/hw-base.c
+++ b/sim/common/hw-base.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 "defs.h"
 
 #include "hw-main.h"
 #include "hw-base.h"
diff --git a/sim/common/hw-device.c b/sim/common/hw-device.c
index bc91264c0208..9b743ead1f2c 100644
--- a/sim/common/hw-device.c
+++ b/sim/common/hw-device.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 "defs.h"
 
 #include "hw-main.h"
 #include "hw-base.h"
diff --git a/sim/common/hw-events.c b/sim/common/hw-events.c
index 81628f0b642f..620b47d5255a 100644
--- a/sim/common/hw-events.c
+++ b/sim/common/hw-events.c
@@ -17,6 +17,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "hw-main.h"
 #include "hw-base.h"
diff --git a/sim/common/hw-handles.c b/sim/common/hw-handles.c
index bbd08f632fdd..fb878e492774 100644
--- a/sim/common/hw-handles.c
+++ b/sim/common/hw-handles.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 "defs.h"
 
 #include "hw-main.h"
 #include "hw-base.h"
diff --git a/sim/common/hw-instances.c b/sim/common/hw-instances.c
index 6227c0a2343c..9d786198fd5b 100644
--- a/sim/common/hw-instances.c
+++ b/sim/common/hw-instances.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 "defs.h"
 
 #include "hw-main.h"
 #include "hw-base.h"
diff --git a/sim/common/hw-ports.c b/sim/common/hw-ports.c
index 50e2cbc30e45..fbc7278ddd1f 100644
--- a/sim/common/hw-ports.c
+++ b/sim/common/hw-ports.c
@@ -17,6 +17,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "hw-main.h"
 #include "hw-base.h"
diff --git a/sim/common/hw-properties.c b/sim/common/hw-properties.c
index 11a371cea00f..3836aa73527e 100644
--- a/sim/common/hw-properties.c
+++ b/sim/common/hw-properties.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 "defs.h"
+
 #include "hw-main.h"
 #include "hw-base.h"
 
diff --git a/sim/common/hw-tree.c b/sim/common/hw-tree.c
index 4d50ec6ed62e..1bf4edab746b 100644
--- a/sim/common/hw-tree.c
+++ b/sim/common/hw-tree.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 "defs.h"
 
 #include "hw-main.h"
 #include "hw-base.h"
diff --git a/sim/common/nrun.c b/sim/common/nrun.c
index 1ceb0837e2c2..97957403d79b 100644
--- a/sim/common/nrun.c
+++ b/sim/common/nrun.c
@@ -15,9 +15,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/>.  */
 
 /* Need to be before general includes, to pick up e.g. _GNU_SOURCE.  */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include "defs.h"
 
 #include <signal.h>
 #include <stdlib.h>
diff --git a/sim/common/sim-abort.c b/sim/common/sim-abort.c
index bf05504255fc..06df127c19c0 100644
--- a/sim/common/sim-abort.c
+++ b/sim/common/sim-abort.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/sim/common/sim-arange.c b/sim/common/sim-arange.c
index a40dabbeb7d7..5a28a2c0c495 100644
--- a/sim/common/sim-arange.c
+++ b/sim/common/sim-arange.c
@@ -20,6 +20,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifndef _SIM_ARANGE_C_
 #define _SIM_ARANGE_C_
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "libiberty.h"
 #include "sim-basics.h"
 #include "sim-arange.h"
diff --git a/sim/common/sim-basics.h b/sim/common/sim-basics.h
index e822fb2eb818..6254190cf62b 100644
--- a/sim/common/sim-basics.h
+++ b/sim/common/sim-basics.h
@@ -26,9 +26,7 @@
 
 /* Basic configuration */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include "defs.h"
 
 /* Basic host dependant mess - hopefully <stdio.h> + <stdarg.h> will
    bring potential conflicts out in the open */
diff --git a/sim/common/sim-bits.c b/sim/common/sim-bits.c
index 9e9063cb594c..4be07521b00f 100644
--- a/sim/common/sim-bits.c
+++ b/sim/common/sim-bits.c
@@ -23,6 +23,9 @@
 #ifndef _SIM_BITS_C_
 #define _SIM_BITS_C_
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-basics.h"
 #include "sim-assert.h"
 #include "sim-io.h"
diff --git a/sim/common/sim-close.c b/sim/common/sim-close.c
index 6878dfcbf312..78beffd5dd65 100644
--- a/sim/common/sim-close.c
+++ b/sim/common/sim-close.c
@@ -18,6 +18,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 "defs.h"
+
 #include "sim-main.h"
 #include "sim-module.h"
 #include "gdb/remote-sim.h"
diff --git a/sim/common/sim-command.c b/sim/common/sim-command.c
index d49ac8a26282..b5ba2c05054d 100644
--- a/sim/common/sim-command.c
+++ b/sim/common/sim-command.c
@@ -18,6 +18,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 "defs.h"
+
 #include "sim-main.h"
 #include "sim-options.h"
 #include "sim-utils.h"
diff --git a/sim/common/sim-config.c b/sim/common/sim-config.c
index 2acd1e4f77af..df99d6a957fd 100644
--- a/sim/common/sim-config.c
+++ b/sim/common/sim-config.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 "defs.h"
 
 #include "sim-main.h"
 #include "sim-assert.h"
diff --git a/sim/common/sim-core.c b/sim/common/sim-core.c
index 9b1e16832104..028bbabd59db 100644
--- a/sim/common/sim-core.c
+++ b/sim/common/sim-core.c
@@ -23,6 +23,9 @@
 #ifndef SIM_CORE_C
 #define SIM_CORE_C
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 #include "libiberty.h"
diff --git a/sim/common/sim-cpu.c b/sim/common/sim-cpu.c
index 552e48c19707..587a3e8c9e1c 100644
--- a/sim/common/sim-cpu.c
+++ b/sim/common/sim-cpu.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdlib.h>
 
 #include "sim-main.h"
diff --git a/sim/common/sim-endian.c b/sim/common/sim-endian.c
index 395b487ee81d..5f0e46a84e5b 100644
--- a/sim/common/sim-endian.c
+++ b/sim/common/sim-endian.c
@@ -23,6 +23,9 @@
 #ifndef _SIM_ENDIAN_C_
 #define _SIM_ENDIAN_C_
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-basics.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-engine.c b/sim/common/sim-engine.c
index fcdf284127f5..a5f84af2801b 100644
--- a/sim/common/sim-engine.c
+++ b/sim/common/sim-engine.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-events.c b/sim/common/sim-events.c
index 60e4c55a874c..5a5798d102a8 100644
--- a/sim/common/sim-events.c
+++ b/sim/common/sim-events.c
@@ -23,6 +23,9 @@
 #ifndef _SIM_EVENTS_C_
 #define _SIM_EVENTS_C_
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 #include "sim-cpu.h"
diff --git a/sim/common/sim-fpu.c b/sim/common/sim-fpu.c
index bff5b08b5e59..fe8ecf8a3ce5 100644
--- a/sim/common/sim-fpu.c
+++ b/sim/common/sim-fpu.c
@@ -35,6 +35,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifndef SIM_FPU_C
 #define SIM_FPU_C
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-basics.h"
 #include "sim-fpu.h"
 
diff --git a/sim/common/sim-hload.c b/sim/common/sim-hload.c
index 243437dba171..f33dcf6368a8 100644
--- a/sim/common/sim-hload.c
+++ b/sim/common/sim-hload.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "bfd.h"
 #include "sim-utils.h"
diff --git a/sim/common/sim-hrw.c b/sim/common/sim-hrw.c
index 920cc1606888..3df91d2b712d 100644
--- a/sim/common/sim-hrw.c
+++ b/sim/common/sim-hrw.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-hw.c b/sim/common/sim-hw.c
index 984817f25fd0..95d95042ded4 100644
--- a/sim/common/sim-hw.c
+++ b/sim/common/sim-hw.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 #include "sim-options.h"
diff --git a/sim/common/sim-info.c b/sim/common/sim-info.c
index 7dcb656f8154..3c92c87faab1 100644
--- a/sim/common/sim-info.c
+++ b/sim/common/sim-info.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-inline.c b/sim/common/sim-inline.c
index 93ea6f03cad5..7c3edd0d1cd1 100644
--- a/sim/common/sim-inline.c
+++ b/sim/common/sim-inline.c
@@ -26,6 +26,9 @@
 #undef SIM_INLINE_P
 #define SIM_INLINE_P 1
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-inline.h"
 #include "sim-main.h"
 
diff --git a/sim/common/sim-io.c b/sim/common/sim-io.c
index f418c3748cdc..bfe14845c10f 100644
--- a/sim/common/sim-io.c
+++ b/sim/common/sim-io.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 "defs.h"
 
 #include "sim-main.h"
 #include "sim-io.h"
@@ -35,6 +37,8 @@
 
 #include <stdlib.h>
 
+#undef open
+
 /* Define the rate at which the simulator should poll the host
    for a quit. */
 #ifndef POLL_QUIT_INTERVAL
diff --git a/sim/common/sim-load.c b/sim/common/sim-load.c
index 04681c524a0c..3d5f605e3d2f 100644
--- a/sim/common/sim-load.c
+++ b/sim/common/sim-load.c
@@ -18,9 +18,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    as it is used by simulators that don't use it [though that doesn't mean
    to suggest that they shouldn't :-)].  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "ansidecl.h"
 #include <stdio.h> /* for NULL */
 #include <stdarg.h>
diff --git a/sim/common/sim-memopt.c b/sim/common/sim-memopt.c
index a102d74ecd0b..636f6a9a0feb 100644
--- a/sim/common/sim-memopt.c
+++ b/sim/common/sim-memopt.c
@@ -17,7 +17,8 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "sim-assert.h"
diff --git a/sim/common/sim-model.c b/sim/common/sim-model.c
index 5596656eff51..e1af9d4b1e46 100644
--- a/sim/common/sim-model.c
+++ b/sim/common/sim-model.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-model.h"
 #include "libiberty.h"
diff --git a/sim/common/sim-module.c b/sim/common/sim-module.c
index 3bb7db0df769..97d619c4aedd 100644
--- a/sim/common/sim-module.c
+++ b/sim/common/sim-module.c
@@ -19,7 +19,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-io.h"
 #include "sim-options.h"
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index 1efb21fc62b8..d242828ff2f0 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -17,7 +17,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include <string.h>
 #include <stdlib.h>
diff --git a/sim/common/sim-profile.c b/sim/common/sim-profile.c
index 455e1a246d93..f2d65e093030 100644
--- a/sim/common/sim-profile.c
+++ b/sim/common/sim-profile.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-io.h"
 #include "sim-options.h"
diff --git a/sim/common/sim-reason.c b/sim/common/sim-reason.c
index 0f128c2a4240..73a57654c246 100644
--- a/sim/common/sim-reason.c
+++ b/sim/common/sim-reason.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-reg.c b/sim/common/sim-reg.c
index 457ac223da37..ee340884aa3c 100644
--- a/sim/common/sim-reg.c
+++ b/sim/common/sim-reg.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-resume.c b/sim/common/sim-resume.c
index 6fe9a4233f6e..8f854da84751 100644
--- a/sim/common/sim-resume.c
+++ b/sim/common/sim-resume.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-run.c b/sim/common/sim-run.c
index 54f6286f09e7..f2e477e3361b 100644
--- a/sim/common/sim-run.c
+++ b/sim/common/sim-run.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-signal.c b/sim/common/sim-signal.c
index 9596847af555..f9fef4c24c64 100644
--- a/sim/common/sim-signal.c
+++ b/sim/common/sim-signal.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 #include "sim-main.h"
 
diff --git a/sim/common/sim-stop.c b/sim/common/sim-stop.c
index 305c455dc49f..aa48fc3e6f36 100644
--- a/sim/common/sim-stop.c
+++ b/sim/common/sim-stop.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-syscall.c b/sim/common/sim-syscall.c
index e91453d5ba1f..9118f8dc15f0 100644
--- a/sim/common/sim-syscall.c
+++ b/sim/common/sim-syscall.c
@@ -17,7 +17,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <errno.h>
 
diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c
index 26d9556322cf..b8224e0b8346 100644
--- a/sim/common/sim-trace.c
+++ b/sim/common/sim-trace.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-io.h"
 #include "sim-options.h"
diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c
index 86ab059744ce..abb87f8c5a04 100644
--- a/sim/common/sim-utils.c
+++ b/sim/common/sim-utils.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/common/sim-watch.c b/sim/common/sim-watch.c
index 8630b063bb65..fa035b380549 100644
--- a/sim/common/sim-watch.c
+++ b/sim/common/sim-watch.c
@@ -17,7 +17,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-options.h"
 #include "libiberty.h"
diff --git a/sim/common/syscall.c b/sim/common/syscall.c
index f2883c493acd..60314bf79e68 100644
--- a/sim/common/syscall.c
+++ b/sim/common/syscall.c
@@ -23,9 +23,9 @@
    tree, nor should it live in the gdb source tree.  K&R C must be
    supported.  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "ansidecl.h"
 #include "libiberty.h"
 #include <stdarg.h>
diff --git a/sim/cr16/cr16_sim.h b/sim/cr16/cr16_sim.h
index 8232f0743f7b..52114e30f81b 100644
--- a/sim/cr16/cr16_sim.h
+++ b/sim/cr16/cr16_sim.h
@@ -18,7 +18,6 @@
    along with this program. If not, see <http://www.gnu.org/licenses/>.  */
 
 
-#include "config.h"
 #include <stdio.h>
 #include <ctype.h>
 #include <limits.h>
diff --git a/sim/cr16/gencode.c b/sim/cr16/gencode.c
index 335ab2607fca..30fda931c8c0 100644
--- a/sim/cr16/gencode.c
+++ b/sim/cr16/gencode.c
@@ -17,8 +17,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 "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <ctype.h>
 #include <limits.h>
@@ -67,6 +68,7 @@ write_template (void)
 {
   int i = 0,j, k, flags;
 
+  printf ("#include \"defs.h\"\n");
   printf ("#include \"sim-main.h\"\n");
   printf ("#include \"simops.h\"\n\n");
 
@@ -131,6 +133,7 @@ write_opcodes (void)
   int i = 0, j = 0, k;
   
   /* write out opcode table.  */
+  printf ("#include \"defs.h\"\n");
   printf ("#include \"sim-main.h\"\n");
   printf ("#include \"simops.h\"\n\n");
   printf ("struct simops Simops[] = {\n");
diff --git a/sim/cr16/interp.c b/sim/cr16/interp.c
index 8f7fafa715e9..e8e27275f484 100644
--- a/sim/cr16/interp.c
+++ b/sim/cr16/interp.c
@@ -17,7 +17,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <inttypes.h>
 #include <signal.h>
 #include <stdlib.h>
diff --git a/sim/cr16/simops.c b/sim/cr16/simops.c
index ca96dd075883..b383dfa1f926 100644
--- a/sim/cr16/simops.c
+++ b/sim/cr16/simops.c
@@ -17,8 +17,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/>.  */
 
-
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <signal.h>
 #include <errno.h>
diff --git a/sim/cris/dv-cris.c b/sim/cris/dv-cris.c
index 1bb89e48f705..b4251d0b5e41 100644
--- a/sim/cris/dv-cris.c
+++ b/sim/cris/dv-cris.c
@@ -17,6 +17,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 "defs.h"
+
 #include "sim-main.h"
 #include "hw-main.h"
 
diff --git a/sim/cris/dv-cris_900000xx.c b/sim/cris/dv-cris_900000xx.c
index c6afe020c861..5cecdc7b0a55 100644
--- a/sim/cris/dv-cris_900000xx.c
+++ b/sim/cris/dv-cris_900000xx.c
@@ -18,6 +18,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 "defs.h"
+
 #include "sim-main.h"
 #include "hw-main.h"
 
diff --git a/sim/cris/dv-rv.c b/sim/cris/dv-rv.c
index cef164b0983b..310155c84420 100644
--- a/sim/cris/dv-rv.c
+++ b/sim/cris/dv-rv.c
@@ -18,6 +18,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 "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/cris/rvdummy.c b/sim/cris/rvdummy.c
index 788f8edb504e..b53e823f8f7a 100644
--- a/sim/cris/rvdummy.c
+++ b/sim/cris/rvdummy.c
@@ -29,9 +29,8 @@ main (int argc, char *argv[])
 }
 #else
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "getopt.h"
 #include "libiberty.h"
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index edd7885caf70..ce35a4e1ccd1 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -20,7 +20,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Based on the fr30 file, mixing in bits from the i960 and pruning of
    dead code.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "libiberty.h"
 #include "bfd.h"
 #include "elf-bfd.h"
diff --git a/sim/cris/traps.c b/sim/cris/traps.c
index 1c8ca41d14ee..74088e66123d 100644
--- a/sim/cris/traps.c
+++ b/sim/cris/traps.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-syscall.h"
 #include "sim-options.h"
diff --git a/sim/d10v/d10v_sim.h b/sim/d10v/d10v_sim.h
index 64f974f01dbc..71c753ae6a2d 100644
--- a/sim/d10v/d10v_sim.h
+++ b/sim/d10v/d10v_sim.h
@@ -1,4 +1,3 @@
-#include "config.h"
 #include <stdio.h>
 #include <ctype.h>
 #include <limits.h>
diff --git a/sim/d10v/gencode.c b/sim/d10v/gencode.c
index 9f8a41c93694..6e006d089a67 100644
--- a/sim/d10v/gencode.c
+++ b/sim/d10v/gencode.c
@@ -1,4 +1,3 @@
-#include "config.h"
 #include <stdio.h>
 #include <ctype.h>
 #include <limits.h>
diff --git a/sim/d10v/interp.c b/sim/d10v/interp.c
index 86e566a79fb8..e16f0aa1de2d 100644
--- a/sim/d10v/interp.c
+++ b/sim/d10v/interp.c
@@ -1,4 +1,6 @@
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <inttypes.h>
 #include <signal.h>
 #include "bfd.h"
diff --git a/sim/d10v/simops.c b/sim/d10v/simops.c
index ed0c8a362591..af725ad9bb99 100644
--- a/sim/d10v/simops.c
+++ b/sim/d10v/simops.c
@@ -1,4 +1,5 @@
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <signal.h>
 #include <errno.h>
diff --git a/sim/erc32/erc32.c b/sim/erc32/erc32.c
index a93b62b798c4..747ac780b898 100644
--- a/sim/erc32/erc32.c
+++ b/sim/erc32/erc32.c
@@ -18,7 +18,9 @@
 
 /* The control space devices */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/sim/erc32/exec.c b/sim/erc32/exec.c
index 8daf759514ec..d8a8c6c662b9 100644
--- a/sim/erc32/exec.c
+++ b/sim/erc32/exec.c
@@ -16,7 +16,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sis.h"
 #include <math.h>
 #include <stdio.h>
diff --git a/sim/erc32/float.c b/sim/erc32/float.c
index 6d3d2bd73d26..d2ae39785a32 100644
--- a/sim/erc32/float.c
+++ b/sim/erc32/float.c
@@ -26,7 +26,9 @@
      4. Clear host exception bits.
  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sis.h"
 #include <fenv.h>
 
diff --git a/sim/erc32/func.c b/sim/erc32/func.c
index 52428e48350f..ff53f3bca511 100644
--- a/sim/erc32/func.c
+++ b/sim/erc32/func.c
@@ -16,7 +16,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 #include <string.h>
 #include <stdio.h>
diff --git a/sim/erc32/help.c b/sim/erc32/help.c
index 419ab0d33ef0..211de52f5362 100644
--- a/sim/erc32/help.c
+++ b/sim/erc32/help.c
@@ -16,7 +16,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include "sis.h"
 
diff --git a/sim/erc32/interf.c b/sim/erc32/interf.c
index c8e025b23e08..2a36a61fc5f5 100644
--- a/sim/erc32/interf.c
+++ b/sim/erc32/interf.c
@@ -16,7 +16,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 #include <string.h>
 #include <stdio.h>
diff --git a/sim/erc32/sis.c b/sim/erc32/sis.c
index 05044c3ad8ff..749d25620b44 100644
--- a/sim/erc32/sis.c
+++ b/sim/erc32/sis.c
@@ -16,7 +16,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 #include <string.h>
 #include <stdlib.h>
diff --git a/sim/erc32/sis.h b/sim/erc32/sis.h
index 428a6bdcf151..3aca894af7d3 100644
--- a/sim/erc32/sis.h
+++ b/sim/erc32/sis.h
@@ -13,7 +13,6 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "config.h"
 #include "ansidecl.h"
 #include "gdb/callback.h"
 #include "gdb/remote-sim.h"
diff --git a/sim/example-synacor/interp.c b/sim/example-synacor/interp.c
index d2080b6f7f22..eed1f27818c6 100644
--- a/sim/example-synacor/interp.c
+++ b/sim/example-synacor/interp.c
@@ -25,7 +25,8 @@
    For more specific details on these functions, see the gdb/remote-sim.h
    header file.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "sim-options.h"
diff --git a/sim/example-synacor/sim-main.c b/sim/example-synacor/sim-main.c
index a7d748f3022c..d7a68b38bf46 100644
--- a/sim/example-synacor/sim-main.c
+++ b/sim/example-synacor/sim-main.c
@@ -21,7 +21,8 @@
 /* This file contains the main simulator decoding logic.  i.e. everything that
    is architecture specific.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 \f
diff --git a/sim/frv/sim-main.h b/sim/frv/sim-main.h
index 25a0e566dca6..1515c325e737 100644
--- a/sim/frv/sim-main.h
+++ b/sim/frv/sim-main.h
@@ -19,10 +19,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Main header for the frv.  */
 
-/* sim-basics.h includes config.h but cgen-types.h must be included before
-   sim-basics.h and cgen-types.h needs config.h.  */
-#include "config.h"
-
 /* This is a global setting.  Different cpu families can't mix-n-match -scache
    and -pbb.  However some cpu families may use -simple while others use
    one of -scache/-pbb. ???? */
diff --git a/sim/ft32/interp.c b/sim/ft32/interp.c
index ba2297f4078e..39c4a1226288 100644
--- a/sim/ft32/interp.c
+++ b/sim/ft32/interp.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <fcntl.h>
 #include <signal.h>
 #include <stdlib.h>
diff --git a/sim/h8300/compile.c b/sim/h8300/compile.c
index fb0e51b2e58d..cdf8c75d5cb7 100644
--- a/sim/h8300/compile.c
+++ b/sim/h8300/compile.c
@@ -17,7 +17,9 @@
  * AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 #include <time.h>
 #include <stdlib.h>
diff --git a/sim/h8300/sim-main.h b/sim/h8300/sim-main.h
index b6169b3bc126..68e44ae9333d 100644
--- a/sim/h8300/sim-main.h
+++ b/sim/h8300/sim-main.h
@@ -1,6 +1,5 @@
 /* Main header for the Hitachi h8/300 architecture.  */
 
-#include "config.h"
 #include "bfd.h"
 
 #ifndef SIM_MAIN_H
diff --git a/sim/iq2000/iq2000.c b/sim/iq2000/iq2000.c
index 66d7b47dfb4f..018c6a63a3f3 100644
--- a/sim/iq2000/iq2000.c
+++ b/sim/iq2000/iq2000.c
@@ -17,6 +17,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 "defs.h"
+
 #define WANT_CPU
 #define WANT_CPU_IQ2000BF
 
diff --git a/sim/iq2000/sim-if.c b/sim/iq2000/sim-if.c
index 4db2e4d9b060..b363eb04a218 100644
--- a/sim/iq2000/sim-if.c
+++ b/sim/iq2000/sim-if.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 
 #include <stdlib.h>
diff --git a/sim/iq2000/sim-main.h b/sim/iq2000/sim-main.h
index 829f9bb56ba1..d0ae1cfef7b1 100644
--- a/sim/iq2000/sim-main.h
+++ b/sim/iq2000/sim-main.h
@@ -4,10 +4,6 @@
 #ifndef SIM_MAIN_H
 #define SIM_MAIN_H
 
-/* sim-basics.h includes config.h but cgen-types.h must be included before
-   sim-basics.h and cgen-types.h needs config.h.  */
-#include "config.h"
-
 /* This is a global setting.  Different cpu families can't mix-n-match -scache
    and -pbb.  However some cpu families may use -simple while others use
    one of -scache/-pbb. ???? */
diff --git a/sim/m32c/gdb-if.c b/sim/m32c/gdb-if.c
index c2aff064ff0f..22e1067613b3 100644
--- a/sim/m32c/gdb-if.c
+++ b/sim/m32c/gdb-if.c
@@ -18,7 +18,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <assert.h>
 #include <signal.h>
diff --git a/sim/m32c/int.c b/sim/m32c/int.c
index ffc96ae5dde2..4275399683de 100644
--- a/sim/m32c/int.c
+++ b/sim/m32c/int.c
@@ -18,6 +18,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "int.h"
 #include "cpu.h"
diff --git a/sim/m32c/load.c b/sim/m32c/load.c
index 86e774e3abe9..277fc141495d 100644
--- a/sim/m32c/load.c
+++ b/sim/m32c/load.c
@@ -18,7 +18,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/sim/m32c/main.c b/sim/m32c/main.c
index ac36bc570714..4c2c255ecd5b 100644
--- a/sim/m32c/main.c
+++ b/sim/m32c/main.c
@@ -18,8 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
diff --git a/sim/m32c/mem.c b/sim/m32c/mem.c
index 13513552cd0e..8384c09610d4 100644
--- a/sim/m32c/mem.c
+++ b/sim/m32c/mem.c
@@ -18,8 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/m32c/misc.c b/sim/m32c/misc.c
index 50692e5ac723..5e09885be644 100644
--- a/sim/m32c/misc.c
+++ b/sim/m32c/misc.c
@@ -18,6 +18,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 
diff --git a/sim/m32c/opc2c.c b/sim/m32c/opc2c.c
index 64874279179a..c904e29eab78 100644
--- a/sim/m32c/opc2c.c
+++ b/sim/m32c/opc2c.c
@@ -18,6 +18,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 #include <string.h>
diff --git a/sim/m32c/reg.c b/sim/m32c/reg.c
index 1b3c774cf817..a57b6a11c685 100644
--- a/sim/m32c/reg.c
+++ b/sim/m32c/reg.c
@@ -18,6 +18,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/m32c/safe-fgets.c b/sim/m32c/safe-fgets.c
index 3516fa80bd0f..6ca0c06af892 100644
--- a/sim/m32c/safe-fgets.c
+++ b/sim/m32c/safe-fgets.c
@@ -18,6 +18,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/m32c/srcdest.c b/sim/m32c/srcdest.c
index d5feb1716fb9..f3040c571e84 100644
--- a/sim/m32c/srcdest.c
+++ b/sim/m32c/srcdest.c
@@ -18,6 +18,8 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sim/m32c/syscalls.c b/sim/m32c/syscalls.c
index 86695cb4dde7..25e859c61b85 100644
--- a/sim/m32c/syscalls.c
+++ b/sim/m32c/syscalls.c
@@ -18,7 +18,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
diff --git a/sim/m32c/trace.c b/sim/m32c/trace.c
index 43a4604b9467..05a45d349cfc 100644
--- a/sim/m32c/trace.c
+++ b/sim/m32c/trace.c
@@ -18,7 +18,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
diff --git a/sim/m32r/dv-m32r_cache.c b/sim/m32r/dv-m32r_cache.c
index 44e2537dc6dd..bb63b3d6b23b 100644
--- a/sim/m32r/dv-m32r_cache.c
+++ b/sim/m32r/dv-m32r_cache.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/m32r/dv-m32r_uart.c b/sim/m32r/dv-m32r_uart.c
index e4b091203ed4..c6b529d9352d 100644
--- a/sim/m32r/dv-m32r_uart.c
+++ b/sim/m32r/dv-m32r_uart.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c
index 8d9f4324c9cd..a6d8c486168c 100644
--- a/sim/m32r/sim-if.c
+++ b/sim/m32r/sim-if.c
@@ -17,6 +17,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 "defs.h"
+
 #include "sim-main.h"
 #include "sim-options.h"
 #include "libiberty.h"
diff --git a/sim/m32r/traps-linux.c b/sim/m32r/traps-linux.c
index 1ee1781f0eb5..63ed13788a51 100644
--- a/sim/m32r/traps-linux.c
+++ b/sim/m32r/traps-linux.c
@@ -17,6 +17,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 "defs.h"
+
 #include "sim-main.h"
 #include "sim-syscall.h"
 #include "syscall.h"
diff --git a/sim/m32r/traps.c b/sim/m32r/traps.c
index 9fca2b1ec1d1..ffa09f1527f0 100644
--- a/sim/m32r/traps.c
+++ b/sim/m32r/traps.c
@@ -17,6 +17,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 "defs.h"
+
 #include "sim-main.h"
 #include "sim-syscall.h"
 #include "targ-vals.h"
diff --git a/sim/m68hc11/dv-m68hc11.c b/sim/m68hc11/dv-m68hc11.c
index f4815883a339..5b2d1ba0b523 100644
--- a/sim/m68hc11/dv-m68hc11.c
+++ b/sim/m68hc11/dv-m68hc11.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "sim-hw.h"
diff --git a/sim/m68hc11/dv-m68hc11eepr.c b/sim/m68hc11/dv-m68hc11eepr.c
index 88bd121980d8..1e4cb5eab054 100644
--- a/sim/m68hc11/dv-m68hc11eepr.c
+++ b/sim/m68hc11/dv-m68hc11eepr.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/m68hc11/dv-m68hc11sio.c b/sim/m68hc11/dv-m68hc11sio.c
index b6eacb4883e7..cf51d17f9ff9 100644
--- a/sim/m68hc11/dv-m68hc11sio.c
+++ b/sim/m68hc11/dv-m68hc11sio.c
@@ -20,6 +20,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/m68hc11/dv-m68hc11spi.c b/sim/m68hc11/dv-m68hc11spi.c
index 1e9d56c849d0..6fe759d34490 100644
--- a/sim/m68hc11/dv-m68hc11spi.c
+++ b/sim/m68hc11/dv-m68hc11spi.c
@@ -20,6 +20,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/m68hc11/dv-m68hc11tim.c b/sim/m68hc11/dv-m68hc11tim.c
index cd8274ffc34f..39a21cca1da1 100644
--- a/sim/m68hc11/dv-m68hc11tim.c
+++ b/sim/m68hc11/dv-m68hc11tim.c
@@ -20,6 +20,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/m68hc11/dv-nvram.c b/sim/m68hc11/dv-nvram.c
index 586ee2ff5fc3..88fab2f44612 100644
--- a/sim/m68hc11/dv-nvram.c
+++ b/sim/m68hc11/dv-nvram.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/m68hc11/emulos.c b/sim/m68hc11/emulos.c
index 247e66871cfb..d7436f79b364 100644
--- a/sim/m68hc11/emulos.c
+++ b/sim/m68hc11/emulos.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
diff --git a/sim/m68hc11/gencode.c b/sim/m68hc11/gencode.c
index 2a2210d7ac66..46817606797d 100644
--- a/sim/m68hc11/gencode.c
+++ b/sim/m68hc11/gencode.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/m68hc11/interp.c b/sim/m68hc11/interp.c
index 07e4a8858a74..d4b2531abea0 100644
--- a/sim/m68hc11/interp.c
+++ b/sim/m68hc11/interp.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 #include "sim-hw.h"
diff --git a/sim/m68hc11/interrupts.c b/sim/m68hc11/interrupts.c
index 03c78ac21816..1adce5082190 100644
--- a/sim/m68hc11/interrupts.c
+++ b/sim/m68hc11/interrupts.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-options.h"
 
diff --git a/sim/m68hc11/m68hc11_sim.c b/sim/m68hc11/m68hc11_sim.c
index 0d7860170bc7..3c619c14ab0b 100644
--- a/sim/m68hc11/m68hc11_sim.c
+++ b/sim/m68hc11/m68hc11_sim.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 #include "sim-module.h"
diff --git a/sim/mcore/interp.c b/sim/mcore/interp.c
index f726c1e7db77..8a960421abf7 100644
--- a/sim/mcore/interp.c
+++ b/sim/mcore/interp.c
@@ -17,7 +17,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/microblaze/interp.c b/sim/microblaze/interp.c
index bff73279d263..b3ff2f6dc7f4 100644
--- a/sim/microblaze/interp.c
+++ b/sim/microblaze/interp.c
@@ -16,7 +16,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/mips/cp1.c b/sim/mips/cp1.c
index f5d3d1dd5fbe..03ed0c0558ff 100644
--- a/sim/mips/cp1.c
+++ b/sim/mips/cp1.c
@@ -40,6 +40,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    (Originally, this code was in interp.c)
 */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 
 #include <stdlib.h>
diff --git a/sim/mips/dsp.c b/sim/mips/dsp.c
index b82ff6880d26..fb25caa83560 100644
--- a/sim/mips/dsp.c
+++ b/sim/mips/dsp.c
@@ -17,6 +17,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 
 int DSPLO_REGNUM[4] =
diff --git a/sim/mips/dv-tx3904cpu.c b/sim/mips/dv-tx3904cpu.c
index bf23a066857c..43f38d2a7aeb 100644
--- a/sim/mips/dv-tx3904cpu.c
+++ b/sim/mips/dv-tx3904cpu.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/mips/dv-tx3904irc.c b/sim/mips/dv-tx3904irc.c
index d9a919752e3d..0896b0fabb0b 100644
--- a/sim/mips/dv-tx3904irc.c
+++ b/sim/mips/dv-tx3904irc.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/mips/dv-tx3904sio.c b/sim/mips/dv-tx3904sio.c
index 9676344bc33c..c81b2dd3a5e7 100644
--- a/sim/mips/dv-tx3904sio.c
+++ b/sim/mips/dv-tx3904sio.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/mips/dv-tx3904tmr.c b/sim/mips/dv-tx3904tmr.c
index 48b169fd9b8c..5b5d8ac97f79 100644
--- a/sim/mips/dv-tx3904tmr.c
+++ b/sim/mips/dv-tx3904tmr.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/mips/interp.c b/sim/mips/interp.c
index 64259cc3fed4..8066f39cc3b6 100644
--- a/sim/mips/interp.c
+++ b/sim/mips/interp.c
@@ -22,7 +22,9 @@ code on the hardware.
 
 */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "bfd.h"
 #include "sim-main.h"
 #include "sim-utils.h"
@@ -32,9 +34,6 @@ code on the hardware.
 
 #include "itable.h"
 
-
-#include "config.h"
-
 #include <stdio.h>
 #include <stdarg.h>
 #include <ansidecl.h>
diff --git a/sim/mips/m16run.c b/sim/mips/m16run.c
index 44fb9e4538ca..a04e3eed3bf3 100644
--- a/sim/mips/m16run.c
+++ b/sim/mips/m16run.c
@@ -17,6 +17,9 @@
  
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "m16_idecode.h"
 #include "m32_idecode.h"
diff --git a/sim/mips/mdmx.c b/sim/mips/mdmx.c
index 948bb0d2ebe5..6978251a241b 100644
--- a/sim/mips/mdmx.c
+++ b/sim/mips/mdmx.c
@@ -18,6 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 
 #include "sim-main.h"
diff --git a/sim/mips/micromipsrun.c b/sim/mips/micromipsrun.c
index 3950dc2fafd8..53a5c0811877 100644
--- a/sim/mips/micromipsrun.c
+++ b/sim/mips/micromipsrun.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 "defs.h"
+
 #include "sim-main.h"
 #include "micromips16_idecode.h"
 #include "micromips32_idecode.h"
diff --git a/sim/mips/sim-main.c b/sim/mips/sim-main.c
index 620f4b2990be..24e16029d22e 100644
--- a/sim/mips/sim-main.c
+++ b/sim/mips/sim-main.c
@@ -19,6 +19,9 @@
 #ifndef SIM_MAIN_C
 #define SIM_MAIN_C
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
 
diff --git a/sim/mn10300/dv-mn103cpu.c b/sim/mn10300/dv-mn103cpu.c
index 3c3e843fa647..2a3591b8a37a 100644
--- a/sim/mn10300/dv-mn103cpu.c
+++ b/sim/mn10300/dv-mn103cpu.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/mn10300/dv-mn103int.c b/sim/mn10300/dv-mn103int.c
index cb81bc11527e..2c47ca0e0558 100644
--- a/sim/mn10300/dv-mn103int.c
+++ b/sim/mn10300/dv-mn103int.c
@@ -18,6 +18,8 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "hw-main.h"
diff --git a/sim/mn10300/dv-mn103iop.c b/sim/mn10300/dv-mn103iop.c
index ecce7ec1fd50..1fd8d178ba5b 100644
--- a/sim/mn10300/dv-mn103iop.c
+++ b/sim/mn10300/dv-mn103iop.c
@@ -18,6 +18,9 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "hw-main.h"
 
diff --git a/sim/mn10300/dv-mn103ser.c b/sim/mn10300/dv-mn103ser.c
index 8d9bf8fa4fbc..3465954f75f7 100644
--- a/sim/mn10300/dv-mn103ser.c
+++ b/sim/mn10300/dv-mn103ser.c
@@ -18,6 +18,9 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "hw-main.h"
 #include "dv-sockser.h"
diff --git a/sim/mn10300/dv-mn103tim.c b/sim/mn10300/dv-mn103tim.c
index 61807c993222..ad9c24bbc6e8 100644
--- a/sim/mn10300/dv-mn103tim.c
+++ b/sim/mn10300/dv-mn103tim.c
@@ -18,6 +18,9 @@
     
     */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "hw-main.h"
 #include "sim-assert.h"
diff --git a/sim/mn10300/interp.c b/sim/mn10300/interp.c
index 55e9e212fe7a..b6c5d5b087ef 100644
--- a/sim/mn10300/interp.c
+++ b/sim/mn10300/interp.c
@@ -1,4 +1,6 @@
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <signal.h>
 
 #include "sim-main.h"
diff --git a/sim/mn10300/op_utils.c b/sim/mn10300/op_utils.c
index 882ff4624099..cd0f1a667e49 100644
--- a/sim/mn10300/op_utils.c
+++ b/sim/mn10300/op_utils.c
@@ -1,3 +1,6 @@
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-syscall.h"
 #include "targ-vals.h"
diff --git a/sim/moxie/interp.c b/sim/moxie/interp.c
index 4228dd5a4668..327f4e6e85e7 100644
--- a/sim/moxie/interp.c
+++ b/sim/moxie/interp.c
@@ -17,7 +17,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <fcntl.h>
 #include <signal.h>
 #include <stdlib.h>
diff --git a/sim/msp430/msp430-sim.c b/sim/msp430/msp430-sim.c
index 4e213f978c6b..58a54698993f 100644
--- a/sim/msp430/msp430-sim.c
+++ b/sim/msp430/msp430-sim.c
@@ -19,7 +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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/or1k/sim-if.c b/sim/or1k/sim-if.c
index 41dbaaebf1dd..005124b9ad7f 100644
--- a/sim/or1k/sim-if.c
+++ b/sim/or1k/sim-if.c
@@ -16,6 +16,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 "defs.h"
+
 #include "sim-main.h"
 #include "sim-options.h"
 #include "libiberty.h"
diff --git a/sim/or1k/sim-main.h b/sim/or1k/sim-main.h
index cac1abb2b8fb..f91a351a2db1 100644
--- a/sim/or1k/sim-main.h
+++ b/sim/or1k/sim-main.h
@@ -21,8 +21,6 @@
 
 #define WITH_SCACHE_PBB 1
 
-#include "config.h"
-
 #include "ansidecl.h"
 #include "or1k-desc.h"
 #include "sim-basics.h"
diff --git a/sim/or1k/traps.c b/sim/or1k/traps.c
index 0a0f1aa07114..7f5a38f68bef 100644
--- a/sim/or1k/traps.c
+++ b/sim/or1k/traps.c
@@ -16,6 +16,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 "defs.h"
+
 #define WANT_CPU_OR1K32BF
 #define WANT_CPU
 
diff --git a/sim/ppc/Makefile.in b/sim/ppc/Makefile.in
index 7686937f4213..5a15eed63082 100644
--- a/sim/ppc/Makefile.in
+++ b/sim/ppc/Makefile.in
@@ -628,7 +628,7 @@ mon.o: mon.c $(BASICS_H) $(CPU_H) $(MON_H)
 # As a kludge, build the common stuff here for now.
 gentmap: $(srcdir)/../common/gentmap.c Makefile targ-vals.def
 	$(LINK_FOR_BUILD) -I. -I../common -I$(srcdir)/../common \
-		$(srcdir)/../common/gentmap.c
+		$(srcdir)/../common/gentmap.c -DUSE_CONFIG_H
 
 targ-vals.def: $(srcdir)/../common/nltvals.def
 	rm -f targ-vals.def tmp-def
diff --git a/sim/ppc/basics.h b/sim/ppc/basics.h
index 2b923ea3cc3e..057cf1ab0e45 100644
--- a/sim/ppc/basics.h
+++ b/sim/ppc/basics.h
@@ -21,6 +21,8 @@
 #ifndef _BASICS_H_
 #define _BASICS_H_
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
 /* from Michael Meissner, macro's to handle concating symbols better */
 
@@ -85,7 +87,6 @@ typedef enum {
 
 /* Basic configuration */
 
-#include "config.h"
 #include "ppc-config.h"
 #include "inline.h"
 
diff --git a/sim/ppc/debug.c b/sim/ppc/debug.c
index dba14255366b..53a392a303ef 100644
--- a/sim/ppc/debug.c
+++ b/sim/ppc/debug.c
@@ -21,7 +21,9 @@
 #ifndef _DEBUG_C_
 #define _DEBUG_C_
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "basics.h"
 
 #include <stdlib.h>
diff --git a/sim/ppc/defs.h b/sim/ppc/defs.h
new file mode 100644
index 000000000000..66e76d26dbad
--- /dev/null
+++ b/sim/ppc/defs.h
@@ -0,0 +1,26 @@
+/* The configure generated header settings.
+
+   Copyright 2002-2021 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/>.  */
+
+/* This file should be included by every .c file before any other header.  */
+
+#ifndef DEFS_H
+#define DEFS_H
+
+/* Include sim's various configure tests.  */
+#include "config.h"
+
+#endif
diff --git a/sim/ppc/filter_filename.c b/sim/ppc/filter_filename.c
index 2457b687907e..b59ca21ca559 100644
--- a/sim/ppc/filter_filename.c
+++ b/sim/ppc/filter_filename.c
@@ -17,7 +17,9 @@
  
     */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "ppc-config.h"
 #include "filter_filename.h"
 
diff --git a/sim/ppc/inline.c b/sim/ppc/inline.c
index 8813169c60ef..1db2dec5c30c 100644
--- a/sim/ppc/inline.c
+++ b/sim/ppc/inline.c
@@ -21,7 +21,9 @@
 #ifndef _INLINE_C_
 #define _INLINE_C_
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "ppc-config.h"
 
 #include "inline.h"
diff --git a/sim/ppc/sim-endian.c b/sim/ppc/sim-endian.c
index 1ffa2d7e4eb7..2625d80d0b8b 100644
--- a/sim/ppc/sim-endian.c
+++ b/sim/ppc/sim-endian.c
@@ -21,7 +21,9 @@
 #ifndef _SIM_ENDIAN_C_
 #define _SIM_ENDIAN_C_
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "basics.h"
 
 
diff --git a/sim/ppc/words.h b/sim/ppc/words.h
index 7645349ac5b4..641f22514ecc 100644
--- a/sim/ppc/words.h
+++ b/sim/ppc/words.h
@@ -43,9 +43,8 @@
 */
 
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+/* This must come before any other includes.  */
+#include "defs.h"
 
 /* bit based */
 typedef char natural8;
diff --git a/sim/pru/interp.c b/sim/pru/interp.c
index 8d247f3795f2..51a11ab8a475 100644
--- a/sim/pru/interp.c
+++ b/sim/pru/interp.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdbool.h>
 #include <stdint.h>
 #include <stddef.h>
diff --git a/sim/pru/pru.h b/sim/pru/pru.h
index c2b631cda664..17febb295b7a 100644
--- a/sim/pru/pru.h
+++ b/sim/pru/pru.h
@@ -19,7 +19,6 @@
 #ifndef PRU_H
 #define PRU_H
 
-#include "config.h"
 #include "opcode/pru.h"
 
 /* Needed for handling the dual PRU address space.  */
diff --git a/sim/pru/sim-main.h b/sim/pru/sim-main.h
index 966cacf5693d..8233c20cefd7 100644
--- a/sim/pru/sim-main.h
+++ b/sim/pru/sim-main.h
@@ -19,8 +19,6 @@
 #ifndef PRU_SIM_MAIN
 #define PRU_SIM_MAIN
 
-#include "config.h"
-
 #include <stdint.h>
 #include <stddef.h>
 #include "pru.h"
diff --git a/sim/riscv/interp.c b/sim/riscv/interp.c
index 6192b6dc5b23..d430d77d701c 100644
--- a/sim/riscv/interp.c
+++ b/sim/riscv/interp.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 #include "sim-options.h"
diff --git a/sim/riscv/machs.c b/sim/riscv/machs.c
index 853a3afb42f6..9ff230336787 100644
--- a/sim/riscv/machs.c
+++ b/sim/riscv/machs.c
@@ -18,7 +18,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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include "sim-main.h"
 
diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c
index 6a2904cced73..bd0ae2590e9b 100644
--- a/sim/riscv/sim-main.c
+++ b/sim/riscv/sim-main.c
@@ -21,7 +21,8 @@
 /* This file contains the main simulator decoding logic.  i.e. everything that
    is architecture specific.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <inttypes.h>
 #include <time.h>
diff --git a/sim/rl78/cpu.c b/sim/rl78/cpu.c
index fde8afee96b0..1bd8b6ee38f2 100644
--- a/sim/rl78/cpu.c
+++ b/sim/rl78/cpu.c
@@ -19,7 +19,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
diff --git a/sim/rl78/gdb-if.c b/sim/rl78/gdb-if.c
index f4b6754f5873..090a3fc9bc48 100644
--- a/sim/rl78/gdb-if.c
+++ b/sim/rl78/gdb-if.c
@@ -18,7 +18,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <assert.h>
 #include <signal.h>
diff --git a/sim/rl78/load.c b/sim/rl78/load.c
index c137ba6e40e4..a2a57b0b198d 100644
--- a/sim/rl78/load.c
+++ b/sim/rl78/load.c
@@ -19,8 +19,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/rl78/main.c b/sim/rl78/main.c
index 8d8a79d5da89..178fa75f79f9 100644
--- a/sim/rl78/main.c
+++ b/sim/rl78/main.c
@@ -19,8 +19,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
diff --git a/sim/rl78/mem.c b/sim/rl78/mem.c
index 77e4987b6ff1..0b6ab8e79f18 100644
--- a/sim/rl78/mem.c
+++ b/sim/rl78/mem.c
@@ -19,7 +19,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/rl78/rl78.c b/sim/rl78/rl78.c
index 006691c4c0af..e45750ad7bf5 100644
--- a/sim/rl78/rl78.c
+++ b/sim/rl78/rl78.c
@@ -19,7 +19,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/rl78/trace.c b/sim/rl78/trace.c
index 6f897eb03393..1b4b365af1e3 100644
--- a/sim/rl78/trace.c
+++ b/sim/rl78/trace.c
@@ -19,8 +19,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
diff --git a/sim/rx/err.c b/sim/rx/err.c
index e72b6d3ddeeb..c9b1c3cb57cb 100644
--- a/sim/rx/err.c
+++ b/sim/rx/err.c
@@ -18,6 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/sim/rx/fpu.c b/sim/rx/fpu.c
index 6c4738c0b21d..611d9123d481 100644
--- a/sim/rx/fpu.c
+++ b/sim/rx/fpu.c
@@ -18,7 +18,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/sim/rx/gdb-if.c b/sim/rx/gdb-if.c
index ec4191095888..e18055607892 100644
--- a/sim/rx/gdb-if.c
+++ b/sim/rx/gdb-if.c
@@ -18,7 +18,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <assert.h>
 #include <signal.h>
diff --git a/sim/rx/load.c b/sim/rx/load.c
index b04826f55c7f..d14488802779 100644
--- a/sim/rx/load.c
+++ b/sim/rx/load.c
@@ -18,8 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/sim/rx/main.c b/sim/rx/main.c
index 20a8434388e9..5d7092ba1d14 100644
--- a/sim/rx/main.c
+++ b/sim/rx/main.c
@@ -18,8 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
diff --git a/sim/rx/mem.c b/sim/rx/mem.c
index 7e62bfb89535..f9b9cc1a97ed 100644
--- a/sim/rx/mem.c
+++ b/sim/rx/mem.c
@@ -18,6 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 /* This slows down the simulator and we get some false negatives from
    gcc, like when it uses a long-sized hole to hold a byte-sized
    variable, knowing that it doesn't care about the other bits.  But,
@@ -25,7 +28,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1.  */
 #define RDCHECK 0
 
-#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/rx/misc.c b/sim/rx/misc.c
index 2a4a2539e417..e7447aca463d 100644
--- a/sim/rx/misc.c
+++ b/sim/rx/misc.c
@@ -18,8 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 
 #include "cpu.h"
diff --git a/sim/rx/reg.c b/sim/rx/reg.c
index bdf2debac69d..1d27c59bb943 100644
--- a/sim/rx/reg.c
+++ b/sim/rx/reg.c
@@ -18,8 +18,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 "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/rx/rx.c b/sim/rx/rx.c
index e3737a56e98a..869dd3aa89c9 100644
--- a/sim/rx/rx.c
+++ b/sim/rx/rx.c
@@ -18,7 +18,9 @@ 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/>.  */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/sim/rx/syscalls.c b/sim/rx/syscalls.c
index 0c75c7dcdf8a..970128457916 100644
--- a/sim/rx/syscalls.c
+++ b/sim/rx/syscalls.c
@@ -18,8 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
diff --git a/sim/rx/trace.c b/sim/rx/trace.c
index a005797b4ecb..bb191dbdd393 100644
--- a/sim/rx/trace.c
+++ b/sim/rx/trace.c
@@ -18,8 +18,9 @@ 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/>.  */
 
+/* This must come before any other includes.  */
+#include "defs.h"
 
-#include "config.h"
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
diff --git a/sim/sh/interp.c b/sim/sh/interp.c
index fa361bacc229..bfd692ea73c2 100644
--- a/sim/sh/interp.c
+++ b/sim/sh/interp.c
@@ -18,7 +18,8 @@
 
 */
 
-#include "config.h"
+/* This must come before any other includes.  */
+#include "defs.h"
 
 #include <ctype.h>
 #include <stdio.h>
diff --git a/sim/v850/interp.c b/sim/v850/interp.c
index ff2f6a23e56d..79c6e0f7ddcc 100644
--- a/sim/v850/interp.c
+++ b/sim/v850/interp.c
@@ -1,3 +1,6 @@
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-options.h"
 #include "v850_sim.h"
diff --git a/sim/v850/sim-main.h b/sim/v850/sim-main.h
index e7276a68f8f6..6556273f6781 100644
--- a/sim/v850/sim-main.h
+++ b/sim/v850/sim-main.h
@@ -5,7 +5,6 @@
 
 #define WITH_TARGET_WORD_MSB 31
 
-#include "config.h"
 #include "sim-basics.h"
 #include "sim-signal.h"
 #include "sim-fpu.h"
diff --git a/sim/v850/simops.c b/sim/v850/simops.c
index bd23f92aba4d..62a2bbcbb615 100644
--- a/sim/v850/simops.c
+++ b/sim/v850/simops.c
@@ -1,3 +1,6 @@
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "v850_sim.h"
 #include "simops.h"
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] sim: leverage gnulib
  2021-05-07  4:00 [PATCH 1/2] sim: switch config.h usage to defs.h Mike Frysinger
@ 2021-05-07  4:00 ` Mike Frysinger
  2021-05-07 14:27   ` Tom Tromey
  2021-05-25  2:00   ` [PATCH v2] " Mike Frysinger
  0 siblings, 2 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-05-07  4:00 UTC (permalink / raw)
  To: gdb-patches

We use getline, so leverage gnulib to provide fallback implementation.
---
 sim/common/Make-common.in |  9 +++++++--
 sim/common/defs.h         | 10 ++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index c92228bb929f..5cba640c5972 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -40,6 +40,10 @@ srccom = $(srcdir)/../common
 srcroot = $(srcdir)/../..
 srcsim = $(srcdir)/..
 
+# Helper code from gnulib.
+GNULIB_BUILDDIR = ../../gnulib
+include $(GNULIB_BUILDDIR)/Makefile.gnulib.inc
+
 prefix = @prefix@
 exec_prefix = @exec_prefix@
 
@@ -232,8 +236,9 @@ CSEARCH = -I. -I$(srcdir) -I../common -I$(srccom) \
   -I../../include -I$(srcroot)/include \
   -I../../bfd -I$(srcroot)/bfd \
   -I../../opcodes -I$(srcroot)/opcodes \
+  -I../.. \
   @INCINTL@
-ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
+ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(INCGNU) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
 BUILD_CFLAGS = $(CFLAGS_FOR_BUILD) $(CSEARCH)
 
 COMMON_DEP_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS)
@@ -248,7 +253,7 @@ LIBINTL_DEP = @LIBINTL_DEP@
 CONFIG_LIBS = @LIBS@ $(ZLIB)
 LIBDEPS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL_DEP) $(LIBIBERTY_LIB)
 EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \
-	$(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL)
+	$(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL) $(LIBGNU)
 
 LIB_OBJS = callback.o modules.o syscall.o targ-map.o version.o \
 	$(SIM_OBJS)
diff --git a/sim/common/defs.h b/sim/common/defs.h
index 3a0737cb9b89..697fe955e1a8 100644
--- a/sim/common/defs.h
+++ b/sim/common/defs.h
@@ -22,6 +22,16 @@
 
 #ifdef HAVE_CONFIG_H
 
+/* Include gnulib's various configure tests.  */
+#include "gnulib/config.h"
+
+/* Reset macros that our config.h will provide.  */
+#undef PACKAGE_NAME
+#undef PACKAGE
+#undef PACKAGE_VERSION
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+
 /* Include sim's various configure tests.  */
 #include "config.h"
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] sim: leverage gnulib
  2021-05-07  4:00 ` [PATCH 2/2] sim: leverage gnulib Mike Frysinger
@ 2021-05-07 14:27   ` Tom Tromey
  2021-05-07 16:47     ` Mike Frysinger
  2021-05-25  2:00   ` [PATCH v2] " Mike Frysinger
  1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2021-05-07 14:27 UTC (permalink / raw)
  To: Mike Frysinger via Gdb-patches

>>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:

Mike> We use getline, so leverage gnulib to provide fallback implementation.

You'll need to update the top-level Makefile to ensure that sim depends
on gnulib.  Otherwise a clean parallel build might fail.

Top level patches normally have to go via gcc first.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] sim: leverage gnulib
  2021-05-07 14:27   ` Tom Tromey
@ 2021-05-07 16:47     ` Mike Frysinger
  2021-05-07 20:32       ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2021-05-07 16:47 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Mike Frysinger via Gdb-patches

On 07 May 2021 08:27, Tom Tromey wrote:
> >>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Mike> We use getline, so leverage gnulib to provide fallback implementation.
> 
> You'll need to update the top-level Makefile to ensure that sim depends
> on gnulib.  Otherwise a clean parallel build might fail.

yeah, i saw that, and then promptly forgot.  i can do another patch for that.

i assume the rest of this looks fine to you then :).
-mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] sim: leverage gnulib
  2021-05-07 16:47     ` Mike Frysinger
@ 2021-05-07 20:32       ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2021-05-07 20:32 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Mike Frysinger via Gdb-patches

Mike> i assume the rest of this looks fine to you then :).

Yeah, it seemed fine to me.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] sim: leverage gnulib
  2021-05-07  4:00 ` [PATCH 2/2] sim: leverage gnulib Mike Frysinger
  2021-05-07 14:27   ` Tom Tromey
@ 2021-05-25  2:00   ` Mike Frysinger
  1 sibling, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2021-05-25  2:00 UTC (permalink / raw)
  To: gdb-patches

We use getline, so leverage gnulib to provide fallback implementation.
---
 configure                 |  3 +++
 configure.ac              |  3 +++
 sim/common/ChangeLog      |  9 +++++++++
 sim/common/Make-common.in |  9 +++++++--
 sim/common/defs.h         | 12 ++++++++++++
 sim/ppc/Makefile.in       |  2 +-
 6 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 544a8d19c76e..3dd206525a7b 100755
--- a/configure
+++ b/configure
@@ -7504,6 +7504,9 @@ case " ${configdirs} " in
   *\ gdbserver\ *)
     configdirs="${configdirs} gnulib gdbsupport"
     ;;
+  *\ sim\ *)
+    configdirs="${configdirs} gnulib"
+    ;;
 esac
 
 # Strip out unwanted targets.
diff --git a/configure.ac b/configure.ac
index 59b4194fb24e..797a624621e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2812,6 +2812,9 @@ case " ${configdirs} " in
   *\ gdbserver\ *)
     configdirs="${configdirs} gnulib gdbsupport"
     ;;
+  *\ sim\ *)
+    configdirs="${configdirs} gnulib"
+    ;;
 esac
 
 # Strip out unwanted targets.
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index 76bf134fa378..931a7be726ce 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,12 @@
+2021-05-18  Mike Frysinger  <vapier@gentoo.org>
+
+	* Make-common.in (GNULIB_BUILDDIR): Define.
+	Include $(GNULIB_BUILDDIR)/Makefile.gnulib.inc.
+	(CSEARCH): Add -I../...
+	(ALL_CFLAGS): Add $(INCGNU).
+	(EXTRA_LIBS): Add $(LIBGNU).
+	* defs.h: Include gnulib/config.h.  Undefine PACKAGE* defines.
+
 2021-05-17  Mike Frysinger  <vapier@gentoo.org>
 
 	* sim-base.h (SIM_HAVE_COMMON_SIM_STATE): Delete.
diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index d38c849c40d1..8f52cf5e53f4 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -40,6 +40,10 @@ srccom = $(srcdir)/../common
 srcroot = $(srcdir)/../..
 srcsim = $(srcdir)/..
 
+# Helper code from gnulib.
+GNULIB_BUILDDIR = ../../gnulib
+include $(GNULIB_BUILDDIR)/Makefile.gnulib.inc
+
 prefix = @prefix@
 exec_prefix = @exec_prefix@
 
@@ -232,8 +236,9 @@ CSEARCH = -I. -I$(srcdir) -I../common -I$(srccom) \
   -I../../include -I$(srcroot)/include \
   -I../../bfd -I$(srcroot)/bfd \
   -I../../opcodes -I$(srcroot)/opcodes \
+  -I../.. \
   @INCINTL@
-ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
+ALL_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(INCGNU) $(SIM_EXTRA_CFLAGS) $(CFLAGS)
 BUILD_CFLAGS = $(CFLAGS_FOR_BUILD) $(CSEARCH)
 
 COMMON_DEP_CFLAGS = $(CONFIG_CFLAGS) $(CSEARCH) $(SIM_EXTRA_CFLAGS)
@@ -248,7 +253,7 @@ LIBINTL_DEP = @LIBINTL_DEP@
 CONFIG_LIBS = @LIBS@ $(ZLIB)
 LIBDEPS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL_DEP) $(LIBIBERTY_LIB)
 EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \
-	$(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL)
+	$(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL) $(LIBGNU)
 
 LIB_OBJS = callback.o modules.o syscall.o targ-map.o version.o \
 	$(SIM_OBJS)
diff --git a/sim/common/defs.h b/sim/common/defs.h
index 3a0737cb9b89..957e36d3c93c 100644
--- a/sim/common/defs.h
+++ b/sim/common/defs.h
@@ -22,6 +22,18 @@
 
 #ifdef HAVE_CONFIG_H
 
+/* Include gnulib's various configure tests.  */
+#include "gnulib/config.h"
+
+/* Reset macros that our config.h will provide.  */
+#undef PACKAGE
+#undef PACKAGE_BUGREPORT
+#undef PACKAGE_NAME
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+#undef PACKAGE_URL
+#undef PACKAGE_VERSION
+
 /* Include sim's various configure tests.  */
 #include "config.h"
 
diff --git a/sim/ppc/Makefile.in b/sim/ppc/Makefile.in
index 5ce511e96b3f..1996e13279c7 100644
--- a/sim/ppc/Makefile.in
+++ b/sim/ppc/Makefile.in
@@ -147,7 +147,7 @@ LIB_INCLUDES	= -I$(srcdir)/../../include
 BFD_INCLUDES	= -I../../bfd -I$(srcdir)/../../bfd
 GDB_INCLUDES	= -I../../gdb -I$(srcdir)/../../gdb  -I$(srcdir)/../../gdb/config
 
-INCLUDES	= -I. -I$(srcdir) $(LIB_INCLUDES) $(BFD_INCLUDES) $(GDB_INCLUDES)
+INCLUDES	= -I. -I$(srcdir) $(LIB_INCLUDES) $(BFD_INCLUDES) $(GDB_INCLUDES) -I../..
 
 LIBIBERTY_LIB	= ../../libiberty/libiberty.a
 BFD_LIB		= ../../bfd/libbfd.a
-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-25  2:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07  4:00 [PATCH 1/2] sim: switch config.h usage to defs.h Mike Frysinger
2021-05-07  4:00 ` [PATCH 2/2] sim: leverage gnulib Mike Frysinger
2021-05-07 14:27   ` Tom Tromey
2021-05-07 16:47     ` Mike Frysinger
2021-05-07 20:32       ` Tom Tromey
2021-05-25  2:00   ` [PATCH v2] " Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).