clang and CFLAGS

Hi,

Does anyone know where I can find detailed documentation about using CFLAGS with Clang? I've had a search online but have not found anything that gives much information except that they need to go in /etc/src.conf. I'd like to know the proper syntax/formatting. I'm tracking 10-CURRENT because it is relevant to a project I am working on.

Thank you.
 
I had the same question -- clang man page cannot even hold the candle to that of the gcc. However, since clang aims to be gcc-4.2 compatible, and at the same time offer tricks for newer CPUs/gcc-s (like -mssse3 for example), it should have the same flags. IMO it's safe to use gcc flags (except for OpenMP related things -- clang doesn't support it yet). So far, I've been using gcc-4.8 flags for clang without any problem whatsoever.
 
synack said:
Does anyone know where I can find detailed documentation about using CFLAGS with Clang?
There isn't any because you're not supposed to muck about with them. It's best to leave those flags alone.
 
What about options like NO_WERROR? I'm trying to build -CURRENT but warnings are causing the build to fail.
 
In most such cases there are workarounds, that are not related to *WERROR, but for starters, you could try the -fpermissive flag (for more, read the gcc manpage). Perhaps you could also include which port is the one giving you the problems, since your report is pretty generic.

Note, that not all ports are guaranteed to build on 10-CURRENT, so make sure you bookmark/read "ports-and-clang wiki", and "world-and-clang wiki". Also "when-did-that-port-break wiki" might also be useful (especially the link to pointyhat).

Another useful source of information for such questions are freebsd-current and freebsd-ports mailing lists.
 
Then you should post a question regarding your # make buildworld failure in the Base System section of the forums, specifically, Installing & Upgrading, since both question and the answer would be more suited there. Don't forget to include your /etc/make.conf and /etc/src.conf. In most cases it's because of bad configuration, for example:

synack said:
...
I've had a search online but have not found anything that gives much information except that they need to go in /etc/src.conf.
...

no, they go in /etc/make.conf. See make.conf(5)(), src.conf(5)() and build(7)(). Since /etc/make.conf is read by make, you should read make(1)() to see how to format it properly (because it's just another Makefile).

So you could try such /etc/make.conf
Code:
CC=clang
CXX=clang++
CPP=clang-cpp
CPUTYPE?=native

.if !empty(.CURDIR:M/usr/src*) || !empty(.CURDIR:M/usr/obj*)
CFLAGS+=-my-option1 -my-option2 -my-option3 ...
CXXFLAGS+=-my-option1 -my-option2 ...
.endif

Note the ?= for defining the CPUTYPE (with a straightforward = world won't build) and += when defining the CFLAGS/CXXFLAGS (this preserves existing flags, and appends new). Such make.conf is minimal, doesn't try anything fancy that might break your build (except the CFLAGS which, as @SirDice mentioned, should in fact be left alone.

I hope this helps, if not, let us know the details of your problem! Cheers! :)
 
Last edited by a moderator:
Back
Top