kerl.mk 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. export KERL
  9. KERL_GIT ?= https://github.com/kerl/kerl
  10. KERL_COMMIT ?= master
  11. KERL_MAKEFLAGS ?=
  12. OTP_GIT ?= https://github.com/erlang/otp
  13. define kerl_otp_target
  14. ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(1)),)
  15. $(KERL_INSTALL_DIR)/$(1): $(KERL)
  16. MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $(1) $(1)
  17. $(KERL) install $(1) $(KERL_INSTALL_DIR)/$(1)
  18. endif
  19. endef
  20. define kerl_hipe_target
  21. ifeq ($(wildcard $(KERL_INSTALL_DIR)/$1-native),)
  22. $(KERL_INSTALL_DIR)/$1-native: $(KERL)
  23. KERL_CONFIGURE_OPTIONS=--enable-native-libs \
  24. MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $1 $1-native
  25. $(KERL) install $1-native $(KERL_INSTALL_DIR)/$1-native
  26. endif
  27. endef
  28. $(KERL):
  29. $(verbose) mkdir -p $(ERLANG_MK_TMP)
  30. $(gen_verbose) git clone --depth 1 $(KERL_GIT) $(ERLANG_MK_TMP)/kerl
  31. $(verbose) cd $(ERLANG_MK_TMP)/kerl && git checkout $(KERL_COMMIT)
  32. $(verbose) chmod +x $(KERL)
  33. distclean:: distclean-kerl
  34. distclean-kerl:
  35. $(gen_verbose) rm -rf $(KERL)
  36. # Allow users to select which version of Erlang/OTP to use for a project.
  37. ifneq ($(strip $(LATEST_ERLANG_OTP)),)
  38. ERLANG_OTP := $(notdir $(lastword $(sort $(wildcard $(KERL_INSTALL_DIR)/*[^-native]))))
  39. endif
  40. ERLANG_OTP ?=
  41. ERLANG_HIPE ?=
  42. # Use kerl to enforce a specific Erlang/OTP version for a project.
  43. ifneq ($(strip $(ERLANG_OTP)),)
  44. export PATH := $(KERL_INSTALL_DIR)/$(ERLANG_OTP)/bin:$(PATH)
  45. SHELL := env PATH=$(PATH) $(SHELL)
  46. $(eval $(call kerl_otp_target,$(ERLANG_OTP)))
  47. # Build Erlang/OTP only if it doesn't already exist.
  48. ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(ERLANG_OTP))$(BUILD_ERLANG_OTP),)
  49. $(info Building Erlang/OTP $(ERLANG_OTP)... Please wait...)
  50. $(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_OTP) ERLANG_OTP=$(ERLANG_OTP) BUILD_ERLANG_OTP=1 >&2)
  51. endif
  52. else
  53. # Same for a HiPE enabled VM.
  54. ifneq ($(strip $(ERLANG_HIPE)),)
  55. export PATH := $(KERL_INSTALL_DIR)/$(ERLANG_HIPE)-native/bin:$(PATH)
  56. SHELL := env PATH=$(PATH) $(SHELL)
  57. $(eval $(call kerl_hipe_target,$(ERLANG_HIPE)))
  58. # Build Erlang/OTP only if it doesn't already exist.
  59. ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(ERLANG_HIPE))$(BUILD_ERLANG_OTP),)
  60. $(info Building HiPE-enabled Erlang/OTP $(ERLANG_OTP)... Please wait...)
  61. $(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_HIPE) ERLANG_HIPE=$(ERLANG_HIPE) BUILD_ERLANG_OTP=1 >&2)
  62. endif
  63. endif
  64. endif