add a simple prerequisite check
[openwrt/svn-archive/archive.git] / openwrt / 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 include $(TOPDIR)/rules.mk
9 include $(INCLUDE_DIR)/verbose.mk
10
11 $(TMP_DIR):
12 mkdir -p $@
13
14 prereq:
15 @echo
16 @if [ -f $(TMP_DIR)/.prereq-error ]; then \
17 cat $(TMP_DIR)/.prereq-error; \
18 echo; \
19 rm -rf $(TMP_DIR); \
20 false; \
21 fi
22 @rm -rf $(TMP_DIR)
23 @mkdir -p $(TMP_DIR)
24
25 define Require
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 $(INCLUDE_DIR)/prereq.mk 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 endif
42 endef
43
44
45 define RequireCommand
46 define Require/$(1)
47 which $(1)
48 endef
49
50 $$(eval $$(call Require,$(1),$(2)))
51 endef
52
53 # Required for the toolchain
54 define Require/working-make
55 echo 'all: test' > $(TMP_DIR)/check.mk
56 echo 'e0 = $$$$(foreach s,foobar,$$$$(eval $$$$s:))' >> $(TMP_DIR)/check.mk
57 echo 'e1 = $$$$(foreach s,foobar, $$$$(eval $$$$s:))' >> $(TMP_DIR)/check.mk
58 echo 'test: $$$$(strip $$$$(e0)) $$$$(strip $$$$(e1))' >> $(TMP_DIR)/check.mk
59 $(NO_TRACE_MAKE) -f $(TMP_DIR)/check.mk
60 endef
61
62 $(eval $(call Require,working-make, \
63 Your make version is buggy. Please install GNU make v3.81 or later. \
64 ))
65
66 define Require/working-gcc
67 echo 'int main(int argc, char **argv) { return 0; }' | \
68 gcc -x c -o $(TMP_DIR)/a.out -
69 endef
70
71 $(eval $(call Require,working-gcc, \
72 No working GNU C Compiler was found on your system. \
73 ))
74
75 define Require/working-g++
76 echo 'int main(int argc, char **argv) { return 0; }' | \
77 g++ -x c++ -o $(TMP_DIR)/a.out -lstdc++ -
78 endef
79
80 $(eval $(call Require,working-g++, \
81 No working GNU C++ Compiler was found on your system. \
82 ))
83
84 define Require/zlib
85 echo 'int main(int argc, char **argv) { gzdopen(0, "rb"); return 0; }' | \
86 gcc -x c -o $(TMP_DIR)/a.out -lz -
87 endef
88
89 $(eval $(call Require,zlib, \
90 The development version of zlib was not found on your system. \
91 ))
92
93
94 $(eval $(call RequireCommand,bison, \
95 Please install GNU bison. \
96 ))
97
98 $(eval $(call RequireCommand,flex, \
99 Please install flex. \
100 ))
101
102 $(eval $(call RequireCommand,python, \
103 Please install python. \
104 ))
105
106 $(eval $(call RequireCommand,unzip, \
107 Please install unzip. \
108 ))
109
110 $(eval $(call RequireCommand,bzip2, \
111 Please install bzip2. \
112 ))
113
114 $(eval $(call RequireCommand,patch, \
115 Please install patch. \
116 ))
117
118