首页 > 解决方案 > 在构建 .so 后删除 .cc 不受控制

问题描述

最近我遇到了一个非常奇怪的行为Makefile

在当前目录中,我有hello.pyx

#cython: language_level=3

print("Hello, world!")

..我有Makefile

includes=$(shell python3 -c "import sysconfig; print(sysconfig.get_path('include'))")
CFLAGS=-shared -pthread -fPIC -fwrapv -Oz -flto -Wall -fno-strict-aliasing -I$(includes)
LDFLAGS=-Wl,-plugin-opt=O2

%.cc: %.pyx
        cython --cplus $< -o $@

%.so: %.cc
        clang++ ${CFLAGS} ${LDFLAGS} $< -o $@

clean:
        rm -f *.cc *.so

.PHONY: clean

当我使用 构建hello.so当前目录时,它会在构建后make -f ../Makefile hello.so删除:.cc.so

cython --cplus hello.pyx -o hello.cc
clang++ -shared -pthread -fPIC -fwrapv -Oz -flto -Wall -fno-strict-aliasing -I/usr/include/python3.7m -Wl,-plugin-opt=O2 hello.cc -o hello.so
rm hello.cc

我试过删除目标.PHONYclean,但它没有帮助。

我该如何make停止rm hello.cc

标签: makefilecython

解决方案


该文件被视为中间文件。为了防止它被删除,您所要做的就是在 makefile 中的任何位置将其作为目标或先决条件提及,如下所示:

sources: $(patsubst %.so,%.cc,$(MAKECMDGOALS))

推荐阅读