3

I have a Makefile that says:

aaa:bbb
    echo 456
bbb:
    echo 123

When there is no bbb file in the directory, these two rules will execute regardless of whether there is an aaa file or not.

But why?

1 Answer 1

4

You have said that aaa depends on bbb. This means that to create or update aaa, the bbb target needs to be made.

If aaa and bbb exist as files in the current directory, and if aaa is newer than bbb, then neither target needs to be rebuilt, but if aaa is outdated in comparison to bbb or if bbb is missing, then aaa will have to be built to ensure that it is up to date (if bbb is missing, this would need to involve rebuilding bbb too).

The example below shows that if the two targets actually create the relevant files, then the targets do not get built upon a second invocation of make. If the bbb file is removed, both targets are rebuilt:

$ cat Makefile
aaa: bbb
        echo 456
        touch aaa

bbb:
        echo 123
        touch bbb
$ rm -f aaa bbb
$ make
echo 123
123
touch bbb
echo 456
456
touch aaa
$ make
`aaa' is up to date.
$ rm bbb
$ make
echo 123
123
touch bbb
echo 456
456
touch aaa
1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.