aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sfx.mk
blob: 75d34da345732d46f0de8b40448c13e40e348cf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 -xzf - -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) -czf - $(RELX_RELEASE) >> $(SFX_OUTPUT)
	$(verbose) chmod +x $(SFX_OUTPUT)

endif
endif