Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

makefile can a target have multiple words?

Tags:

makefile

I want to run my make task with .. make git pull

.PHONY: What do I put here? git pull ping suggests 3 targets right?

git pull:
    ~/ansible-ctrl/scripts/04-pull-git-latest.sh

ping:
    ~/ansible-ctrl/scripts/06-ping-ansible.sh

make git pull .. works sometimes, seems a bit hit and miss.

What do I put in the .PHONY bit?

Is this multiple word target approach valid?

Would problems arise if I used arguments?

Could I have a simple example that uses this approach correctly please (if there is such a thing)?

like image 890
danday74 Avatar asked Feb 05 '23 08:02

danday74


2 Answers

On the topic of rule syntax the GNU make manual reads:

The targets are file names, separated by spaces.

So in your example make sees two targets, git and pull. There was a question before on using spaces in a target. The answers however seem clunky (or don't even seem to work judging from the comments).

In general GNU make doesn't handle white spaces in filenames (and thus targets/prerequisites) well. This question (6 years ago!) references a bug about it, which still seems to be open.

My advice, just like @uzsolt pointed out in the comments, drop the space!

like image 132
super schaap Avatar answered May 05 '23 09:05

super schaap


As @sycko points out, make sees two targets git and pull, which are jointly made by the actions that you provided (this behaviour is occasionally useful).

It seems worth pointing out, though, that the reason that it sometimes works when you type make git pull, is that make interprets that invocation as a request that it makes both the git and the pull targets (this, also, is occasionally useful). Thus make pull git would probably have the same effect. That is, it only works by accident.

I'm not completely sure why this sometimes fails; but it's not too hard to confuse make's dependency logic, and I'm not particularly surprised at this construction behaving unpredictably.

like image 25
Norman Gray Avatar answered May 05 '23 08:05

Norman Gray