GNU make for the win …

I’ve just replaced my little shell script that was helping me to update the hash files inside my postfix configuration. While before I had hardcoded the paths/names, they are now simply fetched by means of find. In addition to the old capabilities, the new make file will also copy any files required inside the chrooted /etc, if they aren’t up-do-date. Since make works by means of timestamps of the targets, this is easily achieved.

Here’s how it looks (stripped the “intro” of the make file, though).

config-files := $(shell find /var/spool/postfix/etc/ -type f)
hash-files   := $(shell find $(CURDIR) -name '*.hash')
hashdb-files := $(addsuffix .db,$(hash-files))

.PHONY: all
all: $(hashdb-files) $(config-files)
    newaliases
    postfix check
    postfix reload

/var/spool/postfix/etc/%: /etc/%
    cp --preserve=timestamps $(patsubst /var/spool/postfix%,%,$@) $@

%.hash.db: %.hash
    postmap $(patsubst %.db,%,$@)
    @chown root:postfix $@ $(patsubst %.db,%,$@)
    @chmod u=rwX,g=r,o= $@ $(patsubst %.db,%,$@)
ifeq ($(filter $(MAKECMDGOALS),all rebuild),)
    postfix check
    postfix reload
endif

.PHONY: info
info:
    -@echo "config-files = $(config-files)"
    -@echo "hash-files   = $(hash-files)"
    -@echo "hashdb-files = $(hashdb-files)"

.PHONY: rebuild
rebuild: clean all

.PHONY: clean
clean:
    -@echo "Cleaning $(CURDIR) ..."
    -@rm -f $(hashdb-files)

You can download it here.

// Oliver

This entry was posted in /dev/null. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *