Bug 51341 - make cannot detect head file change by dependency file with gcc 4.6.1 on ubuntu 11.10
Summary: make cannot detect head file change by dependency file with gcc 4.6.1 on ubun...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-28 22:46 UTC by davidz
Modified: 2011-12-09 14:06 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description davidz 2011-11-28 22:46:01 UTC
The issue is that make command cannot detect changes in head file. i.e, if I touch "test.h", make command will not recompile. 

This works with gcc 4.5.4 on the same OS.

--test.h--
#include <iostream>
void hello()
{
std::cout << "Hello\n";
}

--test.cc--
#include "test.h"
int main()
{
hello();
}

--Makefile--
sources := test.cc	
objects := test.o
depends := test.d
main := test

$(main) : % : %.o 
	g++ $< -o $@

%.o : %.cc
	g++ -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" $< -o $@

clean :
	-rm -rf $(objects) $(depends) $(main)

ifneq ($(MAKECMDGOALS),clean)
-include $(depends)
endif
Comment 1 Andrew Pinski 2011-11-28 22:54:33 UTC
-MT changes the target to the .d rather than adding it to the .o one.
Comment 2 Andrew Pinski 2011-11-28 22:57:30 UTC
This was an expected change, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12448 .  Which says you need another -MT option to include the .o target.
Comment 3 davidz 2011-11-29 14:56:41 UTC
I am a little confused. -MT will create .d file. Then make command will include .d and re-compile if dependency file changes. The issue is that g++ 4.6.1 doesn't re-compile if I touch .h. Does this mean my test.d format is wrong? If I need another -MT, what syntax it should be? Thanks a lot!

(In reply to comment #2)
> This was an expected change, see
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12448 .  Which says you need
> another -MT option to include the .o target.
Comment 4 Jonathan Wakely 2011-11-29 15:26:29 UTC
(In reply to comment #3)
> I am a little confused. -MT will create .d file. Then make command will include
> .d and re-compile if dependency file changes. The issue is that g++ 4.6.1
> doesn't re-compile if I touch .h. Does this mean my test.d format is wrong? If

Did you read the linked bug report?  Did you look at the content of test.d?

> I need another -MT, what syntax it should be? Thanks a lot!

g++ -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" "-MT$@" $< -o $@
Comment 5 davidz 2011-12-09 14:06:22 UTC
This did solve the issue. Thanks a lot for the explain and syntax!

(In reply to comment #4)
> (In reply to comment #3)
> > I am a little confused. -MT will create .d file. Then make command will include
> > .d and re-compile if dependency file changes. The issue is that g++ 4.6.1
> > doesn't re-compile if I touch .h. Does this mean my test.d format is wrong? If
> 
> Did you read the linked bug report?  Did you look at the content of test.d?
> 
> > I need another -MT, what syntax it should be? Thanks a lot!
> 
> g++ -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" "-MT$@" $< -o $@