makefile如何将其转换为宏
makefile how to turn this into a macro
在尝试编写非递归make时,我有以下块:
dir := $(ROOT)/libs/libA/
include $(dir)/rules.mk
dir := $(ROOT)/libs/libB/
include $(dir)/rules.mk
dir := $(ROOT)/libs/libC/
include $(dir)/rules.mk
这显然是不必要的重复。我怎么能写一个宏来折叠这一切,这样我只需要提供libA
、libB
和libC
?我还需要在每个include
之前设置dir
。
以下是如何按顺序在每个子目录列表中包含一个rules.mk
makefile,并使变量DIR
等于每个rules.mk
中的子目录。我使用变量名DIR
,而不是您想要的dir
,因为我认为makefile中的"全局"变量名应该是大写的。
有关非递归makefile的其他实现细节,请参阅
evbergen.home.xs4all.nl/non-recurve-make.html
# include the makefile $2/rules.mk
# and make the variable $1 be equal to the directory $2, inside that makefile
define INCLUDE_DIR
$1 := $2
include $$($1)/rules.mk
endef
# do INCLUDE_DIR for directory variable name $1 and directories $2
define INCLUDE_DIRS
$(foreach dir, $2, $(eval $(call INCLUDE_DIR,$1, $(dir))))
endef
DIRS :=
$(ROOT)/libs/libA
$(ROOT)/libs/libB
$(call INCLUDE_DIRS,DIR, $(DIRS))
LIBS := libA libB libC
include $(patsubst %, $(ROOT)/libs/%/rules.mk, $(LIBS))
如果您能够使用GNU make,那么以下操作应该有效:
get_mk := $(ROOT)/libs/$(1)/rules.mk
include $(call get_mk,libA)
include $(call get_mk,libB)
include $(call get_mk,libC)
有关call
的更多信息,请访问http://www.gnu.org/software/make/manual/make.html#Call-函数。
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 将 makefile 转换为其相关的 cmakefile
- 将一个用户的gnu makefile转换为另一个用户
- 如何转换一个普通的makefile以创建可以在另一台计算机上使用的静态可执行文件
- 如何将makefile转换为JSON编译数据库
- 将Makefile转换为Android.mk
- 将 Makefile 项目转换为 Cmake
- 正在将Makefile转换为CMakeLists.txt
- makefile如何将其转换为宏
- 错误:在makefile中从' void* '转换为' int '会失去精度[-fpermissive]
- 为Tiva C系列转换一个Makefile到CMakeLists.txt
- 将makefile转换为cmake
- 将'makefile.vc'转换为'.sln'解决方案文件
- 将qmake文件转换为Unix makefile