How to execute commands in case of interruption of makefile execution - Linux
This is a discussion on How to execute commands in case of interruption of makefile execution - Linux ; 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 ...
-
How to execute commands in case of interruption of makefile execution
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
-
Re: How to execute commands in case of interruption of makefile execution
wyse03br@yahoo.com.br writes:
> 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.
-
Re: How to execute commands in case of interruption of makefile execution
wyse03br@yahoo.com.br wrote:
> 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
>
> Thanks in advance.
>
> Walter
-
Re: How to execute commands in case of interruption of makefile execution
Unfortunately I can't add the wrapper, the Makefile is called from a
monolithic application.
Thanks anyway.
toby wrote:
> May I suggest doing this with shell commands, in a wrapper or nested
> make?
> make || do_on_failure
> do_always
-
Re: How to execute commands in case of interruption of makefileexecution
wyse03br@yahoo.com.br writes:
[Please do not top-post. Rest of the message re-ordered]
> toby wrote:
>> 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).
> 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.
-
Re: How to execute commands in case of interruption of makefile execution
wyse03br@yahoo.com.br wrote:
> 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
>
> Thanks anyway.
>
> toby wrote:
> > May I suggest doing this with shell commands, in a wrapper or nested
> > make?
> > make || do_on_failure
> > do_always
-
Re: How to execute commands in case of interruption of makefile execution
Paul Pluzhnikov wrote:
> wyse03br@yahoo.com.br writes:
>
> [Please do not top-post. Rest of the message re-ordered]
>
> > toby wrote:
> >> 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"?)
>
> 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).
>
> > 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.
-
Re: How to execute commands in case of interruption of makefile execution
On 2006-12-26, wyse03br@yahoo.com.br wrote:
> 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
-
Re: How to execute commands in case of interruption of makefile execution
toby wrote:
> Paul Pluzhnikov wrote:
> > > toby wrote:
> > >> 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...
-
Re: How to execute commands in case of interruption of makefile execution
Paul Pluzhnikov wrote:
> You sure can:
>
> all:
> 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