Other Remove a flag from CFLAGS in a makefile

polo

New Member

Reaction score: 1
Messages: 2

In a GNU makefile, it is possible to use filter-out to remove a flag from CFLAG like this :

Makefile:
CFLAGS:=$(filter-out -flag,$(CFLAGS))

However, I can't make it work with a FreeBSD makefile.

Is filter-out supported by FreeBSD ? Otherwise, what can I do to remove a specific flag from CFLAGS in a makefile ?
 

Bobi B.

Well-Known Member

Reaction score: 198
Messages: 418

Perhaps you can use replace:
Makefile:
CFLAGS:= $(CFLAGS:-flag=)
but be aware this is POSIX make syntax and can collide with more complex make(1) variable modifiers.
 
OP
P

polo

New Member

Reaction score: 1
Messages: 2

Here is the filter-out like feature in FreeBSD's Makefile (from man page):

:Npattern This is identical to `:M', but selects all words which do not match pattern.

Usage :
Makefile:
CFLAGS= -foo -bar -flag

all:
    @echo ${CFLAGS}
    @echo ${CFLAGS:N-flag}

Code:
$ make
-foo -bar -flag
-foo -bar
 
Top