1 /* Specific flags and argument handling of the Fortran front-end.
2 Copyright (C) 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC 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)
11 GNU CC 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.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include <sys/types.h>
26 #include "gansidecl.h"
36 /* This bit is set if we saw a `-xfoo' language specification. */
37 #define LANGSPEC (1<<1)
38 /* This bit is set if they did `-lm' or `-lmath'. */
39 #define MATHLIB (1<<2)
40 /* This bit is set if they did `-lc'. */
41 #define WITHLIBC (1<<3)
44 #define MATH_LIBRARY "-lm"
47 #ifndef FORTRAN_LIBRARY
48 #define FORTRAN_LIBRARY "-lf2c"
51 extern char *xmalloc PROTO((size_t));
54 lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
58 int *in_added_libraries;
62 /* If non-zero, the user gave us the `-v' flag. */
63 int saw_verbose_flag = 0;
65 /* This will be 0 if we encounter a situation where we should not
69 /* The number of arguments being added to what's in argv, other than
70 libraries. We use this to track the number of times we've inserted
74 /* Used to track options that take arguments, so we don't go wrapping
75 those with -xf77/-xnone. */
78 /* The new argument list will be contained in this. */
81 /* Non-zero if we saw a `-xfoo' language specification on the
82 command line. Used to avoid adding our own -xf77 if the user
83 already gave a language for the file. */
86 /* "-lm" or "-lmath" if it appears on the command line. */
89 /* "-lc" if it appears on the command line. */
92 /* An array used to flag each argument that needs a bit set for
93 LANGSPEC, MATHLIB, or WITHLIBC. */
96 /* By default, we throw on the math library. */
99 /* The total number of arguments with the new stuff. */
102 /* The argument list. */
105 /* The number of libraries added in. */
108 /* The total number of arguments with the new stuff. */
113 added_libraries = *in_added_libraries;
115 args = (int *) xmalloc (argc * sizeof (int));
116 bzero ((char *) args, argc * sizeof (int));
118 for (i = 1; i < argc; i++)
120 /* If the previous option took an argument, we swallow it here. */
127 /* We don't do this anymore, since we don't get them with minus
129 if (argv[i][0] == '\0' || argv[i][1] == '\0')
132 if (argv[i][0] == '-')
134 if (library != 0 && (strcmp (argv[i], "-nostdlib") == 0
135 || strcmp (argv[i], "-nodefaultlibs") == 0))
139 else if (strcmp (argv[i], "-lm") == 0
140 || strcmp (argv[i], "-lmath") == 0
142 || strcmp (argv[i], ALT_LIBM) == 0
149 else if (strcmp (argv[i], "-lc") == 0)
151 else if (strcmp (argv[i], "-v") == 0)
153 saw_verbose_flag = 1;
156 /* If they only gave us `-v', don't try to link in libf2c. */
160 else if (strncmp (argv[i], "-x", 2) == 0)
162 else if (((argv[i][2] == '\0'
163 && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
164 || strcmp (argv[i], "-Tdata") == 0))
166 else if (library != 0 && ((argv[i][2] == '\0'
167 && (char *) strchr ("cSEM", argv[i][1]) != NULL)
168 || strcmp (argv[i], "-MM") == 0))
170 /* Don't specify libraries if we won't link, since that would
176 /* Pass other options through. */
189 /* If the filename ends in .c or .i, put options around it.
190 But not if a specified -x option is currently active. */
191 len = strlen (argv[i]);
193 && (argv[i][len - 1] == 'c' || argv[i][len - 1] == 'i')
194 && argv[i][len - 2] == '.')
203 (*fn) ("argument to `%s' missing\n", quote);
205 /* If we know we don't have to do anything, bail now. */
206 if (! added && ! library)
212 num_args = argc + added + need_math;
213 arglist = (char **) xmalloc (num_args * sizeof (char *));
215 /* NOTE: We start at 1 now, not 0. */
216 for (i = 0, j = 0; i < argc; i++, j++)
218 arglist[j] = argv[i];
220 /* Make sure -lf2c is before the math library, since libf2c
221 itself uses those math routines. */
222 if (!saw_math && (args[i] & MATHLIB) && library)
228 if (!saw_libc && (args[i] & WITHLIBC) && library)
234 /* Wrap foo.c and foo.i files in a language specification to
235 force the gcc compiler driver to run cc1plus on them. */
236 if (args[i] & LANGSPEC)
238 int len = strlen (argv[i]);
239 switch (argv[i][len - 1])
242 arglist[j++] = "-xf77-cpp-input";
245 /* Don't do ratfor for ".for". */
246 if (argv[i][len - 2] == '.')
248 arglist[j++] = "-xratfor";
252 arglist[j++] = "-xf77";
255 arglist[j++] = argv[i];
256 arglist[j] = "-xnone";
260 /* Add `-lf2c' if we haven't already done so. */
263 arglist[j++] = FORTRAN_LIBRARY;
267 arglist[j++] = saw_math;
270 arglist[j++] = MATH_LIBRARY;
274 arglist[j++] = saw_libc;
280 *in_added_libraries = added_libraries;