133965Sjdp/* Generate parameters for an a.out system.
2218822Sdim   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 2001, 2002, 2007
378828Sobrien   Free Software Foundation, Inc.
433965Sjdp
533965SjdpThis file is part of BFD, the Binary File Descriptor library.
633965Sjdp
733965SjdpThis program is free software; you can redistribute it and/or modify
833965Sjdpit under the terms of the GNU General Public License as published by
933965Sjdpthe Free Software Foundation; either version 2 of the License, or
1033965Sjdp(at your option) any later version.
1133965Sjdp
1233965SjdpThis program is distributed in the hope that it will be useful,
1333965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1433965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1533965SjdpGNU General Public License for more details.
1633965Sjdp
1733965SjdpYou should have received a copy of the GNU General Public License
1833965Sjdpalong with this program; if not, write to the Free Software
19218822SdimFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2033965Sjdp
2133965Sjdp#include "/usr/include/a.out.h"
2233965Sjdp#include <stdio.h>
2333965Sjdp
24107492Sobrien#ifndef _
25107492Sobrien#define _(X) X
26107492Sobrien#endif
27107492Sobrien
2833965Sjdpint
2933965Sjdpmain (argc, argv)
3033965Sjdp     int argc; char** argv;
3133965Sjdp{
3233965Sjdp  struct exec my_exec;
3333965Sjdp  int page_size;
3433965Sjdp  char *target = "unknown", *arch = "unknown";
3533965Sjdp  FILE *file = fopen("gen-aout", "r");
3633965Sjdp
3733965Sjdp  if (file == NULL) {
3833965Sjdp      fprintf(stderr, "Cannot open gen-aout!\n");
3933965Sjdp      return -1;
4033965Sjdp  }
4133965Sjdp  if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
4233965Sjdp      fprintf(stderr, "Cannot read gen-aout!\n");
4333965Sjdp      return -1;
4433965Sjdp  }
4533965Sjdp
4633965Sjdp  target = argv[1];
4733965Sjdp  if (target == NULL) {
4833965Sjdp      fprintf(stderr, "Usage: gen-aout target_name\n");
4933965Sjdp      exit (1);
5033965Sjdp  }
5133965Sjdp
5233965Sjdp#ifdef N_TXTOFF
5333965Sjdp  page_size = N_TXTOFF(my_exec);
5433965Sjdp  if (page_size == 0)
5533965Sjdp    printf("#define N_HEADER_IN_TEXT(x) 1\n");
5633965Sjdp  else
5733965Sjdp    printf("#define N_HEADER_IN_TEXT(x) 0\n");
5833965Sjdp#endif
5933965Sjdp
6033965Sjdp  printf("#define BYTES_IN_WORD %d\n", sizeof (int));
6133965Sjdp  if (my_exec.a_entry == 0) {
6233965Sjdp      printf("#define ENTRY_CAN_BE_ZERO\n");
6333965Sjdp      printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
6433965Sjdp  }
6533965Sjdp  else {
6633965Sjdp      printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
6733965Sjdp      printf("/*#define N_SHARED_LIB(x) 0*/\n");
6833965Sjdp  }
6933965Sjdp
7033965Sjdp  printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
7133965Sjdp
7233965Sjdp#ifdef PAGSIZ
7333965Sjdp  if (page_size == 0)
7433965Sjdp    page_size = PAGSIZ;
7533965Sjdp#endif
7633965Sjdp  if (page_size != 0)
7733965Sjdp    printf("#define TARGET_PAGE_SIZE %d\n", page_size);
7833965Sjdp  else
7933965Sjdp    printf("/* #define TARGET_PAGE_SIZE ??? */\n");
8033965Sjdp  printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
8133965Sjdp
8233965Sjdp#ifdef vax
8333965Sjdp  arch = "vax";
8433965Sjdp#endif
8533965Sjdp#ifdef m68k
8633965Sjdp  arch = "m68k";
8733965Sjdp#endif
8833965Sjdp  if (arch[0] == '1')
8933965Sjdp    {
9060484Sobrien      fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
9160484Sobrien      fprintf (stderr, _("         fix DEFAULT_ARCH in the output file yourself\n"));
9233965Sjdp      arch = "unknown";
9333965Sjdp    }
9489857Sobrien  printf("#define DEFAULT_ARCH bfd_arch_%s\n\n", arch);
9533965Sjdp
9689857Sobrien  printf("/* Do not \"beautify\" the CONCAT* macro args.  Traditional C will not");
9789857Sobrien  printf("   remove whitespace added here, and thus will fail to concatenate");
9889857Sobrien  printf("   the tokens.  */");
9989857Sobrien  printf("\n#define MY(OP) CONCAT2 (%s_,OP)\n\n", target);
10033965Sjdp  printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
10133965Sjdp
102218822Sdim  printf("#include \"sysdep.h\"\n");
10333965Sjdp  printf("#include \"bfd.h\"\n");
10433965Sjdp  printf("#include \"libbfd.h\"\n");
10533965Sjdp  printf("#include \"libaout.h\"\n");
10633965Sjdp  printf("\n#include \"aout-target.h\"\n");
10733965Sjdp
10833965Sjdp  return 0;
10933965Sjdp}
110