开发者

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 hap开发者_如何转开发pen 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


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

file.out: file.in
        lockfile $@.lock
        file-maker < $< > $@; \
        status=$$?; \
        rm -f $@.lock; \
        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.


This is kind of a kludge, but it works:

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


You want the .DELETE_ON_ERROR target, which allows you to specify files to be deleted upon errors.

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

EDIT

My bad, that's a half-truth. It allows you specify that you want files to be deleted, but as for which ones and under what circumstances, that's up to make.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜