kerl.mk 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (c) 2015-2017, 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: distclean-kerl
  4. KERL_INSTALL_DIR ?= $(HOME)/erlang
  5. ifeq ($(strip $(KERL)),)
  6. KERL := $(ERLANG_MK_TMP)/kerl/kerl
  7. endif
  8. KERL_DIR = $(ERLANG_MK_TMP)/kerl
  9. export KERL
  10. KERL_GIT ?= https://github.com/kerl/kerl
  11. KERL_COMMIT ?= master
  12. KERL_MAKEFLAGS ?=
  13. OTP_GIT ?= https://github.com/erlang/otp
  14. define kerl_otp_target
  15. $(KERL_INSTALL_DIR)/$(1): $(KERL)
  16. $(verbose) if [ ! -d $$@ ]; then \
  17. MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $(1) $(1); \
  18. $(KERL) install $(1) $(KERL_INSTALL_DIR)/$(1); \
  19. fi
  20. endef
  21. $(KERL): $(KERL_DIR)
  22. $(KERL_DIR): | $(ERLANG_MK_TMP)
  23. $(gen_verbose) git clone --depth 1 $(KERL_GIT) $(ERLANG_MK_TMP)/kerl
  24. $(verbose) cd $(ERLANG_MK_TMP)/kerl && git checkout $(KERL_COMMIT)
  25. $(verbose) chmod +x $(KERL)
  26. distclean:: distclean-kerl
  27. distclean-kerl:
  28. $(gen_verbose) rm -rf $(KERL_DIR)
  29. # Allow users to select which version of Erlang/OTP to use for a project.
  30. ifneq ($(strip $(LATEST_ERLANG_OTP)),)
  31. # In some environments it is necessary to filter out master.
  32. ERLANG_OTP := $(notdir $(lastword $(sort\
  33. $(filter-out $(KERL_INSTALL_DIR)/master $(KERL_INSTALL_DIR)/OTP_R%,\
  34. $(filter-out %-rc1 %-rc2 %-rc3,$(wildcard $(KERL_INSTALL_DIR)/*[^-native]))))))
  35. endif
  36. ERLANG_OTP ?=
  37. # Use kerl to enforce a specific Erlang/OTP version for a project.
  38. ifneq ($(strip $(ERLANG_OTP)),)
  39. export PATH := $(KERL_INSTALL_DIR)/$(ERLANG_OTP)/bin:$(PATH)
  40. SHELL := env PATH=$(PATH) $(SHELL)
  41. $(eval $(call kerl_otp_target,$(ERLANG_OTP)))
  42. # Build Erlang/OTP only if it doesn't already exist.
  43. ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(ERLANG_OTP))$(BUILD_ERLANG_OTP),)
  44. $(info Building Erlang/OTP $(ERLANG_OTP)... Please wait...)
  45. $(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_OTP) ERLANG_OTP=$(ERLANG_OTP) BUILD_ERLANG_OTP=1 >&2)
  46. endif
  47. endif