prereq.mk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 CleanupPython3
  55. define Require/python3-cleanup
  56. if [ -f "$(STAGING_DIR_HOST)/bin/python" ] && \
  57. $(STAGING_DIR_HOST)/bin/python -V 2>&1 | \
  58. grep -q 'Python 3'; then \
  59. rm $(STAGING_DIR_HOST)/bin/python; \
  60. fi
  61. endef
  62. $$(eval $$(call Require,python3-cleanup))
  63. endef
  64. define QuoteHostCommand
  65. '$(subst ','"'"',$(strip $(1)))'
  66. endef
  67. # 1: display name
  68. # 2: failure message
  69. # 3: test
  70. define TestHostCommand
  71. define Require/$(1)
  72. ($(3)) >/dev/null 2>/dev/null
  73. endef
  74. $$(eval $$(call Require,$(1),$(2)))
  75. endef
  76. # 1: canonical name
  77. # 2: failure message
  78. # 3+: candidates
  79. define SetupHostCommand
  80. define Require/$(1)
  81. [ -f "$(STAGING_DIR_HOST)/bin/$(strip $(1))" ] && exit 0; \
  82. for cmd in $(call QuoteHostCommand,$(3)) $(call QuoteHostCommand,$(4)) \
  83. $(call QuoteHostCommand,$(5)) $(call QuoteHostCommand,$(6)) \
  84. $(call QuoteHostCommand,$(7)) $(call QuoteHostCommand,$(8)) \
  85. $(call QuoteHostCommand,$(9)) $(call QuoteHostCommand,$(10)) \
  86. $(call QuoteHostCommand,$(11)) $(call QuoteHostCommand,$(12)); do \
  87. if [ -n "$$$$$$$$cmd" ]; then \
  88. bin="$$$$$$$$(PATH="$(subst $(space),:,$(filter-out $(STAGING_DIR_HOST)/%,$(subst :,$(space),$(PATH))))" \
  89. which "$$$$$$$${cmd%% *}")"; \
  90. if [ -x "$$$$$$$$bin" ] && eval "$$$$$$$$cmd" >/dev/null 2>/dev/null; then \
  91. mkdir -p "$(STAGING_DIR_HOST)/bin"; \
  92. ln -sf "$$$$$$$$bin" "$(STAGING_DIR_HOST)/bin/$(strip $(1))"; \
  93. exit 0; \
  94. fi; \
  95. fi; \
  96. done; \
  97. exit 1
  98. endef
  99. $$(eval $$(call Require,$(1),$(if $(2),$(2),Missing $(1) command)))
  100. endef