Marcro在Makefile中定义变量

时间:2020-07-02 12:32:48

标签: makefile

目录中有6个程序:

  • call_api_pcie
  • call_api_pcie_static
  • call_api_sockrpc
  • call_api_sockrpc_static
  • call_api_sockraw
  • call_api_sockraw_static

我想使用一些标志/配置让Makefile知道列表中有哪个程序

将使用一些标志或配置来定义是否使用此功能/程序。

PROG_USE_PCIE := 1
PROG_USE_SOCKRAW := 1
RROG_USE_SOCKRPC := 1
PROG_USE_STATIC := 1

如果启用了[PROG_USE_XX],则在变量中创建一个列表以定义所有这些程序

PROGRAM_NAME := call_api
MY_PROGRAM := nothing

如果启用了配置/标志[PROG_USE_XX],则添加匹配的程序

#if [PROG_USE_xx] is enabled, it will be include 
ifeq [PROG_USE_STATIC==1] && [PROG_USE_PCIE==1] 
    MY_PROGRAM += call_api_pcie_static
endif 
ifeq [PROG_USE_STATIC==1] && [PROG_USE_SOCKRAW==1]
    MY_PROGRAM += call_api_sockraw_static
endif
ifeq [PROG_USE_STATIC==1] && [PROG_USE_SOCKRPC==1]
    MY_PROGRAM += call_api_sockrpc_static
endif
ifeq [PROG_USE_PCIE==1]
    MY_PROGRAM += call_api_pcie
endif
ifeq [PROG_USE_SOCKRPC==1]
    MY_PROGRAM += call_api_sockrpc
endif
ifeq [PROG_USE_SOCKRAW==1]
    MY_PROGRAM += call_api_sockraw
endif

是否有任何简单的方法来定义这些标志和列表?

涉及Makefile中的“安装”部分

pushd ${BUILD_DIR} && cp -f ${MY_PROGRAM} ${dest_dir} && popd

1 个答案:

答案 0 :(得分:0)

我想我会这样:

PROGS := pcie sockraw sockrpc
PROG_USE_STATIC := 1

PROGRAM_NAME := call_api
MY_PROGRAM := #nothing                                                                                                                                   

PROGS := $(addprefix $(PROGRAM_NAME)_, $(PROGS))

ifeq ($(PROG_USE_STATIC),1)
PROGS += $(addsuffix _static, $(PROGS))
endif

MY_PROGRAM := $(PROGS)