Patchwork Fix build for mingw32 on windows ($@ in macro)

login
register
mail settings
Submitter Stefan Weil
Date Nov. 19, 2009, 7:07 p.m.
Message ID <1258657672-9897-1-git-send-email-weil@mail.berlios.de>
Download mbox | patch
Permalink /patch/38866/
State New
Headers show

Comments

Stefan Weil - Nov. 19, 2009, 7:07 p.m.
Make using mingw32 on windows does not preserve $@ in macros
when they are modified using this pattern:
target: macro += something

This behaviour results in an error when QEMU_CFLAGS containing
"-MMD -MP -MT $@" is modified for compilation of source files
which use SDL: $@ will expand to nothing, -MT no longer has
the correct argument (it will take the next one from the command
line) and the build will fail or run with a wrong command line.

The problem is fixed by using a new macro QEMU_DGFLAGS
which is not modified by a target rule.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 rules.mak |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
Sebastian Herbszt - Nov. 19, 2009, 8:13 p.m.
Stefan Weil wrote:
> Make using mingw32 on windows does not preserve $@ in macros
> when they are modified using this pattern:
> target: macro += something
> 
> This behaviour results in an error when QEMU_CFLAGS containing
> "-MMD -MP -MT $@" is modified for compilation of source files
> which use SDL: $@ will expand to nothing, -MT no longer has
> the correct argument (it will take the next one from the command
> line) and the build will fail or run with a wrong command line.
> 
> The problem is fixed by using a new macro QEMU_DGFLAGS
> which is not modified by a target rule.
> 
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>

Tested-by: Sebastian Herbszt <herbszt@gmx.de>
malc - Nov. 19, 2009, 9:32 p.m.
On Thu, 19 Nov 2009, Stefan Weil wrote:

> Make using mingw32 on windows does not preserve $@ in macros
> when they are modified using this pattern:
> target: macro += something
> 
> This behaviour results in an error when QEMU_CFLAGS containing
> "-MMD -MP -MT $@" is modified for compilation of source files
> which use SDL: $@ will expand to nothing, -MT no longer has
> the correct argument (it will take the next one from the command
> line) and the build will fail or run with a wrong command line.
> 
> The problem is fixed by using a new macro QEMU_DGFLAGS
> which is not modified by a target rule.

Why not just stuff `-MMD -MP -MT $@' into the rules?

[..snip..]
Jamie Lokier - Nov. 20, 2009, 1:26 a.m.
Stefan Weil wrote:
> Make using mingw32 on windows does not preserve $@ in macros
> when they are modified using this pattern:
> target: macro += something

Is it not using GNU Make, or is it some ancient version?
("make --version" shows the version, if it's GNU Make).

-- Jamie
Stefan Weil - Nov. 20, 2009, 6:40 a.m.
malc schrieb:
> On Thu, 19 Nov 2009, Stefan Weil wrote:
>
>> Make using mingw32 on windows does not preserve $@ in macros
>> when they are modified using this pattern:
>> target: macro += something
>>
>> This behaviour results in an error when QEMU_CFLAGS containing
>> "-MMD -MP -MT $@" is modified for compilation of source files
>> which use SDL: $@ will expand to nothing, -MT no longer has
>> the correct argument (it will take the next one from the command
>> line) and the build will fail or run with a wrong command line.
>>
>> The problem is fixed by using a new macro QEMU_DGFLAGS
>> which is not modified by a target rule.
>
> Why not just stuff `-MMD -MP -MT $@' into the rules?
>
> [..snip..]

As in most cases, there are many ways to do something...

During my test, I had the dependency flags in the rules.

I decided to use a macro to allow people running make
without dependency generation (make QEMU_DGFLAGS=).

Stefan
Stefan Weil - Nov. 20, 2009, 7:33 a.m.
Jamie Lokier schrieb:
> Stefan Weil wrote:
>   
>> Make using mingw32 on windows does not preserve $@ in macros
>> when they are modified using this pattern:
>> target: macro += something
>>     
>
> Is it not using GNU Make, or is it some ancient version?
> ("make --version" shows the version, if it's GNU Make).
>
> -- Jamie
>
>   

GNU make 3.79.1 (2004)

-- Stefan
Jamie Lokier - Nov. 20, 2009, 2:55 p.m.
Stefan Weil wrote:
> Jamie Lokier schrieb:
> > Stefan Weil wrote:
> >   
> >> Make using mingw32 on windows does not preserve $@ in macros
> >> when they are modified using this pattern:
> >> target: macro += something
> >>     
> >
> > Is it not using GNU Make, or is it some ancient version?
> > ("make --version" shows the version, if it's GNU Make).
> >
> > -- Jamie
> 
> GNU make 3.79.1 (2004)

3.79.1 is ancient, the GNU version being released in June 2000 :-)

The behaviour of

    target: macro += something

appears to be fixed in GNU make 3.80, which was released in October 2002.
(I've just tested 3.79.1 and 3.80 from GNU's ftp site).

Is there not an update for mingw32 for a more recent make?

-- Jamie
Sebastian Herbszt - Nov. 20, 2009, 4:58 p.m.
Jamie Lokier wrote:
> Stefan Weil wrote:
>> Make using mingw32 on windows does not preserve $@ in macros
>> when they are modified using this pattern:
>> target: macro += something
> 
> Is it not using GNU Make, or is it some ancient version?
> ("make --version" shows the version, if it's GNU Make).
> 
> -- Jamie

$ make --version
GNU Make version 3.79.1, by Richard Stallman and Roland McGrath.
Built for i686-pc-msys

- Sebastian
Stefan Weil - Nov. 20, 2009, 6:26 p.m.
Jamie Lokier schrieb:
> Stefan Weil wrote:
>> Jamie Lokier schrieb:
>>> Stefan Weil wrote:
>>>
>>>> Make using mingw32 on windows does not preserve $@ in macros
>>>> when they are modified using this pattern:
>>>> target: macro += something
>>>>
>>> Is it not using GNU Make, or is it some ancient version?
>>> ("make --version" shows the version, if it's GNU Make).
>>>
>>> -- Jamie
>> GNU make 3.79.1 (2004)
>
> 3.79.1 is ancient, the GNU version being released in June 2000 :-)
>
> The behaviour of
>
> target: macro += something
>
> appears to be fixed in GNU make 3.80, which was released in October 2002.
> (I've just tested 3.79.1 and 3.80 from GNU's ftp site).
>
> Is there not an update for mingw32 for a more recent make?
>
> -- Jamie

Of course it's ancient, but from the timestamp (if it was correct)
I'd estimate that it takes 3 to 4 years to get a GNU release to windows :-)

MSYS make 3.81-2 is available (and there is also a MinGW make, a
make using MSVCRT). The MinGW update tool does not
update MSYS make automatically (at least in my installation),
and I rarely compile using mingw32 on windows (cross compilation
from linux works better). So keeping MinGW/MSYS up-to-date
is a little difficult.

-- Stefan

Patch

diff --git a/rules.mak b/rules.mak
index 77a801b..16713ba 100644
--- a/rules.mak
+++ b/rules.mak
@@ -11,16 +11,17 @@  MAKEFLAGS += -rR
 %.m:
 %.mak:
 
-QEMU_CFLAGS += -MMD -MP -MT $@
+# Flags for dependency generation
+QEMU_DGFLAGS += -MMD -MP -MT $@
 
 %.o: %.c $(GENERATED_HEADERS)
-	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) -c -o $@ $<,"  CC    $(TARGET_DIR)$@")
+	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  CC    $(TARGET_DIR)$@")
 
 %.o: %.S
-	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) -c -o $@ $<,"  AS    $(TARGET_DIR)$@")
+	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  AS    $(TARGET_DIR)$@")
 
 %.o: %.m
-	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) -c -o $@ $<,"  OBJC  $(TARGET_DIR)$@")
+	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  OBJC  $(TARGET_DIR)$@")
 
 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(1) $(ARLIBS_BEGIN) $(ARLIBS) $(ARLIBS_END) $(LIBS),"  LINK  $(TARGET_DIR)$@")