summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.editorconfig12
-rw-r--r--.gitignore6
-rw-r--r--.shellcheckrc13
-rw-r--r--.shellspec1
-rw-r--r--Makefile93
5 files changed, 125 insertions, 0 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..93c82e7
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+max_line_length = 100
+
+[Makefile]
+indent_style = tab
+tab_width = 4
+smart_tabs = true
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1f18ee1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+bin/*
+man/*.html
+**.sh
+
+!spec/*.sh
+!*.in
diff --git a/.shellcheckrc b/.shellcheckrc
new file mode 100644
index 0000000..5c7220e
--- /dev/null
+++ b/.shellcheckrc
@@ -0,0 +1,13 @@
+# We use POSIX sh as a baseline.
+shell=sh
+
+# Be extra careful.
+enable=require-variable-braces
+enable=quote-safe-variables
+enable=avoid-nullary-conditions
+enable=check-unassigned-uppercase
+
+# SC2039 - The only extension of POSIX sh that we use is `local`, allow it.
+# SC1091 - False-positives due to use of @@.*@@ consts replaced during `make`.
+disable=SC2039
+disable=SC1091
diff --git a/.shellspec b/.shellspec
new file mode 100644
index 0000000..c99d2e7
--- /dev/null
+++ b/.shellspec
@@ -0,0 +1 @@
+--require spec_helper
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..6523e39
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,93 @@
+name = commune
+version = 20200226
+
+prefix ?=
+bindir ?= $(prefix)/bin
+libdir ?= $(prefix)/lib
+localstatedir ?= $(prefix)/var
+
+libdir := $(libdir)/$(name)
+
+BINS := $(patsubst %.in, %, $(wildcard bin/*.in))
+LIBS := $(patsubst %.in, %, $(wildcard lib/*.in))
+MANS := $(patsubst %.adoc, %, $(wildcard man/*.adoc))
+HTMLS := $(patsubst %.adoc, %.html, $(wildcard man/*.adoc))
+
+INSTALLS := \
+ $(addprefix $(DESTDIR)$(bindir)/,$(BINS:bin/%=%)) \
+ $(addprefix $(DESTDIR)$(libdir)/,$(LIBS:lib/%=%))
+
+.PHONY: all
+all: bin lib man html
+
+.PHONY: clean
+clean:
+ rm -f $(BINS) $(LIBS) $(MANS) $(HTMLS)
+
+.PHONY: install
+install: $(INSTALLS)
+
+.PHONY: lint
+lint:
+ printf '%s\n' $(patsubst %,%.in,$(BINS)) $(patsubst %,%.in,$(LIBS)) | xargs shellcheck
+
+.PHONY: test
+test: check
+
+.PHONY: check
+check: bin lib
+ shellspec $(SHELLSPEC_FLAGS)
+
+.PHONY: maint
+maint: lint check
+
+.PHONY: bin
+bin: $(BINS)
+
+.PHONY: lib
+lib: $(LIBS)
+
+.PHONY: man
+man: $(MANS)
+
+.PHONY: html
+html: $(HTMLS)
+
+bin/%: bin/%.in
+ sed \
+ -e "s|@@name@@|$(name)|g" \
+ -e "s|@@version@@|$(version)|g" \
+ -e "s|@@prefix@@|$(prefix)|g" \
+ -e "s|@@bindir@@|$(bindir)|g" \
+ -e "s|@@libdir@@|$$\{PRAXIS_LIBDIR:-$(libdir)\}|g" \
+ -e "s|@@localstatedir@@|$(localstatedir)|g" \
+ $< > $@.temp
+ chmod +x $@.temp
+ mv $@.temp $@
+
+lib/%: lib/%.in
+ sed \
+ -e "s|@@name@@|$(name)|g" \
+ -e "s|@@version@@|$(version)|g" \
+ -e "s|@@prefix@@|$(prefix)|g" \
+ -e "s|@@bindir@@|$(bindir)|g" \
+ -e "s|@@libdir@@|$$\{PRAXIS_LIBDIR:-$(libdir)\}|g" \
+ -e "s|@@localstatedir@@|$(localstatedir)|g" \
+ $< > $@.temp
+ chmod +x $@.temp
+ mv $@.temp $@
+
+.DELETE_ON_ERROR: man/%.html
+man/%.html: man/%.adoc
+ asciidoctor --failure-level=WARNING -b html5 -B $(PWD) -o $@ $<
+
+.DELETE_ON_ERROR: man/%
+man/%: man/%.adoc
+ asciidoctor --failure-level=WARNING -b manpage -B $(PWD) -d manpage -o $@ $<
+
+$(DESTDIR)$(bindir)/%: bin/%
+ install -D $< $@
+
+$(DESTDIR)$(libdir)/%: lib/%
+ install -D -m 0644 $< $@
+