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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [fortran/] [gfortranspec.c] - Blame information for rev 838

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

Line No. Rev Author Line
1 285 jeremybenn
/* Specific flags and argument handling of the Fortran front-end.
2
   Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3
   2007, 2008, 2009, 2010
4
   Free Software Foundation, Inc.
5
 
6
This file is part of GCC.
7
 
8
GNU CC is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 3, or (at your option)
11
any later version.
12
 
13
GNU CC is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with GCC; see the file COPYING3.  If not see
20
<http://www.gnu.org/licenses/>.  */
21
 
22
/* This file is copied more or less verbatim from g77.  */
23
/* This file contains a filter for the main `gcc' driver, which is
24
   replicated for the `gfortran' driver by adding this filter.  The purpose
25
   of this filter is to be basically identical to gcc (in that
26
   it faithfully passes all of the original arguments to gcc) but,
27
   unless explicitly overridden by the user in certain ways, ensure
28
   that the needs of the language supported by this wrapper are met.
29
 
30
   For GNU Fortran 95(gfortran), we do the following to the argument list
31
   before passing it to `gcc':
32
 
33
   1.  Make sure `-lgfortran -lm' is at the end of the list.
34
 
35
   2.  Make sure each time `-lgfortran' or `-lm' is seen, it forms
36
       part of the series `-lgfortran -lm'.
37
 
38
   #1 and #2 are not done if `-nostdlib' or any option that disables
39
   the linking phase is present, or if `-xfoo' is in effect.  Note that
40
   a lack of source files or -l options disables linking.
41
 
42
   This program was originally made out of gcc/cp/g++spec.c, but the
43
   way it builds the new argument list was rewritten so it is much
44
   easier to maintain, improve the way it decides to add or not add
45
   extra arguments, etc.  And several improvements were made in the
46
   handling of arguments, primarily to make it more consistent with
47
   `gcc' itself.  */
48
 
49
#include "config.h"
50
#include "system.h"
51
#include "gcc.h"
52
 
53
#include "coretypes.h"
54
#include "tm.h"
55
#include "intl.h"
56
 
57
#ifndef MATH_LIBRARY
58
#define MATH_LIBRARY "-lm"
59
#endif
60
 
61
#ifndef FORTRAN_LIBRARY
62
#define FORTRAN_LIBRARY "-lgfortran"
63
#endif
64
 
65
#ifdef HAVE_LD_STATIC_DYNAMIC
66
#define ADD_ARG_LIBGFORTRAN(arg) \
67
  { \
68
    if (static_lib && !static_linking) \
69
      append_arg ("-Wl,-Bstatic"); \
70
    append_arg (arg); \
71
    if (static_lib && !static_linking) \
72
      append_arg ("-Wl,-Bdynamic"); \
73
  }
74
#else
75
#define ADD_ARG_LIBGFORTRAN(arg) append_arg (arg);
76
#endif
77
 
78
 
79
/* Options this driver needs to recognize, not just know how to
80
   skip over.  */
81
typedef enum
82
{
83
  OPTION_b,                     /* Aka --prefix.  */
84
  OPTION_B,                     /* Aka --target.  */
85
  OPTION_c,                     /* Aka --compile.  */
86
  OPTION_E,                     /* Aka --preprocess.  */
87
  OPTION_help,                  /* --help.  */
88
  OPTION_i,                     /* -imacros, -include, -include-*.  */
89
  OPTION_l,
90
  OPTION_L,                     /* Aka --library-directory.  */
91
  OPTION_nostdlib,              /* Aka --no-standard-libraries, or
92
                                   -nodefaultlibs.  */
93
  OPTION_o,                     /* Aka --output.  */
94
  OPTION_S,                     /* Aka --assemble.  */
95
  OPTION_static,                /* -static.  */
96
  OPTION_static_libgfortran,    /* -static-libgfortran.  */
97
  OPTION_syntax_only,           /* -fsyntax-only.  */
98
  OPTION_v,                     /* Aka --verbose.  */
99
  OPTION_version,               /* --version.  */
100
  OPTION_V,                     /* Aka --use-version.  */
101
  OPTION_x,                     /* Aka --language.  */
102
  OPTION_                       /* Unrecognized or unimportant.  */
103
}
104
Option;
105
 
106
/* The original argument list and related info is copied here.  */
107
static int g77_xargc;
108
static const char *const *g77_xargv;
109
static void lookup_option (Option *, int *, const char **, const char *);
110
static void append_arg (const char *);
111
 
112
/* The new argument list will be built here.  */
113
static int g77_newargc;
114
static const char **g77_newargv;
115
 
116
/* --- This comes from gcc.c (2.8.1) verbatim: */
117
 
118
/* This defines which switch letters take arguments.  */
119
 
120
#ifndef SWITCH_TAKES_ARG
121
#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR)
122
#endif
123
 
124
/* This defines which multi-letter switches take arguments.  */
125
 
126
#ifndef WORD_SWITCH_TAKES_ARG
127
#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
128
#endif
129
 
130
/* --- End of verbatim.  */
131
 
132
/* Assumes text[0] == '-'.  Returns number of argv items that belong to
133
   (and follow) this one, an option id for options important to the
134
   caller, and a pointer to the first char of the arg, if embedded (else
135
   returns NULL, meaning no arg or it's the next argv).
136
 
137
   Note that this also assumes gcc.c's pass converting long options
138
   to short ones, where available, has already been run.  */
139
 
140
static void
141
lookup_option (Option *xopt, int *xskip, const char **xarg, const char *text)
142
{
143
  Option opt = OPTION_;
144
  int skip;
145
  const char *arg = NULL;
146
 
147
  if ((skip = SWITCH_TAKES_ARG (text[1])))
148
    skip -= (text[2] != '\0');  /* See gcc.c.  */
149
 
150
  if (text[1] == 'B')
151
    opt = OPTION_B, skip = (text[2] == '\0'), arg = text + 2;
152
  else if (text[1] == 'b')
153
    opt = OPTION_b, skip = (text[2] == '\0'), arg = text + 2;
154
  else if ((text[1] == 'c') && (text[2] == '\0'))
155
    opt = OPTION_c, skip = 0;
156
  else if ((text[1] == 'E') && (text[2] == '\0'))
157
    opt = OPTION_E, skip = 0;
158
  else if (text[1] == 'i')
159
    opt = OPTION_i, skip = 0;
160
  else if (text[1] == 'l')
161
    opt = OPTION_l;
162
  else if (text[1] == 'L')
163
    opt = OPTION_L, arg = text + 2;
164
  else if (text[1] == 'o')
165
    opt = OPTION_o;
166
  else if ((text[1] == 'S') && (text[2] == '\0'))
167
    opt = OPTION_S, skip = 0;
168
  else if (text[1] == 'V')
169
    opt = OPTION_V, skip = (text[2] == '\0');
170
  else if ((text[1] == 'v') && (text[2] == '\0'))
171
    opt = OPTION_v, skip = 0;
172
  else if (text[1] == 'x')
173
    opt = OPTION_x, arg = text + 2;
174
  else if (text[1] == 'J')
175
    ;
176
  else
177
    {
178
      if ((skip = WORD_SWITCH_TAKES_ARG (text + 1)) != 0)  /* See gcc.c.  */
179
        ;
180
      else if (!strcmp (text, "-fhelp"))        /* Really --help!! */
181
        opt = OPTION_help;
182
      else if (!strcmp (text, "-nostdlib")
183
               || !strcmp (text, "-nodefaultlibs"))
184
        opt = OPTION_nostdlib;
185
      else if (!strcmp (text, "-fsyntax-only"))
186
        opt = OPTION_syntax_only;
187
      else if (!strcmp (text, "-static-libgfortran"))
188
        opt = OPTION_static_libgfortran;
189
      else if (!strcmp (text, "-fversion"))     /* Really --version!! */
190
        opt = OPTION_version;
191
      else if (!strcmp (text, "-Xlinker") || !strcmp (text, "-specs"))
192
        skip = 1;
193
      else
194
        skip = 0;
195
    }
196
 
197
  if (xopt != NULL)
198
    *xopt = opt;
199
  if (xskip != NULL)
200
    *xskip = skip;
201
  if (xarg != NULL)
202
    {
203
      if ((arg != NULL) && (arg[0] == '\0'))
204
        *xarg = NULL;
205
      else
206
        *xarg = arg;
207
    }
208
}
209
 
210
/* Append another argument to the list being built.  As long as it is
211
   identical to the corresponding arg in the original list, just increment
212
   the new arg count.  Otherwise allocate a new list, etc.  */
213
 
214
static void
215
append_arg (const char *arg)
216
{
217
  static int newargsize;
218
 
219
#if 0
220
  fprintf (stderr, "`%s'\n", arg);
221
#endif
222
 
223
  if (g77_newargv == g77_xargv
224
      && g77_newargc < g77_xargc
225
      && (arg == g77_xargv[g77_newargc]
226
          || !strcmp (arg, g77_xargv[g77_newargc])))
227
    {
228
      ++g77_newargc;
229
      return;                   /* Nothing new here.  */
230
    }
231
 
232
  if (g77_newargv == g77_xargv)
233
    {                           /* Make new arglist.  */
234
      int i;
235
 
236
      newargsize = (g77_xargc << 2) + 20;       /* This should handle all.  */
237
      g77_newargv = (const char **) xmalloc (newargsize * sizeof (char *));
238
 
239
      /* Copy what has been done so far.  */
240
      for (i = 0; i < g77_newargc; ++i)
241
        g77_newargv[i] = g77_xargv[i];
242
    }
243
 
244
  if (g77_newargc == newargsize)
245
    fatal ("overflowed output arg list for '%s'", arg);
246
 
247
  g77_newargv[g77_newargc++] = arg;
248
}
249
 
250
void
251
lang_specific_driver (int *in_argc, const char *const **in_argv,
252
                      int *in_added_libraries ATTRIBUTE_UNUSED)
253
{
254
  int argc = *in_argc;
255
  const char *const *argv = *in_argv;
256
  int i;
257
  int verbose = 0;
258
  Option opt;
259
  int skip;
260
  const char *arg;
261
 
262
  /* This will be NULL if we encounter a situation where we should not
263
     link in libf2c.  */
264
  const char *library = FORTRAN_LIBRARY;
265
 
266
  /* 0 => -xnone in effect.
267
     1 => -xfoo in effect.  */
268
  int saw_speclang = 0;
269
 
270
  /* 0 => initial/reset state
271
     1 => last arg was -l<library>
272
     2 => last two args were -l<library> -lm.  */
273
  int saw_library = 0;
274
 
275
  /* By default, we throw on the math library if we have one.  */
276
  int need_math = (MATH_LIBRARY[0] != '\0');
277
 
278
  /* Whether we should link a static libgfortran.  */
279
  int static_lib = 0;
280
 
281
  /* Whether we need to link statically.  */
282
  int static_linking = 0;
283
 
284
  /* The number of input and output files in the incoming arg list.  */
285
  int n_infiles = 0;
286
  int n_outfiles = 0;
287
 
288
#if 0
289
  fprintf (stderr, "Incoming:");
290
  for (i = 0; i < argc; i++)
291
    fprintf (stderr, " %s", argv[i]);
292
  fprintf (stderr, "\n");
293
#endif
294
 
295
  g77_xargc = argc;
296
  g77_xargv = argv;
297
  g77_newargc = 0;
298
  g77_newargv = CONST_CAST2 (const char **, const char *const *, argv);
299
 
300
  /* First pass through arglist.
301
 
302
     If -nostdlib or a "turn-off-linking" option is anywhere in the
303
     command line, don't do any library-option processing (except
304
     relating to -x).  Also, if -v is specified, but no other options
305
     that do anything special (allowing -V version, etc.), remember
306
     to add special stuff to make gcc command actually invoke all
307
     the different phases of the compilation process so all the version
308
     numbers can be seen.
309
 
310
     Also, here is where all problems with missing arguments to options
311
     are caught.  If this loop is exited normally, it means all options
312
     have the appropriate number of arguments as far as the rest of this
313
     program is concerned.  */
314
 
315
  for (i = 1; i < argc; ++i)
316
    {
317
      if ((argv[i][0] == '+') && (argv[i][1] == 'e'))
318
        {
319
          continue;
320
        }
321
 
322
      if ((argv[i][0] != '-') || (argv[i][1] == '\0'))
323
        {
324
          ++n_infiles;
325
          continue;
326
        }
327
 
328
      lookup_option (&opt, &skip, NULL, argv[i]);
329
 
330
      switch (opt)
331
        {
332
        case OPTION_nostdlib:
333
        case OPTION_c:
334
        case OPTION_S:
335
        case OPTION_syntax_only:
336
        case OPTION_E:
337
          /* These options disable linking entirely or linking of the
338
             standard libraries.  */
339
          library = 0;
340
          break;
341
 
342
        case OPTION_static_libgfortran:
343
          static_lib = 1;
344
          break;
345
 
346
        case OPTION_static:
347
          static_linking = 1;
348
 
349
        case OPTION_l:
350
          ++n_infiles;
351
          break;
352
 
353
        case OPTION_o:
354
          ++n_outfiles;
355
          break;
356
 
357
        case OPTION_v:
358
          verbose = 1;
359
          break;
360
 
361
        case OPTION_b:
362
        case OPTION_B:
363
        case OPTION_L:
364
        case OPTION_i:
365
        case OPTION_V:
366
          /* These options are useful in conjunction with -v to get
367
             appropriate version info.  */
368
          break;
369
 
370
        case OPTION_version:
371
          printf ("GNU Fortran %s%s\n", pkgversion_string, version_string);
372
          printf ("Copyright %s 2010 Free Software Foundation, Inc.\n\n",
373
                  _("(C)"));
374
          printf (_("GNU Fortran comes with NO WARRANTY, to the extent permitted by law.\n\
375
You may redistribute copies of GNU Fortran\n\
376
under the terms of the GNU General Public License.\n\
377
For more information about these matters, see the file named COPYING\n\n"));
378
          exit (0);
379
          break;
380
 
381
        case OPTION_help:
382
          /* Let gcc.c handle this, as it has a really
383
             cool facility for handling --help and --verbose --help.  */
384
          return;
385
 
386
        default:
387
          break;
388
        }
389
 
390
      /* This is the one place we check for missing arguments in the
391
         program.  */
392
 
393
      if (i + skip < argc)
394
        i += skip;
395
      else
396
        fatal ("argument to '%s' missing", argv[i]);
397
    }
398
 
399
  if ((n_outfiles != 0) && (n_infiles == 0))
400
    fatal ("no input files; unwilling to write output files");
401
 
402
  /* If there are no input files, no need for the library.  */
403
  if (n_infiles == 0)
404
    library = 0;
405
 
406
  /* Second pass through arglist, transforming arguments as appropriate.  */
407
 
408
  append_arg (argv[0]);          /* Start with command name, of course.  */
409
 
410
  for (i = 1; i < argc; ++i)
411
    {
412
      if (argv[i][0] == '\0')
413
        {
414
          append_arg (argv[i]); /* Interesting.  Just append as is.  */
415
          continue;
416
        }
417
 
418
      if ((argv[i][0] == '-') && (argv[i][1] != 'l'))
419
        {
420
          /* Not a filename or library.  */
421
 
422
          if (saw_library == 1 && need_math)    /* -l<library>.  */
423
            append_arg (MATH_LIBRARY);
424
 
425
          saw_library = 0;
426
 
427
          lookup_option (&opt, &skip, &arg, argv[i]);
428
 
429
          if (argv[i][1] == '\0')
430
            {
431
              append_arg (argv[i]);     /* "-" == Standard input.  */
432
              continue;
433
            }
434
 
435
          if (opt == OPTION_x)
436
            {
437
              /* Track input language.  */
438
              const char *lang;
439
 
440
              if (arg == NULL)
441
                lang = argv[i + 1];
442
              else
443
                lang = arg;
444
 
445
              saw_speclang = (strcmp (lang, "none") != 0);
446
            }
447
 
448
          append_arg (argv[i]);
449
 
450
          for (; skip != 0; --skip)
451
            append_arg (argv[++i]);
452
 
453
          continue;
454
        }
455
 
456
      /* A filename/library, not an option.  */
457
 
458
      if (saw_speclang)
459
        saw_library = 0; /* -xfoo currently active.  */
460
      else
461
        {                       /* -lfoo or filename.  */
462
          if (strcmp (argv[i], MATH_LIBRARY) == 0)
463
            {
464
              if (saw_library == 1)
465
                saw_library = 2;        /* -l<library> -lm.  */
466
              else
467
                {
468
                  ADD_ARG_LIBGFORTRAN (FORTRAN_LIBRARY);
469
                }
470
            }
471
          else if (strcmp (argv[i], FORTRAN_LIBRARY) == 0)
472
            {
473
              saw_library = 1;  /* -l<library>.  */
474
              ADD_ARG_LIBGFORTRAN (argv[i]);
475
              continue;
476
            }
477
          else
478
            {                   /* Other library, or filename.  */
479
              if (saw_library == 1 && need_math)
480
                append_arg (MATH_LIBRARY);
481
              saw_library = 0;
482
            }
483
        }
484
      append_arg (argv[i]);
485
    }
486
 
487
  /* Append `-lg2c -lm' as necessary.  */
488
 
489
  if (library)
490
    {                           /* Doing a link and no -nostdlib.  */
491
      if (saw_speclang)
492
        append_arg ("-xnone");
493
 
494
      switch (saw_library)
495
        {
496
        case 0:
497
          ADD_ARG_LIBGFORTRAN (library);
498
          /* Fall through.  */
499
 
500
        case 1:
501
          if (need_math)
502
            append_arg (MATH_LIBRARY);
503
        default:
504
          break;
505
        }
506
    }
507
 
508
#ifdef ENABLE_SHARED_LIBGCC
509
  if (library)
510
    {
511
      int i;
512
 
513
      for (i = 1; i < g77_newargc; i++)
514
        if (g77_newargv[i][0] == '-')
515
          if (strcmp (g77_newargv[i], "-static-libgcc") == 0
516
              || strcmp (g77_newargv[i], "-static") == 0)
517
            break;
518
 
519
      if (i == g77_newargc)
520
        append_arg ("-shared-libgcc");
521
    }
522
 
523
#endif
524
 
525
  if (verbose && g77_newargv != g77_xargv)
526
    {
527
      fprintf (stderr, _("Driving:"));
528
      for (i = 0; i < g77_newargc; i++)
529
        fprintf (stderr, " %s", g77_newargv[i]);
530
      fprintf (stderr, "\n");
531
    }
532
 
533
  *in_argc = g77_newargc;
534
  *in_argv = g77_newargv;
535
}
536
 
537
 
538
/* Called before linking.  Returns 0 on success and -1 on failure.  */
539
int
540
lang_specific_pre_link (void)   /* Not used for F77.  */
541
{
542
  return 0;
543
}
544
 
545
/* Number of extra output files that lang_specific_pre_link may generate.  */
546
int lang_specific_extra_outfiles = 0;    /* Not used for F77.  */

powered by: WebSVN 2.1.0

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