aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/msdos/mklibgcc.c
blob: 705b3d5c4046c3e97d7f14631918762fea0662ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
#include <string.h>
#include <dirent.h>

char *skips[] = {
  "__main",
  "_ctors",
  "_exit",
  "_ctor_list",
  "_dtor_list",
  0
};

int
do_clean()
{
  DIR *dir;
  struct dirent *de;
  remove("mklibnow.bat");

  dir = opendir("lgcctmp");
  if (!dir)
    return 0;
  while ((de=readdir(dir)))
  {
    char buf[30];
    if (de->d_name[0] == '.')
      continue;
    sprintf(buf, "lgcctmp/%s", de->d_name);
    unlink(buf);
  }
  closedir(dir);
  return 0;
}

int
main(int argc, char **argv)
{
  char *cc = argv[1];
  char *csrc=argv[2];
  int i;
  FILE *batfile;
  FILE *cfile;

  if (argc > 1 && strcmp(argv[1], "-c")==0)
    return do_clean();

  mkdir("lgcctmp", 0755);

  batfile = fopen("mklibnow.bat", "a");
  if (!batfile)
  {
    perror("mklibnow.bat");
    return 1;
  }
  fprintf(batfile, "@echo off\n");

  for (i=3; i<argc; i++)
  {
    char basename[30], *bp;
    int s;
    for (s=0; skips[s]; s++)
      if (strcmp(skips[s], argv[i]) == 0)
	break;
    if (skips[s])
      continue;
    strcpy(basename, "lgcctmp/");
    if (strncmp(argv[i], "_fix", 4)==0)
    {
      strcat(basename, "fx");
      strcat(basename, argv[i]+4);
    }
    else if (strncmp(argv[i], "_float", 4)==0)
    {
      strcat(basename, "flt");
      strcat(basename, argv[i]+6);
    }
    else
    {
      strcat(basename, argv[i]);
    }
    bp = basename + strlen(basename);
    fprintf(batfile, "%s -c %s.c -o %s.o\n", cc, basename, basename);
    strcpy(bp, ".c");
    cfile = fopen(basename, "w");
    if (cfile)
    {
      *bp = 0;
      fprintf(cfile, "#define L%s\n#include \"%s\"\n", argv[i], csrc);
      fclose(cfile);
    }
    else
      perror(basename);
  }

  fclose(batfile);
  return 0;
}