aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-07-02 22:09:07 +0200
committerMattias Andrée <maandree@kth.se>2023-07-02 22:09:07 +0200
commit31e4c2917b05f10b5f9bd5ce429dbf42a8346b6d (patch)
tree71cb3d8bb1e14c1f945061f3cfb9160861b65118
parentUpdate link to libkeccak in DEPENDENCIES (diff)
downloadsha3sum-31e4c2917b05f10b5f9bd5ce429dbf42a8346b6d.tar.gz
sha3sum-31e4c2917b05f10b5f9bd5ce429dbf42a8346b6d.tar.bz2
sha3sum-31e4c2917b05f10b5f9bd5ce429dbf42a8346b6d.tar.xz
Make makefile portable1.2.3
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--Makefile92
-rw-r--r--algorithm-map16
-rw-r--r--config.mk15
-rw-r--r--unportable.mk11
4 files changed, 78 insertions, 56 deletions
diff --git a/Makefile b/Makefile
index cd71a99..93c0b1d 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/algorithm-map b/algorithm-map
new file mode 100644
index 0000000..ea96067
--- /dev/null
+++ b/algorithm-map
@@ -0,0 +1,16 @@
+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
diff --git a/config.mk b/config.mk
index abcfadf..7f52810 100644
--- a/config.mk
+++ b/config.mk
@@ -1,16 +1,9 @@
-PREFIX = /usr/local
+PREFIX = /usr
MANPREFIX = $(PREFIX)/share/man
LIBEXEC = libexec
-WARN = -pedantic -Wdouble-promotion -Wformat=2 -Winit-self -Wmissing-include-dirs \
- -Wtrampolines -Wfloat-equal -Wshadow -Wmissing-prototypes -Wmissing-declarations \
- -Wredundant-decls -Wnested-externs -Winline -Wno-variadic-macros -Wswitch-default \
- -Wpadded -Wsync-nand -Wunsafe-loop-optimizations -Wcast-align -Wstrict-overflow \
- -Wdeclaration-after-statement -Wundef -Wbad-function-cast -Wcast-qual -Wlogical-op \
- -Wstrict-prototypes -Wold-style-definition -Wpacked -Wvector-operation-performance \
- -Wunsuffixed-float-constants -Wsuggest-attribute=const -Wsuggest-attribute=noreturn \
- -Wsuggest-attribute=pure -Wsuggest-attribute=format -Wnormalized=nfkc
+CC = c99
-CFLAGS = -std=c99 -Wall -Wextra $(WARN) -O3
CPPFLAGS =
-LDFLAGS = -s -lkeccak
+CFLAGS = -Wall -O3
+LDFLAGS = -lkeccak
diff --git a/unportable.mk b/unportable.mk
new file mode 100644
index 0000000..a732332
--- /dev/null
+++ b/unportable.mk
@@ -0,0 +1,11 @@
+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($*)' > $@