[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Make does not throw an error for target without a recipe?
From: |
Martin Dorey |
Subject: |
RE: Make does not throw an error for target without a recipe? |
Date: |
Thu, 26 Jun 2014 21:02:25 +0000 |
> I'm afraid none of this exercise is helpful for solving the problem
Perhaps putting my point in different words will better convey it: you could
simply adjust your expectation, to regard this as a failure:
make: Nothing to be done for `foo'.
But...
> To put it concisely: how do I get Make to *fail* if it cannot
> create one of the targets?
... if you're really insistent on "get Make to return a non-zero exit status if
I haven't told it how to create one of the targets" then, per
http://www.gnu.org/software/make/manual/make.html#Last-Resort, you could do:
address@hidden:~/tmp/batrick-2014-06-26$ cat test.mk
TARGETS = foo
all: $(TARGETS)
$(TARGETS): /etc/passwd
%::; @echo no recipe for $@ 1>&2 && exit 1
address@hidden:~/tmp/batrick-2014-06-26$ rm foo
address@hidden:~/tmp/batrick-2014-06-26$ make -f test.mk foo; echo $?
no recipe for foo
make: *** [foo] Error 1
2
address@hidden:~/tmp/batrick-2014-06-26$
If Make doesn't think foo needs an update, mind:
address@hidden:~/tmp/batrick-2014-06-26$ touch foo
address@hidden:~/tmp/batrick-2014-06-26$ make -f test.mk foo; echo $?
make: `foo' is up to date.
0
address@hidden:~/tmp/batrick-2014-06-26$
-----Original Message-----
From: Patrick Donnelly [mailto:address@hidden
Sent: Thursday, June 26, 2014 13:43
To: Martin Dorey
Cc: address@hidden
Subject: Re: Make does not throw an error for target without a recipe?
Hi Martin,
On Thu, Jun 26, 2014 at 4:33 PM, Martin Dorey <address@hidden> wrote:
>> Why is it trying to build target test.mk...???
>
> That's explained by
> https://www.gnu.org/software/make/manual/make.html#Remaking-Makefiles.
Thanks, that makes sense.
>> Then it decides it was successful?
>
> For some value of "successful". With your makefile:
>
> address@hidden:~/tmp/batrick-2014-06-26$ make -f test.mk foo
> make: Nothing to be done for `foo'.
> address@hidden:~/tmp/batrick-2014-06-26$
>
> If we add a semicolon, telling make that the recipe to update foo is empty:
>
> address@hidden:~/tmp/batrick-2014-06-26$ sed -i -e 's/passwd/passwd;/' test.mk
> address@hidden:~/tmp/batrick-2014-06-26$
>
> Then the message changes:
>
> address@hidden:~/tmp/batrick-2014-06-26$ make -f test.mk foo
> make: `foo' is up to date.
> address@hidden:~/tmp/batrick-2014-06-26$
>
> If we give it a recipe that actually works:
>
> address@hidden:~/tmp/batrick-2014-06-26$ sed -i -e 's/passwd;/passwd; @touch
> $@/' test.mk
> address@hidden:~/tmp/batrick-2014-06-26$
>
> Then we get silent success, following the Unix Bushido:
>
> address@hidden:~/tmp/batrick-2014-06-26$ make -f test.mk foo
> address@hidden:~/tmp/batrick-2014-06-26$
>
> Though a second invocation has nothing to do, and says so:
>
> address@hidden:~/tmp/batrick-2014-06-26$ make -f test.mk foo
> make: `foo' is up to date.
> address@hidden:~/tmp/batrick-2014-06-26$
I'm afraid none of this exercise is helpful for solving the problem
though. To put it concisely: how do I get Make to *fail* if it cannot
create one of the targets?
--
Patrick Donnelly
Re: Make does not throw an error for target without a recipe?, Paul Smith, 2014/06/26
Re: Make does not throw an error for target without a recipe?, Paul Smith, 2014/06/26