How to build several targets by invoking only one command?
I got a Makefile like the following:
.PHONY: all
all: aaa.2 bbb.2
aaa.2 : aaa.1 common.1
create_2 $@
bbb.2 : bbb.1 common.1
create_2 $@
The program create_2 takes long time to start, but i开发者_Python百科s able to create several %.2 files at once, therefore I would like to invoke create_2 only once.
For example if common.1 has changed, I would like create_2 aaa.2 bbb.2
to be invoked instead of both create_2 aaa.2
and create_2 bbb.2
.
I tried with a create_2 $?
recipe in the 'all' target, but without success.
I'm searching for a solution that is working with both gmake and clearmake (in gnu compatibility mode).
Make is basically file-oriented, and what you want is something process-oriented, so... maybe that excuses the fact that this is a horrible kludge:
.PHONY: all
all: marker
aaa.2 : aaa.1 common.1
@touch $@
bbb.2 : bbb.1 common.1
@touch $@
marker: aaa.2 bbb.2
create_2 $?
@touch $@
Note that marker
is a dummy file, and that the rules for aaa.2
and bbb.2
touch those targets but don't really rebuild them. It's ugly, but it does the job.
This hack might help you out:
.PHONY: all
all: file1 file2
>---@if [ -f work ]; then \
>--->---touch file1 file2; \
>--->---echo "touch file1 file 2"; \
>---fi
>---rm -f work
file1:
>---touch work
file2:
>---touch work
This causes both files to be rebuilt if any of them need rebuilding. You could probably use this hack, create work1
and work2
files instead of only work
and use a more complicated if
condition to rebuild just what needs rebuilding. Works with GNU Make at least.
精彩评论