deps.mk 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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" | $(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. else \
  37. echo "Unknown or invalid dependency: $(1). Please consult the erlang.mk README for instructions." >&2; \
  38. exit 78; \
  39. fi
  40. endef
  41. define dep_target
  42. $(DEPS_DIR)/$(1):
  43. @mkdir -p $(DEPS_DIR)
  44. @if [ ! -f $(PKG_FILE2) ]; then $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL)); fi
  45. ifeq (,$(dep_$(1)))
  46. DEPPKG=$$$$(awk 'BEGIN { FS = "\t" }; $$$$1 == "$(1)" { print $$$$2 " " $$$$3 " " $$$$4 }' $(PKG_FILE2);) \
  47. VS=$$$$(echo $$$$DEPPKG | cut -d " " -f1); \
  48. REPO=$$$$(echo $$$$DEPPKG | cut -d " " -f2); \
  49. COMMIT=$$$$(echo $$$$DEPPKG | cut -d " " -f3); \
  50. $(call dep_fetch,$(1))
  51. else
  52. VS=$(word 1,$(dep_$(1))); \
  53. REPO=$(word 2,$(dep_$(1))); \
  54. COMMIT=$(word 3,$(dep_$(1))); \
  55. $(call dep_fetch,$(1))
  56. endif
  57. endef
  58. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  59. distclean-deps:
  60. $(gen_verbose) rm -rf $(DEPS_DIR)
  61. # Packages related targets.
  62. $(PKG_FILE2):
  63. $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL))
  64. pkg-list: $(PKG_FILE2)
  65. @cat $(PKG_FILE2) | awk 'BEGIN { FS = "\t" }; { print \
  66. "Name:\t\t" $$1 "\n" \
  67. "Repository:\t" $$3 "\n" \
  68. "Website:\t" $$5 "\n" \
  69. "Description:\t" $$6 "\n" }'
  70. ifdef q
  71. pkg-search: $(PKG_FILE2)
  72. @cat $(PKG_FILE2) | grep -i ${q} | awk 'BEGIN { FS = "\t" }; { print \
  73. "Name:\t\t" $$1 "\n" \
  74. "Repository:\t" $$3 "\n" \
  75. "Website:\t" $$5 "\n" \
  76. "Description:\t" $$6 "\n" }'
  77. else
  78. pkg-search:
  79. $(error Usage: make pkg-search q=STRING)
  80. endif
  81. distclean-pkg:
  82. $(gen_verbose) rm -f $(PKG_FILE2)
  83. help::
  84. @printf "%s\n" "" \
  85. "Package-related targets:" \
  86. " pkg-list List all known packages" \
  87. " pkg-search q=STRING Search for STRING in the package index"