在没有控制的情况下构建.so后,请删除.cc [英] make remove .cc after building .so without control

查看:47
本文介绍了在没有控制的情况下构建.so后,请删除.cc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我遇到了 Makefile 的一种极端奇怪的行为:

Recently I encountered an extremly strange behavior of 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

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

When I build hello.so in current dir using make -f ../Makefile hello.so, it deletes .cc after building .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 ,但这无济于事.

I tried remove target .PHONY and clean, but it doesn't help.

如何停止 rm hello.cc 中的 make ?

推荐答案

该文件被视为

That file is considered an intermediate file. All you have to do to keep it from being removed is mention it as a target or prerequisite anywhere in the makefile, like this:

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

这篇关于在没有控制的情况下构建.so后,请删除.cc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆