[英]makefile performs target even without any changes
I have a simple makefile
that works fine, but it seems to perform the all
target even if no changes occurred. 我有一个可以正常工作的简单
makefile
,但是即使没有发生任何更改,它似乎也可以执行all
目标。 I would expect a 我期望一个
make: Nothing to be done for 'all'.
Message, but it keeps executing the target whenever I call make
. 消息,但是每当我调用
make
时,它都会继续执行目标。 Here is my simple makefile: 这是我的简单makefile:
BASEDIR = /home/someuser/STA
SRC_DIR = ${BASEDIR}/src
OBJ_DIR = ${BASEDIR}/obj
INC_DIR = ${BASEDIR}/inc
SRC_FILES = $(wildcard ${SRC_DIR}/*.cpp)
SRC_FILES_NOTDIR = $(notdir ${SRC_FILES})
OBJ_FILES_NOTDIR = $(patsubst %.cpp, %.cpp.o, ${SRC_FILES_NOTDIR})
OBJ_FILES = $(addprefix ${OBJ_DIR}/,${OBJ_FILES_NOTDIR})
INC_FILES = $(wildcard ${INC_DIR}/*.h)
all: ${OBJ_FILES}
g++ ${OBJ_FILES} -o program
${OBJ_DIR}/%.cpp.o: ${SRC_DIR}/%.cpp ${INC_FILES}
g++ -I${INC_DIR} -o $@ -c $<
And here is what printed to terminal when I call make
twice: 这是我两次拨打
make
时打印到终端的内容:
$ make
g++ <somedir/file1>.cpp.o <somedir/file2>.cpp.o -o program
$ make
g++ <somedir/file1>.cpp.o <somedir/file2>.cpp.o -o program
Replace all
that is not a file and does not exist (reason why make tries to build it each time) by program
, a real file that make can see. 更换
all
这不是一个文件,不存在(之所以做出尝试构建各一次)的program
,一个真正的文件,使可以看到。 If you really want an all
symbolic target, declare it as phony and add a rule without recipe to tell make that all
depends on program
: 如果您真的想要一个
all
符号目标,请将其声明为phony,并添加一个不带配方的规则,以告知all
取决于program
:
.PHONY: all
all: program
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.