2
0

prereq.mk 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #
  2. # Copyright (C) 2006-2015 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifneq ($(__prereq_inc),1)
  8. __prereq_inc:=1
  9. prereq:
  10. if [ -f $(TMP_DIR)/.prereq-error ]; then \
  11. echo; \
  12. cat $(TMP_DIR)/.prereq-error; \
  13. rm -f $(TMP_DIR)/.prereq-error; \
  14. echo; \
  15. false; \
  16. fi
  17. .SILENT: prereq
  18. endif
  19. PREREQ_PREV=
  20. # 1: display name
  21. # 2: error message
  22. define Require
  23. export PREREQ_CHECK=1
  24. ifeq ($$(CHECK_$(1)),)
  25. prereq: prereq-$(1)
  26. prereq-$(1): $(if $(PREREQ_PREV),prereq-$(PREREQ_PREV)) FORCE
  27. printf "Checking '$(1)'... "
  28. if $(NO_TRACE_MAKE) -f $(firstword $(MAKEFILE_LIST)) check-$(1) >/dev/null 2>/dev/null; then \
  29. echo 'ok.'; \
  30. else \
  31. echo 'failed.'; \
  32. echo "$(PKG_NAME): $(strip $(2))" >> $(TMP_DIR)/.prereq-error; \
  33. fi
  34. check-$(1): FORCE
  35. $(call Require/$(1))
  36. CHECK_$(1):=1
  37. .SILENT: prereq-$(1) check-$(1)
  38. .NOTPARALLEL:
  39. endif
  40. PREREQ_PREV=$(1)
  41. endef
  42. define RequireCommand
  43. define Require/$(1)
  44. which $(1)
  45. endef
  46. $$(eval $$(call Require,$(1),$(2)))
  47. endef
  48. define RequireHeader
  49. define Require/$(1)
  50. [ -e "$(1)" ]
  51. endef
  52. $$(eval $$(call Require,$(1),$(2)))
  53. endef
  54. define QuoteHostCommand
  55. '$(subst ','"'"',$(strip $(1)))'
  56. endef
  57. # 1: display name
  58. # 2: failure message
  59. # 3: test
  60. define TestHostCommand
  61. define Require/$(1)
  62. ($(3)) >/dev/null 2>/dev/null
  63. endef
  64. $$(eval $$(call Require,$(1),$(2)))
  65. endef
  66. # 1: canonical name
  67. # 2: failure message
  68. # 3+: candidates
  69. define SetupHostCommand
  70. define Require/$(1)
  71. [ -f "$(STAGING_DIR_HOST)/bin/$(strip $(1))" ] && exit 0; \
  72. for cmd in $(call QuoteHostCommand,$(3)) $(call QuoteHostCommand,$(4)) \
  73. $(call QuoteHostCommand,$(5)) $(call QuoteHostCommand,$(6)) \
  74. $(call QuoteHostCommand,$(7)) $(call QuoteHostCommand,$(8)) \
  75. $(call QuoteHostCommand,$(9)) $(call QuoteHostCommand,$(10)) \
  76. $(call QuoteHostCommand,$(11)) $(call QuoteHostCommand,$(12)); do \
  77. if [ -n "$$$$$$$$cmd" ]; then \
  78. bin="$$$$$$$$(PATH="$(subst $(space),:,$(filter-out $(STAGING_DIR_HOST)/%,$(subst :,$(space),$(PATH))))" \
  79. which "$$$$$$$${cmd%% *}")"; \
  80. if [ -x "$$$$$$$$bin" ] && eval "$$$$$$$$cmd" >/dev/null 2>/dev/null; then \
  81. mkdir -p "$(STAGING_DIR_HOST)/bin"; \
  82. ln -sf "$$$$$$$$bin" "$(STAGING_DIR_HOST)/bin/$(strip $(1))"; \
  83. exit 0; \
  84. fi; \
  85. fi; \
  86. done; \
  87. exit 1
  88. endef
  89. $$(eval $$(call Require,$(1),$(if $(2),$(2),Missing $(1) command)))
  90. endef