e514855a67fdf3177a583270a22f97934097dce8
[openwrt-10.03/.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 include $(TOPDIR)/rules.mk
9
10 $(TMP_DIR):
11         mkdir -p $@
12
13 prereq:
14         echo
15         if [ -f $(TMP_DIR)/.prereq-error ]; then \
16                 cat $(TMP_DIR)/.prereq-error; \
17                 echo; \
18                 rm -rf $(TMP_DIR); \
19                 false; \
20         fi
21         rm -rf $(TMP_DIR)
22         mkdir -p $(TMP_DIR)
23
24 .SILENT: $(TMP_DIR) prereq
25
26 define Require
27   ifeq ($$(CHECK_$(1)),)
28     prereq: prereq-$(1)
29
30     prereq-$(1): $(TMP_DIR) FORCE
31                 echo -n "Checking '$(1)'... "
32                 if $(NO_TRACE_MAKE) -f $(INCLUDE_DIR)/prereq.mk check-$(1) >/dev/null 2>/dev/null; then \
33                         echo 'ok.'; \
34                 else \
35                         echo 'failed.'; \
36                         echo -e "$(strip $(2))" >> $(TMP_DIR)/.prereq-error; \
37                 fi
38
39     check-$(1): FORCE
40           $(call Require/$(1))
41     CHECK_$(1):=1
42
43     .SILENT: prereq-$(1) check-$(1)
44   endif
45 endef
46
47
48 define RequireCommand
49   define Require/$(1)
50     which $(1)
51   endef
52
53   $$(eval $$(call Require,$(1),$(2)))
54 endef
55
56 # Required for the toolchain
57 define Require/working-make
58         echo 'all: test' > $(TMP_DIR)/check.mk
59         echo 'e0 = $$$$(foreach s,foobar,$$$$(eval $$$$s:))' >> $(TMP_DIR)/check.mk
60         echo 'e1 = $$$$(foreach s,foobar, $$$$(eval $$$$s:))' >> $(TMP_DIR)/check.mk
61         echo 'test: $$$$(strip $$$$(e0)) $$$$(strip $$$$(e1))' >> $(TMP_DIR)/check.mk
62         $(NO_TRACE_MAKE) -f $(TMP_DIR)/check.mk
63 endef
64
65 $(eval $(call Require,working-make, \
66         Your make version is buggy. Please install GNU make v3.81 or later. \
67 ))
68
69 define Require/working-gcc
70         echo 'int main(int argc, char **argv) { return 0; }' | \
71                 gcc -x c -o $(TMP_DIR)/a.out -
72 endef
73
74 $(eval $(call Require,working-gcc, \
75         No working GNU C Compiler (gcc) was found on your system. \
76 ))
77
78 define Require/working-g++
79         echo 'int main(int argc, char **argv) { return 0; }' | \
80                 g++ -x c++ -o $(TMP_DIR)/a.out -lstdc++ -
81 endef
82
83 $(eval $(call Require,working-g++, \
84         No working GNU C++ Compiler (g++) was found on your system. \
85 ))
86
87 define Require/ncurses
88         echo 'int main(int argc, char **argv) { initscr(); return 0; }' | \
89                 gcc -include ncurses.h -x c -o $(TMP_DIR)/a.out -lncurses -
90 endef
91
92 $(eval $(call Require,ncurses, \
93         No ncurses development files were not found on your system. \
94 ))
95
96
97 define Require/zlib
98         echo 'int main(int argc, char **argv) { gzdopen(0, "rb"); return 0; }' | \
99                 gcc -include zlib.h -x c -o $(TMP_DIR)/a.out -lz -
100 endef
101
102 $(eval $(call Require,zlib, \
103         No zlib development files were not found on your system. \
104 ))
105
106
107 $(eval $(call RequireCommand,bison, \
108         Please install GNU bison. \
109 ))
110
111 $(eval $(call RequireCommand,flex, \
112         Please install flex. \
113 ))
114
115 $(eval $(call RequireCommand,python, \
116         Please install python. \
117 ))
118
119 $(eval $(call RequireCommand,unzip, \
120         Please install unzip. \
121 ))
122
123 $(eval $(call RequireCommand,bzip2, \
124         Please install bzip2. \
125 ))
126
127 $(eval $(call RequireCommand,patch, \
128         Please install patch. \
129 ))
130
131 $(eval $(call RequireCommand,perl, \
132         Please install perl. \
133 ))