ticoff.em revision 104834
177298Sobrien# This shell script emits a C file. -*- C -*-
277298Sobrien# It does some substitutions.
377298Sobrien(echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
477298Sobriencat >>e${EMULATION_NAME}.c <<EOF
577298Sobrien/* This file is part of GLD, the Gnu Linker.
677298Sobrien   Copyright 1999, 2000 Free Software Foundation, Inc.
777298Sobrien
877298SobrienThis program is free software; you can redistribute it and/or modify
977298Sobrienit under the terms of the GNU General Public License as published by
1077298Sobrienthe Free Software Foundation; either version 2 of the License, or
1177298Sobrien(at your option) any later version.
1277298Sobrien
1377298SobrienThis program is distributed in the hope that it will be useful,
1477298Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1577298SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1677298SobrienGNU General Public License for more details.
1777298Sobrien
1877298SobrienYou should have received a copy of the GNU General Public License
1977298Sobrienalong with this program; if not, write to the Free Software
2077298SobrienFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2177298Sobrien
2277298Sobrien/* For TI COFF */
2377298Sobrien/* Need to determine load and run pages for output sections */ 
2477298Sobrien  
2577298Sobrien#define TARGET_IS_${EMULATION_NAME}
2677298Sobrien
2777298Sobrien#include "bfd.h"
2877298Sobrien#include "sysdep.h"
2977298Sobrien#include "bfdlink.h"
3077298Sobrien
3177298Sobrien#include "ld.h"
3277298Sobrien#include "ldmain.h"
3377298Sobrien#include "ldmisc.h"
3477298Sobrien
3577298Sobrien#include "ldexp.h"
3677298Sobrien#include "ldlang.h"
3777298Sobrien#include "ldfile.h"
3877298Sobrien#include "ldemul.h"
3977298Sobrien
4077298Sobrien#include "getopt.h"
4177298Sobrien
4277298Sobrienstatic int coff_version;
4377298Sobrien
4477298Sobrienstatic void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
4577298Sobrienstatic char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
4677298Sobrienstatic int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
4777298Sobrienstatic void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *));
4877298Sobrien
4977298Sobrien/* TI COFF extra command line options */
5077298Sobrien#define OPTION_COFF_FORMAT		(300 + 1)
5177298Sobrien
5277298Sobrienstatic struct option longopts[] = 
5377298Sobrien{
5477298Sobrien  /* TI COFF options */
5577298Sobrien  {"format", required_argument, NULL, OPTION_COFF_FORMAT },
5677298Sobrien  {NULL, no_argument, NULL, 0}
5777298Sobrien};
5877298Sobrien
5977298Sobrienstatic void
6077298Sobriengld_${EMULATION_NAME}_list_options (file)
6177298Sobrien    FILE * file;
6277298Sobrien{
6377298Sobrien  fprintf (file, _("  --format 0|1|2         Specify which COFF version to use"));
6477298Sobrien}				  
6577298Sobrien
6677298Sobrienstatic int
6777298Sobriengld_${EMULATION_NAME}_parse_args(argc, argv)
6877298Sobrien     int argc;
6977298Sobrien     char **argv;
7077298Sobrien{
7177298Sobrien  int longind;
7277298Sobrien  int optc;
7377298Sobrien  int prevoptind = optind;
7477298Sobrien  int prevopterr = opterr;
7577298Sobrien  int wanterror;
7677298Sobrien  static int lastoptind = -1;
7777298Sobrien
7877298Sobrien  if (lastoptind != optind)
7977298Sobrien    opterr = 0;
8077298Sobrien  wanterror = opterr;
8177298Sobrien
8277298Sobrien  lastoptind = optind;
8377298Sobrien
8477298Sobrien  optc = getopt_long_only (argc, argv, "-", longopts, &longind);
8577298Sobrien  opterr = prevopterr;
8677298Sobrien
8777298Sobrien  switch (optc)
8877298Sobrien    {
8977298Sobrien    default:
9077298Sobrien      if (wanterror)
9177298Sobrien	xexit (1);
9277298Sobrien      optind =  prevoptind;
9377298Sobrien      return 0;
9477298Sobrien
9577298Sobrien    case OPTION_COFF_FORMAT:
9677298Sobrien      if ((*optarg == '0' || *optarg == '1' || *optarg == '2')
9777298Sobrien          && optarg[1] == '\0')
9877298Sobrien      {
9977298Sobrien        extern void lang_add_output_format
10077298Sobrien          PARAMS ((const char *, const char *, const char *, int));
10177298Sobrien        static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}";
10277298Sobrien        coff_version = *optarg - '0';
10377298Sobrien        buf[4] = *optarg;
10477298Sobrien	lang_add_output_format (buf, NULL, NULL, 0);	
10577298Sobrien      }
10677298Sobrien      else
10777298Sobrien        {
10877298Sobrien	  einfo (_("%P%F: invalid COFF format version %s\n"), optarg);
10977298Sobrien
11077298Sobrien        }
11177298Sobrien      break;
11277298Sobrien    }
11377298Sobrien  return 1;
11477298Sobrien}
11577298Sobrien
11677298Sobrienstatic void
11777298Sobriengld_${EMULATION_NAME}_before_parse()
11877298Sobrien{
11977298Sobrien#ifndef TARGET_			/* I.e., if not generic.  */
12077298Sobrien  ldfile_set_output_arch ("`echo ${ARCH}`");
12177298Sobrien#endif /* not TARGET_ */
12277298Sobrien}
12377298Sobrien
12477298Sobrienstatic char *
12577298Sobriengld_${EMULATION_NAME}_get_script (isfile)
12677298Sobrien     int *isfile;
12777298SobrienEOF
12877298Sobrienif test -n "$COMPILE_IN"
12977298Sobrienthen
13077298Sobrien# Scripts compiled in.
13177298Sobrien
13277298Sobrien# sed commands to quote an ld script as a C string.
13377298Sobriensc='s/["\\]/\\&/g
13477298Sobriens/$/\\n\\/
13577298Sobrien1s/^/"/
13677298Sobrien$s/$/n"/
13777298Sobrien'
13877298Sobriencat >>e${EMULATION_NAME}.c <<EOF
13977298Sobrien{			     
14077298Sobrien  *isfile = 0;
14177298Sobrien  if (link_info.relocateable == true && config.build_constructors == true)
14277298Sobrien    return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
14377298Sobrien  else if (link_info.relocateable == true)
14477298Sobrien    return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
14577298Sobrien  else if (!config.text_read_only)
14677298Sobrien    return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
14777298Sobrien  else if (!config.magic_demand_paged)
14877298Sobrien    return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
14977298Sobrien  else
15077298Sobrien    return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
15177298Sobrien}
15277298SobrienEOF
15377298Sobrien
15477298Sobrienelse
15577298Sobrien# Scripts read from the filesystem.
15677298Sobrien
15777298Sobriencat >>e${EMULATION_NAME}.c <<EOF
15877298Sobrien{			     
15977298Sobrien  *isfile = 1;
16077298Sobrien
16177298Sobrien  if (link_info.relocateable == true && config.build_constructors == true)
16277298Sobrien    return "ldscripts/${EMULATION_NAME}.xu";
16377298Sobrien  else if (link_info.relocateable == true)
16477298Sobrien    return "ldscripts/${EMULATION_NAME}.xr";
16577298Sobrien  else if (!config.text_read_only)
16677298Sobrien    return "ldscripts/${EMULATION_NAME}.xbn";
16777298Sobrien  else if (!config.magic_demand_paged)
16877298Sobrien    return "ldscripts/${EMULATION_NAME}.xn";
16977298Sobrien  else
17077298Sobrien    return "ldscripts/${EMULATION_NAME}.x";
17177298Sobrien}
17277298SobrienEOF
17377298Sobrien
17477298Sobrienfi
17577298Sobrien
17677298Sobriencat >>e${EMULATION_NAME}.c <<EOF
17777298Sobrienstruct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 
17877298Sobrien{
17977298Sobrien  gld_${EMULATION_NAME}_before_parse,
18077298Sobrien  syslib_default,
18177298Sobrien  hll_default,
18277298Sobrien  after_parse_default,
18377298Sobrien  after_open_default,
18477298Sobrien  after_allocation_default,
18577298Sobrien  set_output_arch_default,
18677298Sobrien  ldemul_default_target,
18777298Sobrien  before_allocation_default,
18877298Sobrien  gld_${EMULATION_NAME}_get_script,
18977298Sobrien  "${EMULATION_NAME}",
19077298Sobrien  "${OUTPUT_FORMAT}",
19177298Sobrien  NULL, /* finish */
19277298Sobrien  NULL, /* create output section statements */
19377298Sobrien  NULL, /* open dynamic archive */
19477298Sobrien  NULL, /* place orphan */
19577298Sobrien  NULL, /* set_symbols */
19677298Sobrien  gld_${EMULATION_NAME}_parse_args,
19777298Sobrien  NULL, /* unrecognized_file */
19877298Sobrien  gld_${EMULATION_NAME}_list_options,
19977298Sobrien  NULL, /* recognized file */
200104834Sobrien  NULL,	/* find_potential_libraries */
201104834Sobrien  NULL	/* new_vers_pattern */
20277298Sobrien};
20377298SobrienEOF
204