1/* Specific flags and argument handling of the C front-end.
2   Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 2, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING.  If not, write to the Free
18Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
1902110-1301, USA.  */
20
21#include "config.h"
22#include "system.h"
23#include "coretypes.h"
24#include "tm.h"
25#include "gcc.h"
26
27/* Filter argc and argv before processing by the gcc driver proper.  */
28void
29lang_specific_driver (int *in_argc ATTRIBUTE_UNUSED,
30		      const char *const **in_argv ATTRIBUTE_UNUSED,
31		      int *in_added_libraries ATTRIBUTE_UNUSED)
32{
33  /* Systems which use the NeXT runtime by default should arrange
34     for the shared libgcc to be used when -fgnu-runtime is passed
35     through specs.  */
36#if defined(ENABLE_SHARED_LIBGCC) && ! defined(NEXT_OBJC_RUNTIME)
37  int i;
38
39  /* The new argument list will be contained in this.  */
40  const char **arglist;
41
42  /* True if we should add -shared-libgcc to the command-line.  */
43  int shared_libgcc = 0;
44
45  /* The total number of arguments with the new stuff.  */
46  int argc;
47
48  /* The argument list.  */
49  const char *const *argv;
50
51  argc = *in_argc;
52  argv = *in_argv;
53
54  for (i = 1; i < argc; i++)
55    {
56      if (argv[i][0] == '-')
57	{
58	  if (strcmp (argv[i], "-static-libgcc") == 0
59	      || strcmp (argv[i], "-static") == 0)
60	    return;
61	}
62      else
63	{
64	  int len;
65
66	  /* If the filename ends in .m or .mi, we are compiling ObjC
67	     and want to pass -shared-libgcc.  */
68	  len = strlen (argv[i]);
69	  if ((len > 2 && argv[i][len - 2] == '.' && argv[i][len - 1] == 'm')
70	      ||  (len > 3 && argv[i][len - 3] == '.' && argv[i][len - 2] == 'm'
71		   && argv[i][len - 1] == 'i'))
72	    shared_libgcc = 1;
73	}
74    }
75
76  if  (shared_libgcc)
77    {
78      /* Make sure to have room for the trailing NULL argument.  */
79      arglist = XNEWVEC (const char *, argc + 2);
80
81      i = 0;
82      do
83	{
84	  arglist[i] = argv[i];
85	  i++;
86	}
87      while (i < argc);
88
89      arglist[i++] = "-shared-libgcc";
90
91      arglist[i] = NULL;
92
93      *in_argc = i;
94      *in_argv = arglist;
95    }
96#endif
97}
98
99/* Called before linking.  Returns 0 on success and -1 on failure.  */
100int
101lang_specific_pre_link (void)
102{
103  return 0;  /* Not used for C.  */
104}
105
106/* Number of extra output files that lang_specific_pre_link may generate.  */
107int lang_specific_extra_outfiles = 0;  /* Not used for C.  */
108