Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Makefile, how to cleanup lockfile files?

In GNU Make 3.81, I need to remove a lockfile in the event of an error in any part of the toolchain. Is there a special target that will allow me to do this? Do I need to write a wrapper script?

In the example below, I need unlock_id to happen if the rule for file.out fails.

Thanks! -Jeff

all: lock_id file.out unlock_id

file.out: file.in
    file-maker < file.in > $@

lock_id:
    lockfile file.lock

unlock_id:
    rm -rf file.lock
like image 677
Jeff Avatar asked Jul 01 '11 21:07

Jeff


2 Answers

I would do the lock/unlock in the same target as file-maker:

file.out: file.in
        lockfile [email protected]
        file-maker < $< > $@; \
        status=$$?; \
        rm -f [email protected]; \
        exit $$status

This executes the file-maker and unlock steps in the same shell, saving the status of file-maker so make will fail if file-maker fails.

like image 75
Jack Kelly Avatar answered Oct 04 '22 00:10

Jack Kelly


This is kind of a kludge, but it works:

all:
        @$(MAKE) file.out || $(MAKE) unlock_id
like image 45
Beta Avatar answered Oct 04 '22 01:10

Beta