Patchwork [13/39] properly detect compiler in tests/Makefile

login
register
mail settings
Submitter Paolo Bonzini
Date Oct. 12, 2010, 1 p.m.
Message ID <1286888457-5033-14-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/67561/
State New
Headers show

Comments

Paolo Bonzini - Oct. 12, 2010, 1 p.m.
`make speed' only makes sense if not cross-compiling, so sha1 can
use the CC for the system that is hosting qemu.  sha1-i386 is also
wrong, since there is usually no variable for the target CC; guess
some plausible values.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/Makefile |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
Blue Swirl - Oct. 12, 2010, 7:04 p.m.
On Tue, Oct 12, 2010 at 1:00 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> `make speed' only makes sense if not cross-compiling, so sha1 can
> use the CC for the system that is hosting qemu.  sha1-i386 is also
> wrong, since there is usually no variable for the target CC; guess
> some plausible values.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tests/Makefile |   14 ++++++++++++--
>  1 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/tests/Makefile b/tests/Makefile
> index ff7f787..a789e2d 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -64,11 +64,21 @@ linux-test: linux-test.c
>        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lm
>
>  # speed test
> +ifeq ($(shell uname -m), x86_64)
> +CC_I386 = $(CC) -m32
> +else
> +ifeq ($(shell uname -m), i386)
> +CC_I386 = $(CC)
> +else
> +CC_I386 = i386-pc-linux-gnu-$(CC)
> +endif
> +endif

I'd move this logic to configure.
Paolo Bonzini - Oct. 13, 2010, 7:19 a.m.
On 10/12/2010 09:04 PM, Blue Swirl wrote:
>> diff --git a/tests/Makefile b/tests/Makefile
>> index ff7f787..a789e2d 100644
>> --- a/tests/Makefile
>> +++ b/tests/Makefile
>> @@ -64,11 +64,21 @@ linux-test: linux-test.c
>>         $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<  -lm
>>
>>   # speed test
>> +ifeq ($(shell uname -m), x86_64)
>> +CC_I386 = $(CC) -m32
>> +else
>> +ifeq ($(shell uname -m), i386)
>> +CC_I386 = $(CC)
>> +else
>> +CC_I386 = i386-pc-linux-gnu-$(CC)
>> +endif
>> +endif
>
> I'd move this logic to configure.

I can do that, but it seemed overengineered for a variable that's only 
needed only in one makefile rule, and furthermore a rule that will be 
invoked manually by the user.  In fact I was tempted to hardcode 
"CC_I386=$(CC) -m32" which would work on x86_64 and i386 (and leave the 
task of overriding it to the user).

Paolo
Blue Swirl - Oct. 13, 2010, 7:05 p.m.
On Wed, Oct 13, 2010 at 7:19 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 10/12/2010 09:04 PM, Blue Swirl wrote:
>>>
>>> diff --git a/tests/Makefile b/tests/Makefile
>>> index ff7f787..a789e2d 100644
>>> --- a/tests/Makefile
>>> +++ b/tests/Makefile
>>> @@ -64,11 +64,21 @@ linux-test: linux-test.c
>>>        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<  -lm
>>>
>>>  # speed test
>>> +ifeq ($(shell uname -m), x86_64)
>>> +CC_I386 = $(CC) -m32
>>> +else
>>> +ifeq ($(shell uname -m), i386)
>>> +CC_I386 = $(CC)
>>> +else
>>> +CC_I386 = i386-pc-linux-gnu-$(CC)
>>> +endif
>>> +endif
>>
>> I'd move this logic to configure.
>
> I can do that, but it seemed overengineered for a variable that's only
> needed only in one makefile rule, and furthermore a rule that will be
> invoked manually by the user.  In fact I was tempted to hardcode
> "CC_I386=$(CC) -m32" which would work on x86_64 and i386 (and leave the task
> of overriding it to the user).

That part in configure could be extended to handle other targets as
well. If Alpha, ARM, CRIS, or MIPS (cross-)compilers are available, we
can easily build tests for those too. In the original Makefile
location, this would be a mess.

Patch

diff --git a/tests/Makefile b/tests/Makefile
index ff7f787..a789e2d 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -64,11 +64,21 @@  linux-test: linux-test.c
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lm
 
 # speed test
+ifeq ($(shell uname -m), x86_64)
+CC_I386 = $(CC) -m32
+else
+ifeq ($(shell uname -m), i386)
+CC_I386 = $(CC)
+else
+CC_I386 = i386-pc-linux-gnu-$(CC)
+endif
+endif
+
 sha1-i386: sha1.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
+	$(CC_I386) $(CFLAGS) $(LDFLAGS) -o $@ $<
 
 sha1: sha1.c
-	$(HOST_CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
 
 speed: sha1 sha1-i386
 	time ./sha1