makefile - 在构建 .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
我试过删除目标.PHONY
和clean
,但它没有帮助。
我该如何make
停止rm hello.cc
?
解决方案
该文件被视为中间文件。为了防止它被删除,您所要做的就是在 makefile 中的任何位置将其作为目标或先决条件提及,如下所示:
sources: $(patsubst %.so,%.cc,$(MAKECMDGOALS))
推荐阅读
- java - 使用 webview 和 Fragment 在 android 中动态添加选项卡
- javascript - Handlebars 动态数据显示:“Uncaught SyntaxError: Invalid or unexpected token”
- javascript - 如何使 javascript 函数永远不会返回与以前相同的值?
- reactjs - Regrex to exclude double space in Textfields input
- python-3.x - 覆盆子 pi4 上的英特尔 Realsense 和烧瓶 - RuntimeError: failed to set power state
- javascript - 使用 Javascript 根据匹配的属性过滤掉数组
- excel - 将不同范围添加到图表中的同一系列
- android - 如何在xml android中制作这种视图?
- htmx - 如何向当前元素的相对位置的元素发送事件
- pandas - 在 pandas 中查询/过滤,同时保留超出查询范围的时间点值(时间序列数据)