12159047fSniklas# This shell script emits a C file. -*- C -*-
22159047fSniklas# It does some substitutions.
32159047fSniklascat >e${EMULATION_NAME}.c <<EOF
42159047fSniklas/* This file is is generated by a shell script.  DO NOT EDIT! */
52159047fSniklas
62159047fSniklas/* emulate the original gld for the given ${EMULATION_NAME}
7*007c2a45Smiod   Copyright 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003, 2004
8b55d4692Sfgsch   Free Software Foundation, Inc.
92159047fSniklas   Written by Steve Chamberlain steve@cygnus.com
102159047fSniklas
112159047fSniklasThis file is part of GLD, the Gnu Linker.
122159047fSniklas
132159047fSniklasThis program is free software; you can redistribute it and/or modify
142159047fSniklasit under the terms of the GNU General Public License as published by
152159047fSniklasthe Free Software Foundation; either version 2 of the License, or
162159047fSniklas(at your option) any later version.
172159047fSniklas
182159047fSniklasThis program is distributed in the hope that it will be useful,
192159047fSniklasbut WITHOUT ANY WARRANTY; without even the implied warranty of
202159047fSniklasMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
212159047fSniklasGNU General Public License for more details.
222159047fSniklas
232159047fSniklasYou should have received a copy of the GNU General Public License
242159047fSniklasalong with this program; if not, write to the Free Software
252159047fSniklasFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
262159047fSniklas
272159047fSniklas#define TARGET_IS_${EMULATION_NAME}
282159047fSniklas
292159047fSniklas#include "bfd.h"
302159047fSniklas#include "sysdep.h"
312159047fSniklas#include "bfdlink.h"
322159047fSniklas
332159047fSniklas#include "ld.h"
342159047fSniklas#include "ldmain.h"
352159047fSniklas#include "ldmisc.h"
362159047fSniklas
37b55d4692Sfgsch#include "ldexp.h"
38b55d4692Sfgsch#include "ldlang.h"
39b55d4692Sfgsch#include "ldfile.h"
40b55d4692Sfgsch#include "ldemul.h"
41b55d4692Sfgsch
42c074d1c9SdrahnEOF
43c074d1c9Sdrahn
44c074d1c9Sdrahn# Import any needed special functions and/or overrides.
45c074d1c9Sdrahn#
46c074d1c9Sdrahnif test -n "$EXTRA_EM_FILE" ; then
47c074d1c9Sdrahn. ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
48c074d1c9Sdrahnfi
49c074d1c9Sdrahn
50c074d1c9Sdrahnif test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
51c074d1c9Sdrahncat >>e${EMULATION_NAME}.c <<EOF
52c074d1c9Sdrahn
532159047fSniklasstatic void
54*007c2a45Smiodgld${EMULATION_NAME}_before_parse (void)
552159047fSniklas{
562159047fSniklas#ifndef TARGET_			/* I.e., if not generic.  */
57*007c2a45Smiod  ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
582159047fSniklas#endif /* not TARGET_ */
592159047fSniklas}
602159047fSniklas
61c074d1c9SdrahnEOF
62c074d1c9Sdrahnfi
63c074d1c9Sdrahn
64c074d1c9Sdrahnif test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
65c074d1c9Sdrahncat >>e${EMULATION_NAME}.c <<EOF
66c074d1c9Sdrahn
672159047fSniklasstatic char *
68*007c2a45Smiodgld${EMULATION_NAME}_get_script (int *isfile)
692159047fSniklasEOF
702159047fSniklas
712159047fSniklasif test -n "$COMPILE_IN"
722159047fSniklasthen
732159047fSniklas# Scripts compiled in.
742159047fSniklas
752159047fSniklas# sed commands to quote an ld script as a C string.
76b305b0f1Sespiesc="-f stringify.sed"
772159047fSniklas
782159047fSniklascat >>e${EMULATION_NAME}.c <<EOF
792159047fSniklas{
802159047fSniklas  *isfile = 0;
812159047fSniklas
82*007c2a45Smiod  if (link_info.relocatable && config.build_constructors)
832159047fSniklas    return
842159047fSniklasEOF
852159047fSniklassed $sc ldscripts/${EMULATION_NAME}.xu                 >> e${EMULATION_NAME}.c
86*007c2a45Smiodecho '  ; else if (link_info.relocatable) return'     >> e${EMULATION_NAME}.c
872159047fSniklassed $sc ldscripts/${EMULATION_NAME}.xr                 >> e${EMULATION_NAME}.c
882159047fSniklasecho '  ; else if (!config.text_read_only) return'     >> e${EMULATION_NAME}.c
892159047fSniklassed $sc ldscripts/${EMULATION_NAME}.xbn                >> e${EMULATION_NAME}.c
902159047fSniklasecho '  ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
912159047fSniklassed $sc ldscripts/${EMULATION_NAME}.xn                 >> e${EMULATION_NAME}.c
922159047fSniklasecho '  ; else return'                                 >> e${EMULATION_NAME}.c
932159047fSniklassed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
942159047fSniklasecho '; }'                                             >> e${EMULATION_NAME}.c
952159047fSniklas
962159047fSniklaselse
972159047fSniklas# Scripts read from the filesystem.
982159047fSniklas
992159047fSniklascat >>e${EMULATION_NAME}.c <<EOF
1002159047fSniklas{
1012159047fSniklas  *isfile = 1;
1022159047fSniklas
103*007c2a45Smiod  if (link_info.relocatable && config.build_constructors)
1042159047fSniklas    return "ldscripts/${EMULATION_NAME}.xu";
105*007c2a45Smiod  else if (link_info.relocatable)
1062159047fSniklas    return "ldscripts/${EMULATION_NAME}.xr";
1072159047fSniklas  else if (!config.text_read_only)
1082159047fSniklas    return "ldscripts/${EMULATION_NAME}.xbn";
1092159047fSniklas  else if (!config.magic_demand_paged)
1102159047fSniklas    return "ldscripts/${EMULATION_NAME}.xn";
1112159047fSniklas  else
1122159047fSniklas    return "ldscripts/${EMULATION_NAME}.x";
1132159047fSniklas}
1142159047fSniklasEOF
115c074d1c9Sdrahnfi
1162159047fSniklasfi
1172159047fSniklas
1182159047fSniklascat >>e${EMULATION_NAME}.c <<EOF
1192159047fSniklas
1202159047fSniklasstruct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1212159047fSniklas{
122c074d1c9Sdrahn  ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
123c074d1c9Sdrahn  ${LDEMUL_SYSLIB-syslib_default},
124c074d1c9Sdrahn  ${LDEMUL_HLL-hll_default},
125c074d1c9Sdrahn  ${LDEMUL_AFTER_PARSE-after_parse_default},
126c074d1c9Sdrahn  ${LDEMUL_AFTER_OPEN-after_open_default},
127c074d1c9Sdrahn  ${LDEMUL_AFTER_ALLOCATION-after_allocation_default},
128c074d1c9Sdrahn  ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
129c074d1c9Sdrahn  ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
130c074d1c9Sdrahn  ${LDEMUL_BEFORE_ALLOCATION-before_allocation_default},
131c074d1c9Sdrahn  ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
1322159047fSniklas  "${EMULATION_NAME}",
133b305b0f1Sespie  "${OUTPUT_FORMAT}",
134c074d1c9Sdrahn  ${LDEMUL_FINISH-NULL},
135c074d1c9Sdrahn  ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
136c074d1c9Sdrahn  ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-NULL},
137c074d1c9Sdrahn  ${LDEMUL_PLACE_ORPHAN-NULL},
138c074d1c9Sdrahn  ${LDEMUL_SET_SYMBOLS-NULL},
139c074d1c9Sdrahn  ${LDEMUL_PARSE_ARGS-NULL},
140c074d1c9Sdrahn  NULL,	/* add_options */
141c074d1c9Sdrahn  NULL,	/* handle_option */
142c074d1c9Sdrahn  ${LDEMUL_UNRECOGNIZED_FILE-NULL},
143c074d1c9Sdrahn  ${LDEMUL_LIST_OPTIONS-NULL},
144c074d1c9Sdrahn  ${LDEMUL_RECOGNIZED_FILE-NULL},
145c074d1c9Sdrahn  ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
146c074d1c9Sdrahn  ${LDEMUL_NEW_VERS_PATTERN-NULL}
1472159047fSniklas};
1482159047fSniklasEOF
149