ramips: remove factory image for TP-Link Archer C20 v1
[openwrt/openwrt.git] / include / prereq.mk
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2006-2020 OpenWrt.org
4
5 ifneq ($(__prereq_inc),1)
6 __prereq_inc:=1
7
8 prereq:
9 if [ -f $(TMP_DIR)/.prereq-error ]; then \
10 echo; \
11 cat $(TMP_DIR)/.prereq-error; \
12 rm -f $(TMP_DIR)/.prereq-error; \
13 echo; \
14 false; \
15 fi
16
17 .SILENT: prereq
18 endif
19
20 PREREQ_PREV=
21
22 # 1: display name
23 # 2: error message
24 define Require
25 export PREREQ_CHECK=1
26 ifeq ($$(CHECK_$(1)),)
27 prereq: prereq-$(1)
28
29 prereq-$(1): $(if $(PREREQ_PREV),prereq-$(PREREQ_PREV)) FORCE
30 printf "Checking '$(1)'... "
31 if $(NO_TRACE_MAKE) -f $(firstword $(MAKEFILE_LIST)) check-$(1) >/dev/null 2>/dev/null; then \
32 echo 'ok.'; \
33 else \
34 echo 'failed.'; \
35 echo "$(PKG_NAME): $(strip $(2))" >> $(TMP_DIR)/.prereq-error; \
36 fi
37
38 check-$(1): FORCE
39 $(call Require/$(1))
40 CHECK_$(1):=1
41
42 .SILENT: prereq-$(1) check-$(1)
43 .NOTPARALLEL:
44 endif
45
46 PREREQ_PREV=$(1)
47 endef
48
49
50 define RequireCommand
51 define Require/$(1)
52 command -pv $(1)
53 endef
54
55 $$(eval $$(call Require,$(1),$(2)))
56 endef
57
58 define RequireHeader
59 define Require/$(1)
60 [ -e "$(1)" ]
61 endef
62
63 $$(eval $$(call Require,$(1),$(2)))
64 endef
65
66 define CleanupPython2
67 define Require/python2-cleanup
68 if [ -f "$(STAGING_DIR_HOST)/bin/python" ] && \
69 $(STAGING_DIR_HOST)/bin/python -V 2>&1 | \
70 grep -q 'Python 2'; then \
71 rm $(STAGING_DIR_HOST)/bin/python; \
72 fi
73 endef
74
75 $$(eval $$(call Require,python2-cleanup))
76 endef
77
78 define QuoteHostCommand
79 '$(subst ','"'"',$(strip $(1)))'
80 endef
81
82 # 1: display name
83 # 2: failure message
84 # 3: test
85 define TestHostCommand
86 define Require/$(1)
87 ($(3)) >/dev/null 2>/dev/null
88 endef
89
90 $$(eval $$(call Require,$(1),$(2)))
91 endef
92
93 # 1: canonical name
94 # 2: failure message
95 # 3+: candidates
96 define SetupHostCommand
97 define Require/$(1)
98 [ -f "$(STAGING_DIR_HOST)/bin/$(strip $(1))" ] && exit 0; \
99 for cmd in $(call QuoteHostCommand,$(3)) $(call QuoteHostCommand,$(4)) \
100 $(call QuoteHostCommand,$(5)) $(call QuoteHostCommand,$(6)) \
101 $(call QuoteHostCommand,$(7)) $(call QuoteHostCommand,$(8)) \
102 $(call QuoteHostCommand,$(9)) $(call QuoteHostCommand,$(10)) \
103 $(call QuoteHostCommand,$(11)) $(call QuoteHostCommand,$(12)); do \
104 if [ -n "$$$$$$$$cmd" ]; then \
105 bin="$$$$$$$$(PATH="$(subst $(space),:,$(filter-out $(STAGING_DIR_HOST)/%,$(subst :,$(space),$(PATH))))" \
106 command -pv "$$$$$$$${cmd%% *}")"; \
107 if [ -x "$$$$$$$$bin" ] && eval "$$$$$$$$cmd" >/dev/null 2>/dev/null; then \
108 mkdir -p "$(STAGING_DIR_HOST)/bin"; \
109 ln -sf "$$$$$$$$bin" "$(STAGING_DIR_HOST)/bin/$(strip $(1))"; \
110 exit 0; \
111 fi; \
112 fi; \
113 done; \
114 exit 1
115 endef
116
117 $$(eval $$(call Require,$(1),$(if $(2),$(2),Missing $(1) command)))
118 endef