使用GCC的C makefile - 从子文件夹列表中生成源文件列表
c++ makefile using gcc - generate source file list from a list of subfolders
所以我有一些有效的规则:
# Folders
SRCDIR = src
SUBFOLDERS = test test/test2
OBJDIR = obj
# Just for me so I can read my own makefile :o
_TARGET = $@
_DEPEND = $<
# Get sources from /src and /src/test/ and /src/test/test2/
SOURCES = $(wildcard $(SRCDIR)/*.cpp ))
SOURCES = $(wildcard $(SRCDIR)/test/*.cpp ))
SOURCES = $(wildcard $(SRCDIR)/test/test2/*.cpp ))
OBJECTS = $(addprefix $(OBJDIR)/, $(patsubst src/%, %, $(SOURCES:.cpp=.o))
# Main target 'make debug'
debug: debugging $(OBJECTS)
@echo building: gcc $(OBJECTS) -o out.exe
# Compiling each file
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
g++ -c $(_DEPEND) -o $(_TARGET)
debugging:
@echo $(SOURCES)
@echo $(OBJECTS)
注意:我必须手工浏览此代码,因此可能会有一些错误,但希望它清楚我要做什么。
假设我想添加更多源文件子文件夹:src/another, src/andanother
。现在,我必须添加更多SOURCES = ...
行才能做到这一点。有没有办法在规则中做到这一点。我一直在修改它,但我无法提出有效的规则。我想要的是,我将一个新文件夹添加到SUBFOLDERS
列表中,我的代码自动拾取.cpp文件。
注意我不想使用诸如$(shell find ... )
之类的东西,因为Windows发现很烂,我希望它与Possiblt Windows/Linux一样便携。
您可以使用make foreach。喜欢:
SOURCES = $(foreach dir,${SUBFOLDERS},$(wildcard ${dir}/*.cpp))
更多信息:https://www.gnu.org/software/make/manual/html_node/foreach-function.html
相关文章:
- 如何将更多文件夹添加到c++include路径
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 如何在文档文件夹中创建目录
- 使用GCC的C makefile - 从子文件夹列表中生成源文件列表
- 如何使用 Win API 获取文件夹中的文件列表(带过滤器)
- QDIR入口列表可以使用文件夹快捷方式透明地工作
- 读取文件夹中的文件列表时获取分段折叠
- wxWidgets - 将所有文件夹写入列表框
- 如何在Windows中为当前用户获取库文件夹列表
- 按最顶端合并文件夹列表
- 如何获取给定文件夹中具有特定扩展名的文件列表
- 如何在Windows平台中获取远程Windows服务器的共享文件夹的文件列表
- 如何获得ftp服务器中所有文件和文件夹的列表(c++)
- 如何在c++中用一个目录中的所有文件夹填充一个列表框
- Linux dient:获取目录中所有文件夹的列表
- 获取用户计算机上文件名按文本行筛选的文件和文件夹列表
- 获取受UAC保护的文件夹列表
- 获取文件夹中文件的有序列表