The new build system inlines platform-specific code instead of
referencing a file from /usr/lib/. This allows for creating a working
shell script without having to run `make install` which is useful during
testing. The inline code replacement is done using m4(1).

Signed-off-by: Lukas Fleischer <[email protected]>
---
 Makefile                                        | 24 ++++++++----------------
 src/Makefile                                    | 10 ++++++++++
 src/{password-store.sh => password-store.sh.in} |  9 ++++++++-
 3 files changed, 26 insertions(+), 17 deletions(-)
 create mode 100644 src/Makefile
 rename src/{password-store.sh => password-store.sh.in} (98%)
 mode change 100755 => 100644

diff --git a/Makefile b/Makefile
index bee69e1..c714031 100644
--- a/Makefile
+++ b/Makefile
@@ -1,18 +1,18 @@
 PREFIX ?= /usr
 DESTDIR ?=
 BINDIR ?= $(PREFIX)/bin
-LIBDIR ?= $(PREFIX)/lib
 MANDIR ?= $(PREFIX)/share/man
 
-PLATFORMFILE := src/platform/$(shell uname | cut -d _ -f 1 | tr '[:upper:]' 
'[:lower:]').sh
+.PHONY: build clean install uninstall install-common
 
-.PHONY: install uninstall install-common
+build:
+       make -C src/
 
-all:
-       @echo "Password store is a shell script, so there is nothing to do. Try 
\"make install\" instead."
+clean:
+       make -C src/ clean
 
 install-common:
-       @mkdir -p "$(DESTDIR)$(BINDIR)" "$(DESTDIR)$(LIBDIR)" 
"$(DESTDIR)$(MANDIR)/man1" 
"$(DESTDIR)$(PREFIX)/share/bash-completion/completions/"
+       @mkdir -p "$(DESTDIR)$(BINDIR)" "$(DESTDIR)$(MANDIR)/man1" 
"$(DESTDIR)$(PREFIX)/share/bash-completion/completions/"
        @install -m 0644 -v man/pass.1 "$(DESTDIR)$(MANDIR)/man1/pass.1"
        @install -m 0644 -v src/completion/pass.bash-completion 
"$(DESTDIR)$(PREFIX)/share/bash-completion/completions/pass"
 
@@ -22,16 +22,8 @@ install-common:
 #      Uncomment to install the fish completion file.
 #      @install -m 0644 -v src/completion/pass.fish-completion 
"$(DESTDIR)$(PREFIX)/share/fish/completions/pass.fish"
 
-ifneq ($(strip $(wildcard $(PLATFORMFILE))),)
-install: install-common
-       @install -m 0644 -v "$(PLATFORMFILE)" 
"$(DESTDIR)$(LIBDIR)/password-store.platform.sh"
-       @mkdir -p -v "$(DESTDIR)$(BINDIR)/"
-       sed 's:.*platform-defined-functions.*:source 
$(DESTDIR)$(LIBDIR)/password-store.platform.sh:' src/password-store.sh > 
"$(DESTDIR)$(BINDIR)/pass"
-       @chmod 0755 "$(DESTDIR)$(BINDIR)/pass"
-else
-install: install-common
-       @install -m 0755 -v src/password-store.sh "$(DESTDIR)$(BINDIR)/pass"
-endif
+install: build install-common
+       install -m 0755 src/password-store.sh > "$(DESTDIR)$(BINDIR)/pass"
 
 uninstall:
        @rm -vf "$(DESTDIR)$(BINDIR)/pass" "$(DESTDIR)$(MANDIR)/man1/pass.1" 
"$(DESTDIR)$(PREFIX)/share/bash-completion/completions/password-store" 
"$(DESTDIR)$(LIBDIR)/password-store.platform.sh"
diff --git a/src/Makefile b/src/Makefile
new file mode 100644
index 0000000..1171824
--- /dev/null
+++ b/src/Makefile
@@ -0,0 +1,10 @@
+all: password-store.sh
+
+clean:
+       rm -f password-store.sh
+
+%.sh: %.sh.in
+       m4 -P $< >$@
+       chmod +x $@
+
+.PHONY: all clean
diff --git a/src/password-store.sh b/src/password-store.sh.in
old mode 100755
new mode 100644
similarity index 98%
rename from src/password-store.sh
rename to src/password-store.sh.in
index eb98fad..0830010
--- a/src/password-store.sh
+++ b/src/password-store.sh.in
@@ -177,7 +177,14 @@ tmpdir() {
 GETOPT="getopt"
 SHRED="shred -f -z"
 
-# source /path/to/platform-defined-functions
+m4_dnl include platform specific functions during build
+m4_define(`newline', `
+')
+m4_define(`normalize', `m4_translit(`$1', newline, `')')
+m4_define(`tolower', `m4_translit(`$1', `A-Z', `a-z')')
+m4_define(`stripsuffix', `m4_patsubst(`$1', `_.*$', `')')
+m4_define(`uname', stripsuffix(tolower(normalize(m4_esyscmd(`uname')))))
+m4_sinclude(`platform/'uname`.sh')
 
 #
 # END platform definable
-- 
1.9.2

_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to