deps.mk 2.6 KB

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