deps.mk 3.0 KB

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