Вопрос

Considering this (very) simple Makefile,

all: a b
    @echo done
a:
    touch $@
b:
    touch $@

I didn't get the behaviour I expected.

In fact, I wish my rule "all" to be executed only if one of its depencies isn't up to date.

However on first $ make I get

touch a
touch b
done

And on others

done

I undenstand that "up to date" normally qualify a file but... Is there any way to have rule "all" considered up to date when all its dependies are ?

Thanks a lot,

ps: I know the trick $ touch all, but that's not the point

Это было полезно?

Решение

No. If the target does not exist then make will always run the recipe.

There are hacky ways that your all recipe could check to see if any of the prerequisites had been built and behave differently if so. At least, if you're using GNU make.

ETA:

One way would be to add a $(eval BUILT = 1) to each target, then in the all target you can see if BUILT is set. This requires a moderately recent version of GNU make:

BUILT =

all: a b
        @[ -n '$(BUILT)' ] && echo done
a:
        touch $@ $(eval BUILT = 1)
b:
        touch $@ $(eval BUILT = 1)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top