kerl.mk 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. ERLANG_OTP ?=
  38. ERLANG_HIPE ?=
  39. # Use kerl to enforce a specific Erlang/OTP version for a project.
  40. ifneq ($(strip $(ERLANG_OTP)),)
  41. export PATH := $(KERL_INSTALL_DIR)/$(ERLANG_OTP)/bin:$(PATH)
  42. SHELL := env PATH=$(PATH) $(SHELL)
  43. $(eval $(call kerl_otp_target,$(ERLANG_OTP)))
  44. # Build Erlang/OTP only if it doesn't already exist.
  45. ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(ERLANG_OTP))$(BUILD_ERLANG_OTP),)
  46. $(info Building Erlang/OTP $(ERLANG_OTP)... Please wait...)
  47. $(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_OTP) ERLANG_OTP=$(ERLANG_OTP) BUILD_ERLANG_OTP=1 >&2)
  48. endif
  49. else
  50. # Same for a HiPE enabled VM.
  51. ifneq ($(strip $(ERLANG_HIPE)),)
  52. export PATH := $(KERL_INSTALL_DIR)/$(ERLANG_HIPE)-native/bin:$(PATH)
  53. SHELL := env PATH=$(PATH) $(SHELL)
  54. $(eval $(call kerl_hipe_target,$(ERLANG_HIPE)))
  55. # Build Erlang/OTP only if it doesn't already exist.
  56. ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(ERLANG_HIPE))$(BUILD_ERLANG_OTP),)
  57. $(info Building HiPE-enabled Erlang/OTP $(ERLANG_OTP)... Please wait...)
  58. $(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_HIPE) ERLANG_HIPE=$(ERLANG_HIPE) BUILD_ERLANG_OTP=1 >&2)
  59. endif
  60. endif
  61. endif