sfx.mk 865 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_REL
  5. ifdef SFX
  6. # Configuration.
  7. SFX_ARCHIVE ?= $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/$(RELX_REL_NAME)-$(RELX_REL_VSN).tar.gz
  8. SFX_OUTPUT_FILE ?= $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME).run
  9. # Core targets.
  10. rel:: sfx
  11. # Plugin-specific targets.
  12. define sfx_stub
  13. #!/bin/sh
  14. TMPDIR=`mktemp -d`
  15. ARCHIVE=`awk '/^__ARCHIVE_BELOW__$$/ {print NR + 1; exit 0;}' $$0`
  16. FILENAME=$$(basename $$0)
  17. REL=$${FILENAME%.*}
  18. tail -n+$$ARCHIVE $$0 | tar -xzf - -C $$TMPDIR
  19. $$TMPDIR/bin/$$REL console
  20. RET=$$?
  21. rm -rf $$TMPDIR
  22. exit $$RET
  23. __ARCHIVE_BELOW__
  24. endef
  25. sfx:
  26. $(call render_template,sfx_stub,$(SFX_OUTPUT_FILE))
  27. $(gen_verbose) cat $(SFX_ARCHIVE) >> $(SFX_OUTPUT_FILE)
  28. $(verbose) chmod +x $(SFX_OUTPUT_FILE)
  29. endif
  30. endif