bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/10188] New: windres should be able to generate deps.


From: rgammans at computer-surgery dot co dot uk
Subject: [Bug binutils/10188] New: windres should be able to generate deps.
Date: 22 May 2009 17:18:39 -0000

A resource file often references in other files, but there  currently is no
automated way of building these depency.

This patch add 'deps' as an optionally output format to windres which can be
used to do exactly this.

Index: binutils/resrc.c
===================================================================
RCS file: /cvs/src/src/binutils/resrc.c,v
retrieving revision 1.35
diff -u -b -B -u -r1.35 resrc.c
--- binutils/resrc.c    30 Jul 2008 04:34:56 -0000      1.35
+++ binutils/resrc.c    22 May 2009 17:06:23 -0000
@@ -723,6 +723,7 @@
 
   e = open_file_search (filename, FOPEN_RB, "bitmap file", &real_filename);
 
+  if (!e) return;
   if (stat (real_filename, &s) < 0)
     fatal (_("stat failed on bitmap file `%s': %s"), real_filename,
           strerror (errno));
@@ -766,6 +767,7 @@
 
   e = open_file_search (filename, FOPEN_RB, "cursor file", &real_filename);
 
+  if (!e) return;
   /* A cursor file is basically an icon file.  The start of the file
      is a three word structure.  The first word is ignored.  The
      second word is the type of data.  The third word is the number of
@@ -962,6 +964,7 @@
 
   e = open_file_search (filename, FOPEN_RB, "font file", &real_filename);
 
+  if (!e) return;
   if (stat (real_filename, &s) < 0)
     fatal (_("stat failed on font file `%s': %s"), real_filename,
           strerror (errno));
@@ -1168,6 +1171,7 @@
 
   e = open_file_search (filename, FOPEN_RB, "icon file", &real_filename);
 
+  if (!e) return;
   /* The start of an icon file is a three word structure.  The first
      word is ignored.  The second word is the type of data.  The third
      word is the number of entries.  */
@@ -1498,6 +1502,8 @@
   e = open_file_search (filename, FOPEN_RB, "messagetable file",
                        &real_filename);
 
+  if (!e) return;
+
   if (stat (real_filename, &s) < 0)
     fatal (_("stat failed on bitmap file `%s': %s"), real_filename,
           strerror (errno));
@@ -1720,6 +1726,7 @@
   e = open_file_search (filename, FOPEN_RB, "file", &real_filename);
 
 
+  if (!e) return;
   if (stat (real_filename, &s) < 0)
     fatal (_("stat failed on file `%s': %s"), real_filename,
           strerror (errno));
Index: binutils/windres.c
===================================================================
RCS file: /cvs/src/src/binutils/windres.c,v
retrieving revision 1.38
diff -u -b -B -u -r1.38 windres.c
--- binutils/windres.c  9 Feb 2009 15:40:24 -0000       1.38
+++ binutils/windres.c  22 May 2009 17:06:24 -0000
@@ -71,7 +71,9 @@
   /* Binary RES file.  */
   RES_FORMAT_RES,
   /* COFF file.  */
-  RES_FORMAT_COFF
+  RES_FORMAT_COFF,
+  /* Dependencies list for make rules - we can only sanely use this for 
output*/
+  RES_FORMAT_DEPSONLY
 };
 
 /* A structure used to map between format types and strings.  */
@@ -89,6 +91,7 @@
   { "rc", RES_FORMAT_RC },
   { "res", RES_FORMAT_RES },
   { "coff", RES_FORMAT_COFF },
+  { "dep", RES_FORMAT_DEPSONLY },
   { NULL, RES_FORMAT_UNKNOWN }
 };
 
@@ -101,6 +104,7 @@
   { "exe", RES_FORMAT_COFF },
   { "obj", RES_FORMAT_COFF },
   { "o", RES_FORMAT_COFF },
+  { "d", RES_FORMAT_DEPSONLY },
   { NULL, RES_FORMAT_UNKNOWN }
 };
 
@@ -132,6 +136,9 @@
 static void target_put_16 (void *, rc_uint_type);
 static rc_uint_type target_get_32 (const void *, rc_uint_type);
 static void target_put_32 (void *, rc_uint_type);
+static void write_deps_file (const char * filename);
+static void read_deps_file (void);
+static void add_fname (const char*);
 
 
 /* When we are building a resource tree, we allocate everything onto
@@ -181,8 +188,38 @@
   return obstack_alloc (&reswr_obstack, (size_t) bytes);
 }
 
+
+/* This structure is used for storing referenced filenames */
+struct dependant 
+{
+  /* next name */
+  struct dependant *next;
+  /* file name */
+  char *name;
+};               
+
+/* Keep the head of the dependecies list to hand */  
+static struct dependant *dep_list = NULL;
+
+/* Extend dependencies list */
+void 
+add_fname(s)
+    const char* s;
+{
+struct dependant *item;
+  
+  item = xmalloc(sizeof (struct dependant));
+  item->name = xstrdup(s);
+  item->next = dep_list;
+  dep_list=item;
+
+}
+
+
 /* Open a file using the include directory search list.  */
 
+int missingfiles=0;
+
 FILE *
 open_file_search (const char *filename, const char *mode, const char *errmsg,
                  char **real_filename)
@@ -194,6 +231,7 @@
   if (e != NULL)
     {
       *real_filename = xstrdup (filename);
+      add_fname(filename);
       return e;
     }
 
@@ -209,6 +247,8 @@
          if (e != NULL)
            {
              *real_filename = n;
+            
+             add_fname(n);
              return e;
            }
 
@@ -217,9 +257,10 @@
        }
     }
 
-  fatal (_("can't open %s `%s': %s"), errmsg, filename, strerror (errno));
+  fprintf (stderr, _("can't open %s `%s': %s\n"), errmsg, filename, strerror
(errno));
 
-  /* Return a value to avoid a compiler warning.  */
+  add_fname(filename);
+  missingfiles =1;
   return NULL;
 }
 
@@ -688,7 +729,7 @@
   -h --help                    Print this help message\n\
   -V --version                 Print version information\n"));
   fprintf (stream, _("\
-FORMAT is one of rc, res, or coff, and is deduced from the file name\n\
+FORMAT is one of rc, res, dep or coff, and is deduced from the file name\n\
 extension if not specified.  A single file name is an input file.\n\
 No input-file is stdin, default rc.  No output-file is stdout, default 
rc.\n"));
 
@@ -1031,11 +1072,17 @@
     case RES_FORMAT_COFF:
       resources = read_coff_rsrc (input_filename, target);
       break;
+    case RES_FORMAT_DEPSONLY:
+      read_deps_file ();
+      break;
     }
 
   if (resources == NULL)
     fatal (_("no resources"));
 
+  if (missingfiles && (output_format != RES_FORMAT_DEPSONLY))
+    fatal("resources incomplete");
+ 
   /* Sort the resources.  This is required for COFF, convenient for
      rc, and unimportant for res.  */
   resources = sort_resources (resources);
@@ -1056,12 +1103,48 @@
     case RES_FORMAT_COFF:
       write_coff_file (output_filename, target, resources);
       break;
+    case RES_FORMAT_DEPSONLY:
+      write_deps_file (output_filename);
+      break;
     }
 
   xexit (0);
   return 0;
 }
 
+void
+read_deps_file ()
+{
+  fatal ("It is not possible to read deps files usefully");
+}
+
+
+void
+write_deps_file (const char *filename)
+{
+  FILE *e;
+  struct dependant *list;
+        
+  if (filename == NULL)
+    e = stdout;
+  else
+    {
+      e = fopen (filename, FOPEN_WT);
+      if (e == NULL)
+       fatal ("can't open `%s' for output: %s", filename, strerror (errno));
+    }
+
+  list=dep_list;
+  while(list) {  
+      fprintf(e," %s",list->name);
+      list=list->next;
+  }
+  fprintf(e,"\n");
+  fclose (e);
+}
+
+
+
 static int
 find_arch_match(const char *tname,const char **arch)
 {

-- 
           Summary: windres should be able to generate deps.
           Product: binutils
           Version: unspecified
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: binutils
        AssignedTo: unassigned at sources dot redhat dot com
        ReportedBy: rgammans at computer-surgery dot co dot uk
                CC: bug-binutils at gnu dot org
GCC target triplet: i586-mingw32


http://sourceware.org/bugzilla/show_bug.cgi?id=10188

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]