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