Using Makefiles in Python projects

Cameron Simpson cs at cskk.id.au
Thu Nov 7 19:14:31 EST 2019


On 08Nov2019 10:30, David <bouncingcats at gmail.com> wrote:
>On Fri, 8 Nov 2019 at 09:43, Cameron Simpson <cs at cskk.id.au> wrote:
>[...]
>
>>     _help:
>>             @echo '_build: make $(py_static_bundle)'
>>             @echo '_deploy_tip: formally deploy the current tip to the dev host dev tree:'
>>             @echo '_sync_dev: rsync the current working files into the dev tip tree'
>
>[...]
>
>> Things to note:
>>
>> "Virtual targets" are actions rather than result files, and start with
>> an underscore.
>>
>> The default target is _help, which recites a description of the other
>> targets.
>
>Hi, as you might be aware, the above recipe will not be run if a file
>named '_help' exists.

Hence the funny name. I don't make files whole names begin with 
underscores.

>The Gnu make documentation term for what you call "virtual targets"
>is "phony targets", and it discusses them here:
>https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets
>
>I would add the line:
>.PHONY: _help
>And similar for all the other phony targets.

If you're using GNU make, go right ahead. But that approach treats 
.PHONY like a label to be applied to _its_ dependents. Probably that's 
exactly what it does. However, that is the inverse of the normal 
target:dependent relationship one puts in Makefiles.

My personal approach is this:

    _always:
        :

    _help:  _always

i.e. make the "phony" targets depend on "_always", which are thus always 
out of date and thus will always run. You've still to avoid making a 
"_always", but that is a smaller thing than the whole "_*" space, if 
that is a concern.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list