3

( my question is different from Force Makefile to execute script before building targets )

I've got the following Makefile:

.PHONY: dump_params all

all: tmpA

tmpA: tmpB tmpC dump_params
    cat $(filter tmp%,$^) > $@

tmpB: dump_params
    touch $@

tmpC: dump_params
    touch $@

dump_params:
    echo "Makefile was run." >> config.txt

with the target dump_params I want to create/append a file each time a new target is invoked (to keep track of the version of the tools used). However, when I call

make tmpA

all the targets are built from scratch

$ make tmpA
echo "Makefile was run " >> config.txt
touch tmpB
touch tmpC
cat tmpB tmpC > tmpA

$ make tmpA
echo "Makefile was run." >> config.txt
touch tmpB
touch tmpC
cat tmpB tmpC > tmpA

How can I prevent Make to re-build everything because of that target 'dump_params'? Is there a another way to create this kind of log file ?

EDIT: I'm using a parallel make (option -j). Defining a macro to create the file in the statements section is not an option.

Community
  • 1
  • 1
Pierre
  • 34,472
  • 31
  • 113
  • 192

3 Answers3

5

Use order-only prerequisites?

.PHONY: dump_params all

all: tmpA

tmpA: tmpB tmpC | dump_params
    cat $(filter tmp%,$^) > $@

tmpB: | dump_params
    touch $@

tmpC: | dump_params
    touch $@

dump_params:
    echo "Makefile was run." >> config.txt
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
5

Another option is to use immediately expanded shell functions, like:

__dummy := $(shell echo "Makefile was run." >> config.txt)

Since it's immediately expanded the shell script will be invoked once, as the makefile is read in. There's no need to define a dump_params target or include it as a prerequisite. This is more old-school, but has the advantage that it will run for every invocation of make, without having to go through and ensure every target has the proper order-only prerequisite defined.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
0

Non-answer, but snakemake (and there are others, I suspect) supports tracking of rules (the code), parameters, inputs, and executable versions.

https://bitbucket.org/johanneskoester/snakemake

seandavi
  • 2,818
  • 4
  • 25
  • 52
  • Thank you Sean, but I'd like to stick to qmake + SGE ( http://gridscheduler.sourceforge.net/htmlman/htmlman1/qmake.html ) – Pierre Oct 30 '13 at 14:59