> 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: martind@swiftboat:~/tmp/batrick-2014-06-26$ cat test.mk TARGETS = foo all: $(TARGETS) $(TARGETS): /etc/passwd %::; @echo no recipe for $@ 1>&2 && exit 1 martind@swiftboat:~/tmp/batrick-2014-06-26$ rm foo martind@swiftboat:~/tmp/batrick-2014-06-26$ make -f test.mk foo; echo $? no recipe for foo make: *** [foo] Error 1 2 martind@swiftboat:~/tmp/batrick-2014-06-26$ If Make doesn't think foo needs an update, mind: martind@swiftboat:~/tmp/batrick-2014-06-26$ touch foo martind@swiftboat:~/tmp/batrick-2014-06-26$ make -f test.mk foo; echo $? make: `foo' is up to date. 0 martind@swiftboat:~/tmp/batrick-2014-06-26$ -----Original Message----- From: Patrick Donnelly [mailto:batr...@batbytes.com] Sent: Thursday, June 26, 2014 13:43 To: Martin Dorey Cc: bug-make@gnu.org 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 <martin.do...@hds.com> 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: > > martind@swiftboat:~/tmp/batrick-2014-06-26$ make -f test.mk foo > make: Nothing to be done for `foo'. > martind@swiftboat:~/tmp/batrick-2014-06-26$ > > If we add a semicolon, telling make that the recipe to update foo is empty: > > martind@swiftboat:~/tmp/batrick-2014-06-26$ sed -i -e 's/passwd/passwd;/' > test.mk > martind@swiftboat:~/tmp/batrick-2014-06-26$ > > Then the message changes: > > martind@swiftboat:~/tmp/batrick-2014-06-26$ make -f test.mk foo > make: `foo' is up to date. > martind@swiftboat:~/tmp/batrick-2014-06-26$ > > If we give it a recipe that actually works: > > martind@swiftboat:~/tmp/batrick-2014-06-26$ sed -i -e 's/passwd;/passwd; > @touch $@/' test.mk > martind@swiftboat:~/tmp/batrick-2014-06-26$ > > Then we get silent success, following the Unix Bushido: > > martind@swiftboat:~/tmp/batrick-2014-06-26$ make -f test.mk foo > martind@swiftboat:~/tmp/batrick-2014-06-26$ > > Though a second invocation has nothing to do, and says so: > > martind@swiftboat:~/tmp/batrick-2014-06-26$ make -f test.mk foo > make: `foo' is up to date. > martind@swiftboat:~/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 _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make