diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 92 |
1 files changed, 47 insertions, 45 deletions
@@ -1,17 +1,20 @@ -.NONPOSIX: +.POSIX: CONFIGFILE = config.mk include $(CONFIGFILE) LIBEXECDIR = $(PREFIX)/$(LIBEXEC) -BIN =\ + +BIN_GENERIC =\ keccaksum\ + sha3sum\ + +BIN_SPECIFIC =\ keccak-224sum\ keccak-256sum\ keccak-384sum\ keccak-512sum\ - sha3sum\ sha3-224sum\ sha3-256sum\ sha3-384sum\ @@ -23,48 +26,38 @@ BIN =\ shake256sum\ shake512sum +BIN = $(BIN_GENERIC) $(BIN_SPECIFIC) MAN1 = $(BIN:=.1) HDR = arg.h common.h -keccaksum = Keccak[] -keccak-224sum = Keccak-224 -keccak-256sum = Keccak-256 -keccak-384sum = Keccak-384 -keccak-512sum = Keccak-512 -sha3sum = SHA3 -sha3-224sum = SHA3-224 -sha3-256sum = SHA3-256 -sha3-384sum = SHA3-384 -sha3-512sum = SHA3-512 -rawshake128sum = RawSHAKE128 -rawshake256sum = RawSHAKE256 -rawshake512sum = RawSHAKE512 -shake128sum = SHAKE128 -shake256sum = SHAKE256 -shake512sum = SHAKE512 - all: $(BIN) $(MAN1) mcb: sha3sum-mcb $(MAN1) -sha3sum-mcb.c: commands.h +sha3sum-mcb.o: commands.h +$(BIN:=.o): $(HDR) +$(BIN:=.bo): $(HDR) +$(BIN): common.o -%: %.o common.o - $(CC) -o $@ $< common.o $(LDFLAGS) +.o: + $(CC) -o $@ $@.o common.o $(LDFLAGS) -%.o: %.c $(HDR) +.c.o: $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -%.bo: %.c $(HDR) +.c.bo: $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) \ -Dmain="main_$$(printf '%s\n' $* | tr - _)(int, char *[]); int main_$$(printf '%s\n' $* | tr - _)" -%.1: xsum.man - u=$$(printf '%s\n' $* | tr a-z A-Z); \ - if test $* = sha3sum; then \ - sed -e 's/xsum/$*/g' -e 's/XSUM/'"$$u"'/g' -e 's/Xsum/$($*)/g' -e 's/^\\# ONLY SHA3: //' < xsum.man > $@; \ +$(MAN1): xsum.man algorithm-map + set -e; \ + f="$$(printf '%s\n' "$@" | sed 's/\.1$$//')"; \ + u="$$(printf '%s\n' "$$f" | tr a-z A-Z)"; \ + a="$$(sed -n 's/^'"$$f"'\s*=\s*//p' < algorithm-map | sed 's/\s*$$//')"; \ + if test "$$f" = sha3sum; then \ + sed -e "s/xsum/$$f/g" -e "s/XSUM/$$u/g" -e "s/Xsum/$$a/g" -e 's/^\\# ONLY SHA3: //' < xsum.man > $@; \ else \ - sed -e 's/xsum/$*/g' -e 's/XSUM/'"$$u"'/g' -e 's/Xsum/$($*)/g' -e '/^\\# ONLY SHA3: /d' < xsum.man > $@; \ + sed -e "s/xsum/$$f/g" -e "s/XSUM/$$u/g" -e "s/Xsum/$$a/g" -e '/^\\# ONLY SHA3: /d' < xsum.man > $@; \ fi commands.h: Makefile @@ -74,18 +67,6 @@ commands.h: Makefile sha3sum-mcb: sha3sum-mcb.o common.o $(BIN:=.bo) $(CC) -o $@ sha3sum-mcb.o common.o $(BIN:=.bo) $(LDFLAGS) -keccak-%sum.c: - printf '%s\n' '#include "common.h"' 'KECCAK_MAIN($*)' > $@ - -sha3-%sum.c: - printf '%s\n' '#include "common.h"' 'SHA3_MAIN($*)' > $@ - -rawshake%sum.c: - printf '%s\n' '#include "common.h"' 'RAWSHAKE_MAIN($*)' > $@ - -shake%sum.c: - printf '%s\n' '#include "common.h"' 'SHAKE_MAIN($*)' > $@ - check: $(BIN) ./test @@ -103,7 +84,7 @@ install-mcb: sha3sum-mcb $(MAN1) mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1" mkdir -p -- "$(DESTDIR)$(PREFIX)/share/licenses/sha3sum" set -e && cd "$(DESTDIR)$(PREFIX)/bin/" && \ - for f in $(BIN); do ln -sf -- ../$(LIBEXEC)/sha3sum "$$f"; done + for f in $(BIN); do ln -sf -- ../$(LIBEXEC)/sha3sum "$$f" || exit 1; done cp -- sha3sum-mcb "$(DESTDIR)$(LIBEXECDIR)/sha3sum" cp -- $(MAN1) "$(DESTDIR)$(MANPREFIX)/man1/" cp -- LICENSE "$(DESTDIR)$(PREFIX)/share/licenses/sha3sum/" @@ -115,8 +96,29 @@ uninstall: -rm -f -- "$(DESTDIR)$(LIBEXECDIR)/sha3sum" clean: - -rm -rf -- $(MAN1) $(BIN) sha3sum-mcb *.o *.bo *.su commands.h keccak-*sum.c sha3-*sum.c rawshake*sum.c shake*sum.c .testdir + -rm -rf -- $(MAN1) $(BIN) sha3sum-mcb *.o *.bo *.su commands.h .testdir + -rm -rf -- keccak-*sum.c sha3-*sum.c rawshake*sum.c shake*sum.c + +$(BIN_SPECIFIC:=.c): + +@set -e; \ + f="$$(\ + set -e; \ + sed -n 's/^\([a-z0-9-]\+\)%\([^:]*\):.*$$/\1 \2/p' < unportable.mk | while read start end; do \ + end="$$(printf '%s\n' "$$end" | sed 's/\./\\\./g')"; \ + x="$$(printf '%s\n' '$@' | sed -n 's/^'"$$start"'\(.*\)'"$$end"'$$/\1/p')"; \ + if test -n "$$x"; then \ + printf '%s\n' "$$x"; \ + break; \ + fi; \ + done; \ + )"; \ + if test -z "$$f"; then \ + printf 'No rule to make target %s\n' "$@" >&2; \ + exit 1; \ + fi; \ + sed "/^[a-z]/s/%/$$f/g" < unportable.mk | sed 's/\$$\*/'"$$f/g" | $(MAKE) -f - "$@" .SUFFIXES: +.SUFFIXES: .c .o .bo -.PHONY: all check install uninstall clean +.PHONY: all mcb check install install-mcb uninstall clean |