2
votes

At the make manual said:

During the first phase it reads all the makefiles, included makefiles, etc. and internalizes all the variables and their values, implicit and explicit rules, and constructs a dependency graph of all the targets and their prerequisites.

I don't understand how the dependency graph constructed? Consider the following makefile:

%.o: %.z
    echo This is overriden implicit rule
default: foo.o

clean:
    rm -f fmake test_second
%.o: %.c
    echo This is customized implicit rule

After make command

echo This is customized implicit rule
This is customized implicit rule

is displayed, but I'm expexted that

echo This is overriden implicit rule
This is overriden implicit rule

will be, because in make rule only overrides if both the target and the prerequisite patterns match. In this case I think that %.o: %.z implicit rules matched to pattern already.

1
Let me guess: foo.c exists, but foo.z does not. Am I right?Beta
@Beta foo.z is existsuser2889159
There's no way we can tell you what's going on based on this description. It all depends on what files exist etc. The simplest thing for you to do is run make with the -d option and make will print out exactly what steps its following. If indeed there is a foo.z file here then the behavior you're seeing should not happen given the makefile here. So, something in your actual setup is not as you've described it here.MadScientist

1 Answers

4
votes

I've been doing a lot of work with Makefiles in a very, very large codebase for the last year or so. I am heartily sick of make(1s)!

The answer, in general, is "last declaration wins". You also have to contend with the default make suffix rules (on Solaris these are found in /usr/share/lib/make/make.rules).

So if you want your overridden implicit rule to stand, place it last in the Makefile hierarchy. If you want to flush the suffixes list, you can do either or both of

1 add a .SUFFIXES:

line to your Makefile,

2 call make with -r

in MAKEFLAGS (env var) or on the make invocation command line.

[Also, you can prepend "@" to the start of your command to just see the output of it, rather than the

echo [output goes here]

as well as the actual

[output goes here]

You could also gather insight by using one of the debugging options that make(1s) allows. On Solaris, that's -d, -dd, -D or -DD. For GNU Make, it's -d or --debug. Caution, though, dump the output from the command to a file, because there is a lot of it.

You might want to read http://freecode.com/articles/what-is-wrong-with-make, as a piece of on-the-side illumination.