makefile 如何运行所有目录的文件呢?

2022-04-24 09:28:31 +08:00
 MID
比如 cmake 里面是这么写的:
cmake_minimum_required(VERSION 3.5.1)
project(alichain)

set(CMAKE_CXX_STANDARD 11)

add_subdirectory("Backend Server")
add_subdirectory("Main Server")
add_subdirectory("Client")

那怎么改成 makefile 呢?求助
1439 次点击
所在节点    C++
2 条回复
ivan_wl
2022-04-24 09:44:37 +08:00
make 可以 shell 调用命令,如果非要用纯 make 实现的话,我目前项目中使用的:

rwildcard = $(strip $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)))
findall = $(foreach d,$1,$(call rwildcard,$(strip $d)/,$(strip $2)))

C_SRCS := $(call findall, $(PRJ_SCOPE), *.c)
H_SRCS := $(call findall, $(PRJ_SCOPE), *.h)

参考 https://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make
mxx894
2022-04-24 21:12:01 +08:00
可以调用 find 命令,生成依赖。另外 makefile 的推导功能很强大。

C_SOURCES = $(shell find ./ -type f -iname "*.c")
OBJECTS += $(addprefix $(BUILD)/Obj/,$(notdir $(C_SOURCES:%.c=%.o)))

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/848873

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX