prereq-build: add check for true and false
[openwrt/staging/jow.git] / include / prereq-build.mk
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2006-2020 OpenWrt.org
4
5 include $(TOPDIR)/rules.mk
6 include $(INCLUDE_DIR)/prereq.mk
7
8 SHELL:=sh
9 PKG_NAME:=Build dependency
10
11 $(eval $(call TestHostCommand,true, \
12 Please install GNU 'coreutils', \
13 $(TRUE)))
14
15 $(eval $(call TestHostCommand,false, \
16 Please install GNU 'coreutils', \
17 $(FALSE); [ $$$$$$$$? = 1 ] && $(TRUE)))
18
19 # Required for the toolchain
20 $(eval $(call TestHostCommand,working-make, \
21 Please install GNU make v4.1 or later., \
22 $(MAKE) -v | grep -E 'Make (4\.[1-9]|[5-9]\.)'))
23
24 $(eval $(call TestHostCommand,case-sensitive-fs, \
25 OpenWrt can only be built on a case-sensitive filesystem, \
26 rm -f $(TMP_DIR)/test.*; touch $(TMP_DIR)/test.fs; \
27 test ! -f $(TMP_DIR)/test.FS))
28
29 $(eval $(call TestHostCommand,proper-umask, \
30 Please build with umask 022 - other values produce broken packages, \
31 umask | grep -xE 0?0[012][012]))
32
33 ifndef IB
34 $(eval $(call SetupHostCommand,gcc, \
35 Please install the GNU C Compiler (gcc) 6 or later, \
36 $(CC) -dumpversion | grep -E '^([6-9]\.?|1[0-9]\.?)', \
37 gcc -dumpversion | grep -E '^([6-9]\.?|1[0-9]\.?)', \
38 gcc --version | grep -E 'Apple.(LLVM|clang)' ))
39
40 $(eval $(call TestHostCommand,working-gcc, \
41 Please reinstall the GNU C Compiler (6 or later) - \
42 it appears to be broken, \
43 echo 'int main(int argc, char **argv) { return 0; }' | \
44 gcc -x c -o $(TMP_DIR)/a.out -))
45
46 $(eval $(call SetupHostCommand,g++, \
47 Please install the GNU C++ Compiler (g++) 6 or later, \
48 $(CXX) -dumpversion | grep -E '^([6-9]\.?|1[0-9]\.?)', \
49 g++ -dumpversion | grep -E '^([6-9]\.?|1[0-9]\.?)', \
50 g++ --version | grep -E 'Apple.(LLVM|clang)' ))
51
52 $(eval $(call TestHostCommand,working-g++, \
53 Please reinstall the GNU C++ Compiler (6 or later) - \
54 it appears to be broken, \
55 echo 'int main(int argc, char **argv) { return 0; }' | \
56 g++ -x c++ -o $(TMP_DIR)/a.out - -lstdc++ && \
57 $(TMP_DIR)/a.out))
58
59 $(eval $(call RequireCHeader,ncurses.h, \
60 Please install ncurses. (Missing libncurses.so or ncurses.h), \
61 initscr(), -lncurses))
62
63 $(eval $(call SetupHostCommand,git,Please install Git (git-core) >= 1.7.12.2, \
64 git --exec-path | xargs -I % -- grep -q -- --recursive %/git-submodule, \
65 git submodule --help | grep -- --recursive))
66
67 $(eval $(call SetupHostCommand,rsync,Please install 'rsync', \
68 rsync --version </dev/null))
69 endif # IB
70
71 ifeq ($(HOST_OS),Linux)
72 zlib_link_flags := -Wl,-Bstatic -lz -Wl,-Bdynamic
73 else
74 zlib_link_flags := -lz
75 endif
76
77 $(eval $(call TestHostCommand,perl-data-dumper, \
78 Please install the Perl Data::Dumper module, \
79 perl -MData::Dumper -e 1))
80
81 $(eval $(call TestHostCommand,perl-findbin, \
82 Please install the Perl FindBin module, \
83 perl -MFindBin -e 1))
84
85 $(eval $(call TestHostCommand,perl-file-copy, \
86 Please install the Perl File::Copy module, \
87 perl -MFile::Copy -e 1))
88
89 $(eval $(call TestHostCommand,perl-file-compare, \
90 Please install the Perl File::Compare module, \
91 perl -MFile::Compare -e 1))
92
93 $(eval $(call TestHostCommand,perl-thread-queue, \
94 Please install the Perl Thread::Queue module, \
95 perl -MThread::Queue -e 1))
96
97 $(eval $(call SetupHostCommand,tar,Please install GNU 'tar', \
98 gtar --version 2>&1 | grep GNU, \
99 gnutar --version 2>&1 | grep GNU, \
100 tar --version 2>&1 | grep GNU))
101
102 $(eval $(call SetupHostCommand,find,Please install GNU 'find', \
103 gfind --version 2>&1 | grep GNU, \
104 find --version 2>&1 | grep GNU))
105
106 $(eval $(call SetupHostCommand,bash,Please install GNU 'bash', \
107 bash --version 2>&1 | grep GNU))
108
109 $(eval $(call SetupHostCommand,xargs, \
110 Please install 'xargs' that supports '-r/--no-run-if-empty', \
111 gxargs -r --version, \
112 xargs -r --version))
113
114 $(eval $(call SetupHostCommand,patch,Please install GNU 'patch', \
115 gpatch --version 2>&1 | grep 'Free Software Foundation', \
116 patch --version 2>&1 | grep 'Free Software Foundation'))
117
118 $(eval $(call SetupHostCommand,diff,Please install GNU diffutils, \
119 gdiff --version 2>&1 | grep GNU, \
120 diff --version 2>&1 | grep GNU))
121
122 $(eval $(call SetupHostCommand,cp,Please install GNU fileutils, \
123 gcp --help 2>&1 | grep 'Copy SOURCE', \
124 cp --help 2>&1 | grep 'Copy SOURCE'))
125
126 $(eval $(call SetupHostCommand,seq,Please install seq, \
127 gseq --version, \
128 seq --version 2>&1 | grep seq))
129
130 $(eval $(call SetupHostCommand,awk,Please install GNU 'awk', \
131 gawk --version 2>&1 | grep GNU, \
132 awk --version 2>&1 | grep GNU))
133
134 $(eval $(call SetupHostCommand,grep,Please install GNU 'grep', \
135 ggrep --version 2>&1 | grep GNU, \
136 grep --version 2>&1 | grep GNU))
137
138 $(eval $(call SetupHostCommand,egrep,Please install GNU 'grep', \
139 gegrep --version 2>&1 | grep GNU, \
140 egrep --version 2>&1 | grep GNU))
141
142 $(eval $(call SetupHostCommand,getopt, \
143 Please install an extended getopt version that supports --long, \
144 gnugetopt -o t --long test -- --test | grep '^ *--test *--', \
145 getopt -o t --long test -- --test | grep '^ *--test *--', \
146 /usr/local/opt/gnu-getopt/bin/getopt -o t --long test -- --test | grep '^ *--test *--', \
147 /opt/local/bin/getopt -o t --long test -- --test | grep '^ *--test *--'))
148
149 $(eval $(call SetupHostCommand,realpath,Please install a 'realpath' utility, \
150 grealpath /, \
151 realpath /))
152
153 $(eval $(call SetupHostCommand,stat,Cannot find a file stat utility, \
154 gnustat -c%s $(TOPDIR)/Makefile, \
155 gstat -c%s $(TOPDIR)/Makefile, \
156 stat -c%s $(TOPDIR)/Makefile))
157
158 $(eval $(call SetupHostCommand,gzip,Please install 'gzip', \
159 gzip --version </dev/null))
160
161 $(eval $(call SetupHostCommand,unzip,Please install 'unzip', \
162 unzip 2>&1 | grep zipfile, \
163 unzip))
164
165 $(eval $(call SetupHostCommand,bzip2,Please install 'bzip2', \
166 bzip2 --version </dev/null))
167
168 $(eval $(call SetupHostCommand,wget,Please install GNU 'wget', \
169 wget --version | grep GNU))
170
171 $(eval $(call SetupHostCommand,install,Please install GNU 'install', \
172 install --version | grep GNU, \
173 ginstall --version | grep GNU))
174
175 $(eval $(call SetupHostCommand,perl,Please install Perl 5.x, \
176 perl --version | grep "perl.*v5"))
177
178 $(eval $(call CleanupPython2))
179
180 $(eval $(call SetupHostCommand,python,Please install Python >= 3.6, \
181 python3.11 -V 2>&1 | grep 'Python 3', \
182 python3.10 -V 2>&1 | grep 'Python 3', \
183 python3.9 -V 2>&1 | grep 'Python 3', \
184 python3.8 -V 2>&1 | grep 'Python 3', \
185 python3.7 -V 2>&1 | grep 'Python 3', \
186 python3.6 -V 2>&1 | grep 'Python 3', \
187 python3 -V 2>&1 | grep -E 'Python 3\.([6-9]|[0-9][0-9])\.?'))
188
189 $(eval $(call SetupHostCommand,python3,Please install Python >= 3.6, \
190 python3.11 -V 2>&1 | grep 'Python 3', \
191 python3.10 -V 2>&1 | grep 'Python 3', \
192 python3.9 -V 2>&1 | grep 'Python 3', \
193 python3.8 -V 2>&1 | grep 'Python 3', \
194 python3.7 -V 2>&1 | grep 'Python 3', \
195 python3.6 -V 2>&1 | grep 'Python 3', \
196 python3 -V 2>&1 | grep -E 'Python 3\.([6-9]|[0-9][0-9])\.?'))
197
198 $(eval $(call TestHostCommand,python3-distutils, \
199 Please install the Python3 distutils module, \
200 $(STAGING_DIR_HOST)/bin/python3 -c 'from distutils import util'))
201
202 $(eval $(call TestHostCommand,python3-stdlib, \
203 Please install the Python3 stdlib module, \
204 $(STAGING_DIR_HOST)/bin/python3 -c 'import ntpath'))
205
206 $(eval $(call SetupHostCommand,file,Please install the 'file' package, \
207 file --version 2>&1 | grep file))
208
209 $(eval $(call SetupHostCommand,which,Please install 'which', \
210 /usr/bin/which which, \
211 /bin/which which, \
212 which which))
213
214 ifeq ($(HOST_OS),Linux)
215 $(eval $(call RequireCHeader,argp.h, \
216 Missing argp.h Please install the argp-standalone package if musl libc))
217
218 $(eval $(call RequireCHeader,fts.h, \
219 Missing fts.h Please install the musl-fts-dev package if musl libc))
220
221 $(eval $(call RequireCHeader,obstack.h, \
222 Missing obstack.h Please install the musl-obstack-dev package if musl libc))
223
224 $(eval $(call RequireCHeader,libintl.h, \
225 Missing libintl.h Please install the musl-libintl package if musl libc))
226 endif
227
228 $(STAGING_DIR_HOST)/bin/mkhash: $(SCRIPT_DIR)/mkhash.c
229 mkdir -p $(dir $@)
230 $(CC) -O2 -I$(TOPDIR)/tools/include -o $@ $<
231
232 $(STAGING_DIR_HOST)/bin/xxd: $(SCRIPT_DIR)/xxdi.pl
233 $(LN) $< $@
234
235 prereq: $(STAGING_DIR_HOST)/bin/mkhash $(STAGING_DIR_HOST)/bin/xxd
236
237 # Install ldconfig stub
238 $(eval $(call TestHostCommand,ldconfig-stub,Failed to install stub, \
239 $(LN) $(firstword $(wildcard /bin/true /usr/bin/true)) $(STAGING_DIR_HOST)/bin/ldconfig))