Re: CFLAGS.xx/yy.c += ?
- Reply: Bjoern A. Zeeb: "Re: CFLAGS.xx/yy.c += ?"
- In reply to: Ahmad Khalifa : "Re: CFLAGS.xx/yy.c += ?"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 19 Aug 2025 08:06:35 UTC
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= ...
>
> >
> > (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