Question

So I have a script, myscript.py, that produces a few output files, out/a.pickle, out/b.pickle, and out/c.pickle

And I have a Makefile that has the rule:

out/a.pickle: data/data.csv
    myscript.py

Now, If I update the script, firstly, make out/a.pickle says there's nothing to be done here, even though the script has been modified. Isn't make supposed to check to see if things have been updated and then run them? Do I need to add myscript.py as a dependency to out/a.pickle, or something?

Secondly, is there a way to handle the fact that the script has multiple output files? Do I need to create a rule for each?

Was it helpful?

Solution

Make does not examine time stamps on executables. Otherwise, you would have to recompile the universe if gcc or echo or the shell is upgraded, and it's a slippery slope anyway; what if libraries or the kernel also changed in a way which requires you to recompile? You need human intervention at some point anyhow. So the designers of make simply drew the line at explicit dependencies.

(GNU Make has a lot of other built-in implicit dependencies, which are convenient. I vaguely believe that the original make didn't have any built-in dependencies at all. Anybody able to confirm?)

You can declare all the outputs in one rule:

out/a.pickle out/b.pickle out/c.pickle: myscript.py data/data.csv
        ./$^

(Notice how the script is included in the dependencies now. You might want to change that after the script is considered stable. Then you'll need to change the action as well.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top