On Wed, Dec 3, 2025 at 11:50 PM Peter Damianov <[email protected]> wrote:
>
> This patch adds support for compiling Windows resource files
> (.rc) and pre-compiled resource files (.res) directly through the
> GCC driver on PECOFF targets.
>
> Previously, users had to manually invoke windres to compile resource
> files before linking:
>
> windres -o resource.o resource.rc
> gcc main.c resource.o -o program.exe
>
> With this patch, GCC can handle resource files automatically:
>
> gcc main.c resource.rc -o program.exe
> gcc main.c resource.res -o program.exe
>
> Now, for an explanation of each line of the spec:
>
> If any of -E -M or -MM were passed, do nothing. No object files are output.
> "%{!E:%{!M:%{!MM:windres \
>
> For multilib configurations, tell windres to write out the correct COFF format
> %{m32:--target=pe-i386} %{m64:--target=pe-x86-64} \
This is wrong for say aarch64-mingw.
>
> Pass through -I -D -U on to windres, because it supports them.
> %{I*:-I%*} %{D*:-D%*} %{U*:-U%*} \
>
> If -c is passed, pass through -o to windres, if it was specified. Otherwise,
> output to the input basename with .o suffix. Else, output to a
> temp file that will be deleted after linking.
> %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O} %i}}}",
>
> gcc/ChangeLog:
>
> PR driver/108866
> * gcc.cc (default_compilers): Add spec for handling .rc and .res files
>
> Signed-off-by: Peter Damianov <[email protected]>
> ---
> gcc/gcc.cc | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/gcc/gcc.cc b/gcc/gcc.cc
> index b5d0f759f14..70faf4ba877 100644
> --- a/gcc/gcc.cc
> +++ b/gcc/gcc.cc
> @@ -1517,6 +1517,18 @@ static const struct compiler default_compilers[] =
> #endif
> , 0, 0, 0},
>
> +#if TARGET_PECOFF
> + /* Support for Windows resource files. */
> + {".rc", "@windres", 0, 0, 0},
> + {".res", "@windres", 0, 0, 0},
> + {"@windres",
> + "%{!E:%{!M:%{!MM:windres \
> + %{m32:--target=pe-i386} %{m64:--target=pe-x86-64} \
> + %{I*:-I%*} %{D*:-D%*} %{U*:-U%*} \
> + %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O} %i}}}",
> + 0, 0, 0},
> +#endif
I think this should be:
#ifndef EXTRA_DEFAULT_COMPILERS
#define EXTRA_DEFAULT_COMPILERS
#endif
EXTRA_DEFAULT_COMPILERS
and now in config/i386/cygming.h:
/* Support for Windows resource files. */
#define EXTRA_DEFAULT_COMPILERS \
{".rc", "@windres", 0, 0, 0}, \
{".res", "@windres", 0, 0, 0}, \
{"@windres", \
"%{!E:%{!M:%{!MM:windres \
%{m32:--target=pe-i386} %{m64:--target=pe-x86-64} \
%{I*:-I%*} %{D*:-D%*} %{U*:-U%*} \
%{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O} %i}}}", \
0, 0, 0},
And do a similar thing in config/aarch64/cygming.h but without the m32 .
If you want to combine the 2 that would be a good idea too.
Thanks,
Andrew Pinski
> +
> #include "specs.h"
> /* Mark end of table. */
> {0, 0, 0, 0, 0}
> --
> 2.47.3
>