Re: CFLAGS.xx/yy.c += ?

From: Bjoern A. Zeeb <bz_at_freebsd.org>
Date: Tue, 19 Aug 2025 09:35:54 UTC
On Tue, 19 Aug 2025, Konstantin Belousov wrote:

> On Tue, Aug 19, 2025 at 12:05:16AM -0700, Ahmad Khalifa wrote:
>> On Mon Aug 18, 2025 at 11:02 PM +0300, Bjoern A. Zeeb wrote:
>>> Hi,
>>>
>>> I would love to add CFLAGS for just one file as in:
>>> CFLAGS.bar.c += -W...
>>>
>>> My problems are:
>>>
>>> (a) the file is foo/bar.c += ; do we have a way to write that out which
>>>      works?
>>
>> The per-file CFLAGS get added using ${CFLAGS.${.IMPSRC:T}}, so you
>> should just be able to use the name of the file. The :T modifier acts
>> like basename(1).
>> CFLAGS.bar.c=	...

Oh, that's ... okay;  that means it might still apply to multiple files
but okay.


>>>
>>> (b) to further complicate it I believe I need two different -Wno-..
>>>      flags depending on gcc vs. clang on top.  Do we support that
>>>      (per-file and per-compiler)?
>>
>> I don't think we have a built-in way to do this, but adding this to
>> CFLAGS should do the trick:
>> CFLAGS+=	${CFLAGS.${COMPILER_TYPE}.${.IMPSRC:T}}
>>
>> This allows you to do:
>> CFLAGS.clang.bar.c=	...
>> CFLAGS.gcc.bar.c=	...
>
> lib/libsysdecode/Makefile:CFLAGS.gcc.ioctl.c+= -Wno-redundant-decls
> as an existing example

Thanks to both of you for the help;  I'll try to apply it like that and
see.

/bz

-- 
Bjoern A. Zeeb                                                     r15:7