Bug 10188 - windres should be able to generate deps.
Summary: windres should be able to generate deps.
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-22 17:18 UTC by Roger Gammans
Modified: 2010-02-16 11:12 UTC (History)
1 user (show)

See Also:
Host:
Target: i586-mingw32
Build:
Last reconfirmed:


Attachments
Application for FSF copyright assignment (2.54 KB, text/plain)
2009-06-15 15:03 UTC, Nick Clifton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Roger Gammans 2009-05-22 17:18:38 UTC
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)
 {
Comment 1 Nick Clifton 2009-06-15 15:03:14 UTC
Created attachment 3998 [details]
Application for FSF copyright assignment
Comment 2 Nick Clifton 2009-06-15 15:04:54 UTC
Hi Roger,

  Thank you for submitting this enhancement.  Before we can go any further
however, it is necessary for you to complete an FSF binutils copyright
assignment.  Please could you fill out the uploaded form and then send it off in
order to start the ball rolling ?

Cheers
  Nick Clifton
Comment 3 Roger Gammans 2010-02-16 11:12:52 UTC
Sorry for the delay. (I forgot all about it)

That copyright assign mentions "name of manual". Should there be a different one 
for code changes?