Makefile CFLAGS and SRCS-y are ignored in function form

441 Views Asked by At

I have some trouble with making Makefile. This is a part of Makefile.

dirs := fwd common bp bp_manager $(XRTE_HASH)
VPATH_ = $(foreach dir,$(dirs),$(SRCDIR)/$(dir))
INC_ = $(foreach dir,$(dirs),$(wildcard $(dir)/*.h))
CFLAGS_ = $(foreach dir,$(dirs),-I$(SRCDIR)/$(dir))   
SRCS-y_ = $(foreach dir,$(dirs),$(notdir $(wildcard $(dir)/*.c))) 
VPATH += $(VPATH_)
INC += $(INC_)
CFLAGS += $(CFLAGS_)
SRCS-y += $(SRCS-y_)

check: 
    echo $(CFLAGS)
    echo $(SRCS-y)
  • VPATH and INC worked as I intended.
  • CFLAGS doesn't contain CFLAGS_
  • SRCS-y was printed as I inteded, but it has no effect when do "make" - SRCS-y_ was same with null.
  • CFLAGS and SRCS-y is okay when set manually (without function).

I thought Makefile is almost same with csh. Can you explain me why the "make" ignores functions? Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

CFLAGS_ is just a string. $(CFLAGS_) is a variable's value. So you should have:

CFLAGS += $(CFLAGS_)
SRCS-y += $(SRCS-y_)