ynimous
ynimous

Reputation: 5162

dependency on file created by recursive make

Here's a minimal example of what I'm trying to do.

Directory structure:

.
├── Makefile
└── subdir
    ├── a
    └── Makefile

./subdir/Makefile:

a.copy: a
        cp a a.copy

./Makefile:

.PHONY: build_subdir

a.copy: subdir/a.copy
        cp subdir/a.copy a.copy
build_subdir:
        $(MAKE) -C subdir

subdir/a.copy: build_subdir

The first time I run make, everything's fine:

$  make            
make -C subdir
make[1]: Entering directory `/home/kkourt/src/tests/make/subdir'
cp a a.copy
make[1]: Leaving directory `/home/kkourt/src/tests/make/subdir'
cp subdir/a.copy a.copy

Re-runing make is also fine (nothing happens):

$ make
make -C subdir
make[1]: Entering directory `/home/kkourt/src/tests/make/subdir'
make[1]: `a.copy' is up to date.
make[1]: Leaving directory `/home/kkourt/src/tests/make/subdir'

If I update subdir/a, however, ./a is not updated:

$ touch subdir/a      
$ make
make -C subdir
make[1]: Entering directory `/home/kkourt/src/tests/make/subdir'
cp a a.copy
make[1]: Leaving directory `/home/kkourt/src/tests/make/subdir'

If I run make a second time, ./a gets updated

$ make
make -C subdir
make[1]: Entering directory `/home/kkourt/src/tests/make/subdir'
make[1]: `a.copy' is up to date.
make[1]: Leaving director

Why does this happen? shouldn't the check of whether subdir/a.copy is older than a.copy happen after the build_subdir target is finished since it's its dependency? Is there a way to fix this?

Edit:

As MadScientist suggested, I added a dummy recipe and it works:

subdir/a.copy: build_subdir
    @:

Upvotes: 2

Views: 68

Answers (1)

MadScientist
MadScientist

Reputation: 101081

Because your rule subdir/a.copy: build_subdir has no recipe, make "knows" that it can't actually change the timestamp on subdir/a.copy.

You need add a dummy recipe to it, maybe like this:

subdir/a.copy: build_subdir ;

(note I can't test this right now but I think it'll work).

Upvotes: 3

Related Questions