bug-make
[Top][All Lists]
Advanced

[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:17:17 +0000

Maybe that's why my code always uses 
https://www.gnu.org/software/make/manual/make.html#Static-Pattern:

address@hidden:~/tmp/batrick-2014-06-26$ cat test.mk
.SUFFIXES:

TARGETS = foo

$(addsuffix .o,$(TARGETS)): %.o: %.c; cc -o $@ $<

$(TARGETS): %: %.o; ld -o $@ $^

%::; @echo no recipe for $@ 1>&2 && exit 1
address@hidden:~/tmp/batrick-2014-06-26$ make -f test.mk foo
no recipe for foo.c
make: *** [foo.c] Error 1
address@hidden:~/tmp/batrick-2014-06-26$ echo 'int main() {}' > foo.c
address@hidden:~/tmp/batrick-2014-06-26$ make -f test.mk foo
cc -o foo.o foo.c
ld -o foo foo.o
ld: error in foo.o(.eh_frame); no .eh_frame_hdr table will be created.
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$

-----Original Message-----
From: Patrick Donnelly [mailto:address@hidden 
Sent: Thursday, June 26, 2014 14:06
To: Martin Dorey
Cc: address@hidden
Subject: Re: Make does not throw an error for target without a recipe?

On Thu, Jun 26, 2014 at 5:02 PM, Martin Dorey <address@hidden> wrote:
>> 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

Is there a way to get last-resort rules to play nicely with e.g.:

%.o: %.c
    cc -o $@ $<
%: %.o
    ld -o $@ $^ ...

The last-resort rule is preferred over the the %.c -> %.o -> % chain of rules.

-- 
Patrick Donnelly

reply via email to

[Prev in Thread] Current Thread [Next in Thread]