1

当我这样做make clean时抱怨丢失的文件。特别是它抱怨mapnameserver.h包含在nstest.ccand中nstime.cc。我认为这样做make clean会忽略所有其他目标,甚至是隐含的目标。

我想要的是能够做到make clean并且make vectornameserver不会抱怨 nstest.cc 和 nstime.cc 包含的我尚未编写的标头。这可能吗?

以下是 src 目录中的文件

nameserverinterface.h
nstest.cc
nstime.cc
vectornameserver.cc
vectornameserver.h

这是 Makefile

#
# Makefile for CPP
#

# Compiler and compiler options:
CC        = /usr/local/bin/clang++
CXX       = /usr/local/bin/clang++
CXXFLAGS  = -c -pipe -O2 -Wall -W -ansi -pedantic-errors
CXXFLAGS += -Wmissing-braces -Wparentheses -Wold-style-cast
CXXFLAGS += -std=c++11 -stdlib=libc++ -nostdinc++
CXXFLAGS += -I/Users/einar/devel/libcxx/include/

LDFLAGS   = -stdlib=libc++
LDLIBS    = -L/Users/einar/devel/libcxx/lib/


SRCDIR      = ../src
LIBDIR      = ../lib
BINDIR      = ../bin
DEPDIR      = ../dep
VPATH       = $(SRCDIR):$(LIBDIR):$(BINDIR):$(DEPDIR)
LIB_INSTALL =
BIN_INSTALL =

SRC       = $(wildcard $(SRCDIR)/*.cc)
OBJ       = $(notdir $(SRC:.cc=.o))
DEP       = $(addprefix $(DEPDIR)/, $(notdir $(SRC:.cc=.d)))
PROGS     = vectornameserver

MAKEDEPEND  = $(CXX) -MM $(CPPFLAGS) -o $*.d $<
CP          = /bin/cp

###
# 
# Phony targets
#
###
.PHONY: all
all: $(PROGS)

.PHONY: folder_setup
folder_setup:
    mkdir -p $(SRCDIR)
    mkdir -p $(LIBDIR)
    mkdir -p $(BINDIR)
    mkdir -p $(DEPDIR)

.PHONY: clean
clean:
    @$(RM) $(OBJ)

.PHONY: cleaner
cleaner:
    @$(RM) $(OBJ)
    @$(RM) $(PROGS)
    @$(RM) $(DEP)
    @$(RM) $(wildcard $(DEPDIR)/*.d*)

###
#
# Set up targets for program files in this section
# a rule should look like:
# program: obj1.o obj2.o ...
#
###
vectornameserver : vectornameserver.o

###
#
# In this section automatic dependencies are handled.
#
###
$(addprefix $(DEPDIR)/, %.d): %.cc
    @set -e; rm -f $@; \
    $(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
    sed 's,\($*\)\.o[ :]*,\1.o $@: ,g' < $@.$$$$ \
    > $@; rm -f $@.$$$$

###
#
# Include the automatically generated dependency files
#
###
include $(DEP)

提前致谢。

4

1 回答 1

1

问题是你include在makefile中有一个指令。这隐含地使所有包含的依赖文件成为隐式目标,必须在主目标运行之前刷新这些目标。正是这些规则运行编译器并为您提供错误。

因为如果你只是在做一个 make clean,通常你不需要/不需要依赖文件,通常的做法是在ifs 周围包裹适当的 s include

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),cleaner)
-include $(DEP)
endif
endif

如果您这样做,这将避免尝试包含 depfile(并因此重新生成它们)make cleanmake cleaner. 此外,-当您第一次运行 make 时,include 上的前缀会抑制有关 depfile 不存在的警告(如果需要,它将(重新)生成它们并重新读取 makefile 和 depfile。)

于 2013-02-23T23:28:14.573 回答