summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore14
-rw-r--r--Makefile77
-rw-r--r--common.h4
-rw-r--r--config.mk6
-rw-r--r--multicall-hardlinks.mk12
-rw-r--r--multicall-symlinks.mk10
-rw-r--r--pdatools.c.in30
-rw-r--r--singlecall.mk5
8 files changed, 132 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore
index abde984..2cdb29a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,18 @@
*\#*
*~
*.o
+*.a
+*.so
+*.so.*
*.su
-*.bin
+*.lo
+*.bo
/large.h
+/pdatools
+/pdatools.c
+/backlight
+/clock
+/counter
+/dice
+/stopwatch
+/timer
diff --git a/Makefile b/Makefile
index 7e38b58..69b6757 100644
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,14 @@
.POSIX:
CONFIGFILE = config.mk
-include $(CONFIGFILE)
-HDR =\
- common.h\
- large.h
+CALLTYPE = multicall-hardlinks
+# multicall-hardlinks = multiple hardlinks of the same multicall binary is installed
+# multicall-symlinks = multiple links to a multicall binary named $(PREFIX)/bin/pdatools are installed
+# singlecall = separate binaries are install for each command
+
-BIN_ =\
+BIN =\
backlight\
clock\
counter\
@@ -15,31 +16,60 @@ BIN_ =\
stopwatch\
timer
-OBJ = $(BIN_:=.o)
-BIN = $(BIN_:=.bin)
-MAN1 = $(BIN_:=.1)
+HDR =\
+ common.h\
+ large.h
+
+OBJ = $(BIN:=.o)
+BOBJ = $(OBJ:.o=.bo)
+MAN1 = $(BIN:=.1)
+
+
+include $(CONFIGFILE)
+include $(CALLTYPE).mk
-all: $(BIN)
$(OBJ): $(@:.o=.c) $(HDR)
-$(BIN): $(@:.bin=.o)
+$(BOBJ): $(@:.bo=.c) $(HDR)
.c.o:
- $(CC) -c -o $@ $< $(CFLAGS)
+ $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS)
+
+.c.bo:
+ $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -Dmain="$$(printf '%s\n' main__$* | tr - _)" -DMULTICALL_BINARY
-.o.bin:
- $(CC) -o $@ $< $(LDFLAGS)
+pdatools: pdatools.o $(BOBJ)
+ $(CC) -o $@ $@.o $(BOBJ) $(LDFLAGS)
+
+pdatools.c: pdatools.c.in Makefile
+ printf '#define LIST_COMMANDS' > $@
+ printf '\\\n\tX(%s)' $(BIN) | tr - _ >> $@
+ printf '\n\n' >> $@
+ cat pdatools.c.in >> $@
large.h: large.sh
./large.sh > $@
-install: $(BIN)
- mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
+backlight: backlight.o
+ $(CC) -o $@ $@.o $(LDFLAGS)
+
+clock: clock.o
+ $(CC) -o $@ $@.o $(LDFLAGS)
+
+counter: counter.o
+ $(CC) -o $@ $@.o $(LDFLAGS)
+
+dice: dice.o
+ $(CC) -o $@ $@.o $(LDFLAGS)
+
+stopwatch: stopwatch.o
+ $(CC) -o $@ $@.o $(LDFLAGS)
+
+timer: timer.o
+ $(CC) -o $@ $@.o $(LDFLAGS)
+
+install-common:
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1"
- for f in $(BIN_); do\
- ! test -d "$(DESTDIR)$(PREFIX)/bin/$$f" &&\
- cp -- "$$f.bin" "$(DESTDIR)$(PREFIX)/bin/$$f" || exit 1;\
- done
cp -- $(MAN1) "$(DESTDIR)$(MANPREFIX)/man1"
post-install:
@@ -48,12 +78,13 @@ post-install:
uninstall:
-cd -- "$(DESTDIR)$(PREFIX)/bin" && rm -f -- $(BIN_)
- -cd -- "$(DESTDIR)$(MANPREFIX)/man1" && rm -f $(MAN1)
+ -cd -- "$(DESTDIR)$(MANPREFIX)/man1" && rm -f -- $(MAN1)
+ -rm -f -- "$(DESTDIR)$(PREFIX)/lib/pdatools"
clean:
- -rm -rf -- *.o *.su *.bin large.h
+ -rm -rf -- *.o *.a *.lo *.so *.bo *.su $(BIN) large.h pdatools pdatools.c
.SUFFIXES:
-.SUFFIXES: .bin .o .c
+.SUFFIXES: .o .c .bo
-.PHONY: all install post-install uninstall clean
+.PHONY: all install install-common post-install uninstall clean
diff --git a/common.h b/common.h
index 298eff9..627fcc2 100644
--- a/common.h
+++ b/common.h
@@ -1,4 +1,8 @@
/* See LICENSE file for copyright and license details. */
+#ifdef MULTICALL_BINARY
+# define LIBSIMPLY_CONFIG_MULTICALL_BINARY
+#endif
+
#include <libsimple.h>
#include <libsimple-arg.h>
diff --git a/config.mk b/config.mk
index 4792a0b..d7a6d60 100644
--- a/config.mk
+++ b/config.mk
@@ -3,6 +3,8 @@ MANPREFIX = $(PREFIX)/share/man
VIDEO_GROUP = video
+CC = cc
+
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
-CFLAGS = -std=c99 -Wall -Wextra -O2 -g $(CPPFLAGS)
-LDFLAGS = -lsimple
+CFLAGS = -std=c99 -Wall -Wextra -Os
+LDFLAGS = -lsimple -s
diff --git a/multicall-hardlinks.mk b/multicall-hardlinks.mk
new file mode 100644
index 0000000..a01ae8f
--- /dev/null
+++ b/multicall-hardlinks.mk
@@ -0,0 +1,12 @@
+all: pdatools
+
+install: pdatools install-common
+ 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
diff --git a/multicall-symlinks.mk b/multicall-symlinks.mk
new file mode 100644
index 0000000..592804a
--- /dev/null
+++ b/multicall-symlinks.mk
@@ -0,0 +1,10 @@
+all: pdatools
+
+install: pdatools install-common
+ mkdir -p -- "$(DESTDIR)$(PREFIX)/lib"
+ mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
+ cp -- pdatools "$(DESTDIR)$(PREFIX)/lib/"
+ cd -- "$(DESTDIR)$(PREFIX)/bin/" &&\
+ for f in $(BIN); do\
+ ln -s -- ../lib/pdatools "$$f" || exit 1;\
+ done
diff --git a/pdatools.c.in b/pdatools.c.in
new file mode 100644
index 0000000..b297951
--- /dev/null
+++ b/pdatools.c.in
@@ -0,0 +1,30 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdio.h>
+#include <string.h>
+
+#define X(NAM) int main__##NAM(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 main__##NAM(argc, argv);
+ LIST_COMMANDS;
+#undef X
+
+ fprintf(stderr, "%s: unrecognised command for multicall binary\n", *argv);
+ return 127;
+}
diff --git a/singlecall.mk b/singlecall.mk
new file mode 100644
index 0000000..7dbb158
--- /dev/null
+++ b/singlecall.mk
@@ -0,0 +1,5 @@
+all: $(BIN)
+
+install: $(BIN) install-common
+ mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
+ cp -- $(BIN) "$(DESTDIR)$(PREFIX)/bin/"