deps.mk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Copyright (c) 2013-2014, 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-deps distclean-pkg pkg-list pkg-search
  4. # Configuration.
  5. DEPS_DIR ?= $(CURDIR)/deps
  6. export DEPS_DIR
  7. REBAR_DEPS_DIR = $(DEPS_DIR)
  8. export REBAR_DEPS_DIR
  9. ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(DEPS))
  10. ifeq ($(filter $(DEPS_DIR),$(subst :, ,$(ERL_LIBS))),)
  11. ifeq ($(ERL_LIBS),)
  12. ERL_LIBS = $(DEPS_DIR)
  13. else
  14. ERL_LIBS := $(ERL_LIBS):$(DEPS_DIR)
  15. endif
  16. endif
  17. export ERL_LIBS
  18. PKG_FILE2 ?= $(CURDIR)/.erlang.mk.packages.v2
  19. export PKG_FILE2
  20. PKG_FILE_URL ?= https://raw.githubusercontent.com/ninenines/erlang.mk/master/packages.v2.tsv
  21. # Core targets.
  22. deps:: $(ALL_DEPS_DIRS)
  23. @for dep in $(ALL_DEPS_DIRS) ; do \
  24. if [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ] ; then \
  25. $(MAKE) -C $$dep ; \
  26. else \
  27. echo "include $(CURDIR)/erlang.mk" | ERLC_OPTS=+debug_info $(MAKE) -f - -C $$dep ; \
  28. fi ; \
  29. done
  30. distclean:: distclean-deps distclean-pkg
  31. # Deps related targets.
  32. define dep_fetch
  33. if [ "$$$$VS" = "git" ]; then \
  34. git clone -n -- $$$$REPO $(DEPS_DIR)/$(1); \
  35. cd $(DEPS_DIR)/$(1) && git checkout -q $$$$COMMIT; \
  36. elif [ "$$$$VS" = "hg" ]; then \
  37. hg clone -U $$$$REPO $(DEPS_DIR)/$(1); \
  38. cd $(DEPS_DIR)/$(1) && hg update -q $$$$COMMIT; \
  39. else \
  40. echo "Unknown or invalid dependency: $(1). Please consult the erlang.mk README for instructions." >&2; \
  41. exit 78; \
  42. fi
  43. endef
  44. define dep_target
  45. $(DEPS_DIR)/$(1):
  46. @mkdir -p $(DEPS_DIR)
  47. ifeq (,$(dep_$(1)))
  48. @if [ ! -f $(PKG_FILE2) ]; then $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL)); fi
  49. @DEPPKG=$$$$(awk 'BEGIN { FS = "\t" }; $$$$1 == "$(1)" { print $$$$2 " " $$$$3 " " $$$$4 }' $(PKG_FILE2);); \
  50. VS=$$$$(echo $$$$DEPPKG | cut -d " " -f1); \
  51. REPO=$$$$(echo $$$$DEPPKG | cut -d " " -f2); \
  52. COMMIT=$$$$(echo $$$$DEPPKG | cut -d " " -f3); \
  53. $(call dep_fetch,$(1))
  54. else
  55. @VS=$(word 1,$(dep_$(1))); \
  56. REPO=$(word 2,$(dep_$(1))); \
  57. COMMIT=$(word 3,$(dep_$(1))); \
  58. $(call dep_fetch,$(1))
  59. endif
  60. endef
  61. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  62. distclean-deps:
  63. $(gen_verbose) rm -rf $(DEPS_DIR)
  64. # Packages related targets.
  65. $(PKG_FILE2):
  66. @$(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL))
  67. pkg-list: $(PKG_FILE2)
  68. @cat $(PKG_FILE2) | awk 'BEGIN { FS = "\t" }; { print \
  69. "Name:\t\t" $$1 "\n" \
  70. "Repository:\t" $$3 "\n" \
  71. "Website:\t" $$5 "\n" \
  72. "Description:\t" $$6 "\n" }'
  73. ifdef q
  74. pkg-search: $(PKG_FILE2)
  75. @cat $(PKG_FILE2) | grep -i ${q} | awk 'BEGIN { FS = "\t" }; { print \
  76. "Name:\t\t" $$1 "\n" \
  77. "Repository:\t" $$3 "\n" \
  78. "Website:\t" $$5 "\n" \
  79. "Description:\t" $$6 "\n" }'
  80. else
  81. pkg-search:
  82. $(error Usage: make pkg-search q=STRING)
  83. endif
  84. ifeq ($(PKG_FILE2),$(CURDIR)/.erlang.mk.packages.v2)
  85. distclean-pkg:
  86. $(gen_verbose) rm -f $(PKG_FILE2)
  87. endif
  88. help::
  89. @printf "%s\n" "" \
  90. "Package-related targets:" \
  91. " pkg-list List all known packages" \
  92. " pkg-search q=STRING Search for STRING in the package index"