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