2009-07-02 Tristan Gingold <gingold@adacore.com>
[binutils.git] / bfd / gen-aout.c
blob27f7eafe6cad7ad88e706e95523b964ef3bf380a
1 /* Generate parameters for an a.out system.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 2001, 2002, 2007
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 3 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., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "/usr/include/a.out.h"
23 #include <stdio.h>
25 #ifndef _
26 #define _(X) X
27 #endif
29 int
30 main (argc, argv)
31 int argc; char** argv;
33 struct exec my_exec;
34 int page_size;
35 char *target = "unknown", *arch = "unknown";
36 FILE *file = fopen("gen-aout", "r");
38 if (file == NULL) {
39 fprintf(stderr, "Cannot open gen-aout!\n");
40 return -1;
42 if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
43 fprintf(stderr, "Cannot read gen-aout!\n");
44 return -1;
47 target = argv[1];
48 if (target == NULL) {
49 fprintf(stderr, "Usage: gen-aout target_name\n");
50 exit (1);
53 #ifdef N_TXTOFF
54 page_size = N_TXTOFF(my_exec);
55 if (page_size == 0)
56 printf("#define N_HEADER_IN_TEXT(x) 1\n");
57 else
58 printf("#define N_HEADER_IN_TEXT(x) 0\n");
59 #endif
61 printf("#define BYTES_IN_WORD %d\n", sizeof (int));
62 if (my_exec.a_entry == 0) {
63 printf("#define ENTRY_CAN_BE_ZERO\n");
64 printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
66 else {
67 printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
68 printf("/*#define N_SHARED_LIB(x) 0*/\n");
71 printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
73 #ifdef PAGSIZ
74 if (page_size == 0)
75 page_size = PAGSIZ;
76 #endif
77 if (page_size != 0)
78 printf("#define TARGET_PAGE_SIZE %d\n", page_size);
79 else
80 printf("/* #define TARGET_PAGE_SIZE ??? */\n");
81 printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
83 #ifdef vax
84 arch = "vax";
85 #endif
86 #ifdef m68k
87 arch = "m68k";
88 #endif
89 if (arch[0] == '1')
91 fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
92 fprintf (stderr, _(" fix DEFAULT_ARCH in the output file yourself\n"));
93 arch = "unknown";
95 printf("#define DEFAULT_ARCH bfd_arch_%s\n\n", arch);
97 printf("/* Do not \"beautify\" the CONCAT* macro args. Traditional C will not");
98 printf(" remove whitespace added here, and thus will fail to concatenate");
99 printf(" the tokens. */");
100 printf("\n#define MY(OP) CONCAT2 (%s_,OP)\n\n", target);
101 printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
103 printf("#include \"sysdep.h\"\n");
104 printf("#include \"bfd.h\"\n");
105 printf("#include \"libbfd.h\"\n");
106 printf("#include \"libaout.h\"\n");
107 printf("\n#include \"aout-target.h\"\n");
109 return 0;