gen-aout.c revision 1.4
1/* Generate parameters for an a.out system. 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 20 21#include "config.h" 22#include <sys/types.h> 23#include "/usr/include/a.out.h" 24#include <stdio.h> 25 26#ifdef HAVE_LOCALE_H 27# include <locale.h> 28#endif 29 30#ifdef ENABLE_NLS 31# include <libintl.h> 32# define _(String) gettext (String) 33# ifdef gettext_noop 34# define N_(String) gettext_noop (String) 35# else 36# define N_(String) (String) 37# endif 38#else 39/* Stubs that do something close enough. */ 40# define textdomain(String) (String) 41# define gettext(String) (String) 42# define dgettext(Domain,Message) (Message) 43# define dcgettext(Domain,Message,Type) (Message) 44# define bindtextdomain(Domain,Directory) (Domain) 45# define _(String) (String) 46# define N_(String) (String) 47#endif 48 49int 50main (argc, argv) 51 int argc; char** argv; 52{ 53 struct exec my_exec; 54 int page_size; 55 char *target = "unknown", *arch = "unknown"; 56 FILE *file = fopen("gen-aout", "r"); 57 58 if (file == NULL) { 59 fprintf(stderr, "Cannot open gen-aout!\n"); 60 return -1; 61 } 62 if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) { 63 fprintf(stderr, "Cannot read gen-aout!\n"); 64 return -1; 65 } 66 67 target = argv[1]; 68 if (target == NULL) { 69 fprintf(stderr, "Usage: gen-aout target_name\n"); 70 exit (1); 71 } 72 73#ifdef N_TXTOFF 74 page_size = N_TXTOFF(my_exec); 75 if (page_size == 0) 76 printf("#define N_HEADER_IN_TEXT(x) 1\n"); 77 else 78 printf("#define N_HEADER_IN_TEXT(x) 0\n"); 79#endif 80 81 printf("#define BYTES_IN_WORD %d\n", sizeof (int)); 82 if (my_exec.a_entry == 0) { 83 printf("#define ENTRY_CAN_BE_ZERO\n"); 84 printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n"); 85 } 86 else { 87 printf("/*#define ENTRY_CAN_BE_ZERO*/\n"); 88 printf("/*#define N_SHARED_LIB(x) 0*/\n"); 89 } 90 91 printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry); 92 93#ifdef PAGSIZ 94 if (page_size == 0) 95 page_size = PAGSIZ; 96#endif 97 if (page_size != 0) 98 printf("#define TARGET_PAGE_SIZE %d\n", page_size); 99 else 100 printf("/* #define TARGET_PAGE_SIZE ??? */\n"); 101 printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n"); 102 103#ifdef vax 104 arch = "vax"; 105#endif 106#ifdef m68k 107 arch = "m68k"; 108#endif 109 if (arch[0] == '1') 110 { 111 fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;")); 112 fprintf (stderr, _(" fix DEFAULT_ARCH in the output file yourself\n")); 113 arch = "unknown"; 114 } 115 printf("#define DEFAULT_ARCH bfd_arch_%s\n", arch); 116 117 printf("\n#define MY(OP) CAT(%s_,OP)\n", target); 118 printf("#define TARGETNAME \"a.out-%s\"\n\n", target); 119 120 printf("#include \"bfd.h\"\n"); 121 printf("#include \"sysdep.h\"\n"); 122 printf("#include \"libbfd.h\"\n"); 123 printf("#include \"libaout.h\"\n"); 124 printf("\n#include \"aout-target.h\"\n"); 125 126 return 0; 127} 128