In makefile, how to clear file lock files?

In GNU Make 3.81, I need to delete the lock file in case of an error in any part of the tool chain. Is there a special purpose 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 is not met.

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 
+7
source share
3 answers

I would do lock / unlock for the same purpose as file-maker :

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

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

+7
source

This is kind of kludge, but it works:

 all: @$(MAKE) file.out || $(MAKE) unlock_id 
+4
source

You need a .DELETE_ON_ERROR target, which allows you to specify files that you want to delete when errors occur.

http://www.gnu.org/s/hello/manual/make/Special-Targets.html

EDIT

My bad, this is half true. It allows you to specify that you want to delete files, but for what and under what circumstances, before make .

0
source

All Articles