Makefile
本文记录我学习makefile的过程。
Makefile funciton
Define your own function in a Makefile
Define your own function in a Makefile
Defining custom GNU make functions
实例如下:
# 切换到指定目录,然后就进行编译
define cd_and_compile
make -C $(1) || exit "$$?"
endef
# 切换到指定目录,然后就进行清空
define cd_and_clean
make -C $(1) clean || exit "$$?"
endef
# 所有需要编译的模块,已经按照依赖关系排序
MOD:= mod1 mod1 mod1 mod1
# 先全部清空,然后进行全编
all: clean $(MOD)
# 单编 mod1
mod1:
$(call cd_and_compile, $@)
官方文档 8 Functions for Transforming Text
Text Functions
在官方文档的这一章节定义了很多非常好用的由于文本操作的函数。
patsubst
CSDN的makefile中的patsubst结合具体例子,介绍地较好。
问题:patsubst中添加or
答:在How to add “or” in pathsubst in Makefile中,给出了比较好的方法。
Invoke shell command in makefile
如何在makefile中执行shell命令?
下面给出了例子:
$(shell mkdir -p ../appcom)
make install
最好使用install
命令
$(shell mkdir -p ../appcom)
install -v ./lib/* ../appcom
源代码分布在多个目录
有的时候,一个target的source code文件分布在多个目录,这种情况下如何来处理呢?
下面给出了例子
VPATH = .:../core:../core/celery:../core/data_model:../core/datetime:../core/feature
INC = -I. -I.. -I../hundsun -I../third_party
SRCS := $(wildcard *.cpp)
#SRCS += $(wildcard ../core/celery/*.cpp)
SRCS += $(wildcard ../core/datetime/*.cpp)
SRCS += $(wildcard ../core/data_model/*.cpp)
SRCS += $(wildcard ../core/feature/*.cpp)
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
TARGET := libfsc_quote_predict.so
LIBS = -lalgo_public -lh5api -lhiredis -lredis++ -ltensorflow
include ../make/master.mk