TARGETS := $(shell { \ if [ $$(date +%m) -lt 6 ]; then \ echo "$$(date +%Y)0101.key $$(date +%Y)0601.key" ; \ else \ echo "$$(date +%Y)0601.key $$(($$(date +%Y) + 1))0101.key" ; \ fi \ }) all: $(TARGETS) %.key: @set -eu ; \ openssl genrsa -out "$@" 2048 ; \ chgrp opendkim "$@" ; \ chmod 0640 "$@" ; \ echo ; \ data="$$(printf "v=DKIM1; k=rsa; p=%s" \ "$$(openssl rsa -in "$@" -pubout -outform der 2>/dev/null | openssl base64 -A)")" ; \ pos=0 ; \ printf "%s._domainkey\tIN\tTXT\t" "$$(echo "$@" | cut -d. -f1)" ; \ while true ; do \ printf "\"%s\"" \ "$$(echo "$$data" | cut -c $$((pos + 1))-$$((pos + 254)))" ; \ pos="$$((pos + 254))" ; \ [ $${#data} -gt $$pos ] || break ; \ printf " " ; \ done ; \ echo