[patch binutils]: Add --preprocessor-arg option to windres tool

Kai Tietz ktietz70@googlemail.com
Mon Apr 11 12:30:00 GMT 2011


2011/4/11 Nick Clifton <nickc@redhat.com>:
> Hi Kai,
>
>> Ok, added documentation and NEWS entry for this new option.
>>
>> Ok for apply?
>
> Yes - with two small changes:
>
>  1) Add entries in the ChangeLog for the additions to NEWS and
> binutils.texi.
>
>  2) Please could you change the description of the --preprocessor-arg option
> so that it is a little clearer.  I suggest:
>
>  @item --preprocessor-arg @var{option}
>  When @command{windres} reads an @code{rc} file, it runs it through
>  the C preprocessor first.  This option may be used to specify
>  additional text to be passed to preprocessor on its command line.
>  This option can be used multiple  times to add multiple options to
>  the preprocessor command line.

Ok, modified as suggested. I added to this patch also new testcase,
which required an extension of winres rc scipt-based option scanning.

ChangLog binutils/

2011-04-11  Kai Tietz

	* windres.c (usage): Add new --preprocessor-arg option.
	(option_values): Add new OPTION_PREPROCESSOR_ARG enumerator.
	(option long_options): Add preprocessor-arg option.
	(main): Handle it.
	* doc/binutils.texi: Add documentation for --preprocessor-arg
	option.
	* NEWS: Add line about new --preprocessor-arg option for windres.

ChangLog binutils/testsuite/

2011-04-11  Kai Tietz

	* binutils-all/windres/windres.exp: Add '// cpparg <option>' command
	to rc file interpretation to specify addition pre-processor commands
	as script option.
	* binutils-all/windres/strtab3.rc: New.
	* binutils-all/windres/strtab3.rsd: New.
	* binutils-all/windres/README: Add note about cpparg script option.
	argument


Regards,
Kai
-------------- next part --------------
Index: src/binutils/windres.c
===================================================================
--- src.orig/binutils/windres.c	2011-04-09 18:01:32.861135500 +0200
+++ src/binutils/windres.c	2011-04-11 13:38:57.699191700 +0200
@@ -665,6 +665,7 @@ usage (FILE *stream, int status)
   -O --output-format=<format>  Specify output format\n\
   -F --target=<target>         Specify COFF target\n\
      --preprocessor=<program>  Program to use to preprocess rc file\n\
+     --preprocessor-arg=<arg>  Additional preprocessor argument\n\
   -I --include-dir=<dir>       Include directory when preprocessing rc file\n\
   -D --define <sym>[=<val>]    Define SYM when preprocessing rc file\n\
   -U --undefine <sym>          Undefine SYM when preprocessing rc file\n\
@@ -734,7 +735,8 @@ enum option_values
   OPTION_USE_TEMP_FILE,
   OPTION_NO_USE_TEMP_FILE,
   OPTION_YYDEBUG,
-  OPTION_INCLUDE_DIR
+  OPTION_INCLUDE_DIR,
+  OPTION_PREPROCESSOR_ARG
 };
 
 static const struct option long_options[] =
@@ -745,6 +747,7 @@ static const struct option long_options[
   {"output-format", required_argument, 0, 'O'},
   {"target", required_argument, 0, 'F'},
   {"preprocessor", required_argument, 0, OPTION_PREPROCESSOR},
+  {"preprocessor-arg", required_argument, 0, OPTION_PREPROCESSOR_ARG},
   {"include-dir", required_argument, 0, OPTION_INCLUDE_DIR},
   {"define", required_argument, 0, 'D'},
   {"undefine", required_argument, 0, 'U'},
@@ -888,6 +891,23 @@ main (int argc, char **argv)
 	case OPTION_PREPROCESSOR:
 	  preprocessor = optarg;
 	  break;
+	case OPTION_PREPROCESSOR_ARG:
+	  if (preprocargs == NULL)
+	    {
+	      quotedarg = quot (optarg);
+	      preprocargs = xstrdup (quotedarg);
+	    }
+	  else
+	    {
+	      char *n;
+
+	      quotedarg = quot (optarg);
+	      n = xmalloc (strlen (preprocargs) + strlen (quotedarg) + 2);
+	      sprintf (n, "%s %s", preprocargs, quotedarg);
+	      free (preprocargs);
+	      preprocargs = n;
+	    }
+	  break;
 
 	case 'D':
 	case 'U':
Index: src/binutils/NEWS
===================================================================
--- src.orig/binutils/NEWS	2010-11-11 18:04:30.000000000 +0100
+++ src/binutils/NEWS	2011-04-11 13:47:24.878595300 +0200
@@ -1,5 +1,8 @@
 -*- text -*-
 
+* Add --preprocessor-arg option to windres to specify additional options
+  passed to preprocessor.
+
 Changes in 2.21:
 
 
Index: src/binutils/doc/binutils.texi
===================================================================
--- src.orig/binutils/doc/binutils.texi	2010-12-18 12:26:24.000000000 +0100
+++ src/binutils/doc/binutils.texi	2011-04-11 14:23:52.602400900 +0200
@@ -3450,6 +3450,13 @@ preprocessor first.  This option may be
 to use, including any leading arguments.  The default preprocessor
 argument is @code{gcc -E -xc-header -DRC_INVOKED}.
 
+@item --preprocessor-arg @var{option}
+When @command{windres} reads an @code{rc} file, it runs it through
+the C preprocessor first.  This option may be used to specify additional
+text to be passed to preprocessor on its command line.
+This option can be used multiple times to add multiple options to the
+preprocessor command line.
+
 @item -I @var{directory}
 @itemx --include-dir @var{directory}
 Specify an include directory to use when reading an @code{rc} file.
Index: src/binutils/testsuite/binutils-all/windres/README
===================================================================
--- src.orig/binutils/testsuite/binutils-all/windres/README	2011-04-11 14:17:36.000000000 +0200
+++ src/binutils/testsuite/binutils-all/windres/README	2011-04-11 14:14:04.591233000 +0200
@@ -12,6 +12,7 @@ contains one command:
 
 	// parse-only
 	// xfail *-*-*
+	// cpparg <preprocessor options passed via --preprocessor-arg>
 
 parse-only must preceed any xfail commands, and indicates that a
 comparison with the *.rsd file will not happen.  xfail indicates when
Index: src/binutils/testsuite/binutils-all/windres/strtab3.rc
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/binutils/testsuite/binutils-all/windres/strtab3.rc	2011-04-11 14:04:11.813459800 +0200
@@ -0,0 +1,14 @@
+// cpparg -DTEST=1
+
+#include "windows.h"
+
+LANGUAGE 0, 0
+
+STRINGTABLE MOVEABLE PURE DISCARDABLE
+BEGIN
+#ifdef TEST
+  1 "hello, world"
+#else
+  1 "fail"
+#endif
+END
Index: src/binutils/testsuite/binutils-all/windres/strtab3.rsd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/binutils/testsuite/binutils-all/windres/strtab3.rsd	2011-04-11 14:02:36.651375700 +0200
@@ -0,0 +1,8 @@
+ 0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+ 0010 00000000 00000000 00000000 00000000  ................
+ 0020 38000000 20000000 ffff0600 ffff0100  8... ...........
+ 0030 00000000 30100000 00000000 00000000  ....0...........
+ 0040 00000c00 68006500 6c006c00 6f002c00  ....h.e.l.l.o.,.
+ 0050 20007700 6f007200 6c006400 00000000   .w.o.r.l.d.....
+ 0060 00000000 00000000 00000000 00000000  ................
+ 0070 00000000 00000000                    ........        
Index: src/binutils/testsuite/binutils-all/windres/windres.exp
===================================================================
--- src.orig/binutils/testsuite/binutils-all/windres/windres.exp	2011-04-11 14:17:36.000000000 +0200
+++ src/binutils/testsuite/binutils-all/windres/windres.exp	2011-04-11 14:10:55.976782000 +0200
@@ -56,6 +56,7 @@ foreach res $res_list {
     set sroot [file rootname $res]
     set broot [file tail $sroot]
     set done 0
+    set cpp_opts ""
 
     set rc [open $res]
     while { [gets $rc line] != -1 } {
@@ -66,10 +67,14 @@ foreach res $res_list {
 	    setup_xfail $sys
 	    continue
 	}
+	if [regexp "cpparg *(\[^ \]*)" $line junk cppopt] {
+	    set cpp_opts "--preprocessor-arg \"$cppopt\""
+	    continue
+	}
     }
 
     verbose "$wr -J rc -O res $res tmpdir/$broot.res" 1
-    catch "exec $wr -J rc -O res $res tmpdir/$broot.res" err
+    catch "exec $wr $cpp_opts -J rc -O res $res tmpdir/$broot.res" err
 
     if ![string match "" $err] then {
 	send_log "$err\n"


More information about the Binutils mailing list