include: remove trailing whitespaces
[openwrt.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 QuoteHostCommand
70 '$(subst ','"'"',$(strip $(1)))'
71 endef
72
73 # 1: display name
74 # 2: failure message
75 # 3: test
76 define TestHostCommand
77   define Require/$(1)
78         ($(3)) >/dev/null 2>/dev/null
79   endef
80
81   $$(eval $$(call Require,$(1),$(2)))
82 endef
83
84 # 1: canonical name
85 # 2: failure message
86 # 3+: candidates
87 define SetupHostCommand
88   define Require/$(1)
89         for cmd in $(call QuoteHostCommand,$(3)) $(call QuoteHostCommand,$(4)) \
90                    $(call QuoteHostCommand,$(5)) $(call QuoteHostCommand,$(6)) \
91                    $(call QuoteHostCommand,$(7)) $(call QuoteHostCommand,$(8)) \
92                            $(call QuoteHostCommand,$(9)); do \
93                 if [ -n "$$$$$$$$cmd" ]; then \
94                         bin="$$$$$$$$(PATH="$(subst $(space),:,$(filter-out $(STAGING_DIR_HOST)/%,$(subst :,$(space),$(PATH))))" \
95                                 which "$$$$$$$${cmd%% *}")"; \
96                         if [ -x "$$$$$$$$bin" ] && eval "$$$$$$$$cmd" >/dev/null 2>/dev/null; then \
97                                 mkdir -p "$(STAGING_DIR_HOST)/bin"; \
98                                 ln -sf "$$$$$$$$bin" "$(STAGING_DIR_HOST)/bin/$(strip $(1))"; \
99                                 exit 0; \
100                         fi; \
101                 fi; \
102         done; \
103         exit 1
104   endef
105
106   $$(eval $$(call Require,$(1),$(if $(2),$(2),Missing $(1) command)))
107 endef