deps.mk 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_FILE ?= $(CURDIR)/.erlang.mk.packages.v2
  19. export PKG_FILE
  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_git
  33. git clone -n -- $(2) $(DEPS_DIR)/$(1)
  34. cd $(DEPS_DIR)/$(1) ; git checkout -q $(3)
  35. endef
  36. define dep_fetch
  37. @mkdir -p $(DEPS_DIR)
  38. ifeq (,$(dep_$(1)))
  39. @if [ ! -f $(PKG_FILE) ]; then $(call core_http_get,$(PKG_FILE),$(PKG_FILE_URL)); fi
  40. $(eval DEP_FETCH_PKG := $(shell awk 'BEGIN { FS = "\t" }; $$1 == "$(1)" { print $$2 " " $$3 " "$$4 }' $(PKG_FILE)))
  41. $(call dep_fetch_$(word 1,$(DEP_FETCH_PKG)),$(1),$(word 2,$(DEP_FETCH_PKG)),$(word 3,$(DEP_FETCH_PKG)))
  42. else
  43. $(call dep_fetch_$(word 1,$(dep_$(1))),$(1),$(word 2,$(dep_$(1))),$(word 3,$(dep_$(1))))
  44. endif
  45. endef
  46. define dep_target
  47. $(DEPS_DIR)/$(1):
  48. $(call dep_fetch,$(1))
  49. endef
  50. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  51. distclean-deps:
  52. $(gen_verbose) rm -rf $(DEPS_DIR)
  53. # Packages related targets.
  54. $(PKG_FILE):
  55. $(call core_http_get,$(PKG_FILE),$(PKG_FILE_URL))
  56. pkg-list: $(PKG_FILE)
  57. @cat $(PKG_FILE) | awk 'BEGIN { FS = "\t" }; { print \
  58. "Name:\t\t" $$1 "\n" \
  59. "Repository:\t" $$3 "\n" \
  60. "Website:\t" $$5 "\n" \
  61. "Description:\t" $$6 "\n" }'
  62. ifdef q
  63. pkg-search: $(PKG_FILE)
  64. @cat $(PKG_FILE) | grep -i ${q} | 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. else
  70. pkg-search:
  71. $(error Usage: make pkg-search q=STRING)
  72. endif
  73. distclean-pkg:
  74. $(gen_verbose) rm -f $(PKG_FILE)
  75. help::
  76. @printf "%s\n" "" \
  77. "Package-related targets:" \
  78. " pkg-list List all known packages" \
  79. " pkg-search q=STRING Search for STRING in the package index"