为什么这个 makefile 最后会删除两个 .c 文件?
Why does this makefile remove two .c files at the end?
我有一个如下所示的 Makefile:
TARGET = Game
OBJ = Game.o BaseGame.o main.o
PFLAGS = -a
CFLAGS = -c -I/usr/include/python2.7/ -Wall -std=c11
LFLAGS = -lpython2.7
CC = gcc
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) $(OBJ) $(LFLAGS) -o $(TARGET)
%.o: %.c
$(CC) $< $(CFLAGS) -o $@
main.c:
cython main.py $(PFLAGS) --embed
%.c: %.py
cython $< $(PFLAGS)
clean:
rm -f *.o *.c html/* $(TARGET)
当我在终端上运行 "make"时,这是输出:
cython Game.py -a
gcc Game.c -c -I/usr/include/python2.7/ -Wall -std=c11 -o Game.o
cython BaseGame.py -a
gcc BaseGame.c -c -I/usr/include/python2.7/ -Wall -std=c11 -o BaseGame.o
cython main.py -a --embed
gcc main.c -c -I/usr/include/python2.7/ -Wall -std=c11 -o main.o
gcc Game.o BaseGame.o main.o -lpython2.7 -o Game
rm Game.c BaseGame.c
我的问题是,为什么 makefile 完成后会删除 Game.c 和 BaseGame.c?最后一个命令甚至不在 makefile 中!
您是否注意到 clean
部分中的“*.c”?
clean:
rm -f *.o *.c html/* $(TARGET)
make
保留中间文件(.c 文件是中间文件)
使用
.PRECIOUS: <list of file names>
在生成文件中
以下来自https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
.珍贵
The targets which .PRECIOUS depends on are given the following special treatment: if make is killed or interrupted during the execution of their recipes, the target is not deleted. See Interrupting or Killing make. Also, if the target is an intermediate file, it will not be deleted after it is no longer needed, as is normally done. See Chains of Implicit Rules. In this latter respect it overlaps with the .SECONDARY special target.
You can also list the target pattern of an implicit rule (such as ‘%.o’) as a prerequisite file of the special target .PRECIOUS to preserve intermediate files created by rules whose target patterns match that file’s name.
我有一个如下所示的 Makefile:
TARGET = Game
OBJ = Game.o BaseGame.o main.o
PFLAGS = -a
CFLAGS = -c -I/usr/include/python2.7/ -Wall -std=c11
LFLAGS = -lpython2.7
CC = gcc
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) $(OBJ) $(LFLAGS) -o $(TARGET)
%.o: %.c
$(CC) $< $(CFLAGS) -o $@
main.c:
cython main.py $(PFLAGS) --embed
%.c: %.py
cython $< $(PFLAGS)
clean:
rm -f *.o *.c html/* $(TARGET)
当我在终端上运行 "make"时,这是输出:
cython Game.py -a
gcc Game.c -c -I/usr/include/python2.7/ -Wall -std=c11 -o Game.o
cython BaseGame.py -a
gcc BaseGame.c -c -I/usr/include/python2.7/ -Wall -std=c11 -o BaseGame.o
cython main.py -a --embed
gcc main.c -c -I/usr/include/python2.7/ -Wall -std=c11 -o main.o
gcc Game.o BaseGame.o main.o -lpython2.7 -o Game
rm Game.c BaseGame.c
我的问题是,为什么 makefile 完成后会删除 Game.c 和 BaseGame.c?最后一个命令甚至不在 makefile 中!
您是否注意到 clean
部分中的“*.c”?
clean:
rm -f *.o *.c html/* $(TARGET)
make
保留中间文件(.c 文件是中间文件)
使用
.PRECIOUS: <list of file names>
在生成文件中
以下来自https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
.珍贵
The targets which .PRECIOUS depends on are given the following special treatment: if make is killed or interrupted during the execution of their recipes, the target is not deleted. See Interrupting or Killing make. Also, if the target is an intermediate file, it will not be deleted after it is no longer needed, as is normally done. See Chains of Implicit Rules. In this latter respect it overlaps with the .SECONDARY special target.
You can also list the target pattern of an implicit rule (such as ‘%.o’) as a prerequisite file of the special target .PRECIOUS to preserve intermediate files created by rules whose target patterns match that file’s name.