diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-03 11:06:36 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-03 11:06:36 +0200 |
commit | cfc081f9c4f5f538145cbd93f98f714d0be1dad0 (patch) | |
tree | aa9c213cb875568d11194c10f92849605d2d3c0d | |
parent | Use strcmpnul (diff) | |
download | contacts-cfc081f9c4f5f538145cbd93f98f714d0be1dad0.tar.gz contacts-cfc081f9c4f5f538145cbd93f98f714d0be1dad0.tar.bz2 contacts-cfc081f9c4f5f538145cbd93f98f714d0be1dad0.tar.xz |
m + Add multicall binary
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 47 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | common.h | 20 | ||||
-rw-r--r-- | config.mk | 4 | ||||
-rw-r--r-- | contacts.c.in | 30 |
6 files changed, 91 insertions, 14 deletions
@@ -6,6 +6,7 @@ *.so.* *.su *.lo +*.bo /find-contact-by-email /find-contact-by-name /find-contact-by-pgpkey @@ -30,3 +31,5 @@ /set-contact-organisations /set-contact-pgpkeys /set-contact-sites +/contacts +/contacts.c @@ -32,18 +32,28 @@ HDR =\ common.h OBJ = $(BIN:=.o) +BOBJ = $(BIN:=.bo) -all: $(BIN) +all: $(BIN) contacts $(OBJ): $(@:.o=.c) $(HDR) - -libcontacts.a: $(OBJ) - $(AR) rc $@ $(OBJ) - $(AR) -s $@ +$(BOBJ): $(@:.bo=.c) $(HDR) .c.o: $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) +.c.bo: + $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -Dmain="$$(printf '%s\n' $*_main | tr - _)" -DMULTICALL_BINARY + +contacts: contacts.o $(BOBJ) + $(CC) -o $@ $@.o $(BOBJ) $(LDFLAGS) + +contacts.c: contacts.c.in Makefile + printf '#define LIST_COMMANDS' > $@ + printf '\\\n\tX(%s)' $(BIN) | tr - _ >> $@ + printf '\n\n' >> $@ + cat contacts.c.in >> $@ + find-contact-by-email: find-contact-by-email.o $(CC) -o $@ $@.o $(LDFLAGS) @@ -120,13 +130,34 @@ install: $(BIN) mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" cp -- $(BIN) "$(DESTDIR)$(PREFIX)/bin/" +install-mcb: contacts + mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" + set -- $(BIN) &&\ + cp -- "$$1" "$(DESTDIR)$(PREFIX)/bin/$$1" &&\ + linkto="$$1" &&\ + shift 1 &&\ + cd -- "$(DESTDIR)$(PREFIX)/bin/" &&\ + for f; do\ + ln -- "$$linkto" "$$f" || exit 1;\ + done + +install-mcb-symlinks: contacts + mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" + mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" + cp -- contacts "$(DESTDIR)$(PREFIX)/lib/" + cd -- "$(DESTDIR)$(PREFIX)/bin/" &&\ + for f in $(BIN); do\ + ln -s -- ../lib/contacts "$$f" || exit 1;\ + done + uninstall: -cd -- "$(DESTDIR)$(PREFIX)/bin" && rm -f -- $(BIN) + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/contacts" clean: - -rm -f -- *.o *.a *.lo *.so *.su $(BIN) + -rm -f -- *.o *.a *.lo *.so *.bo *.su $(BIN) contacts contacts.c .SUFFIXES: -.SUFFIXES: .c .o +.SUFFIXES: .c .o .bo -.PHONY: all install uninstall clean +.PHONY: all install install-mcb install-mcb-symlinks uninstall clean @@ -27,4 +27,3 @@ Test set-contact-sites Add man pages Add readme Add tests -Add multicall binary @@ -1,4 +1,18 @@ /* See LICENSE file for copyright and license details. */ -#include "libcontacts.h" -#include "libsimple.h" -#include "libsimple-arg.h" +#include <libcontacts.h> +#include <libsimple.h> +#include <libsimple-arg.h> + + +#ifdef MULTICALL_BINARY +# undef NUSAGE +# define NUSAGE(STATUS, SYNOPSIS)\ + static _LIBSIMPLE_NORETURN void\ + usage(void)\ + {\ + const char *syn = SYNOPSIS ? SYNOPSIS : "";\ + fprintf(stderr, "usage: %s%s%s\n", argv0, *syn ? " " : "", syn);\ + exit(STATUS);\ + }\ + extern char *argv0 +#endif @@ -3,6 +3,6 @@ MANPREFIX = $(PREFIX)/share/man CC = cc -CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -I../libcontacts CFLAGS = -std=c99 -Wall -O2 -LDFLAGS = -s -lcontacts -lsimple +LDFLAGS = -s -L../libcontacts -lcontacts -lsimple diff --git a/contacts.c.in b/contacts.c.in new file mode 100644 index 0000000..5e470ac --- /dev/null +++ b/contacts.c.in @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdio.h> +#include <string.h> + +#define X(NAM) int NAM##_main(int, char *[]); +LIST_COMMANDS +#undef X + +char *argv0 = NULL; + +int +main(int argc, char *argv[]) +{ + char *name, *p; + + name = strrchr(*argv, '/'); + if (!name++) + name = *argv; + for (p = name; (p = strchr(p, '-'));) + *p++ = '_'; + +#define X(NAM)\ + if (!strcmp(name, #NAM))\ + return NAM##_main(argc, argv); + LIST_COMMANDS; +#undef X + + fprintf(stderr, "%s: unrecognised command for multicall binary\n", *argv); + return 127; +} |