diff mbox

configure: Default to 'cc', not 'gcc', on MacOS X

Message ID 1353083843-17175-1-git-send-email-peter.maydell@linaro.org
State New
Headers show

Commit Message

Peter Maydell Nov. 16, 2012, 4:37 p.m. UTC
When building for MacOS X, default the C compiler to 'cc' (usually
clang) rather than 'gcc'. This avoids the Apple 'gcc', which is
generally an elderly llvm-gcc provided mostly for legacy purposes,
in favour of the best supported compiler available on the platform.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
I now seem to be getting failures to compile due to weak refs on
clang as well, but defaulting to cc seems like a good long term
plan anyway. I've mostly been building and testing with --cc=clang
so this isn't a sudden compiler switch from my point of view.
I'm ambivalent about whether this should go in 1.3 or not, given
it doesn't actually fix the weakref issues.

 configure |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Comments

Andreas Färber Nov. 17, 2012, 1:02 p.m. UTC | #1
Am 16.11.2012 17:37, schrieb Peter Maydell:
> When building for MacOS X, default the C compiler to 'cc' (usually
> clang) rather than 'gcc'. This avoids the Apple 'gcc', which is
> generally an elderly llvm-gcc provided mostly for legacy purposes,
> in favour of the best supported compiler available on the platform.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> I now seem to be getting failures to compile due to weak refs on
> clang as well, but defaulting to cc seems like a good long term
> plan anyway. I've mostly been building and testing with --cc=clang
> so this isn't a sudden compiler switch from my point of view.
> I'm ambivalent about whether this should go in 1.3 or not, given
> it doesn't actually fix the weakref issues.
> 
>  configure |   19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index f847ee2..ec9932b 100755
> --- a/configure
> +++ b/configure
> @@ -116,7 +116,13 @@ audio_drv_list=""
>  audio_card_list="ac97 es1370 sb16 hda"
>  audio_possible_cards="ac97 es1370 sb16 cs4231a adlib gus hda"
>  block_drv_whitelist=""
> -host_cc="gcc"
> +if test "$(uname -s)" = "Darwin"; then
> +  # On MacOS X the standard supported system compiler is 'cc' (usually clang),
> +  # and 'gcc' is a legacy llvm-gcc which is rather elderly and best avoided.

This comment strikes me as wrong in this generality. It should at least
be qualified with OSX version numbers.

Andreas

> +  host_cc="cc"
> +else
> +  host_cc="gcc"
> +fi
>  libs_softmmu=""
>  libs_tools=""
>  audio_pt_int=""
> @@ -250,7 +256,16 @@ done
>  # Using uname is really, really broken.  Once we have the right set of checks
>  # we can eliminate its usage altogether.
>  
> -cc="${CC-${cross_prefix}gcc}"
> +# Preferred compiler:
> +#  ${CC} (if set)
> +#  ${cross_prefix}gcc (if cross-prefix specified)
> +#  system compiler
> +if test -z "${CC}${cross_prefix}"; then
> +  cc="$host_cc"
> +else
> +  cc="${CC-${cross_prefix}gcc}"
> +fi
> +
>  ar="${AR-${cross_prefix}ar}"
>  objcopy="${OBJCOPY-${cross_prefix}objcopy}"
>  ld="${LD-${cross_prefix}ld}"
>
Peter Maydell Nov. 17, 2012, 1:10 p.m. UTC | #2
On 17 November 2012 13:02, Andreas Färber <andreas.faerber@web.de> wrote:
> Am 16.11.2012 17:37, schrieb Peter Maydell:
>> When building for MacOS X, default the C compiler to 'cc' (usually
>> clang) rather than 'gcc'. This avoids the Apple 'gcc', which is
>> generally an elderly llvm-gcc provided mostly for legacy purposes,
>> in favour of the best supported compiler available on the platform.
>>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>> I now seem to be getting failures to compile due to weak refs on
>> clang as well, but defaulting to cc seems like a good long term
>> plan anyway. I've mostly been building and testing with --cc=clang
>> so this isn't a sudden compiler switch from my point of view.
>> I'm ambivalent about whether this should go in 1.3 or not, given
>> it doesn't actually fix the weakref issues.
>>
>>  configure |   19 +++++++++++++++++--
>>  1 file changed, 17 insertions(+), 2 deletions(-)
>>
>> diff --git a/configure b/configure
>> index f847ee2..ec9932b 100755
>> --- a/configure
>> +++ b/configure
>> @@ -116,7 +116,13 @@ audio_drv_list=""
>>  audio_card_list="ac97 es1370 sb16 hda"
>>  audio_possible_cards="ac97 es1370 sb16 cs4231a adlib gus hda"
>>  block_drv_whitelist=""
>> -host_cc="gcc"
>> +if test "$(uname -s)" = "Darwin"; then
>> +  # On MacOS X the standard supported system compiler is 'cc' (usually clang),
>> +  # and 'gcc' is a legacy llvm-gcc which is rather elderly and best avoided.
>
> This comment strikes me as wrong in this generality. It should at least
> be qualified with OSX version numbers.

How about "and if 'gcc' is not the same as 'cc' then it is a legacy llvm-gcc
which is rather elderly and best avoided" ? I'd rather not get into having
to research which versions of OSX shipped with which compiler as 'cc',
when really the point is that 'cc' will always give you whichever compiler
Apple thought was the best default for that version.

-- PMM
Peter Maydell Nov. 21, 2012, 11:19 p.m. UTC | #3
On 17 November 2012 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 17 November 2012 13:02, Andreas Färber <andreas.faerber@web.de> wrote:
>> Am 16.11.2012 17:37, schrieb Peter Maydell:
>>> +if test "$(uname -s)" = "Darwin"; then
>>> +  # On MacOS X the standard supported system compiler is 'cc' (usually clang),
>>> +  # and 'gcc' is a legacy llvm-gcc which is rather elderly and best avoided.
>>
>> This comment strikes me as wrong in this generality. It should at least
>> be qualified with OSX version numbers.
>
> How about "and if 'gcc' is not the same as 'cc' then it is a legacy llvm-gcc
> which is rather elderly and best avoided" ? I'd rather not get into having
> to research which versions of OSX shipped with which compiler as 'cc',
> when really the point is that 'cc' will always give you whichever compiler
> Apple thought was the best default for that version.

Andreas: ping? are you happy with this suggested rephrasing? Do you
think this is 1.3 material? (now the static-stublib stuff is in it's
less critical, but it still seems like the right idea...)

thanks
-- PMM
Andreas Färber Nov. 22, 2012, 12:04 a.m. UTC | #4
Am 22.11.2012 00:19, schrieb Peter Maydell:
> On 17 November 2012 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>> On 17 November 2012 13:02, Andreas Färber <andreas.faerber@web.de> wrote:
>>> Am 16.11.2012 17:37, schrieb Peter Maydell:
>>>> +if test "$(uname -s)" = "Darwin"; then
>>>> +  # On MacOS X the standard supported system compiler is 'cc' (usually clang),
>>>> +  # and 'gcc' is a legacy llvm-gcc which is rather elderly and best avoided.
>>>
>>> This comment strikes me as wrong in this generality. It should at least
>>> be qualified with OSX version numbers.
>>
>> How about "and if 'gcc' is not the same as 'cc' then it is a legacy llvm-gcc
>> which is rather elderly and best avoided" ? I'd rather not get into having
>> to research which versions of OSX shipped with which compiler as 'cc',
>> when really the point is that 'cc' will always give you whichever compiler
>> Apple thought was the best default for that version.
> 
> Andreas: ping? are you happy with this suggested rephrasing?

Not quite... clang is a relatively new thing. On v10.5.8 ppc64 'cc' is a
symlink to a real (well, Apple-flavoured) 'gcc-4.0'.

What about "... (clang on recent systems) and 'gcc' may be a legacy
llvm-gcc ..."?

> Do you
> think this is 1.3 material? (now the static-stublib stuff is in it's
> less critical, but it still seems like the right idea...)

I wouldn't be opposed to taking the default change into 1.3 as long as
we can still override it to a specific compiler.

But then again there's the question of why not doing it on Linux as well
now that we seem to compile under clang, we have cc -> gcc-4.7 on
openSUSE 12.2. Among our supported platforms only Solaris comes to my
mind where cc might be an incompatible proprietary compiler.

Andreas
Peter Maydell Nov. 22, 2012, 8:33 a.m. UTC | #5
On 22 November 2012 00:04, Andreas Färber <andreas.faerber@web.de> wrote:
> Am 22.11.2012 00:19, schrieb Peter Maydell:
>> On 17 November 2012 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>>> On 17 November 2012 13:02, Andreas Färber <andreas.faerber@web.de> wrote:
>>>> Am 16.11.2012 17:37, schrieb Peter Maydell:
>>>>> +if test "$(uname -s)" = "Darwin"; then
>>>>> +  # On MacOS X the standard supported system compiler is 'cc' (usually clang),
>>>>> +  # and 'gcc' is a legacy llvm-gcc which is rather elderly and best avoided.
>>>>
>>>> This comment strikes me as wrong in this generality. It should at least
>>>> be qualified with OSX version numbers.
>>>
>>> How about "and if 'gcc' is not the same as 'cc' then it is a legacy llvm-gcc
>>> which is rather elderly and best avoided" ? I'd rather not get into having
>>> to research which versions of OSX shipped with which compiler as 'cc',
>>> when really the point is that 'cc' will always give you whichever compiler
>>> Apple thought was the best default for that version.
>>
>> Andreas: ping? are you happy with this suggested rephrasing?
>
> Not quite... clang is a relatively new thing. On v10.5.8 ppc64 'cc' is a
> symlink to a real (well, Apple-flavoured) 'gcc-4.0'.

Yes, that's the case where gcc is the same as cc, ie the "if" condition
in the comment is false. (I guess this is saying my rephrasing is at
best not very clear...)

> What about "... (clang on recent systems) and 'gcc' may be a legacy
> llvm-gcc ..."?

Sounds ok.

>> Do you
>> think this is 1.3 material? (now the static-stublib stuff is in it's
>> less critical, but it still seems like the right idea...)
>
> I wouldn't be opposed to taking the default change into 1.3 as long as
> we can still override it to a specific compiler.

--cc=whatever remains available.

> But then again there's the question of why not doing it on Linux as well
> now that we seem to compile under clang, we have cc -> gcc-4.7 on
> openSUSE 12.2. Among our supported platforms only Solaris comes to my
> mind where cc might be an incompatible proprietary compiler.

Do any of the BSDs ship with some odd non-GPL thing as cc ?

-- PMM
Brad Smith Nov. 22, 2012, 8:38 a.m. UTC | #6
On Thu, Nov 22, 2012 at 08:33:17AM +0000, Peter Maydell wrote:
> On 22 November 2012 00:04, Andreas F??rber <andreas.faerber@web.de> wrote:
> > Am 22.11.2012 00:19, schrieb Peter Maydell:
> >> On 17 November 2012 13:10, Peter Maydell <peter.maydell@linaro.org> wrote:
> >>> On 17 November 2012 13:02, Andreas F??rber <andreas.faerber@web.de> wrote:
> >>>> Am 16.11.2012 17:37, schrieb Peter Maydell:
> >>>>> +if test "$(uname -s)" = "Darwin"; then
> >>>>> +  # On MacOS X the standard supported system compiler is 'cc' (usually clang),
> >>>>> +  # and 'gcc' is a legacy llvm-gcc which is rather elderly and best avoided.
> >>>>
> >>>> This comment strikes me as wrong in this generality. It should at least
> >>>> be qualified with OSX version numbers.
> >>>
> >>> How about "and if 'gcc' is not the same as 'cc' then it is a legacy llvm-gcc
> >>> which is rather elderly and best avoided" ? I'd rather not get into having
> >>> to research which versions of OSX shipped with which compiler as 'cc',
> >>> when really the point is that 'cc' will always give you whichever compiler
> >>> Apple thought was the best default for that version.
> >>
> >> Andreas: ping? are you happy with this suggested rephrasing?
> >
> > Not quite... clang is a relatively new thing. On v10.5.8 ppc64 'cc' is a
> > symlink to a real (well, Apple-flavoured) 'gcc-4.0'.
> 
> Yes, that's the case where gcc is the same as cc, ie the "if" condition
> in the comment is false. (I guess this is saying my rephrasing is at
> best not very clear...)
> 
> > What about "... (clang on recent systems) and 'gcc' may be a legacy
> > llvm-gcc ..."?
> 
> Sounds ok.
> 
> >> Do you
> >> think this is 1.3 material? (now the static-stublib stuff is in it's
> >> less critical, but it still seems like the right idea...)
> >
> > I wouldn't be opposed to taking the default change into 1.3 as long as
> > we can still override it to a specific compiler.
> 
> --cc=whatever remains available.
> 
> > But then again there's the question of why not doing it on Linux as well
> > now that we seem to compile under clang, we have cc -> gcc-4.7 on
> > openSUSE 12.2. Among our supported platforms only Solaris comes to my
> > mind where cc might be an incompatible proprietary compiler.
> 
> Do any of the BSDs ship with some odd non-GPL thing as cc ?

non-GPL yes, odd no.
Peter Maydell Nov. 22, 2012, 8:41 a.m. UTC | #7
On 22 November 2012 08:38, Brad Smith <brad@comstyle.com> wrote:
> On Thu, Nov 22, 2012 at 08:33:17AM +0000, Peter Maydell wrote:
>> On 22 November 2012 00:04, Andreas F??rber <andreas.faerber@web.de> wrote:
>> > But then again there's the question of why not doing it on Linux as well
>> > now that we seem to compile under clang, we have cc -> gcc-4.7 on
>> > openSUSE 12.2. Among our supported platforms only Solaris comes to my
>> > mind where cc might be an incompatible proprietary compiler.
>>
>> Do any of the BSDs ship with some odd non-GPL thing as cc ?
>
> non-GPL yes, odd no.

Does QEMU build OK with them? Should we be preferring them
to gcc?

-- PMM
Brad Smith Nov. 22, 2012, 8:45 a.m. UTC | #8
On Thu, Nov 22, 2012 at 08:41:19AM +0000, Peter Maydell wrote:
> On 22 November 2012 08:38, Brad Smith <brad@comstyle.com> wrote:
> > On Thu, Nov 22, 2012 at 08:33:17AM +0000, Peter Maydell wrote:
> >> On 22 November 2012 00:04, Andreas F??rber <andreas.faerber@web.de> wrote:
> >> > But then again there's the question of why not doing it on Linux as well
> >> > now that we seem to compile under clang, we have cc -> gcc-4.7 on
> >> > openSUSE 12.2. Among our supported platforms only Solaris comes to my
> >> > mind where cc might be an incompatible proprietary compiler.
> >>
> >> Do any of the BSDs ship with some odd non-GPL thing as cc ?
> >
> > non-GPL yes, odd no.
> 
> Does QEMU build OK with them? Should we be preferring them
> to gcc?

The release notes for 1.3 seem to indicate Clang is supported
now so I would think so. AFAIK FreeBSD -current does not
ship with gcc anymore. Bitrig is a fork of OpenBSD that only
ships with Clang.
diff mbox

Patch

diff --git a/configure b/configure
index f847ee2..ec9932b 100755
--- a/configure
+++ b/configure
@@ -116,7 +116,13 @@  audio_drv_list=""
 audio_card_list="ac97 es1370 sb16 hda"
 audio_possible_cards="ac97 es1370 sb16 cs4231a adlib gus hda"
 block_drv_whitelist=""
-host_cc="gcc"
+if test "$(uname -s)" = "Darwin"; then
+  # On MacOS X the standard supported system compiler is 'cc' (usually clang),
+  # and 'gcc' is a legacy llvm-gcc which is rather elderly and best avoided.
+  host_cc="cc"
+else
+  host_cc="gcc"
+fi
 libs_softmmu=""
 libs_tools=""
 audio_pt_int=""
@@ -250,7 +256,16 @@  done
 # Using uname is really, really broken.  Once we have the right set of checks
 # we can eliminate its usage altogether.
 
-cc="${CC-${cross_prefix}gcc}"
+# Preferred compiler:
+#  ${CC} (if set)
+#  ${cross_prefix}gcc (if cross-prefix specified)
+#  system compiler
+if test -z "${CC}${cross_prefix}"; then
+  cc="$host_cc"
+else
+  cc="${CC-${cross_prefix}gcc}"
+fi
+
 ar="${AR-${cross_prefix}ar}"
 objcopy="${OBJCOPY-${cross_prefix}objcopy}"
 ld="${LD-${cross_prefix}ld}"