Makefile 过滤掉不从文件列表中删除文件
Makefile filter-out not removing a file from a list of files
我刚开始使用 Make,我有这个文件:
CODE_FILES := $(shell find . -regextype posix-egrep -regex ".*/[a-z_]*[a-z]\.(cpp|h)")
EXCLUDE := "./bytecode/operators.cpp"
CODE_FILES_COPY = $(filter-out $(EXCLUDE), $(CODE_FILES))
# All nested header files (.h) and source files (.cpp)
# all: a.out
a.out: main.cpp $(CODE_FILES_COPY)
@echo $(EXCLUDE)
@echo $(CODE_FILES_COPY)
@echo $(CODE_FILES)
clang++ main.cpp -o a.out -pthread -std=c++17 -g \
-Wall -Wpedantic -Wextra \
-D DO_CACHE_DECL
# Define: -D PLUMBER_DEBUG -D DO_CACHE_DECL -D TRACKER_DEBUG
./bytecode/operators.out: ./bytecode/operators.cpp
clang++ ./bytecode/operators.cpp -o ./bytecode/operators.out -std=c++17 \
-Wall -Wpedantic -Werror
make clean:
rm -f a.out ./bytecode/operators.out
然而,CODE_FILES_COPY
和 CODE_FILES
完全相同(一长串文件包含例如 ./foo/bar/baz.cpp
)- filter-out
似乎没有用。在这种情况下我做错了什么?
我也可能在文件的其余部分做错了一些事情,但重点是如果我修改 ./bytecode/operators.cpp
会重建 a.out
,这是我不想发生的,因为重建整个项目需要很长时间,编译时间很少 operators.cpp
.
您的 EXCLUDE :=
中有引号围绕 "./bytecode/operators.cpp"
。删除它们,您的排除将匹配。您的文件在列表中不会有引号。
尝试使用
$(info CODE_FILES: $(CODE_FILES))
$(info EXCLUDE: $(EXCLUDE))
看区别
我刚开始使用 Make,我有这个文件:
CODE_FILES := $(shell find . -regextype posix-egrep -regex ".*/[a-z_]*[a-z]\.(cpp|h)")
EXCLUDE := "./bytecode/operators.cpp"
CODE_FILES_COPY = $(filter-out $(EXCLUDE), $(CODE_FILES))
# All nested header files (.h) and source files (.cpp)
# all: a.out
a.out: main.cpp $(CODE_FILES_COPY)
@echo $(EXCLUDE)
@echo $(CODE_FILES_COPY)
@echo $(CODE_FILES)
clang++ main.cpp -o a.out -pthread -std=c++17 -g \
-Wall -Wpedantic -Wextra \
-D DO_CACHE_DECL
# Define: -D PLUMBER_DEBUG -D DO_CACHE_DECL -D TRACKER_DEBUG
./bytecode/operators.out: ./bytecode/operators.cpp
clang++ ./bytecode/operators.cpp -o ./bytecode/operators.out -std=c++17 \
-Wall -Wpedantic -Werror
make clean:
rm -f a.out ./bytecode/operators.out
然而,CODE_FILES_COPY
和 CODE_FILES
完全相同(一长串文件包含例如 ./foo/bar/baz.cpp
)- filter-out
似乎没有用。在这种情况下我做错了什么?
我也可能在文件的其余部分做错了一些事情,但重点是如果我修改 ./bytecode/operators.cpp
会重建 a.out
,这是我不想发生的,因为重建整个项目需要很长时间,编译时间很少 operators.cpp
.
您的 EXCLUDE :=
中有引号围绕 "./bytecode/operators.cpp"
。删除它们,您的排除将匹配。您的文件在列表中不会有引号。
尝试使用
$(info CODE_FILES: $(CODE_FILES))
$(info EXCLUDE: $(EXCLUDE))
看区别