aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore3
-rw-r--r--Makefile31
-rw-r--r--config.mk3
-rw-r--r--sha3sum-mcb.c27
4 files changed, 61 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 667ce2c..5f62ca7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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/
diff --git a/Makefile b/Makefile
index 32c3dfb..9c4e507 100644
--- a/Makefile
+++ b/Makefile
@@ -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:
diff --git a/config.mk b/config.mk
index cd07dc2..abcfadf 100644
--- a/config.mk
+++ b/config.mk
@@ -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;
+}