aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sfx.mk
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/sfx.mk')
-rw-r--r--plugins/sfx.mk45
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/sfx.mk b/plugins/sfx.mk
new file mode 100644
index 0000000..ab9761c
--- /dev/null
+++ b/plugins/sfx.mk
@@ -0,0 +1,45 @@
+# Copyright (c) 2016, Loïc Hoguin <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: sfx
+
+ifdef RELX_RELEASE
+ifdef SFX
+
+# Configuration.
+
+SFX_OUTPUT = $(RELX_OUTPUT_DIR)/$(RELX_RELEASE).run
+
+# Core targets.
+
+rel:: sfx
+
+# Plugin-specific targets.
+
+define sfx_stub
+#!/bin/sh
+
+TMPDIR=`mktemp -d`
+ARCHIVE=`awk '/^__ARCHIVE_BELOW__$$/ {print NR + 1; exit 0;}' $$0`
+FILENAME=$$(basename $$0)
+REL=$${FILENAME%.*}
+
+tail -n+$$ARCHIVE $$0 | tar xz -C $$TMPDIR
+
+$$TMPDIR/$$REL/bin/$$REL console
+RET=$$?
+
+rm -rf $$TMPDIR
+
+exit $$RET
+
+__ARCHIVE_BELOW__
+endef
+
+sfx:
+ $(call render_template,sfx_stub,$(SFX_OUTPUT))
+ $(gen_verbose) tar -C $(RELX_OUTPUT_DIR) -czO $(RELX_RELEASE) >> $(SFX_OUTPUT)
+ $(verbose) chmod +x $(SFX_OUTPUT)
+
+endif
+endif