7 /* This bit is set if we saw a `-xfoo' language specification. */
8 #define LANGSPEC (1<<1)
9 /* This bit is set if they did `-lm' or `-lmath'. */
10 #define MATHLIB (1<<2)
11 /* This bit is set if they did `-lc'. */
12 #define WITHLIBC (1<<3)
15 #define MATH_LIBRARY "-lm"
18 extern char *xmalloc PROTO((size_t));
21 lang_specific_driver (fn, in_argc, in_argv)
28 /* If non-zero, the user gave us the `-v' flag. */
29 int saw_verbose_flag = 0;
31 /* This will be 0 if we encounter a situation where we should not
35 /* The number of arguments being added to what's in argv, other than
36 libraries. We use this to track the number of times we've inserted
40 /* Used to track options that take arguments, so we don't go wrapping
41 those with -xc++/-xnone. */
44 /* The new argument list will be contained in this. */
47 /* Non-zero if we saw a `-xfoo' language specification on the
48 command line. Used to avoid adding our own -xc++ if the user
49 already gave a language for the file. */
52 /* "-lm" or "-lmath" if it appears on the command line. */
55 /* "-lc" if it appears on the command line. */
58 /* An array used to flag each argument that needs a bit set for
59 LANGSPEC, MATHLIB, or WITHLIBC. */
62 /* By default, we throw on the math library. */
65 /* The total number of arguments with the new stuff. */
68 /* The argument list. */
71 /* The total number of arguments with the new stuff. */
78 args = (int *) xmalloc (argc * sizeof (int));
79 bzero ((char *) args, argc * sizeof (int));
81 for (i = 1; i < argc; i++)
83 /* If the previous option took an argument, we swallow it here. */
90 /* We don't do this anymore, since we don't get them with minus
92 if (argv[i][0] == '\0' || argv[i][1] == '\0')
95 if (argv[i][0] == '-')
97 if (library != 0 && (strcmp (argv[i], "-nostdlib") == 0
98 || strcmp (argv[i], "-nodefaultlibs") == 0))
102 else if (strcmp (argv[i], "-lm") == 0
103 || strcmp (argv[i], "-lmath") == 0
105 || strcmp (argv[i], ALT_LIBM) == 0
112 else if (strcmp (argv[i], "-lc") == 0)
114 else if (strcmp (argv[i], "-v") == 0)
116 saw_verbose_flag = 1;
119 /* If they only gave us `-v', don't try to link
124 else if (strncmp (argv[i], "-x", 2) == 0)
126 else if (((argv[i][2] == '\0'
127 && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
128 || strcmp (argv[i], "-Tdata") == 0))
130 else if (library != 0 && ((argv[i][2] == '\0'
131 && (char *) strchr ("cSEM", argv[i][1]) != NULL)
132 || strcmp (argv[i], "-MM") == 0))
134 /* Don't specify libraries if we won't link, since that would
140 /* Pass other options through. */
153 /* If the filename ends in .c or .i, put options around it.
154 But not if a specified -x option is currently active. */
155 len = strlen (argv[i]);
157 && (argv[i][len - 1] == 'c' || argv[i][len - 1] == 'i')
158 && argv[i][len - 2] == '.')
167 (*fn) ("argument to `%s' missing\n", quote);
169 /* If we know we don't have to do anything, bail now. */
170 if (! added && ! library)
176 num_args = argc + added + need_math;
177 arglist = (char **) xmalloc (num_args * sizeof (char *));
179 /* NOTE: We start at 1 now, not 0. */
180 for (i = 0, j = 0; i < argc; i++, j++)
182 arglist[j] = argv[i];
184 /* Make sure -lstdc++ is before the math library, since libstdc++
185 itself uses those math routines. */
186 if (!saw_math && (args[i] & MATHLIB) && library)
192 if (!saw_libc && (args[i] & WITHLIBC) && library)
198 /* Wrap foo.c and foo.i files in a language specification to
199 force the gcc compiler driver to run cc1plus on them. */
200 if (args[i] & LANGSPEC)
202 int len = strlen (argv[i]);
203 if (argv[i][len - 1] == 'i')
204 arglist[j++] = "-xc++-cpp-output";
206 arglist[j++] = "-xc++";
207 arglist[j++] = argv[i];
208 arglist[j] = "-xnone";
212 /* Add `-lstdc++' if we haven't already done so. */
214 arglist[j++] = "-lstdc++";
216 arglist[j++] = saw_math;
218 arglist[j++] = MATH_LIBRARY;
220 arglist[j++] = saw_libc;