1/* Generate parameters for an a.out system.
2   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 2001, 2002, 2007
3   Free Software Foundation, Inc.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
20
21#include "/usr/include/a.out.h"
22#include <stdio.h>
23
24#ifndef _
25#define _(X) X
26#endif
27
28int
29main (argc, argv)
30     int argc; char** argv;
31{
32  struct exec my_exec;
33  int page_size;
34  char *target = "unknown", *arch = "unknown";
35  FILE *file = fopen("gen-aout", "r");
36
37  if (file == NULL) {
38      fprintf(stderr, "Cannot open gen-aout!\n");
39      return -1;
40  }
41  if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
42      fprintf(stderr, "Cannot read gen-aout!\n");
43      return -1;
44  }
45
46  target = argv[1];
47  if (target == NULL) {
48      fprintf(stderr, "Usage: gen-aout target_name\n");
49      exit (1);
50  }
51
52#ifdef N_TXTOFF
53  page_size = N_TXTOFF(my_exec);
54  if (page_size == 0)
55    printf("#define N_HEADER_IN_TEXT(x) 1\n");
56  else
57    printf("#define N_HEADER_IN_TEXT(x) 0\n");
58#endif
59
60  printf("#define BYTES_IN_WORD %d\n", sizeof (int));
61  if (my_exec.a_entry == 0) {
62      printf("#define ENTRY_CAN_BE_ZERO\n");
63      printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
64  }
65  else {
66      printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
67      printf("/*#define N_SHARED_LIB(x) 0*/\n");
68  }
69
70  printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
71
72#ifdef PAGSIZ
73  if (page_size == 0)
74    page_size = PAGSIZ;
75#endif
76  if (page_size != 0)
77    printf("#define TARGET_PAGE_SIZE %d\n", page_size);
78  else
79    printf("/* #define TARGET_PAGE_SIZE ??? */\n");
80  printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
81
82#ifdef vax
83  arch = "vax";
84#endif
85#ifdef m68k
86  arch = "m68k";
87#endif
88  if (arch[0] == '1')
89    {
90      fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
91      fprintf (stderr, _("         fix DEFAULT_ARCH in the output file yourself\n"));
92      arch = "unknown";
93    }
94  printf("#define DEFAULT_ARCH bfd_arch_%s\n\n", arch);
95
96  printf("/* Do not \"beautify\" the CONCAT* macro args.  Traditional C will not");
97  printf("   remove whitespace added here, and thus will fail to concatenate");
98  printf("   the tokens.  */");
99  printf("\n#define MY(OP) CONCAT2 (%s_,OP)\n\n", target);
100  printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
101
102  printf("#include \"sysdep.h\"\n");
103  printf("#include \"bfd.h\"\n");
104  printf("#include \"libbfd.h\"\n");
105  printf("#include \"libaout.h\"\n");
106  printf("\n#include \"aout-target.h\"\n");
107
108  return 0;
109}
110