1# This shell script emits a C file. -*- C -*- 2# It does some substitutions. 3fragment <<EOF 4/* Copyright (C) 1991-2016 Free Software Foundation, Inc. 5 6 This file is part of the GNU Binutils. 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 21 MA 02110-1301, USA. */ 22 23 24/* Emulate the Intel's port of gld. */ 25 26#include "sysdep.h" 27#include "bfd.h" 28#include "libiberty.h" 29#include "safe-ctype.h" 30#include "bfdlink.h" 31 32#include "ld.h" 33#include "ldmisc.h" 34#include "ldmain.h" 35 36#include "ldexp.h" 37#include "ldlang.h" 38#include "ldfile.h" 39#include "ldemul.h" 40 41static void gld960_before_parse (void) 42{ 43 char *env ; 44 env = getenv("G960LIB"); 45 if (env) { 46 ldfile_add_library_path(env, FALSE); 47 } 48 env = getenv("G960BASE"); 49 if (env) 50 ldfile_add_library_path (concat (env, "/lib", (const char *) NULL), 51 FALSE); 52 ldfile_output_architecture = bfd_arch_i960; 53} 54 55static void 56gld960_set_output_arch (void) 57{ 58 if (ldfile_output_machine_name != NULL 59 && *ldfile_output_machine_name != '\0') 60 { 61 char *s, *s1; 62 63 s = concat ("i960:", ldfile_output_machine_name, (char *) NULL); 64 for (s1 = s; *s1 != '\0'; s1++) 65 *s1 = TOLOWER (*s1); 66 ldfile_set_output_arch (s, bfd_arch_unknown); 67 free (s); 68 } 69 70 set_output_arch_default (); 71} 72 73static char * 74gld960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) 75{ 76 char *from_outside = getenv(TARGET_ENVIRON); 77 output_filename = "b.out"; 78 79 if (from_outside != (char *)NULL) 80 return from_outside; 81 82 return "coff-Intel-little"; 83} 84 85static char * 86gld960_get_script (int *isfile) 87EOF 88 89if test x"$COMPILE_IN" = xyes 90then 91# Scripts compiled in. 92 93# sed commands to quote an ld script as a C string. 94sc="-f stringify.sed" 95 96fragment <<EOF 97{ 98 *isfile = 0; 99 100 if (bfd_link_relocatable (&link_info) && config.build_constructors) 101 return 102EOF 103sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c 104echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c 105sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c 106echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c 107sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c 108echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c 109sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c 110echo ' ; else return' >> e${EMULATION_NAME}.c 111sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c 112echo '; }' >> e${EMULATION_NAME}.c 113 114else 115# Scripts read from the filesystem. 116 117fragment <<EOF 118{ 119 *isfile = 1; 120 121 if (bfd_link_relocatable (&link_info) && config.build_constructors) 122 return "ldscripts/${EMULATION_NAME}.xu"; 123 else if (bfd_link_relocatable (&link_info)) 124 return "ldscripts/${EMULATION_NAME}.xr"; 125 else if (!config.text_read_only) 126 return "ldscripts/${EMULATION_NAME}.xbn"; 127 else if (!config.magic_demand_paged) 128 return "ldscripts/${EMULATION_NAME}.xn"; 129 else 130 return "ldscripts/${EMULATION_NAME}.x"; 131} 132EOF 133 134fi 135 136fragment <<EOF 137 138struct ld_emulation_xfer_struct ld_gld960coff_emulation = 139{ 140 gld960_before_parse, 141 syslib_default, 142 hll_default, 143 after_parse_default, 144 after_open_default, 145 after_allocation_default, 146 gld960_set_output_arch, 147 gld960_choose_target, 148 before_allocation_default, 149 gld960_get_script, 150 "960coff", 151 "", 152 finish_default, 153 NULL, /* create output section statements */ 154 NULL, /* open dynamic archive */ 155 NULL, /* place orphan */ 156 NULL, /* set symbols */ 157 NULL, /* parse args */ 158 NULL, /* add_options */ 159 NULL, /* handle_option */ 160 NULL, /* unrecognized file */ 161 NULL, /* list options */ 162 NULL, /* recognized file */ 163 NULL, /* find_potential_libraries */ 164 NULL, /* new_vers_pattern */ 165 NULL /* extra_map_file_text */ 166}; 167EOF 168