1999-09-11 Donn Terry <donn@interix.com>
[binutils.git] / bfd / gen-aout.c
blobb5ed91a096b4ea3db66326a00f2089c3d15ee3a6
1 /* Generate parameters for an a.out system.
2 Copyright (C) 1990, 91, 92, 93, 94, 98 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include "/usr/include/a.out.h"
21 #include <stdio.h>
23 int
24 main (argc, argv)
25 int argc; char** argv;
27 struct exec my_exec;
28 int page_size;
29 char *target = "unknown", *arch = "unknown";
30 FILE *file = fopen("gen-aout", "r");
32 if (file == NULL) {
33 fprintf(stderr, "Cannot open gen-aout!\n");
34 return -1;
36 if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
37 fprintf(stderr, "Cannot read gen-aout!\n");
38 return -1;
41 target = argv[1];
42 if (target == NULL) {
43 fprintf(stderr, "Usage: gen-aout target_name\n");
44 exit (1);
47 #ifdef N_TXTOFF
48 page_size = N_TXTOFF(my_exec);
49 if (page_size == 0)
50 printf("#define N_HEADER_IN_TEXT(x) 1\n");
51 else
52 printf("#define N_HEADER_IN_TEXT(x) 0\n");
53 #endif
55 printf("#define BYTES_IN_WORD %d\n", sizeof (int));
56 if (my_exec.a_entry == 0) {
57 printf("#define ENTRY_CAN_BE_ZERO\n");
58 printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
60 else {
61 printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
62 printf("/*#define N_SHARED_LIB(x) 0*/\n");
65 printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
67 #ifdef PAGSIZ
68 if (page_size == 0)
69 page_size = PAGSIZ;
70 #endif
71 if (page_size != 0)
72 printf("#define TARGET_PAGE_SIZE %d\n", page_size);
73 else
74 printf("/* #define TARGET_PAGE_SIZE ??? */\n");
75 printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
77 #ifdef vax
78 arch = "vax";
79 #endif
80 #ifdef m68k
81 arch = "m68k";
82 #endif
83 if (arch[0] == '1')
85 fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
86 fprintf (stderr, _(" fix DEFAULT_ARCH in the output file yourself\n"));
87 arch = "unknown";
89 printf("#define DEFAULT_ARCH bfd_arch_%s\n", arch);
91 printf("\n#define MY(OP) CAT(%s_,OP)\n", target);
92 printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
94 printf("#include \"bfd.h\"\n");
95 printf("#include \"sysdep.h\"\n");
96 printf("#include \"libbfd.h\"\n");
97 printf("#include \"libaout.h\"\n");
98 printf("\n#include \"aout-target.h\"\n");
100 return 0;