sfx.mk 792 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (c) 2016, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. .PHONY: sfx
  4. ifdef RELX_RELEASE
  5. ifdef SFX
  6. # Configuration.
  7. SFX_OUTPUT = $(RELX_OUTPUT_DIR)/$(RELX_RELEASE).run
  8. # Core targets.
  9. rel:: sfx
  10. # Plugin-specific targets.
  11. define sfx_stub
  12. #!/bin/sh
  13. TMPDIR=`mktemp -d`
  14. ARCHIVE=`awk '/^__ARCHIVE_BELOW__$$/ {print NR + 1; exit 0;}' $$0`
  15. FILENAME=$$(basename $$0)
  16. REL=$${FILENAME%.*}
  17. tail -n+$$ARCHIVE $$0 | tar -xzf - -C $$TMPDIR
  18. $$TMPDIR/$$REL/bin/$$REL console
  19. RET=$$?
  20. rm -rf $$TMPDIR
  21. exit $$RET
  22. __ARCHIVE_BELOW__
  23. endef
  24. sfx:
  25. $(call render_template,sfx_stub,$(SFX_OUTPUT))
  26. $(gen_verbose) tar -C $(RELX_OUTPUT_DIR) -czf - $(RELX_RELEASE) >> $(SFX_OUTPUT)
  27. $(verbose) chmod +x $(SFX_OUTPUT)
  28. endif
  29. endif