views:

153

answers:

4

I'm wondering if there's a way to implement the similar functionality as you get in bash scripts using `trap', but for gmake, such that if the user presses CTRL-C, or if make itself fails, it can call a particular target or macro.

+1  A: 

No. As far as I know there is no such functionality.

JesperE
+1  A: 

make produces return codes. As far as I can remember right now, it returns 0 for success, 2 for failure (please check the documentation). Therefore, would it be enough for you to wrap make inside a shell script for example?

jbatista
I can do that, but trying to avoid it if possible, it's self-contained and I'm *trying* to keep it that way.
Cyrus
+1  A: 

No. GNU make’s signal handling already leaves a lot to be desired. From within its signal handler, it calls functions like printf that are not safe to be called from within a signal handler. I have seen this cause problems, for example .DELETE_ON_ERROR rules don’t always run if stderr is redirected to stdout.

andrew
+1  A: 

Make does not support it, but using BASH tricks you can accomplish something similar.

default: complete

complete: do_mount
        echo "Do something here..."

do_mount:
        mkdir -p "$(MOUNTPOINT)"
        ( while ps -p $$PPID >/dev/null ; do \
                sleep 1 ; \
        done ; \
        unmount "$(MOUNTPOINT)" \
        ) &
        mount "$(MOUNTSOURCE)" "$(MOUNTPOINT)" -o bind

The "unmount" will run after the "make" completes. This is usually a satisfactory solution if you are attempting to cleanup operations that may occur during the build but are not cleaned up normally on "make" exit.

PSpiller