diff options
author | Mattias Andrée <maandree@kth.se> | 2020-10-21 17:22:38 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2020-10-21 17:22:38 +0200 |
commit | 0db712267007206d30f74e6b2e856acf8e5502b7 (patch) | |
tree | 6a0807871dd8e6c2df2b1fa7a46677e3095f1c40 | |
parent | Update test for -z (diff) | |
download | sha3sum-0db712267007206d30f74e6b2e856acf8e5502b7.tar.gz sha3sum-0db712267007206d30f74e6b2e856acf8e5502b7.tar.bz2 sha3sum-0db712267007206d30f74e6b2e856acf8e5502b7.tar.xz |
Add multicall binary option
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 31 | ||||
-rw-r--r-- | config.mk | 3 | ||||
-rw-r--r-- | sha3sum-mcb.c | 27 |
4 files changed, 61 insertions, 3 deletions
@@ -1,11 +1,14 @@ *~ *\#* *.o +*.bo *.su *.1 +/commands.h /*sum /keccak-*sum.c /sha3-*sum.c /rawshake*sum.c /shake*sum.c +/sha3sum-mcb /.testdir/ @@ -3,6 +3,7 @@ CONFIGFILE = config.mk include $(CONFIGFILE) +LIBEXECDIR = $(PREFIX)/$(LIBEXEC) BIN =\ keccaksum\ @@ -40,13 +41,20 @@ shake512sum = SHAKE512 all: $(BIN) $(MAN1) +mcb: sha3sum-mcb $(MAN1) + +sha3sum-mcb.c: commands.h %: %.o common.o - $(CC) -o $@ $^ $(LDFLAGS) + $(CC) -o $@ $< common.o $(LDFLAGS) %.o: %.c $(HDR) $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) +%.bo: %.c $(HDR) + $(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); \ sed -e 's/xsum/$*/g' -e 's/XSUM/'"$$u"'/g' -e 's/Xsum/$($*)/g' < xsum.man > $@ @@ -56,6 +64,13 @@ all: $(BIN) $(MAN1) sed -i '/^\\# ONLY SHA3: /d' $@; \ fi +commands.h: Makefile + (printf '%s' '#define LIST_COMMANDS(_)' && printf '\\\n\t_(%s)' $(BIN) && printf '\n') \ + | sed 's/_(\(.*\))/_("\1", main_\1)/' | sed 's/\(main_.*\)-/\1_/' > $@ + +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($*)' > $@ @@ -79,13 +94,25 @@ install: $(BIN) $(MAN1) cp -- $(MAN1) "$(DESTDIR)$(MANPREFIX)/man1/" cp -- LICENSE "$(DESTDIR)$(PREFIX)/share/licenses/sha3sum/" +install-mcb: sha3sum-mcb $(MAN1) + mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" + mkdir -p -- "$(DESTDIR)$(LIBEXECDIR)" + 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 + cp -- sha3sum-mcb "$(DESTDIR)$(LIBEXECDIR)/sha3sum" + cp -- $(MAN1) "$(DESTDIR)$(MANPREFIX)/man1/" + cp -- LICENSE "$(DESTDIR)$(PREFIX)/share/licenses/sha3sum/" + uninstall: -cd -- "$(DESTDIR)$(PREFIX)/bin" && rm -f -- $(BIN) -cd -- "$(DESTDIR)$(MANPREFIX)/man1" && rm -f -- $(MAN1) -rm -rf -- "$(DESTDIR)$(PREFIX)/share/licenses/sha3sum" + -rm -f -- "$(DESTDIR)$(LIBEXECDIR)/sha3sum" clean: - -rm -rf -- $(MAN1) $(BIN) keccak-*sum.c sha3-*sum.c rawshake*sum.c shake*sum.c .testdir + -rm -rf -- $(MAN1) $(BIN) *.o *.bo *.su commands.h keccak-*sum.c sha3-*sum.c rawshake*sum.c shake*sum.c .testdir .SUFFIXES: @@ -1,5 +1,6 @@ -PREFIX = /usr/local +PREFIX = /usr/local 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 \ diff --git a/sha3sum-mcb.c b/sha3sum-mcb.c new file mode 100644 index 0000000..88990ca --- /dev/null +++ b/sha3sum-mcb.c @@ -0,0 +1,27 @@ +/* See LICENSE file for copyright and license details. */ +#include <string.h> +#include <stdio.h> + +#include "commands.h" + +#define _(NAME, MAIN) int MAIN(int argc, char *argv[]); +LIST_COMMANDS(_) +#undef _ + +int +main(int argc, char *argv[]) +{ + char *p; + + p = strrchr(argv[0], '/'); + p = p ? &p[1] : argv[0]; + + #define _(NAME, MAIN)\ + if (!strcmp(p, NAME))\ + return MAIN(argc, argv); + LIST_COMMANDS(_) + #undef _ + + fprintf(stderr, "%s is a multicall binary and cannot be execute directly\n", argv[0]); + return 127; +} |