commit d0c94265c042fe419926ee3e42fe4821c5e464cb
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Sat Jul 15 21:56:07 2017 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Sat Jul 15 21:56:07 2017 +0200
Add multi-call binary installation
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/Makefile b/Makefile
index 4852381..34c0033 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -151,6 +151,7 @@ MAN7 = blind.7
all: $(BIN)
+mcb: blind-mcb
%: %.o $(COMMON_OBJ)
$(CC) -o $_AT_ $^ $(LDFLAGS)
_AT_@ -158,6 +159,26 @@ all: $(BIN)
%.o: src/%.c src/*.h src/*/*.h platform.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $_AT_ $<
+%.mcb.o: src/%.c src/*.h src/*/*.h platform.h
+ $(CC) $(CFLAGS) $(CPPFLAGS) -Dmain="$$(printf 'main_%s\n' $* | tr -- - _)" -c -o $_AT_ $<
+
+blind-mcb.c: Makefile
+ printf '#include <%s.h>\n' stdio string > blind-mcb.c
+ printf 'int main_%s(int argc, char *argv[]);\n' $(BIN) | tr -- - _ >> blind-mcb.c
+ printf 'int main(int argc, char *argv[]) {\n' >> blind-mcb.c
+ printf 'char *cmd = strrchr(*argv, '"'/'"');\n' >> blind-mcb.c
+ printf 'cmd = cmd ? cmd + 1 : *argv;\n' >> blind-mcb.c
+ for c in $(BIN); do \
+ printf 'if (!strcmp(cmd, "%s"))\n\treturn main_%s(argc, argv);\n' "$$c" "$$c" | \
+ sed '/^\t/s/-/_/g'; \
+ done >> blind-mcb.c
+ printf 'fprintf(stderr, "Invalid command: %%s\\n", cmd);\n' >> blind-mcb.c
+ printf 'return 1;\n' >> blind-mcb.c
+ printf '}\n' >> blind-mcb.c
+
+blind-mcb: blind-mcb.o $(BIN:=.mcb.o) $(COMMON_OBJ)
+ $(CC) -o $_AT_ $^ $(LDFLAGS)
+
generate-macros: src/generate-macros.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o $_AT_ $< $(LDFLAGS)
_AT_@ -181,6 +202,26 @@ install: all
done
cd -- "$(DESTDIR)$(MANPREFIX)/man7" && chmod 644 $(MAN7)
+install-mcb: mcb
+ mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
+ for c in $(BIN); do \
+ $(LN) -f -- blind-single-colour "$(DESTDIR)$(PREFIX)/bin/$$c"; done
+ rm -f -- "$(DESTDIR)$(PREFIX)/bin/blind-single-colour"
+ cp -f -- blind-mcb "$(DESTDIR)$(PREFIX)/bin/blind-single-colour"
+ chmod 755 -- "$(DESTDIR)$(PREFIX)/bin/blind-single-colour"
+ mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1"
+ set -e && for m in $(MAN1); do \
+ sed '1s/ blind$$/ " blind $(VERSION)"/g' \
+ < "man/$$m" > "$(DESTDIR)$(MANPREFIX)/man1/$$m"; \
+ done
+ cd -- "$(DESTDIR)$(MANPREFIX)/man1" && chmod 644 $(MAN1)
+ mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7"
+ set -e && for m in $(MAN7); do \
+ sed '1s/ blind$$/ " blind $(VERSION)"/g' \
+ < "man/$$m" > "$(DESTDIR)$(MANPREFIX)/man7/$$m"; \
+ done
+ cd -- "$(DESTDIR)$(MANPREFIX)/man7" && chmod 644 $(MAN7)
+
uninstall:
cd -- "$(DESTDIR)$(PREFIX)/bin" && rm -f $(BIN)
cd -- "$(DESTDIR)$(MANPREFIX)/man1" && rm -f $(MAN1)
_AT_@ -203,8 +244,9 @@ dist:
clean:
-rm -f $(BIN) *.o blind-$(VERSION).tar.gz platform.h generate-macros
+ -rm -f blind-mcb.c blind-mcb.o blind-mcb
-rm -rf "blind-$(VERSION)"
-.PHONY: all install uninstall dist clean
+.PHONY: all mcb install install-mcb uninstall dist clean
.PRECIOUS: $(COMMON_OBJ) platform.h
diff --git a/config.mk b/config.mk
index 1bbef28..ae035ef 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -5,6 +5,9 @@ VERSION = 1.1
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
+# Commands
+LN = ln -s
+
# You may want to remove -DHAVE_PRCTL, -DHAVE_EPOLL, and
# -DHAVE_SENDFILE from CPPFLAGS if you are not using Linux.
CFLAGS = -std=c11 -Wall -pedantic -O2
Received on Sat Jul 15 2017 - 21:57:22 CEST
This archive was generated by hypermail 2.3.0
: Sat Jul 15 2017 - 22:00:54 CEST