help-make
[Top][All Lists]
Advanced

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

Chicken-n-the-egg: regen .d file w/ missing header


From: Matt England
Subject: Chicken-n-the-egg: regen .d file w/ missing header
Date: Fri, 17 Mar 2006 21:50:33 -0600


I automatically generate header-file dependency makefiles (aka ".d" files) as per:
<http://www.gnu.org/software/make/manual/html_chapter/make_4.html#SEC51>

However, if I rename the header file, and even change this name reference in the .cpp file which includes said header file, my make breaks (see the "make: *** No rule to make target `myheader.h', needed by `main.d'. Stop." error below). Details below; I also include all the start files in the attachment.

It seems to be a "chicken-vs-the-egg", presumably because of the dual-pass functionality of '-include' (I think). Assuming my analysis is correct...what can be done? The only thing I can think of is to manually (within the Makefile) compare all the dates of the .d files and .cpp files and remove the .d files if they are older...essentially doing what I would want the Makefile to do if it didn't have this problem.

But before I write this code, I wanted to check with this email list to see if 1) my analysis was correct, and 2) to see if there's any other way to skin this cat.

Thanks for any help,
-Matt

----------------------- example problem session   -------------------------

address@hidden 9:29pm [~/dfile] 116> dir
total 8
4 -rw-rw-r--  1 mengland mengland   37 2006-03-17 21:26 main.cpp
4 -rwx------  1 mengland mengland 1076 2006-03-17 21:16 Makefile*
0 -rw-rw-r--  1 mengland mengland    0 2006-03-17 21:19 myheader.h
address@hidden 9:29pm [~/dfile] 117> cat main.cpp
#include "myheader.h"
int main() { }
address@hidden 9:29pm [~/dfile] 118> make
-- generating makefile: main.d
g++ -c  main.cpp -o main.o
g++  main.o -o main.exe
address@hidden 9:29pm [~/dfile] 119> mv main.cpp main.cpp.original
address@hidden 9:29pm [~/dfile] 120> cat > main.cpp
#include "myheader2.h"
int main() { }
address@hidden 9:30pm [~/dfile] 121> mv myheader.h myheader2.h
address@hidden 9:30pm [~/dfile] 122> make
make: *** No rule to make target `myheader.h', needed by `main.d'.  Stop.
address@hidden 9:30pm [~/dfile] 123> make clean
rm -rf main.d* main.o main.exe
address@hidden 9:30pm [~/dfile] 124> make
-- generating makefile: main.d
g++ -c  main.cpp -o main.o
g++  main.o -o main.exe
address@hidden 9:30pm [~/dfile] 125> make --version
GNU Make 3.80
Copyright (C) 2002  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
address@hidden 9:31pm [~/dfile] 126> cat /etc/issu
issue      issue.net
address@hidden 9:31pm [~/dfile] 126> cat /etc/issue
Debian GNU/Linux 3.1 \n \l

address@hidden 9:31pm [~/dfile] 127>

----------------------- main.h   -------------------------

----------------------- main.cpp -------------------------

#include "myheader.h"
int main() { }

----------------------- Makefile -------------------------

CPP_FILES := main.cpp
DDD_FILES := $(CPP_FILES:%.cpp=%.d)
OBJ_FILES := $(CPP_FILES:%.cpp=%.o)
EXE_FILES := $(CPP_FILES:%.cpp=%.exe)

all: $(EXE_FILES)

clean:
        rm -rf $(DDD_FILES)* $(OBJ_FILES) $(EXE_FILES)

main.exe: main.o
main.o:   main.cpp
main.d:   main.cpp

NINCLUDE_TARGETS := clean
ifeq ($(strip $(filter $(NINCLUDE_TARGETS),$(MAKECMDGOALS))),)
  -include $(DDD_FILES)
endif

PID := $(shell echo $$$$)
CXX := g++

DFILE_HDR := \
\# DO NOT CHANGE THIS FILE; it was auto-generated by a make process.

# Generate header prerequisites automatically.
# Taken and modified from:
# http://www.gnu.org/software/make/manual/html_chapter/make_4.html#SEC51
$(DDD_FILES):
        @echo -- generating makefile: $@
        @set -e; rm -f $@;                                          \
        echo "$(DFILE_HDR)" > $@;                                   \
        $(CXX) -M $(CXXFLAGS) $< > address@hidden(PID);                      \
        sed 's,^.*\.o[ :]*,$(@:%.d=%.o) $@: ,g' < address@hidden(PID) >> $@;  \
        rm -f address@hidden(PID)

$(EXE_FILES):
           $(CXX) $(LDFLAGS) $^ -o $@

$(OBJ_FILES):
                $(CXX) -c $(CXXFLAGS) $< -o $@

Attachment: files.tar.gz
Description: Binary data


reply via email to

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