12432Sse/* Generate parameters for an a.out system.
22432Sse   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 2001, 2002, 2007
32432Sse   Free Software Foundation, Inc.
439247Sgibbs
52432SseThis file is part of BFD, the Binary File Descriptor library.
62432Sse
72432SseThis program is free software; you can redistribute it and/or modify
82432Sseit under the terms of the GNU General Public License as published by
97228Ssethe Free Software Foundation; either version 2 of the License, or
103533Sse(at your option) any later version.
112432Sse
122432SseThis program is distributed in the hope that it will be useful,
13139834Sscottlbut WITHOUT ANY WARRANTY; without even the implied warranty of
14139825SimpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
152432SseGNU General Public License for more details.
162432Sse
172432SseYou should have received a copy of the GNU General Public License
182432Ssealong with this program; if not, write to the Free Software
192432SseFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
202432Sse
212432Sse#include "/usr/include/a.out.h"
222432Sse#include <stdio.h>
232432Sse
242432Sse#ifndef _
252432Sse#define _(X) X
262432Sse#endif
272432Sse
282432Sseint
292432Ssemain (argc, argv)
302432Sse     int argc; char** argv;
312432Sse{
322432Sse  struct exec my_exec;
332432Sse  int page_size;
342432Sse  char *target = "unknown", *arch = "unknown";
352432Sse  FILE *file = fopen("gen-aout", "r");
362432Sse
372432Sse  if (file == NULL) {
382432Sse      fprintf(stderr, "Cannot open gen-aout!\n");
393533Sse      return -1;
402432Sse  }
412432Sse  if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
42116192Sobrien      fprintf(stderr, "Cannot read gen-aout!\n");
43116192Sobrien      return -1;
44116192Sobrien  }
45116192Sobrien
4639247Sgibbs  target = argv[1];
476132Sdg  if (target == NULL) {
482432Sse      fprintf(stderr, "Usage: gen-aout target_name\n");
493533Sse      exit (1);
502432Sse  }
519429Sse
527228Sse#ifdef N_TXTOFF
5355206Speter  page_size = N_TXTOFF(my_exec);
5420535Sse  if (page_size == 0)
5555206Speter    printf("#define N_HEADER_IN_TEXT(x) 1\n");
5620517Sse  else
572432Sse    printf("#define N_HEADER_IN_TEXT(x) 0\n");
582432Sse#endif
592432Sse
602432Sse  printf("#define BYTES_IN_WORD %d\n", sizeof (int));
616460Sse  if (my_exec.a_entry == 0) {
622432Sse      printf("#define ENTRY_CAN_BE_ZERO\n");
632432Sse      printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
642432Sse  }
652432Sse  else {
662432Sse      printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
672432Sse      printf("/*#define N_SHARED_LIB(x) 0*/\n");
682432Sse  }
692432Sse
702432Sse  printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
712432Sse
722432Sse#ifdef PAGSIZ
732432Sse  if (page_size == 0)
742432Sse    page_size = PAGSIZ;
752432Sse#endif
762432Sse  if (page_size != 0)
7727684Sse    printf("#define TARGET_PAGE_SIZE %d\n", page_size);
782432Sse  else
7927684Sse    printf("/* #define TARGET_PAGE_SIZE ??? */\n");
802432Sse  printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
812432Sse
8227684Sse#ifdef vax
832432Sse  arch = "vax";
8427684Sse#endif
8527684Sse#ifdef m68k
8627684Sse  arch = "m68k";
8727684Sse#endif
8827684Sse  if (arch[0] == '1')
8927684Sse    {
9027684Sse      fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
9127684Sse      fprintf (stderr, _("         fix DEFAULT_ARCH in the output file yourself\n"));
9227684Sse      arch = "unknown";
9327684Sse    }
9427684Sse  printf("#define DEFAULT_ARCH bfd_arch_%s\n\n", arch);
9527684Sse
9627684Sse  printf("/* Do not \"beautify\" the CONCAT* macro args.  Traditional C will not");
9727684Sse  printf("   remove whitespace added here, and thus will fail to concatenate");
982432Sse  printf("   the tokens.  */");
9927684Sse  printf("\n#define MY(OP) CONCAT2 (%s_,OP)\n\n", target);
10027684Sse  printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
10127684Sse
10227684Sse  printf("#include \"sysdep.h\"\n");
10327684Sse  printf("#include \"bfd.h\"\n");
10427684Sse  printf("#include \"libbfd.h\"\n");
10527684Sse  printf("#include \"libaout.h\"\n");
10627684Sse  printf("\n#include \"aout-target.h\"\n");
10727684Sse
1082814Sse  return 0;
1092814Sse}
1102814Sse