12159047fSniklas /* Generate parameters for an a.out system.
2*007c2a45Smiod Copyright 1990, 1991, 1992, 1993, 1994, 1995, 2001, 2002
3b55d4692Sfgsch Free Software Foundation, Inc.
42159047fSniklas
52159047fSniklas This file is part of BFD, the Binary File Descriptor library.
62159047fSniklas
72159047fSniklas This program is free software; you can redistribute it and/or modify
82159047fSniklas it under the terms of the GNU General Public License as published by
92159047fSniklas the Free Software Foundation; either version 2 of the License, or
102159047fSniklas (at your option) any later version.
112159047fSniklas
122159047fSniklas This program is distributed in the hope that it will be useful,
132159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
142159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152159047fSniklas GNU General Public License for more details.
162159047fSniklas
172159047fSniklas You should have received a copy of the GNU General Public License
182159047fSniklas along with this program; if not, write to the Free Software
192159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
202159047fSniklas
212159047fSniklas #include "/usr/include/a.out.h"
222159047fSniklas #include <stdio.h>
232159047fSniklas
24c074d1c9Sdrahn #ifndef _
25c074d1c9Sdrahn #define _(X) X
26598bbe82Sespie #endif
27598bbe82Sespie
282159047fSniklas int
main(argc,argv)292159047fSniklas main (argc, argv)
302159047fSniklas int argc; char** argv;
312159047fSniklas {
322159047fSniklas struct exec my_exec;
332159047fSniklas int page_size;
342159047fSniklas char *target = "unknown", *arch = "unknown";
352159047fSniklas FILE *file = fopen("gen-aout", "r");
362159047fSniklas
372159047fSniklas if (file == NULL) {
382159047fSniklas fprintf(stderr, "Cannot open gen-aout!\n");
392159047fSniklas return -1;
402159047fSniklas }
412159047fSniklas if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
422159047fSniklas fprintf(stderr, "Cannot read gen-aout!\n");
432159047fSniklas return -1;
442159047fSniklas }
452159047fSniklas
462159047fSniklas target = argv[1];
472159047fSniklas if (target == NULL) {
482159047fSniklas fprintf(stderr, "Usage: gen-aout target_name\n");
492159047fSniklas exit (1);
502159047fSniklas }
512159047fSniklas
522159047fSniklas #ifdef N_TXTOFF
532159047fSniklas page_size = N_TXTOFF(my_exec);
542159047fSniklas if (page_size == 0)
552159047fSniklas printf("#define N_HEADER_IN_TEXT(x) 1\n");
562159047fSniklas else
572159047fSniklas printf("#define N_HEADER_IN_TEXT(x) 0\n");
582159047fSniklas #endif
592159047fSniklas
602159047fSniklas printf("#define BYTES_IN_WORD %d\n", sizeof (int));
612159047fSniklas if (my_exec.a_entry == 0) {
622159047fSniklas printf("#define ENTRY_CAN_BE_ZERO\n");
632159047fSniklas printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
642159047fSniklas }
652159047fSniklas else {
662159047fSniklas printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
672159047fSniklas printf("/*#define N_SHARED_LIB(x) 0*/\n");
682159047fSniklas }
692159047fSniklas
702159047fSniklas printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
712159047fSniklas
722159047fSniklas #ifdef PAGSIZ
732159047fSniklas if (page_size == 0)
742159047fSniklas page_size = PAGSIZ;
752159047fSniklas #endif
762159047fSniklas if (page_size != 0)
772159047fSniklas printf("#define TARGET_PAGE_SIZE %d\n", page_size);
782159047fSniklas else
792159047fSniklas printf("/* #define TARGET_PAGE_SIZE ??? */\n");
802159047fSniklas printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
812159047fSniklas
822159047fSniklas #ifdef vax
832159047fSniklas arch = "vax";
842159047fSniklas #endif
852159047fSniklas #ifdef m68k
862159047fSniklas arch = "m68k";
872159047fSniklas #endif
882159047fSniklas if (arch[0] == '1')
892159047fSniklas {
90f7cc78ecSespie fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
91f7cc78ecSespie fprintf (stderr, _(" fix DEFAULT_ARCH in the output file yourself\n"));
922159047fSniklas arch = "unknown";
932159047fSniklas }
94c074d1c9Sdrahn printf("#define DEFAULT_ARCH bfd_arch_%s\n\n", arch);
952159047fSniklas
96c074d1c9Sdrahn printf("/* Do not \"beautify\" the CONCAT* macro args. Traditional C will not");
97c074d1c9Sdrahn printf(" remove whitespace added here, and thus will fail to concatenate");
98c074d1c9Sdrahn printf(" the tokens. */");
99c074d1c9Sdrahn printf("\n#define MY(OP) CONCAT2 (%s_,OP)\n\n", target);
1002159047fSniklas printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
1012159047fSniklas
1022159047fSniklas printf("#include \"bfd.h\"\n");
1032159047fSniklas printf("#include \"sysdep.h\"\n");
1042159047fSniklas printf("#include \"libbfd.h\"\n");
1052159047fSniklas printf("#include \"libaout.h\"\n");
1062159047fSniklas printf("\n#include \"aout-target.h\"\n");
1072159047fSniklas
1082159047fSniklas return 0;
1092159047fSniklas }
110