8 /* This bit is set if we saw a `-xfoo' language specification. */
9 #define LANGSPEC (1<<1)
10 /* This bit is set if they did `-lm' or `-lmath'. */
11 #define MATHLIB (1<<2)
12 /* This bit is set if they did `-lc'. */
13 #define WITHLIBC (1<<3)
16 #define MATH_LIBRARY "-lm"
19 extern char *xmalloc PROTO((size_t));
22 lang_specific_driver (fn, in_argc, in_argv)
29 /* If non-zero, the user gave us the `-v' flag. */
30 int saw_verbose_flag = 0;
32 /* This will be 0 if we encounter a situation where we should not
36 /* The number of arguments being added to what's in argv, other than
37 libraries. We use this to track the number of times we've inserted
41 /* Used to track options that take arguments, so we don't go wrapping
42 those with -xc++/-xnone. */
45 /* The new argument list will be contained in this. */
48 /* Non-zero if we saw a `-xfoo' language specification on the
49 command line. Used to avoid adding our own -xc++ if the user
50 already gave a language for the file. */
53 /* "-lm" or "-lmath" if it appears on the command line. */
56 /* "-lc" if it appears on the command line. */
59 /* An array used to flag each argument that needs a bit set for
60 LANGSPEC, MATHLIB, or WITHLIBC. */
63 /* By default, we throw on the math library. */
66 /* The total number of arguments with the new stuff. */
69 /* The argument list. */
72 /* The total number of arguments with the new stuff. */
79 args = (int *) xmalloc (argc * sizeof (int));
80 bzero ((char *) args, argc * sizeof (int));
82 for (i = 1; i < argc; i++)
84 /* If the previous option took an argument, we swallow it here. */
91 /* We don't do this anymore, since we don't get them with minus
93 if (argv[i][0] == '\0' || argv[i][1] == '\0')
96 if (argv[i][0] == '-')
98 if (library != 0 && (strcmp (argv[i], "-nostdlib") == 0
99 || strcmp (argv[i], "-nodefaultlibs") == 0))
103 else if (strcmp (argv[i], "-lm") == 0
104 || strcmp (argv[i], "-lmath") == 0
106 || strcmp (argv[i], ALT_LIBM) == 0
113 else if (strcmp (argv[i], "-lc") == 0)
115 else if (strcmp (argv[i], "-v") == 0)
117 saw_verbose_flag = 1;
120 /* If they only gave us `-v', don't try to link
125 else if (strncmp (argv[i], "-x", 2) == 0)
127 else if (((argv[i][2] == '\0'
128 && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
129 || strcmp (argv[i], "-Tdata") == 0))
131 else if (library != 0 && ((argv[i][2] == '\0'
132 && (char *) strchr ("cSEM", argv[i][1]) != NULL)
133 || strcmp (argv[i], "-MM") == 0))
135 /* Don't specify libraries if we won't link, since that would
141 /* Pass other options through. */
154 /* If the filename ends in .c or .i, put options around it.
155 But not if a specified -x option is currently active. */
156 len = strlen (argv[i]);
158 && (argv[i][len - 1] == 'c' || argv[i][len - 1] == 'i')
159 && argv[i][len - 2] == '.')
168 (*fn) ("argument to `%s' missing\n", quote);
170 /* If we know we don't have to do anything, bail now. */
171 if (! added && ! library)
177 num_args = argc + added + need_math;
178 arglist = (char **) xmalloc (num_args * sizeof (char *));
180 /* NOTE: We start at 1 now, not 0. */
181 for (i = 0, j = 0; i < argc; i++, j++)
183 arglist[j] = argv[i];
185 /* Make sure -lstdc++ is before the math library, since libstdc++
186 itself uses those math routines. */
187 if (!saw_math && (args[i] & MATHLIB) && library)
193 if (!saw_libc && (args[i] & WITHLIBC) && library)
199 /* Wrap foo.c and foo.i files in a language specification to
200 force the gcc compiler driver to run cc1plus on them. */
201 if (args[i] & LANGSPEC)
203 int len = strlen (argv[i]);
204 if (argv[i][len - 1] == 'i')
205 arglist[j++] = "-xc++-cpp-output";
207 arglist[j++] = "-xc++";
208 arglist[j++] = argv[i];
209 arglist[j] = "-xnone";
213 /* Add `-lstdc++' if we haven't already done so. */
215 arglist[j++] = "-lstdc++";
217 arglist[j++] = saw_math;
219 arglist[j++] = MATH_LIBRARY;
221 arglist[j++] = saw_libc;