Here's my problem:
I have the following Makefile:
a.d:
gcc -m32 -MM -o $@ a.c
sed 's!a.o!$@ a.o!' --in-place $@
a.o:
gcc -c -m32 -o $@ a.c
all: a.d a.o
a.d a.o: a.c a.h
The contents of a.d are:
a.d a.o: a.c a.h
I'm having 2 problems. 1, after running "make all" if I run:
touch a.h
make a.d
I see this:
gcc -m32 -MM -o a.d a.c
sed 's!a.o!a.d a.o!' --in-place a.d
make: 'a.d' is up to date.
The a.d rule clearly ran, why do I see "make: 'a.d' is up to date."?
2, after running "make all" when I run this:
touch a.h
make a.o
I see this:
gcc -m32 -MM -o a.d a.c
sed 's!a.o!a.d a.o!' --in-place a.d
gcc -c -m32 -o a.o a.c
Why did it also run the a.d rule? There are no dependencies on it.
What I really don't understand is when I replace "-include a.d" with the contents of a.d in the make file, for example:
#-include a.d
a.d a.o: a.c a.h
I don't see either problem. Shouldn't the include statement make it as if the include file were included directly in the same make file?
This is what my a.h looks like:
#define FOO 0
And this is a.c:
#include <stdio.h>
#include "a.h"
void foo(void)
{
printf("foo %d", FOO);
}
I'm using Cygwin 64-bit. Here's my output from make -v:
$ make -v
GNU Make 4.1
Built for x86_64-unknown-cygwin
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <
http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.