[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: interrupt make
From: |
Paul Smith |
Subject: |
Re: interrupt make |
Date: |
Tue, 23 Jun 2009 14:19:55 -0400 |
On Mon, 2009-06-22 at 12:30 +0200, Fritz Code wrote:
> error-t:
> @echo "E R R O R";\
> $(error error-message)
> test:
> @(\
> echo "processing test target";\
> if [ -f ${FILE} ]; then\
> echo "file ${FILE} exists";\
> else\
> echo "file does NOT exist";\
> ${MAKE} error-t;\
> echo "after cancel";\
> fi;\
> )
the problem is you're invoking the error function by calling make
recursively:
${MAKE} error-t;\
So, the error function is being invoked in the sub-make, not in the
current make. It causes the sub-make to exit immediately, but it has no
impact on the current make.
Further, GNU make, unlike some other versions of make, does NOT invoke
the shell with the -e option, so a failure in one command doesn't cause
the entire script to fail. That's why you see the "echo after cancel"
command still run.
Stephan is not quite correct: $(error ...) CAN be used inside a command
script, and it works the same way as any other function or variable:
when it is expanded it will cause make to exit immediately.
However, Stephan is correct that this won't work for you, because make
expands ALL variables AND function before it invokes any shell command
(obviously! How could it expand them AFTER it invoked the shell?) and
that means that sticking $(error ...) inside a shell if-statement as
you're doing is useless: as soon as make determines it needs to rebuild
'test', before it even invokes the shell, it will fail which is not what
you want.
Stephan is also correct that you need to get very clear in your mind
what make does and what the shell does, and in which order, or you'll
have an impossible time writing anything but the most simple makefile.
I recommend you forget using $(error ...) for this altogether. I think
what you want is most easily accomplished by something like this:
error = echo "$1"; exit 1
test:
@echo "processing test target";\
if [ -f ${FILE} ]; then\
echo "file ${FILE} exists";\
else\
echo "file does NOT exist";\
$(call error,Failed to build $@);\
echo "after cancel";\
fi