kerl.mk 2.6 KB

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