kerl.mk 2.6 KB

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