aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile47
-rw-r--r--TODO1
-rw-r--r--common.h20
-rw-r--r--config.mk4
-rw-r--r--contacts.c.in30
6 files changed, 91 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index fb34b0a..1411d9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Makefile b/Makefile
index 86040fa..362ada4 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/TODO b/TODO
index 33d0025..33e964e 100644
--- a/TODO
+++ b/TODO
@@ -27,4 +27,3 @@ Test set-contact-sites
Add man pages
Add readme
Add tests
-Add multicall binary
diff --git a/common.h b/common.h
index 14c3319..f4e1dad 100644
--- a/common.h
+++ b/common.h
@@ -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
diff --git a/config.mk b/config.mk
index 34514f2..2c119c1 100644
--- a/config.mk
+++ b/config.mk
@@ -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;
+}