Daniel Loffgren | 9 Jan 2012 17:22
Picon

Building NetBSD without gcc

I have been working on getting NetBSD to compile without gcc, and was making good progress on 5.1, but
decided to move over to current. However, when setting CC in a (for example, the kernel) makefile in
current, it just gets ignored and gcc gets used regardless. I noticed that /usr/share/mk/bsd.own.mk now
has some TOOL_CC variables for various compilers, and found some mention of it on the mailing lists, but
how is this meant to be used? Should variables like CC be completely thrown out by the user? What if they want
to use a compiler that isn't on this TOOL_CC list?
David Holland | 9 Jan 2012 17:27
Picon

Re: Building NetBSD without gcc

On Mon, Jan 09, 2012 at 10:22:20AM -0600, Daniel Loffgren wrote:
 > I have been working on getting NetBSD to compile without gcc, and
 > was making good progress on 5.1, but decided to move over to
 > current. However, when setting CC in a (for example, the kernel)
 > makefile in current, it just gets ignored and gcc gets used
 > regardless. I noticed that /usr/share/mk/bsd.own.mk now has some
 > TOOL_CC variables for various compilers, and found some mention of
 > it on the mailing lists, but how is this meant to be used?

I don't know offhand. There's also a mechanism for using external
toolchains.

 > Should
 > variables like CC be completely thrown out by the user? What if
 > they want to use a compiler that isn't on this TOOL_CC list?

However, ISTM that if 'make CC=xyzcc' ignores the setting and runs gcc
it's a bug. Even if nominally other compilers should be integrated
into the makefile framework, there are times when one wants/needs to
do 'make CC=../some/other/tooldir/gcc' and that ought to behave as
advertised.

--

-- 
David A. Holland
dholland <at> netbsd.org

Joerg Sonnenberger | 9 Jan 2012 17:36
Picon

Re: Building NetBSD without gcc

On Mon, Jan 09, 2012 at 04:27:38PM +0000, David Holland wrote:
> However, ISTM that if 'make CC=xyzcc' ignores the setting and runs gcc
> it's a bug. Even if nominally other compilers should be integrated
> into the makefile framework, there are times when one wants/needs to
> do 'make CC=../some/other/tooldir/gcc' and that ought to behave as
> advertised.

You can't override variables given on the make command line.

Joerg

Daniel Loffgren | 9 Jan 2012 18:54
Picon

Re: Building NetBSD without gcc

> However, ISTM that if 'make CC=xyzcc' ignores the setting and runs gcc
> it's a bug. Even if nominally other compilers should be integrated
> into the makefile framework, there are times when one wants/needs to
> do 'make CC=../some/other/tooldir/gcc' and that ought to behave as
> advertised.

Well, 'make CC=xyz' works, since command line variables take precedence over globals. However, I still
don't believe that it should be explicitly overridden when defined globally (e.g. in the Makefile,) or at
least I didn't expect this behavior. Wouldn't conditional setting of the variables (below) make more sense?

--- /usr/share/mk/bsd.own.mk.old	2012-01-09 05:50:42.000000000 -0600
+++ /usr/share/mk/bsd.own.mk	2012-01-09 05:51:16.000000000 -0600
 <at>  <at>  -447,11 +447,11  <at>  <at> 
 SUPPORTED_${_t}=${AVAILABLE_COMPILER:Nfalse: <at> .c. <at>  ${ !defined(UNSUPPORTED_COMPILER.${.c.}) &&
defined(TOOL_${_t}.${.c.}) :? ${.c.} : } <at> }
 .endfor
 # make bugs prevent moving this into the .for loop
-CC=		${TOOL_CC.${ACTIVE_CC}}
-CPP=		${TOOL_CPP.${ACTIVE_CPP}}
-CXX=		${TOOL_CXX.${ACTIVE_CXX}}
-FC=		${TOOL_FC.${ACTIVE_FC}}
-OBJC=		${TOOL_OBJC.${ACTIVE_OBJC}}
+CC?=		${TOOL_CC.${ACTIVE_CC}}
+CPP?=		${TOOL_CPP.${ACTIVE_CPP}}
+CXX?=		${TOOL_CXX.${ACTIVE_CXX}}
+FC?=		${TOOL_FC.${ACTIVE_FC}}
+OBJC?=		${TOOL_OBJC.${ACTIVE_OBJC}}

 # OBJCOPY flags to create a.out binaries for old firmware
 # shared among src/distrib and ${MACHINE}/conf/Makefile.${MACHINE}.inc
(Continue reading)

Joerg Sonnenberger | 9 Jan 2012 19:13
Picon

Re: Building NetBSD without gcc

On Mon, Jan 09, 2012 at 11:54:00AM -0600, Daniel Loffgren wrote:
> Wouldn't conditional setting of the variables (below) make more sense?
> 
> --- /usr/share/mk/bsd.own.mk.old	2012-01-09 05:50:42.000000000 -0600
> +++ /usr/share/mk/bsd.own.mk	2012-01-09 05:51:16.000000000 -0600
>  <at>  <at>  -447,11 +447,11  <at>  <at> 
>  SUPPORTED_${_t}=${AVAILABLE_COMPILER:Nfalse: <at> .c. <at>  ${ !defined(UNSUPPORTED_COMPILER.${.c.})
&& defined(TOOL_${_t}.${.c.}) :? ${.c.} : } <at> }
>  .endfor
>  # make bugs prevent moving this into the .for loop
> -CC=		${TOOL_CC.${ACTIVE_CC}}
> -CPP=		${TOOL_CPP.${ACTIVE_CPP}}
> -CXX=		${TOOL_CXX.${ACTIVE_CXX}}
> -FC=		${TOOL_FC.${ACTIVE_FC}}
> -OBJC=		${TOOL_OBJC.${ACTIVE_OBJC}}
> +CC?=		${TOOL_CC.${ACTIVE_CC}}
> +CPP?=		${TOOL_CPP.${ACTIVE_CPP}}
> +CXX?=		${TOOL_CXX.${ACTIVE_CXX}}
> +FC?=		${TOOL_FC.${ACTIVE_FC}}
> +OBJC?=		${TOOL_OBJC.${ACTIVE_OBJC}}
>  
>  # OBJCOPY flags to create a.out binaries for old firmware
>  # shared among src/distrib and ${MACHINE}/conf/Makefile.${MACHINE}.inc

It doesn't work.

Joerg

Joerg Sonnenberger | 9 Jan 2012 17:40
Picon

Re: Building NetBSD without gcc

On Mon, Jan 09, 2012 at 10:22:20AM -0600, Daniel Loffgren wrote:
> I have been working on getting NetBSD to compile without gcc, and was
> making good progress on 5.1, but decided to move over to current.

Well, with a few marked exceptions, x86 world builds fine with clang.
No idea about the state of PCC.

> However, when setting CC in a (for example, the kernel) makefile in
> current, it just gets ignored and gcc gets used regardless. I noticed
> that /usr/share/mk/bsd.own.mk now has some TOOL_CC variables for
> various compilers, and found some mention of it on the mailing lists,
> but how is this meant to be used? Should variables like CC be
> completely thrown out by the user? What if they want to use a compiler
> that isn't on this TOOL_CC list?

You can easily add your own by overwriting AVAILABE_COMPILER (make sure
it always contains "false") and adding the appropiate TOOL_*.foo
entries.

Joerg

Iain Hibbert | 9 Jan 2012 21:40

Re: Building NetBSD without gcc

On Mon, 9 Jan 2012, Joerg Sonnenberger wrote:

> On Mon, Jan 09, 2012 at 10:22:20AM -0600, Daniel Loffgren wrote:
> > I have been working on getting NetBSD to compile without gcc, and was
> > making good progress on 5.1, but decided to move over to current.
>
> Well, with a few marked exceptions, x86 world builds fine with clang.
> No idea about the state of PCC.

there are still issues outstanding with pcc, it is work in progress

I use "make HAVE_PCC=" to enable the pcc compiler though I think this is
deprecated somehow

(and, it used to be that HAVE_GCC was disabled by this, but these days
HAVE_GCC is always defined, which is a bug -- I don't know who understands
this stuff and how its supposed to work. Jörg wrote the
AVAILABLE_COMPILERS stuff and Matthew Green broke the HAVE_GCC thing, as I
recall)

iain
Joerg Sonnenberger | 9 Jan 2012 22:10
Picon

Re: Building NetBSD without gcc

On Mon, Jan 09, 2012 at 08:40:38PM +0000, Iain Hibbert wrote:
> I use "make HAVE_PCC=" to enable the pcc compiler though I think this is
> deprecated somehow

It isn't.

> (and, it used to be that HAVE_GCC was disabled by this, but these days
> HAVE_GCC is always defined, which is a bug -- I don't know who understands
> this stuff and how its supposed to work. Jörg wrote the
> AVAILABLE_COMPILERS stuff and Matthew Green broke the HAVE_GCC thing, as I
> recall)

Many HAVE_GCC usages are currently somewhat bogus. They HAVE_* variables
should be turned into proper booleans at some point, but the preference
rules will work.

Joerg

matthew green | 9 Jan 2012 23:04
Picon
Favicon

re: Building NetBSD without gcc


> (and, it used to be that HAVE_GCC was disabled by this, but these days
> HAVE_GCC is always defined, which is a bug -- I don't know who understands
> this stuff and how its supposed to work. Jörg wrote the
> AVAILABLE_COMPILERS stuff and Matthew Green broke the HAVE_GCC thing, as I
> recall)

HAVE_GCC shouldn't have to be defined.  feel free to fix it :-)

Daniel Loffgren | 9 Jan 2012 20:23
Picon

Re: Building NetBSD without gcc

> It doesn't work.

Yes, it seems there was a whitespace issue when copying it from that
terminal. Try this:

--- /usr/share/mk/bsd.own.mk.old	2012-01-09 07:19:54.000000000 -0600
+++ /usr/share/mk/bsd.own.mk	2012-01-09 06:48:06.000000000 -0600
 <at>  <at>  -447,11 +447,11  <at>  <at> 
 SUPPORTED_${_t}=${AVAILABLE_COMPILER:Nfalse: <at> .c. <at>  ${
!defined(UNSUPPORTED_COMPILER.${.c.}) && defined(TOOL_${_t}.${.c.}) :?
${.c.} : } <at> }
 .endfor
 # make bugs prevent moving this into the .for loop
-CC=		${TOOL_CC.${ACTIVE_CC}}
-CPP=		${TOOL_CPP.${ACTIVE_CPP}}
-CXX=		${TOOL_CXX.${ACTIVE_CXX}}
-FC=		${TOOL_FC.${ACTIVE_FC}}
-OBJC=		${TOOL_OBJC.${ACTIVE_OBJC}}
+CC?=		${TOOL_CC.${ACTIVE_CC}}
+CPP?=		${TOOL_CPP.${ACTIVE_CPP}}
+CXX?=		${TOOL_CXX.${ACTIVE_CXX}}
+FC?=		${TOOL_FC.${ACTIVE_FC}}
+OBJC?=		${TOOL_OBJC.${ACTIVE_OBJC}}

 # OBJCOPY flags to create a.out binaries for old firmware
 # shared among src/distrib and ${MACHINE}/conf/Makefile.${MACHINE}.inc

Joerg Sonnenberger | 9 Jan 2012 20:49
Picon

Re: Building NetBSD without gcc

On Mon, Jan 09, 2012 at 01:23:41PM -0600, Daniel Loffgren wrote:
> > It doesn't work.
> 
> Yes, it seems there was a whitespace issue when copying it from that
> terminal. Try this:

You don't understand. Your patch does not work. It cannot work.

Joerg

Daniel Loffgren | 9 Jan 2012 21:28
Picon

Re: Building NetBSD without gcc

> You don't understand. Your patch does not work. It cannot work.

Ah, because of CC's implicit value, forgot about that. Still, wouldn't
an if statement to check for the default cc be better than just
forcibly setting it?


Gmane