help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dependency generation: 'make clean' problem


From: matthias_k
Subject: dependency generation: 'make clean' problem
Date: Thu, 11 Nov 2004 22:26:46 +0100
User-agent: Mozilla Thunderbird 0.8 (X11/20040926)

Hello,

I'm working on a makefile with automatic dependency generation for a C++ program and stumbled over an annoying problem:

Since I am including the generated dependencies files to create the object targets, they are processed *always*, even when I call 'make clean'. Calling clean when no dependency files exist to be included, they will be generated -- and thereafter deleted by the 'rm' command again...

That's not really the behaviour I want. Is there any way to tell make to NOT include and generate the dependency files when "make clean" is called?

Thanks in advance,
Matthias

PS: In case you want to see the source, here's the Makefile, unaltered with all its potential errors *g* (I'm still working on it):

# begin Makefile

TARGET   := gtkmm.elf

SRC_TYPE := cpp
INC_TYPE := h

REL_DIR  := Release
DBG_DIR  := Debug

CXX      := g++
DEBUG    := -g
OPT      := -o2

# Additional directories (system dirs and subdirs of ./ need not be specified)
USER_LIB_DIRS :=
USER_INC_DIRS :=

# Libraries to explicitly link
LIBRARIES := $(shell pkg-config gtkmm-2.4 --libs)

SOURCES := \
main.cpp

LDFLAGS := $(USER_LIB_DIRS) -Wall -pedantic -ansi -std=c++98 $(OPT) $(DEBUG)
CXXFLAGS := $(USER_INC_DIRS) -Wall -pedantic -ansi -std=c++98 -c $(DEBUG)

RM         := rm -rf
ROOT_DIR   := .
OUT_DIR := $(shell if [ -z $(DEBUG) ] ; then echo "$(ROOT_DIR)/$(REL_DIR)" ; else echo "$(ROOT_DIR)/$(DBG_DIR)" ; fi) LOCAL_DIRS := $(shell for FILE in $(ROOT_DIR)/* ; do if [ -d $$FILE ] && [ "$$FILE" != $(OUT_DIR) ]; then echo -n "$$FILE " ; fi ; done)
OUT_FILE   := $(ROOT_DIR)/$(TARGET)
OBJECTS    := $(SOURCES:%.$(SRC_TYPE)=$(OUT_DIR)/%.o)

vpath
vpath %.$(SRC_TYPE) $(LOCAL_DIRS)
vpath %.$(INC_TYPE) $(LOCAL_DIRS)
vpath %.d $(OUT_DIR)

# ---------------------------------------------------------------------------------------------
# Rule Patterns
# ---------------------------------------------------------------------------------------------
$(OUT_DIR)/%.d: %.$(SRC_TYPE)
        @mkdir -p $(OUT_DIR) ; echo ; echo "Processing $(@:.d=.o) ..." ; \
        echo "... creating dependencies for $^" ; \
        set -e; $(RM) $@; \
        $(CXX) -MM -MG -P -w $(CXXFLAGS) $< > $@

$(OUT_DIR)/%.o: %.$(SRC_TYPE) $(OUT_DIR)/%.d
        @mkdir -p $(OUT_DIR) ; set -e ; echo "... building $@" ; \
        $(CXX) $(CXXFLAGS) $< -o $@ ; \
        echo "Success!" && echo

# ---------------------------------------------------------------------------------------------
# Build Targets
# ---------------------------------------------------------------------------------------------

all: $(OUT_FILE) finish

-include $(SOURCES:%.$(SRC_TYPE)=$(OUT_DIR)/%.d)

$(OUT_FILE): $(OBJECTS)
        @set -e; echo "Processing $@ ..." ; echo "... building $@" ; \
        $(CXX) $(LDFLAGS) -o $(ROOT_DIR)/$@ $(OBJECTS) $(LIBRARIES) ; \
        echo "Success!" ; echo

clean:
        @echo "Clean sweep!" ; \
        $(RM) $(OUT_FILE) $(OBJECTS) $(OUT_DIR)/*.d

finish:
        @echo -n "Compilation finished at " ; date ; echo

.PHONY: clean finish

# eof


reply via email to

[Prev in Thread] Current Thread [Next in Thread]