This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch to prevent executable suffix being added to output filename


I would like to submit this patch to EGCS to prevent a suffix from
being added to the output filename if either of the command line
switches -S or -c are specified.  This stops the compiler from
turning a command line like this:

	gcc.exe -S foo.c -o /dev/null

into this:

	gcc.exe -S foo.c -o /dev/null.exe

Here is the patch:

Index: gcc.c
===================================================================
RCS file: /cvs/cvsfiles/devo/egcs-gcc/gcc.c,v
retrieving revision 1.2
diff -p -r1.2 gcc.c
*** gcc.c	1997/11/19 05:53:20	1.2
--- gcc.c	1997/11/19 18:50:54
*************** static struct user_specs *user_specs_hea
*** 553,558 ****
--- 553,567 ----
  #ifndef WORD_SWITCH_TAKES_ARG
  #define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
  #endif
+ 
+ #ifdef HAVE_EXECUTABLE_SUFFIX
+ /* This defines which switches stop a full compilation.  */
+ #define DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)  ((CHAR) == 'c' || (CHAR) == 'S')
+ 	      
+ #ifndef SWITCH_CURTAILS_COMPILATION
+ #define SWITCH_CURTAILS_COMPILATION(CHAR) DEFAULT_SWITCH_CURTAILS_COMPILATION(CHAR)
+ #endif
+ #endif
  
  /* Record the mapping from file suffixes for compilation specs.  */
  
*************** process_command (argc, argv)
*** 2876,2881 ****
--- 2885,2891 ----
  	      warn_std_ptr = &warn_std;
  	      break;
  
+ 	    case 'S':
  	    case 'c':
  	      if (p[1] == 0)
  		{
*************** process_command (argc, argv)
*** 2887,2896 ****
  
  	    case 'o':
  	      have_o = 1;
  #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
- 	      argv[i] = convert_filename (argv[i], 1);
  	      if (p[1] == 0)
! 		argv[i+1] = convert_filename (argv[i+1], 1);
  #endif
  	      goto normal_switch;
  
--- 2897,2935 ----
  
  	    case 'o':
  	      have_o = 1;
+ #if defined(HAVE_EXECUTABLE_SUFFIX)
+ 	      if (! have_c)
+ 		{
+ 		  int skip;
+ 		  
+ 		  /* Forward scan, just in case -S or -c is specified after -o.  */
+ 		  int j = i + 1;
+ 		  if (p[1] == 0)
+ 		    ++j;
+ 		  while (j < argc)
+ 		    {
+ 		      if (argv[j][0] == '-')
+ 			{
+ 			  if (SWITCH_CURTAILS_COMPILATION (argv[j][1])
+ 			      && argv[j][2] == 0)
+ 			    {
+ 			      have_c = 1;
+ 			      break;
+ 			    }
+ 			  else if (skip = SWITCH_TAKES_ARG (argv[j][1]))
+ 			    j += skip - (argv[j][2] != 0);
+ 			  else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))
+ 			    j += skip;
+ 			}
+ 		      j++;
+ 		    }
+ 		}
+ #endif
  #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
  	      if (p[1] == 0)
! 		argv[i+1] = convert_filename (argv[i+1], ! have_c);
! 	      else
! 		argv[i] = convert_filename (argv[i], ! have_c);
  #endif
  	      goto normal_switch;
  
*************** process_command (argc, argv)
*** 2912,2918 ****
      }
  
    if (have_c && have_o && lang_n_infiles > 1)
!     fatal ("cannot specify -o with -c and multiple compilations");
  
    /* Set up the search paths before we go looking for config files.  */
  
--- 2951,2957 ----
      }
  
    if (have_c && have_o && lang_n_infiles > 1)
!     fatal ("cannot specify -o with -c or -S and multiple compilations");
  
    /* Set up the search paths before we go looking for config files.  */
  
Index: tm.texi
===================================================================
RCS file: /cvs/cvsfiles/devo/egcs-gcc/tm.texi,v
retrieving revision 1.2
diff -p -r1.2 tm.texi
*** tm.texi	1997/11/19 05:54:08	1.2
--- tm.texi	1997/11/19 18:51:52
*************** wish to add additional options which tak
*** 76,81 ****
--- 76,96 ----
  should call @code{DEFAULT_WORD_SWITCH_TAKES_ARG} and then check for
  additional options.
  
+ @findex SWITCH_CURTAILS_COMPILATION
+ @item SWITCH_CURTAILS_COMPILATION (@var{char})
+ A C expression which determines whether the option @samp{-@var{char}}
+ stops compilation before the generation of an executable.  The value is
+ boolean, non-zero if the option does stop an executable from being
+ generated, zero otherwise.
+ 
+ By default, this macro is defined as
+ @code{DEFAULT_SWITCH_CURTAILS_COMPILATION}, which handles the standard
+ options properly.  You need not define
+ @code{SWITCH_CURTAILS_COMPILATION} unless you wish to add additional 
+ options which affect the generation of an executable.  Any redefinition
+ should call @code{DEFAULT_SWITCH_CURTAILS_COMPILATION} and then check
+ for additional options.
+ 
  @findex SWITCHES_NEED_SPACES
  @item SWITCHES_NEED_SPACES
  A string-valued C expression which enumerates the options for which


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]