This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


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

proposed windres change



I noticed that a linux-x-cygwin windres was using the native linux gcc
to preprocess the RC files.  Normally this isn't a problem, unless you
want to #include <windows.h> which Linux doesn't have.  This patch
will use the (hopefully) appropriate cross-gcc as a preprocessor, so
that the correct headers will be found.  As the "default" preprocessor
is actually a list of candidates, a new "-v" option causes each
candidate to be printed so you know which default is the one it's
using.  I also snuck in documentation for the -D option I recently
added (sorry).

The search path for foo/bar-windres is foo/bar-gcc, foo/gcc (in case
argv[0] is foo/windres, but even if not), and gcc (the original
default).

DJ

Index: ChangeLog
===================================================================
RCS file: /cvs/binutils/binutils/binutils/ChangeLog,v
retrieving revision 1.9
diff -p -2 -r1.9 ChangeLog
*** ChangeLog	1999/05/16 14:12:19	1.9
--- ChangeLog	1999/05/18 02:51:01
***************
*** 1,2 ****
--- 1,11 ----
+ 1999-05-17  DJ Delorie  <dj@cygnus.com>
+ 
+ 	* windres.c: add verbose option
+ 	(main): process verbose option
+ 	* resrc.c (look_for_default): new.  Look for the default
+ 	preprocessor in a given location.
+ 	(read_rc_file): for foo/bar-windres, look for foo/bar-gcc,
+ 	foo/gcc (in case of foo/windres), and then gcc (the old default).
+ 
  1999-05-16  Nick Clifton  <nickc@cygnus.com>
  
Index: binutils.texi
===================================================================
RCS file: /cvs/binutils/binutils/binutils/binutils.texi,v
retrieving revision 1.1.1.1
diff -p -2 -r1.1.1.1 binutils.texi
*** binutils.texi	1999/05/03 07:29:09	1.1.1.1
--- binutils.texi	1999/05/18 02:51:03
*************** option.  @code{windres} will also search
*** 2049,2055 ****
--- 2049,2060 ----
  files named in the @code{rc} file.
  
+ @item -D @var{target}
  @item --define @var{sym[=val]}
  Specify a @code{-D} option to pass to the preprocessor when reading an
  @code{rc} file.
+ 
+ @item -v
+ Enable verbose mode.  This tells you what the preprocessor is if you
+ didn't specify one.
  
  @item --language @var{val}
Index: resrc.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/resrc.c,v
retrieving revision 1.1.1.1
diff -p -2 -r1.1.1.1 resrc.c
*** resrc.c	1999/05/03 07:29:10	1.1.1.1
--- resrc.c	1999/05/18 02:51:03
*************** static void get_data
*** 121,124 ****
--- 121,170 ----
  static void define_fontdirs PARAMS ((void));
  
+ /* look for the preprocessor program */
+ 
+ FILE *
+ look_for_default (cmd, prefix, end_prefix, preprocargs, filename)
+      char *cmd;
+      char *prefix;
+      int end_prefix;
+      char *preprocargs;
+      char *filename;
+ {
+   char *path = getenv ("PATH");
+   char *space;
+   int found;
+   struct stat s;
+ 
+   strcpy (cmd, prefix);
+ 
+   sprintf (cmd+end_prefix, "%s", DEFAULT_PREPROCESSOR);
+   space = strchr (cmd+end_prefix, ' ');
+   if (space)
+     *space = 0;
+ 
+   if (strchr (cmd, '/'))
+     {
+       found = stat (cmd, &s);
+ 
+       if (found < 0)
+ 	{
+ 	  if (verbose)
+ 	    fprintf (stderr, "Tried `%s'\n", cmd);
+ 	  return 0;
+ 	}
+     }
+ 
+   strcpy (cmd, prefix);
+ 
+   sprintf (cmd+end_prefix, "%s %s %s",
+ 	   DEFAULT_PREPROCESSOR, preprocargs, filename);
+ 
+   if (verbose)
+     fprintf (stderr, "Using `%s'\n", cmd);
+ 
+   cpp_pipe = popen (cmd, FOPEN_RT);
+   return cpp_pipe;
+ }
+ 
  /* Read an rc file.  */
  
*************** read_rc_file (filename, preprocessor, pr
*** 132,138 ****
    char *cmd;
  
-   if (preprocessor == NULL)
-     preprocessor = DEFAULT_PREPROCESSOR;
- 
    if (preprocargs == NULL)
      preprocargs = "";
--- 178,181 ----
*************** read_rc_file (filename, preprocessor, pr
*** 140,150 ****
      filename = "-";
  
!   cmd = xmalloc (strlen (preprocessor)
! 		 + strlen (preprocargs)
! 		 + strlen (filename)
! 		 + 10);
!   sprintf (cmd, "%s %s %s", preprocessor, preprocargs, filename);
  
!   cpp_pipe = popen (cmd, FOPEN_RT);
    if (cpp_pipe == NULL)
      fatal (_("can't popen `%s': %s"), cmd, strerror (errno));
--- 183,253 ----
      filename = "-";
  
!   if (preprocessor)
!     {
!       cmd = xmalloc (strlen (preprocessor)
! 		     + strlen (preprocargs)
! 		     + strlen (filename)
! 		     + 10);
!       sprintf (cmd, "%s %s %s", preprocessor, preprocargs, filename);
  
!       cpp_pipe = popen (cmd, FOPEN_RT);
!     }
!   else
!     {
!       char *dash, *slash, *cp;
! 
!       preprocessor = DEFAULT_PREPROCESSOR;
! 
!       cmd = xmalloc (strlen (program_name)
! 		     + strlen (preprocessor)
! 		     + strlen (preprocargs)
! 		     + strlen (filename)
! 		     + 10);
! 
! 
!       dash = slash = 0;
!       for (cp=program_name; *cp; cp++)
! 	{
! 	  if (*cp == '-')
! 	    dash = cp;
! 	  if (
! #if defined(__DJGPP__) || defined (__CYGWIN__) || defined(__WIN32__)
! 	      *cp == ':' || *cp == '\\' ||
! #endif
! 	      *cp == '/')
! 	    {
! 	      slash = cp;
! 	      dash = 0;
! 	    }
! 	}
! 
!       cpp_pipe = 0;
! 
!       if (dash)
! 	{
! 	  /* First, try looking for a prefixed gcc in the windres
! 	     directory, with the same prefix as windres */
! 
! 	  cpp_pipe = look_for_default (cmd, program_name, dash-program_name+1,
! 				       preprocargs, filename);
! 	}
! 
!       if (slash && !cpp_pipe)
! 	{
! 	  /* Next, try looking for a gcc in the same directory as
!              that windres */
! 
! 	  cpp_pipe = look_for_default (cmd, program_name, slash-program_name+1,
! 				       preprocargs, filename);
! 	}
! 
!       if (!cpp_pipe)
! 	{
! 	  /* Sigh, try the default */
! 
! 	  cpp_pipe = look_for_default (cmd, "", 0, preprocargs, filename);
! 	}
! 
!     }
    if (cpp_pipe == NULL)
      fatal (_("can't popen `%s': %s"), cmd, strerror (errno));
Index: windres.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/windres.c,v
retrieving revision 1.2
diff -p -2 -r1.2 windres.c
*** windres.c	1999/05/11 21:06:16	1.2
--- windres.c	1999/05/18 02:51:03
***************
*** 47,50 ****
--- 47,54 ----
  #include <time.h>
  
+ /* used by resrc.c at least */
+ 
+ int verbose = 0;
+ 
  /* An enumeration of format types.  */
  
*************** static const struct option long_options[
*** 123,126 ****
--- 127,131 ----
    {"preprocessor", required_argument, 0, OPTION_PREPROCESSOR},
    {"target", required_argument, 0, 'F'},
+   {"verbose", no_argument, 0, 'v'},
    {"version", no_argument, 0, OPTION_VERSION},
    {"yydebug", no_argument, 0, OPTION_YYDEBUG},
*************** Options:\n\
*** 706,710 ****
    --preprocessor PROGRAM      Program to use to preprocess rc file\n\
    --include-dir DIR           Include directory when preprocessing rc file\n\
!   --define SYM[=VAL]          Define SYM when preprocessing rc file\n\
    --language VAL              Set language when reading rc file\n"));
  #ifdef YYDEBUG
--- 711,717 ----
    --preprocessor PROGRAM      Program to use to preprocess rc file\n\
    --include-dir DIR           Include directory when preprocessing rc file\n\
!   -DSYM[=VAL], --define SYM[=VAL]\n\
!                               Define SYM when preprocessing rc file\n\
!   -v                          Verbose - tells you what it's doing\n\n
    --language VAL              Set language when reading rc file\n"));
  #ifdef YYDEBUG
*************** main (argc, argv)
*** 795,799 ****
    language = -1;
  
!   while ((c = getopt_long (argc, argv, "i:o:I:O:F:D:", long_options,
  			   (int *) 0)) != EOF)
      {
--- 802,806 ----
    language = -1;
  
!   while ((c = getopt_long (argc, argv, "i:o:I:O:F:D:v", long_options,
  			   (int *) 0)) != EOF)
      {
*************** main (argc, argv)
*** 842,845 ****
--- 849,856 ----
  	      preprocargs = n;
  	    }
+ 	  break;
+ 
+ 	case 'v':
+ 	  verbose ++;
  	  break;
  
Index: windres.h
===================================================================
RCS file: /cvs/binutils/binutils/binutils/windres.h,v
retrieving revision 1.1.1.1
diff -p -2 -r1.1.1.1 windres.h
*** windres.h	1999/05/03 07:29:10	1.1.1.1
--- windres.h	1999/05/18 02:51:03
***************
*** 27,30 ****
--- 27,32 ----
  #include "winduni.h"
  
+ extern int verbose;
+ 
  /* We represent resources internally as a tree, similar to the tree
     used in the .rsrc section of a COFF file.  The root is a

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