OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [gdb-5.0/] [utils/] [wince/] [cesetup.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/* cesetup.c - copy/edit/rename CE SDK files into GNU install area
2
   Copyright 1999 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Binutils.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
 
20
#include "libiberty.h"
21
#include <stdio.h>
22
#include <sys/types.h>
23
#include <sys/stat.h>
24
#include <string.h>
25
#include <dirent.h>
26
 
27
static char *
28
strlwr (char *s)
29
{
30
  char *in_s = s;
31
  while (*s)
32
    {
33
      if (isupper (*s))
34
        *s = tolower (*s);
35
      s++;
36
    }
37
  return in_s;
38
}
39
int
40
copy_include (char *srcn, char *destn)
41
{
42
  FILE *src, *dest;
43
  char line[4096], *q;
44
  int w;
45
 
46
  src = fopen (srcn, "rb");
47
  if (!src)
48
    {
49
      perror (srcn);
50
      return 1;
51
    }
52
  dest = fopen (destn, "wb");
53
  if (!dest)
54
    {
55
      fclose (src);
56
      perror (destn);
57
      return 1;
58
    }
59
 
60
  while (fgets (line, 4096, src))
61
    {
62
      char *last = line + strlen (line);
63
      if (last[-1] == '\n' && last[-2] == '\r')
64
        {
65
          last[-2] = '\n';
66
          last[-1] = 0;
67
        }
68
 
69
      if (strstr(destn, "stdlib.h"))
70
        {
71
          if (strstr (line, "typedef char *va_list"))
72
            {
73
              fprintf (dest, "#include <stdarg.h>\n");
74
              continue;
75
            }
76
          if (strstr (line, "#define va_start"))
77
            continue;
78
          if (strstr (line, "#define va_arg"))
79
            continue;
80
          if (strstr (line, "#define va_end"))
81
            continue;
82
          if (strstr (line, "#define _INTSIZEOF"))
83
            continue;
84
          if (strstr (line, "memcmp("))
85
            continue;
86
          if (strstr (line, "memset("))
87
            continue;
88
          if (strstr (line, "memcpy("))
89
            continue;
90
          if (strstr (line, "matherr(struct"))
91
            continue;
92
        }
93
 
94
      if (q = strstr (line, "[];"))
95
        {
96
          *q = 0;
97
          fprintf(dest, "%s[0%s", line, q+1);
98
          *q = '[';
99
          continue;
100
        }
101
 
102
      if (strstr (line, "_VARIANT_BOOL"))
103
        continue;
104
 
105
      if (strstr (line, "extern void __asm"))
106
        continue;
107
 
108
      if (strncmp (line, "#define DebugBreak () __asm (", 27) == 0)
109
        {
110
          fprintf (dest, "#define DebugBreak () __asm__(%s", line+27);
111
          continue;
112
        }
113
 
114
      w = fputs (line, dest);
115
      if (w < 0)
116
        {
117
          fclose (src);
118
          fclose (dest);
119
          fprintf (stderr, "%s: out of disk space!\n", destn);
120
          exit (1);
121
        }
122
    }
123
  fclose (src);
124
  fclose (dest);
125
  return 0;
126
}
127
 
128
int
129
copy_lib (char *srcn, char *destn)
130
{
131
  FILE *src, *dest;
132
  char buffer[4096];
133
  int r, w;
134
 
135
  src = fopen (srcn, "rb");
136
  if (!src)
137
    {
138
      perror (srcn);
139
      return 1;
140
    }
141
  dest = fopen (destn, "wb");
142
  if (!dest)
143
    {
144
      fclose (src);
145
      perror (destn);
146
      return 1;
147
    }
148
  while ((r = fread (buffer, 1, 4096, src)) > 0)
149
    {
150
      w = fwrite (buffer, 1, r, dest);
151
      if (w < r)
152
        {
153
          fclose (src);
154
          fclose (dest);
155
          fprintf (stderr, "%s: out of disk space!\n", destn);
156
          exit (1);
157
        }
158
    }
159
  fclose (src);
160
  fclose (dest);
161
  return 0;
162
}
163
 
164
int
165
main (int argc, char **argv)
166
{
167
  char *psdk_dir;
168
  char *gnu_dir;
169
  char line[1000];
170
  char line2[1000];
171
  int rv;
172
  struct stat statbuf;
173
  DIR *dir;
174
  struct dirent *de;
175
  int count;
176
 
177
  if (argc < 2)
178
    {
179
      printf ("Type in the location of the CE Platform SDK : ");
180
      fflush (stdout);
181
      fgets (line, 1000, stdin);
182
      while (line[0] && (line[strlen (line)-1] == '\r'
183
                         || line[strlen (line)-1] == '\n'))
184
        line[strlen (line)-1] = 0;
185
      psdk_dir = (char *)malloc (strlen (line)+1);
186
      strcpy (psdk_dir, line);
187
    }
188
  else
189
    psdk_dir = argv[1];
190
 
191
  sprintf (line, "%s/include/windows.h", psdk_dir);
192
  rv = stat (line, &statbuf);
193
  if (rv < 0)
194
    {
195
      printf ("Error: could not find %s - verify the PSDK dir.\n", line);
196
      exit (1);
197
    }
198
 
199
  if (argc < 3)
200
    {
201
      printf ("Type in the location of the GNU CE Tools installation : ");
202
      fflush (stdout);
203
      fgets (line, 1000, stdin);
204
      while (line[0] && (line[strlen (line)-1] == '\r'
205
                         || line[strlen (line)-1] == '\n'))
206
        line[strlen (line)-1] = 0;
207
      gnu_dir = (char *)malloc (strlen (line)+1);
208
      strcpy (gnu_dir, line);
209
    }
210
  else
211
    gnu_dir = argv[2];
212
 
213
  sprintf (line, "%s", gnu_dir);
214
  dir = opendir (line);
215
  if (!dir)
216
    {
217
      printf ("Error: could not find %s - verify the GNU dir.\n", line);
218
      exit (1);
219
    }
220
 
221
  while ((de = readdir (dir)) != 0)
222
    {
223
      char *platform;
224
      int rv;
225
      struct stat statbuf;
226
      DIR *idir;
227
      struct dirent *ide;
228
 
229
      if (strchr (de->d_name, '-') == 0)
230
        continue;
231
 
232
      sprintf (line, "%s/%s/include/.", gnu_dir, de->d_name);
233
      rv = stat (line, &statbuf);
234
      if (rv < 0)
235
        continue;
236
 
237
      if (strncasecmp (de->d_name, "sh", 2) == 0)
238
        platform = "sh3";
239
      else if (strncasecmp (de->d_name, "mips", 4) == 0)
240
        platform = "mips";
241
      else if (strncasecmp (de->d_name, "arm", 3) == 0)
242
        platform = "arm";
243
      else
244
        continue;
245
 
246
      printf ("Installing %s files into %s/%s\n", platform, gnu_dir, de->d_name);
247
 
248
      sprintf (line, "%s/include", psdk_dir);
249
      idir = opendir (line);
250
      if (!idir)
251
        {
252
          printf ("Can't read %s\n", line);
253
          exit (1);
254
        }
255
      count = 0;
256
      while ((ide = readdir (idir)) != 0)
257
        {
258
          if (ide->d_name[0] == '.')
259
            continue;
260
          sprintf (line, "%s/include/%s", psdk_dir, ide->d_name);
261
          sprintf (line2, "%s/%s/include/%s", gnu_dir, de->d_name, strlwr(ide->d_name));
262
 
263
          copy_include (line, line2);
264
          count ++;
265
        }
266
      printf ("%d headers converted and copied\n", count);
267
 
268
      sprintf (line, "%s/lib/%s", psdk_dir, platform);
269
      idir = opendir (line);
270
      if (!idir)
271
        {
272
          printf ("Can't read %s\n", line);
273
          exit (1);
274
        }
275
      count = 0;
276
      while ((ide = readdir (idir)) != 0)
277
        {
278
          if (ide->d_name[0] == '.')
279
            continue;
280
 
281
          sprintf (line, "%s/lib/%s/%s", psdk_dir, platform, ide->d_name);
282
 
283
          if (strcasecmp (ide->d_name + strlen (ide->d_name) - 4, ".lib") == 0)
284
            strcpy (ide->d_name + strlen (ide->d_name) - 4, ".a");
285
          if (strcasecmp (ide->d_name, "corelibc.a") == 0)
286
            strcpy (ide->d_name, "c.a");
287
 
288
          sprintf (line2, "%s/%s/lib/lib%s", gnu_dir, de->d_name, strlwr (ide->d_name));
289
 
290
          copy_lib (line, line2);
291
          count++;
292
        }
293
      printf ("%d libraries copied and renamed\n", count);
294
    }
295
  return 0;
296
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.