1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
MAKEFLAGS += --warn-undefined-variables
cleanfiles := *.o rewrite-time
variants := lockfile-check lockfile-create lockfile-remove lockfile-touch
variants += mail-lock mail-touchlock mail-unlock
generated := $(addprefix bin/,$(variants))
generated += $(patsubst %,man/%.1,$(variants))
cleanfiles += $(generated)
CFLAGS := -g -Wall -Wformat-security -Werror -O2 -fwrapv -fno-strict-aliasing $(CFLAGS)
CPPFLAGS ?=
LDFLAGS ?=
.SUFFIXES:
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
%: %.o
$(CC) -o $@ $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS)
all: $(generated)
.PHONY: all
config.h: debian/changelog rewrite-time
set -ex; \
date="$$(./changelog-date)"; \
ver="$$(./changelog-version)"; \
echo '#pragma once' > $@.tmp; \
echo "#define LOCKFILE_PROGS_DATE \"$$date\"" >> $@.tmp; \
echo "#define LOCKFILE_PROGS_VERSION \"$$ver\"" >> $@.tmp; \
mv config.h.tmp config.h
cleanfiles += config.h config.h.tmp
lockfile-progs.o: config.h
# Two independent binaries because mail-lock may need sgid, etc.
bin/lockfile-create: LOADLIBES += -llockfile
bin/lockfile-create: lockfile-progs.o
mkdir -p bin
$(CC) -o $@ $(LDFLAGS) $< $(LOADLIBES)
bin/mail-lock: bin/lockfile-create
cp -p $^ $@
bin/lockfile-%: bin/lockfile-create
ln $^ $@
bin/mail-%: bin/mail-lock
ln $^ $@
cleandirs += bin
man/lockfile-progs.1: lockfile-progs.1.in debian/changelog rewrite-time
mkdir -p man
set -ex; \
date="$$(./changelog-date)"; \
ver="$$(./changelog-version)"; \
sed -E -e "s/@DATE@/$$date/" -e "s/@VERSION@/$$ver/;" $< > $@.tmp; \
mv $@.tmp $@
cleanfiles += man/lockfile-progs.1 man/lockfile-progs.1.tmp
cleandirs += man
man/%.1: man/lockfile-progs.1
echo .so lockfile-progs.1 > $@
# These tests are quite insufficient, but perhaps better than nothing for now.
check: all
rm -rf check
mkdir check
bin/lockfile-create check/file
bin/lockfile-touch --oneshot check/file
bin/lockfile-check check/file
bin/lockfile-remove check/file
! test -e check/file.lock
bin/lockfile-create --lock-name check/file.lock
bin/lockfile-touch --oneshot --lock-name check/file.lock
bin/lockfile-check --lock-name check/file.lock
bin/lockfile-remove --lock-name check/file.lock
! test -e check/file.lock
bin/lockfile-create --use-pid --lock-name check/file.lock
bin/lockfile-touch --oneshot --lock-name check/file.lock
# PID shouldn't be the same, so this should fail.
bin/lockfile-check --use-pid --lock-name check/file.lock
bin/lockfile-remove --lock-name check/file.lock
! test -e check/file.lock
bin/lockfile-create --use-pid --lock-name check/lockfile.no-pid
.PHONY: check
cleandirs += check
clean:
rm -f $(cleanfiles)
rm -rf $(cleandirs)
.PHONY: clean
|