Linux make 命令正在删除源文件

Linux make command is deleting a source file

我继承了一个项目文件,其中有一个 Makefile,它正在做我以前从未见过的事情 -- 它正在注入一个 rm 命令。我找不到 rm 命令的任何原因,所以我遗漏了一些非常明显或非常深奥的东西。

谢谢

运行 make 的结果是:

bison  --defines --xml --graph=calc.gv -o calc.c calc.y
Bison flags = 
cc    -c -o calc.o calc.c
Making BASE =  calc
cc  -o calc calc.o
Done making BASE
rm calc.c      <======== WHERE IS THIS COMING FROM?

Makefile 是:

BASE = calc
BISON = bison
XSLTPROC = xsltproc

all: $(BASE)

%.c %.h %.xml %.gv: %.y
    $(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $<
    @echo "Bison flags = " $(BISONFLAGS)

$(BASE): $(BASE).o
    @echo "Making BASE = " $(BASE) 
    $(CC) $(CFLAGS) -o $@ $^
    @echo "Done making BASE"

run: $(BASE)
    @echo "Type arithmetic expressions.  Quit with ctrl-d."
    ./$<

html: $(BASE).html
%.html: %.xml
    $(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<

CLEANFILES = $(BASE) *.o $(BASE).[ch] $(BASE).output $(BASE).xml $(BASE).html $(BASE).gv

clean:
    @echo "Running clean" $(CLEANFILES)
    rm -f $(CLEANFILES)

参见https://www.gnu.org/software/make/manual/make.html#Chained-Rules

The second difference is that if make does create b in order to update something else, it deletes b later on after it is no longer needed. Therefore, an intermediate file which did not exist before make also does not exist after make. make reports the deletion to you by printing a rm -f command showing which file it is deleting.