fix dependencies on the virtual kernel package (fixes #878)
[oweals/openwrt.git] / include / prereq.mk
1
2 # Copyright (C) 2006 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 $(TMP_DIR):
9         mkdir -p $@
10
11 prereq:
12         if [ -f $(TMP_DIR)/.prereq-error ]; then \
13                 echo; \
14                 cat $(TMP_DIR)/.prereq-error; \
15                 echo; \
16                 rm -rf $(TMP_DIR); \
17                 false; \
18         fi
19         rm -rf $(TMP_DIR)
20         mkdir -p $(TMP_DIR)
21
22 .SILENT: $(TMP_DIR) prereq
23
24 define Require
25   export PREREQ_CHECK=1
26   ifeq ($$(CHECK_$(1)),)
27     prereq: prereq-$(1)
28
29     prereq-$(1): $(TMP_DIR) FORCE
30                 echo -n "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 -e "$(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   endif
44 endef
45
46
47 define RequireCommand
48   define Require/$(1)
49     which $(1)
50   endef
51
52   $$(eval $$(call Require,$(1),$(2)))
53 endef
54