* genscripts.sh (source_em, fragment): New sh functions.
	Truncate e${EMULATION_NAME}.c file before .em script fills it.
	Use source_em in place of . for the .em script.
	* emultempl/generic.em: Use fragment and source_em functions.
	* emultempl/aix.em: Likewise.
	* emultempl/alphaelf.em: Likewise.
	* emultempl/armcoff.em: Likewise.
	* emultempl/armelf.em: Likewise.
	* emultempl/avrelf.em: Likewise.
	* emultempl/beos.em: Likewise.
	* emultempl/cr16elf.em: Likewise.
	* emultempl/crxelf.em: Likewise.
	* emultempl/elf-generic.em: Likewise.
	* emultempl/elf32.em: Likewise.
	* emultempl/genelf.em: Likewise.
	* emultempl/gld960.em: Likewise.
	* emultempl/gld960c.em: Likewise.
	* emultempl/hppaelf.em: Likewise.
	* emultempl/ia64elf.em: Likewise.
	* emultempl/irix.em: Likewise.
	* emultempl/linux.em: Likewise.
	* emultempl/lnk960.em: Likewise.
	* emultempl/m68hc1xelf.em: Likewise.
	* emultempl/m68kcoff.em: Likewise.
	* emultempl/m68kelf.em: Likewise.
	* emultempl/mipsecoff.em: Likewise.
	* emultempl/mipself.em: Likewise.
	* emultempl/mmix-elfnmmo.em: Likewise.
	* emultempl/mmixelf.em: Likewise.
	* emultempl/mmo.em: Likewise.
	* emultempl/needrelax.em: Likewise.
	* emultempl/netbsd.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/ppc32elf.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/scoreelf.em: Likewise.
	* emultempl/sh64elf.em: Likewise.
	* emultempl/spuelf.em: Likewise.
	* emultempl/sunos.em: Likewise.
	* emultempl/ticoff.em: Likewise.
	* emultempl/vanilla.em: Likewise.
	* emultempl/vxworks.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
	* emultempl/z80.em: Likewise.
 else
   OUTPUT_ARCH=${ARCH}:${MACHINE}
 fi
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* AIX emulation code for ${EMULATION_NAME}
 # sed commands to quote an ld script as a C string.
 sc="-f ${srcdir}/emultempl/ostring.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 gld${EMULATION_NAME}_create_output_section_statements (void)
 
 # This file is sourced from elf32.em, and defines extra alpha
 # specific routines.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "elf/internal.h"
 #include "elf/alpha.h"
 
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* emulate the original gld for the given ${EMULATION_NAME}
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 {
 
 # specific routines.
 #
 test -z "$TARGET2_TYPE" && TARGET2_TYPE="rel"
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "elf/arm.h"
 
     case OPTION_USE_BLX:
       use_blx = 1;
       break;
-    
+
     case OPTION_VFP11_DENORM_FIX:
       if (strcmp (optarg, "none") == 0)
         vfp11_denorm_fix = BFD_ARM_VFP11_FIX_NONE;
 
 # of devices where one needs to address the issue that it is not possible
 # to reach the whole program memory by using 16 bit pointers.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "elf32-avr.h"
 #include "ldctor.h"
 
-/* The fake file and it's corresponding section meant to hold 
+/* The fake file and it's corresponding section meant to hold
    the linker stubs if needed.  */
 
 static lang_input_statement_type *stub_file;
                                               ".trampolines");
   if (avr_stub_section == NULL)
     goto err_ret;
-  
+
   flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
            | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP);
   if (!bfd_set_section_flags (stub_file->the_bfd, avr_stub_section, flags))
     goto err_ret;
 
   avr_stub_section->alignment_power = 1;
-  
+
   ldlang_add_file (stub_file);
 
   return;
 
 static void
 avr_elf_finish (void)
-{ 
+{
   if (!avr_no_stubs)
     {
       /* Now build the linker stubs.  */
 '
 
 PARSE_AND_LIST_LONGOPTS='
-  { "no-call-ret-replacement", no_argument, 
+  { "no-call-ret-replacement", no_argument,
      NULL, OPTION_NO_CALL_RET_REPLACEMENT},
-  { "pmem-wrap-around", required_argument, 
+  { "pmem-wrap-around", required_argument,
     NULL, OPTION_PMEM_WRAP_AROUND},
-  { "no-stubs", no_argument, 
+  { "no-stubs", no_argument,
     NULL, OPTION_NO_STUBS},
-  { "debug-stubs", no_argument, 
+  { "debug-stubs", no_argument,
     NULL, OPTION_DEBUG_STUBS},
-  { "debug-relax", no_argument, 
+  { "debug-relax", no_argument,
     NULL, OPTION_DEBUG_RELAX},
 '
 
 PARSE_AND_LIST_ARGS_CASES='
 
     case OPTION_PMEM_WRAP_AROUND:
-      { 
+      {
         /* This variable is defined in the bfd library.  */
         if ((!strcmp (optarg,"32k"))      || (!strcmp (optarg,"32K")))
           avr_pc_wrap_around = 32768;
 
 else
   OUTPUT_ARCH=${ARCH}:${MACHINE}
 fi
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is part of GLD, the Gnu Linker.
    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
    2005, 2006, 2007 Free Software Foundation, Inc.
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
 echo '; }'                                             >> e${EMULATION_NAME}.c
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 
 # This file is sourced from elf32.em, and defines extra cr16-elf
 # specific routines.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "ldctor.h"
 
 #
 LDEMUL_AFTER_PARSE=cr16elf_after_parse
 LDEMUL_BEFORE_ALLOCATION=cr16elf_before_allocation
-
 
 # This file is sourced from elf32.em, and defines extra crx-elf
 # specific routines.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "ldctor.h"
 
 #
 LDEMUL_AFTER_PARSE=crxelf_after_parse
 LDEMUL_BEFORE_ALLOCATION=crxelf_before_allocation
-
 
 # This file is sourced from elf32.em and from ELF targets that use
 # generic.em.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 gld${EMULATION_NAME}_map_segments (bfd_boolean need_layout)
 
 else
   OUTPUT_ARCH=${ARCH}:${MACHINE}
 fi
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
 if [ "x${USE_LIBPATH}" = xyes ] ; then
   case ${target} in
     *-*-linux-* | *-*-k*bsd*-*)
-  cat >>e${EMULATION_NAME}.c <<EOF
+  fragment <<EOF
 #ifdef HAVE_GLOB
 #include <glob.h>
 #endif
 
 # Import any needed special functions and/or overrides.
 #
-. ${srcdir}/emultempl/elf-generic.em
+source_em ${srcdir}/emultempl/elf-generic.em
 if test -n "$EXTRA_EM_FILE" ; then
-. ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
+  source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
 fi
 
 # Functions in this file can be overridden by setting the LDEMUL_* shell
 # as presumably it is called from the overriding function.
 #
 if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 gld${EMULATION_NAME}_before_parse (void)
 fi
 
 if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* Handle as_needed DT_NEEDED.  */
 
 static bfd_boolean
 EOF
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 /* These variables are required to pass information back and forth
    between after_open and check_needed and stat_needed and vercheck.  */
 EOF
 case ${target} in
   *-*-linux-* | *-*-k*bsd*-*)
-    cat >>e${EMULATION_NAME}.c <<EOF
+    fragment <<EOF
          {
            struct bfd_link_needed_list *l;
 
 EOF
     ;;
 esac
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
        }
     }
 
 
 EOF
 if [ "x${USE_LIBPATH}" = xyes ] ; then
-  cat >>e${EMULATION_NAME}.c <<EOF
+  fragment <<EOF
 
 /* Add the sysroot to every entry in a path separated by
    config.rpath_separator.  */
 EOF
   case ${target} in
     *-*-freebsd* | *-*-dragonfly*)
-      cat >>e${EMULATION_NAME}.c <<EOF
+      fragment <<EOF
 /* Read the system search path the FreeBSD way rather than the Linux way.  */
 #ifdef HAVE_ELF_HINTS_H
 #include <elf-hints.h>
     ;;
 
     *-*-linux-* | *-*-k*bsd*-*)
-      cat >>e${EMULATION_NAME}.c <<EOF
+      fragment <<EOF
 /* For a native linker, check the file /etc/ld.so.conf for directories
    in which we may find shared libraries.  /etc/ld.so.conf is really
    only meaningful on Linux.  */
     ;;
   esac
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 /* See if an input file matches a DT_NEEDED entry by name.  */
 
 EOF
 
 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static bfd_size_type
 gld${EMULATION_NAME}_id_note_section_size (bfd *abfd,
          search_dirs_type *search;
 EOF
 if [ "x${NATIVE}" = xyes ] ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
          const char *lib_path;
 EOF
 fi
 if [ "x${USE_LIBPATH}" = xyes ] ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
          struct bfd_link_needed_list *rp;
          int found;
 EOF
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
          if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
                                                  &n, force))
            break;
 EOF
 if [ "x${USE_LIBPATH}" = xyes ] ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
          if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
                                                  &n, force))
            break;
 EOF
 fi
 if [ "x${NATIVE}" = xyes ] ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
          if (command_line.rpath_link == NULL
              && command_line.rpath == NULL)
            {
 EOF
 fi
 if [ "x${USE_LIBPATH}" = xyes ] ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
          found = 0;
          rp = bfd_elf_get_runpath_list (output_bfd, &link_info);
          for (; !found && rp != NULL; rp = rp->next)
 if [ "x${USE_LIBPATH}" = xyes ] ; then
   case ${target} in
     *-*-freebsd* | *-*-dragonfly*)
-      cat >>e${EMULATION_NAME}.c <<EOF
+      fragment <<EOF
          if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force))
            break;
 EOF
 
     *-*-linux-* | *-*-k*bsd*-*)
     # Linux
-      cat >>e${EMULATION_NAME}.c <<EOF
+      fragment <<EOF
          if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
            break;
 
     ;;
   esac
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
          len = strlen (l->name);
          for (search = search_head; search != NULL; search = search->next)
            {
          if (search != NULL)
            break;
 EOF
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
        }
 
       if (force < 2)
 EOF
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 /* Look through an expression for an assignment statement.  */
 
   else
     ELF_INTERPRETER_SET_DEFAULT=
   fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 /* This is called after the sections have been attached to output
    sections, but before any sizes or addresses have been set.  */
 fi
 
 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 /* Try to open a dynamic archive.  This is where we know that ELF
    dynamic libraries have an extension of .so (or .sl on oddball systems
 fi
 
 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 /* A variant of lang_output_section_find used by place_orphan.  */
 
 fi
 
 if test x"$LDEMUL_FINISH" != xgld"$EMULATION_NAME"_finish; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 gld${EMULATION_NAME}_finish (void)
 fi
 
 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static char *
 gld${EMULATION_NAME}_get_script (int *isfile)
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 EOF
 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
 else
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   else if (!config.magic_demand_paged)
     return "ldscripts/${EMULATION_NAME}.xn";
 EOF
 fi
 if test -n "$GENERATE_PIE_SCRIPT" ; then
 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   else if (link_info.pie && link_info.combreloc
           && link_info.relro && (link_info.flags & DT_BIND_NOW))
     return "ldscripts/${EMULATION_NAME}.xdw";
     return "ldscripts/${EMULATION_NAME}.xdc";
 EOF
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   else if (link_info.pie)
     return "ldscripts/${EMULATION_NAME}.xd";
 EOF
 fi
 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   else if (link_info.shared && link_info.combreloc
           && link_info.relro && (link_info.flags & DT_BIND_NOW))
     return "ldscripts/${EMULATION_NAME}.xsw";
     return "ldscripts/${EMULATION_NAME}.xsc";
 EOF
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   else if (link_info.shared)
     return "ldscripts/${EMULATION_NAME}.xs";
 EOF
 fi
 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   else if (link_info.combreloc && link_info.relro
           && (link_info.flags & DT_BIND_NOW))
     return "ldscripts/${EMULATION_NAME}.xw";
     return "ldscripts/${EMULATION_NAME}.xc";
 EOF
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   else
     return "ldscripts/${EMULATION_NAME}.x";
 }
 if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then
 
 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
  $PARSE_AND_LIST_PROLOGUE
 EOF
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #define OPTION_DISABLE_NEW_DTAGS       (400)
 #define OPTION_ENABLE_NEW_DTAGS                (OPTION_DISABLE_NEW_DTAGS + 1)
 EOF
 
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
     {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
     {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
     {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
 fi
 
 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
     $PARSE_AND_LIST_LONGOPTS
 EOF
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
     {NULL, no_argument, NULL, 0}
   };
 
 EOF
 
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
     case OPTION_DISABLE_NEW_DTAGS:
       link_info.new_dtags = FALSE;
       break;
 EOF
 
   if test -n "$COMMONPAGESIZE"; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
       else if (strcmp (optarg, "relro") == 0)
        link_info.relro = TRUE;
       else if (strcmp (optarg, "norelro") == 0)
 EOF
   fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
       else if (CONST_STRNEQ (optarg, "max-page-size="))
        {
          char *end;
 fi
 
 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
  $PARSE_AND_LIST_ARGS_CASES
 EOF
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
     }
 
   return TRUE;
 EOF
 
 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 gld${EMULATION_NAME}_list_options (FILE * file)
 EOF
 
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   fprintf (file, _("  -Bgroup\t\tSelects group name lookup rules for DSO\n"));
   fprintf (file, _("  --disable-new-dtags\tDisable new dynamic tags\n"));
   fprintf (file, _("  --enable-new-dtags\tEnable new dynamic tags\n"));
 EOF
 
   if test -n "$COMMONPAGESIZE"; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   fprintf (file, _("  -z norelro\t\tDon't create RELRO program header\n"));
 EOF
   fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   fprintf (file, _("  -z now\t\tMark object non-lazy runtime binding\n"));
   fprintf (file, _("  -z origin\t\tMark object requiring immediate \$ORIGIN processing\n\t\t\t  at runtime\n"));
 EOF
 
   if test -n "$COMMONPAGESIZE"; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   fprintf (file, _("  -z relro\t\tCreate RELRO program header\n"));
 EOF
   fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   fprintf (file, _("  -z max-page-size=SIZE\tSet maximum page size to SIZE\n"));
   fprintf (file, _("  -z common-page-size=SIZE\n\t\t\tSet common page size to SIZE\n"));
   fprintf (file, _("  -z KEYWORD\t\tIgnored for Solaris compatibility\n"));
 fi
 
 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
  $PARSE_AND_LIST_OPTIONS
 EOF
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 }
 EOF
 
 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
  $PARSE_AND_LIST_EPILOGUE
 EOF
 fi
 fi
 else
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 #define gld${EMULATION_NAME}_add_options NULL
 #define gld${EMULATION_NAME}_handle_option NULL
 EOF
 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 #define gld${EMULATION_NAME}_list_options NULL
 EOF
 fi
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 {
 
 
 # This file is sourced from generic.em
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 #include "elf-bfd.h"
 
 EOF
-. ${srcdir}/emultempl/elf-generic.em
-cat >>e${EMULATION_NAME}.c <<EOF
+source_em ${srcdir}/emultempl/elf-generic.em
+fragment <<EOF
 
 static void
 gld${EMULATION_NAME}_finish (void)
 
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* emulate the original gld for the given ${EMULATION_NAME}
 # Import any needed special functions and/or overrides.
 #
 if test -n "$EXTRA_EM_FILE" ; then
-. ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
+  source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
 fi
 
 if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 gld${EMULATION_NAME}_before_parse (void)
 fi
 
 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static char *
 gld${EMULATION_NAME}_get_script (int *isfile)
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 fi
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 {
 
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* Copyright 1991, 1992, 1994, 1999, 2000, 2001, 2002, 2003, 2005, 2007
    Free Software Foundation, Inc.
 
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_gld960_emulation =
 {
 
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003, 2004,
    2005, 2007 Free Software Foundation, Inc.
 
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_gld960coff_emulation =
 {
 
 # This file is sourced from elf32.em, and defines extra hppa-elf
 # specific routines.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "ldctor.h"
 #include "elf32-hppa.h"
 
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 /* None zero if generating binary for Intel Itanium processor.  */
 static int itanium = 0;
 '
 
 LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse
-. ${srcdir}/emultempl/needrelax.em
+source_em ${srcdir}/emultempl/needrelax.em
 
 # MA 02110-1301, USA.
 #
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "ld.h"
 #include "ldmain.h"
 EOF
 
 LDEMUL_AFTER_OPEN=irix_after_open
-. "${srcdir}/emultempl/mipself.em"
+source_em "${srcdir}/emultempl/mipself.em"
 
 else
   OUTPUT_ARCH=${ARCH}:${MACHINE}
 fi
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* Linux a.out emulation code for ${EMULATION_NAME}
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 {
 
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* intel coff loader emulation specific stuff
    Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003,
    2005, 2007 Free Software Foundation, Inc.
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_lnk960_emulation =
 {
 
 #
 # Copied from hppaelf and adapted for M68HC11/M68HC12 specific needs.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "ldctor.h"
 #include "elf32-m68hc1x.h"
 
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* Handle embedded relocs for m68k.
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 {
 
     ;;
 esac
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #ifdef SUPPORT_EMBEDDED_RELOCS
 static void check_sections (bfd *, asection *, void *);
 
 else
   OUTPUT_ARCH=${ARCH}:${MACHINE}
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 static void
 gld${EMULATION_NAME}_before_parse (void)
 {
 
 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
 # MA 02110-1301, USA.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 static void
 mips_after_parse (void)
 {
 
 # This file is sourced from elf32.em and mmo.em, used to define
 # MMIX-specific things common to ELF and MMO.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 #include "elf/mmix.h"
 
 /* Set up handling of linker-allocated global registers.  */
 
 # This file is sourced from elf32.em and used to define MMIX and ELF
 # specific things.  First include what we have in common with mmo.
 
-. ${srcdir}/emultempl/mmix-elfnmmo.em
+source_em ${srcdir}/emultempl/mmix-elfnmmo.em
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 elfmmix_before_parse (void)
 
 
 # This file is sourced from generic.em.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* Need to have this macro defined before mmix-elfnmmo, which uses the
    name for the before_allocation function, defined in ldemul.c (for
    the mmo "emulation") or in elf32.em (for the elf64mmix
 #include "elf-bfd.h"
 EOF
 
-. ${srcdir}/emultempl/elf-generic.em
-. ${srcdir}/emultempl/mmix-elfnmmo.em
+source_em ${srcdir}/emultempl/elf-generic.em
+source_em ${srcdir}/emultempl/mmix-elfnmmo.em
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 /* Place an orphan section.  We use this to put random SEC_CODE or
    SEC_READONLY sections right after MMO_TEXT_SECTION_NAME.  Much borrowed
 
 
 LDEMUL_BEFORE_ALLOCATION=need_relax_${EMULATION_NAME}_before_allocation
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 need_relax_${EMULATION_NAME}_before_allocation (void)
 
 
 LDEMUL_BEFORE_PARSE=gldnetbsd_before_parse
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 static void
 gld${EMULATION_NAME}_before_parse (void);
 
 
 fi
 rm -f e${EMULATION_NAME}.c
 (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
    2005, 2006, 2007 Free Software Foundation, Inc.
 
 #define bfd_arm_process_before_allocation \
        bfd_${EMULATION_NAME}_process_before_allocation
 #endif
- 
+
 #include "sysdep.h"
 #include "bfd.h"
 #include "bfdlink.h"
                if ((sec->flags & SEC_CODE) && sec->reloc_count)
                  stub_sec = sec;
              }
-   
+
            if (is_imp && stub_sec)
              {
                long symsize;
           For backwards compatibility, libfoo.a needs to precede
           libfoo.dll and foo.dll in the search.  */
       { "lib%s.a", FALSE },
-      /* The 'native' spelling of an import lib name is "foo.lib".  */         
+      /* The 'native' spelling of an import lib name is "foo.lib".  */
       { "%s.lib", FALSE },
 #ifdef DLL_SUPPORT
       /* Try "<prefix>foo.dll" (preferred dll name, if specified).  */
 
   for (i = 0; libname_fmt[i].format; i++)
     {
-#ifdef DLL_SUPPORT 
+#ifdef DLL_SUPPORT
       if (libname_fmt[i].use_prefix)
        {
          if (!pe_dll_search_prefix)
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
 echo '; }'                                             >> e${EMULATION_NAME}.c
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 
 fi
 rm -f e${EMULATION_NAME}.c
 (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
-cat >>e${EMULATION_NAME}.c <<EOF
-/* Copyright 2006, 2007 Free Software Foundation, Inc.   
+fragment <<EOF
+/* Copyright 2006, 2007 Free Software Foundation, Inc.
    Written by Kai Tietz, OneVision Software GmbH&CoKg.
 
    This file is part of the GNU Binutils.
           For backwards compatibility, libfoo.a needs to precede
           libfoo.dll and foo.dll in the search.  */
       { "lib%s.a", FALSE },
-      /* The 'native' spelling of an import lib name is "foo.lib".  */         
+      /* The 'native' spelling of an import lib name is "foo.lib".  */
       { "%s.lib", FALSE },
 #ifdef DLL_SUPPORT
       /* Try "<prefix>foo.dll" (preferred dll name, if specified).  */
 
   for (i = 0; libname_fmt[i].format; i++)
     {
-#ifdef DLL_SUPPORT 
+#ifdef DLL_SUPPORT
       if (libname_fmt[i].use_prefix)
        {
          if (!pep_dll_search_prefix)
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
 echo '; }'                                             >> e${EMULATION_NAME}.c
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 
 # This file is sourced from elf32.em, and defines extra powerpc32-elf
 # specific routines.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "libbfd.h"
 #include "elf32-ppc.h"
 EOF
 
 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
-  cat >>e${EMULATION_NAME}.c <<EOF
+  fragment <<EOF
 /* Special handling for embedded SPU executables.  */
 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
 
 # This file is sourced from elf32.em, and defines extra powerpc64-elf
 # specific routines.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "ldctor.h"
 #include "libbfd.h"
 EOF
 
 if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
-  cat >>e${EMULATION_NAME}.c <<EOF
+  fragment <<EOF
 /* Special handling for embedded SPU executables.  */
 extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
 static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
 
 # This shell script emits a C file. -*- C -*-
 #   Copyright 2006, 2007 Free Software Foundation, Inc.
-#   Contributed by: 
+#   Contributed by:
 #   Mei Ligang (ligang@sunnorth.com.cn)
 #   Pei-Lin Tsai (pltsai@sunplus.com)
 
 # This file is sourced from elf32.em, and defines extra score-elf
 # specific routines.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static void
 gld${EMULATION_NAME}_before_parse ()
 
 # Replace the elf before_parse function with our own.
 LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
-
 
 LDEMUL_AFTER_ALLOCATION=sh64_elf_${EMULATION_NAME}_after_allocation
 LDEMUL_BEFORE_ALLOCATION=sh64_elf_${EMULATION_NAME}_before_allocation
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "libiberty.h"
 #include "libbfd.h"
 
 # This file is sourced from elf32.em, and defines extra spu specific
 # features.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 #include "ldctor.h"
 #include "elf32-spu.h"
 
 
 ../binutils/bin2c < ${srcdir}/emultempl/spu_ovl.o >> e${EMULATION_NAME}.c
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 };
 
 static const struct _ovl_stream ovl_mgr_stream = {
 EOF
 
 if grep -q 'ld_elf.*ppc.*_emulation' ldemul-list.h; then
-  cat >>e${EMULATION_NAME}.c <<EOF
+  fragment <<EOF
 #include "filenames.h"
 #include <fcntl.h>
 #include <sys/wait.h>
 
 else
   OUTPUT_ARCH=${ARCH}:${MACHINE}
 fi
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* SunOS emulation code for ${EMULATION_NAME}
 if [ "x${host}" = "x${target}" ] ; then
   case " ${EMULATION_LIBPATH} " in
   *" ${EMULATION_NAME} "*)
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
   const char *env;
 
   env = (const char *) getenv ("LD_LIBRARY_PATH");
   ;;
   esac
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 }
 
 /* Despite the name, we use this routine to search for dynamic
 if [ "x${host}" = "x${target}" ] ; then
   case " ${EMULATION_LIBPATH} " in
   *" ${EMULATION_NAME} "*)
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
       {
        const char *lib_path;
 
   ;;
   esac
 fi
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
       if (command_line.rpath != NULL)
        {
          for (search = search_head; search != NULL; search = search->next)
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
 
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 {
 
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
 (echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* This file is part of GLD, the Gnu Linker.
    Copyright 1999, 2000, 2002, 2003, 2004, 2007
    Free Software Foundation, Inc.
 1s/^/"/
 $s/$/n"/
 '
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 0;
   if (link_info.relocatable && config.build_constructors)
 else
 # Scripts read from the filesystem.
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 {
   *isfile = 1;
 
 
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 {
   gld_${EMULATION_NAME}_before_parse,
 
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-cat >e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* A vanilla emulation with no defaults
    Copyright 1991, 1992, 1994, 2000, 2001, 2002, 2003, 2007
    Free Software Foundation, Inc.
 
 #
 
 if test -n "$VXWORKS_BASE_EM_FILE" ; then
-. "${srcdir}/emultempl/${VXWORKS_BASE_EM_FILE}.em"
+  source_em "${srcdir}/emultempl/${VXWORKS_BASE_EM_FILE}.em"
 fi
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 static int force_dynamic;
 
   var="LDEMUL_`echo ${override} | tr a-z A-Z`"
   eval value=\$${var}
   if test "${value}" = "gld${EMULATION_NAME}_${override}"; then
-    cat >>e${EMULATION_NAME}.c <<EOF
+    fragment <<EOF
 #define ${value} vxworks_${override}
 EOF
   else
 
 # This file is sourced from elf32.em, and defines extra xtensa-elf
 # specific routines.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include <xtensa-config.h>
 #include "../bfd/elf-bfd.h"
   Elf_Internal_Shdr *symtab_hdr;
   Elf_Internal_Rela *internal_relocs = NULL;
   unsigned reloc_count;
- 
+
   *error_message = "";
   insn_sec = bfd_get_section_by_name (abfd, insn_sec_name);
   if (insn_sec == NULL)
       *error_message = _("file already has property tables");
       return FALSE;
     }
-  
+
   if (insn_sec->size != 0)
     {
       insn_contents = (bfd_byte *) bfd_malloc (insn_sec->size);
       *error_message = _("could not create new section");
       goto cleanup;
     }
-  
+
   prop_sec->size = entry_count * 12;
   prop_contents = (bfd_byte *) bfd_zalloc (abfd, prop_sec->size);
   elf_section_data (prop_sec)->this_hdr.contents = prop_contents;
      the number of relocations since it does not use reloc_count.  */
   elf_section_data (prop_sec)->rel_hdr.sh_entsize =
     sizeof (Elf32_External_Rela);
-  elf_section_data (prop_sec)->rel_hdr.sh_size = 
+  elf_section_data (prop_sec)->rel_hdr.sh_size =
     elf_section_data (insn_sec)->rel_hdr.sh_size;
 
   if (prop_contents == NULL && prop_sec->size != 0)
       /* If there is already an internal_reloc, then save it so that the
         read_relocs function freshly allocates a copy.  */
       Elf_Internal_Rela *saved_relocs = elf_section_data (insn_sec)->relocs;
-      
+
       elf_section_data (insn_sec)->relocs = NULL;
-      internal_relocs = 
+      internal_relocs =
        _bfd_elf_link_read_relocs (abfd, insn_sec, NULL, NULL, FALSE);
       elf_section_data (insn_sec)->relocs = saved_relocs;
-      
+
       if (internal_relocs == NULL)
        {
          *error_message = _("out of memory");
       elf_section_data (prop_sec)->relocs = internal_relocs;
       prop_sec->reloc_count = reloc_count;
     }
-  
+
   /* Now copy each insn table entry to the prop table entry with
      appropriate flags.  */
   for (entry = 0; entry < entry_count; ++entry)
 
          rela = &internal_relocs[i];
 
-         /* If this relocation is to the .xt.insn section, 
+         /* If this relocation is to the .xt.insn section,
             change the section number and the offset.  */
          r_offset = rela->r_offset;
          r_offset += 4 * (r_offset / 8);
     }
 
   remove_section (abfd, insn_sec);
-  
+
   if (insn_contents)
     free (insn_contents);
-  
+
   return TRUE;
 
  cleanup:
   char *prop_sec_name = NULL;
   char *owned_prop_sec_name = NULL;
   const char *sec_name;
-    
+
   sec_name = bfd_get_section_name (abfd, sec);
   if (strcmp (sec_name, INSN_SEC_BASE_NAME) == 0)
     {
 {
   /* First call the ELF version.  */
   gld${EMULATION_NAME}_after_open ();
-  
+
   /* Now search the input files looking for instruction table sections.  */
   LANG_FOR_EACH_INPUT_STATEMENT (f)
     {
 LDEMUL_AFTER_OPEN=elf_xtensa_after_open
 LDEMUL_CHOOSE_TARGET=elf_xtensa_choose_target
 LDEMUL_BEFORE_ALLOCATION=elf_xtensa_before_allocation
-
 
 LDEMUL_RECOGNIZED_FILE=gldz80_recognized_file
 LDEMUL_AFTER_OPEN=gldz80_after_open
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 /* --- \begin{z80.em} */
 /* Codes for machine types, bitwise or gives the code to use for the
    output.  */
 /* Bitwise or of the machine types seen so far.  */
 static int result_mach_type;
 
-static void 
+static void
 ${LDEMUL_BEFORE_PARSE} (void)
 {
 #ifndef TARGET_                        /* I.e., if not generic.  */
   unsigned long mach_type;
 
   mach_type = bfd_get_mach (entry->the_bfd);
-  switch (mach_type) 
+  switch (mach_type)
     {
-    case bfd_mach_z80strict:      
-      result_mach_type |= M_Z80STRICT; 
+    case bfd_mach_z80strict:
+      result_mach_type |= M_Z80STRICT;
       break;
     case bfd_mach_z80:
-      result_mach_type |= M_Z80; 
+      result_mach_type |= M_Z80;
       break;
     case bfd_mach_z80full:
-      result_mach_type |= M_Z80FULL; 
+      result_mach_type |= M_Z80FULL;
       break;
     case bfd_mach_r800:
-      result_mach_type |= M_R800; 
+      result_mach_type |= M_R800;
       break;
     default:
       result_mach_type |= M_Z80ANY;
 
     *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
 esac
 
+if test -n "${BASH+set}"; then
+  source_em()
+  {
+    local current_script="$em_script"
+    em_script=$1
+    . $em_script
+    em_script=$current_script
+  }
+  fragment()
+  {
+    local lineno=$[${BASH_LINENO[0]} + 1]
+    echo >> e${EMULATION_NAME}.c "#line $lineno \"$em_script\""
+    cat >> e${EMULATION_NAME}.c
+  }
+else
+  source_em()
+  {
+    . $1
+  }
+  fragment()
+  {
+    cat >> e${EMULATION_NAME}.c
+  }
+fi
+
 # Generate e${EMULATION_NAME}.c.
-. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
+# Start with an empty file, then the sourced .em script
+# can use the "fragment" function to append.
+> e${EMULATION_NAME}.c
+source_em ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em