Discussion:
How to execute commands in case of interruption of makefile execution
(too old to reply)
w***@yahoo.com.br
2006-12-26 20:24:23 UTC
Permalink
Hello,

I'd like to execute some cleanup commands in case of interruption
(CTRL-C or something) of the normal makefile execution. These commands
do more than simply delete intermediary files, so .INTERMEDIATE rule
does not solve my problem. A way to execute commands upon termination
of the Makefile, regardless the termination is forced or not (something
like the Perl END routine) would help too.

Is there any way to achieve what I need?

Thanks in advance.

Walter
Pascal Bourguignon
2006-12-26 20:58:20 UTC
Permalink
Post by w***@yahoo.com.br
Hello,
I'd like to execute some cleanup commands in case of interruption
(CTRL-C or something) of the normal makefile execution. These commands
do more than simply delete intermediary files, so .INTERMEDIATE rule
does not solve my problem. A way to execute commands upon termination
of the Makefile, regardless the termination is forced or not (something
like the Perl END routine) would help too.
Is there any way to achieve what I need?
I don't know if it's possible with make (or gnu make) I've never seen
such a thing.


With bash, you can use trap. So you could run your protected commands
from bash:

target:dependencies
bash -c "trap 'clean-up' INT TERM ; do-something"

or just invoke an external script:

target:dependencies
bin/do-something-and-clean-up



In general, in makefiles you just put a clean target to do the
cleaning up of any intermediate files that may remain from previous
makes.
--
__Pascal Bourguignon__ http://www.informatimago.com/
You're always typing.
Well, let's see you ignore my
sitting on your hands.
toby
2006-12-26 21:00:00 UTC
Permalink
Post by w***@yahoo.com.br
Hello,
I'd like to execute some cleanup commands in case of interruption
(CTRL-C or something) of the normal makefile execution. These commands
do more than simply delete intermediary files, so .INTERMEDIATE rule
does not solve my problem. A way to execute commands upon termination
of the Makefile, regardless the termination is forced or not (something
like the Perl END routine) would help too.
Is there any way to achieve what I need?
May I suggest doing this with shell commands, in a wrapper or nested
make?
make || do_on_failure
do_always
Post by w***@yahoo.com.br
Thanks in advance.
Walter
w***@yahoo.com.br
2006-12-26 21:10:36 UTC
Permalink
Unfortunately I can't add the wrapper, the Makefile is called from a
monolithic application.

Thanks anyway.
Post by toby
May I suggest doing this with shell commands, in a wrapper or nested
make?
make || do_on_failure
do_always
Paul Pluzhnikov
2006-12-26 21:29:50 UTC
Permalink
***@yahoo.com.br writes:

[Please do not top-post. Rest of the message re-ordered]
Post by w***@yahoo.com.br
Post by toby
May I suggest doing this with shell commands, in a wrapper or nested
make?
make || do_on_failure
This will execute do_on_failure on *any* failure;
the OP wanted to execute cleanup only on interruption.

It may or may not make sense to cleanup on other failures (perhaps
further investigation of why make failed in non-interrupted case
requires intermediate results).
Post by w***@yahoo.com.br
Unfortunately I can't add the wrapper, the Makefile is called from a
monolithic application.
You sure can:

all:
bash -c "trap 'clean-up' INT TERM ; $(MAKE) $(MFLAGS) target_with_cleanup"

target_with_cleanup: dependencies
whatever ...

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
toby
2006-12-26 21:45:15 UTC
Permalink
Post by Paul Pluzhnikov
[Please do not top-post. Rest of the message re-ordered]
Post by w***@yahoo.com.br
Post by toby
May I suggest doing this with shell commands, in a wrapper or nested
make?
make || do_on_failure
This will execute do_on_failure on *any* failure;
the OP wanted to execute cleanup only on interruption.
Seemed ambiguous to me (^C "or other"?)
Post by Paul Pluzhnikov
It may or may not make sense to cleanup on other failures (perhaps
further investigation of why make failed in non-interrupted case
requires intermediate results).
Post by w***@yahoo.com.br
Unfortunately I can't add the wrapper, the Makefile is called from a
monolithic application.
bash -c "trap 'clean-up' INT TERM ; $(MAKE) $(MFLAGS) target_with_cleanup"
target_with_cleanup: dependencies
whatever ...
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
w***@yahoo.com.br
2006-12-27 11:07:55 UTC
Permalink
Post by toby
Post by Paul Pluzhnikov
Post by toby
May I suggest doing this with shell commands, in a wrapper or nested
make?
make || do_on_failure
This will execute do_on_failure on *any* failure;
the OP wanted to execute cleanup only on interruption.
Seemed ambiguous to me (^C "or other"?)
By "other" I meant abnormal ends caused by interrupt signal sent by
kill, lack of resources, problems on the underlying file system, etc...
w***@yahoo.com.br
2006-12-27 11:34:08 UTC
Permalink
Post by Paul Pluzhnikov
bash -c "trap 'clean-up' INT TERM ; $(MAKE) $(MFLAGS) target_with_cleanup"
target_with_cleanup: dependencies
whatever ...
Yes, it is a clever solution. I'll try to explore this one.

Tks

toby
2006-12-26 21:36:02 UTC
Permalink
Post by w***@yahoo.com.br
Unfortunately I can't add the wrapper, the Makefile is called from a
monolithic application.
You can still do it with a sub-make.

--- Makefile ---
all:
make -f sub.mk || on_failure
do_always
Post by w***@yahoo.com.br
Thanks anyway.
Post by toby
May I suggest doing this with shell commands, in a wrapper or nested
make?
make || do_on_failure
do_always
jasen
2006-12-27 08:58:08 UTC
Permalink
Post by w***@yahoo.com.br
Unfortunately I can't add the wrapper, the Makefile is called from a
monolithic application.
sure you can... have the makefile run a bash script
and the bash script trap aborts and run the real makefile.

Bye.
Jasen
Loading...