86c22f7c959b326a8bed2f9331b38c3758c3151d
[openwrt/openwrt.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
12 # Required for the toolchain
13 $(eval $(call TestHostCommand,working-make, \
14 Please install GNU make v3.82 or later. (This version has bugs), \
15 $(MAKE) -v | grep -E 'Make (3\.8[2-9]|3\.9[0-9]|[4-9]\.)'))
16
17 $(eval $(call TestHostCommand,case-sensitive-fs, \
18 OpenWrt can only be built on a case-sensitive filesystem, \
19 rm -f $(TMP_DIR)/test.*; touch $(TMP_DIR)/test.fs; \
20 test ! -f $(TMP_DIR)/test.FS))
21
22 $(eval $(call TestHostCommand,proper-umask, \
23 Please build with umask 022 - other values produce broken packages, \
24 umask | grep -xE 0?0[012][012]))
25
26 ifndef IB
27 $(eval $(call SetupHostCommand,gcc, \
28 Please install the GNU C Compiler (gcc) 4.8 or later, \
29 $(CC) -dumpversion | grep -E '^(4\.[8-9]|[5-9]\.?|1[0-9]\.?)', \
30 gcc -dumpversion | grep -E '^(4\.[8-9]|[5-9]\.?|1[0-9]\.?)', \
31 gcc --version | grep -E 'Apple.(LLVM|clang)' ))
32
33 $(eval $(call TestHostCommand,working-gcc, \
34 \nPlease reinstall the GNU C Compiler (4.8 or later) - \
35 it appears to be broken, \
36 echo 'int main(int argc, char **argv) { return 0; }' | \
37 gcc -x c -o $(TMP_DIR)/a.out -))
38
39 $(eval $(call SetupHostCommand,g++, \
40 Please install the GNU C++ Compiler (g++) 4.8 or later, \
41 $(CXX) -dumpversion | grep -E '^(4\.[8-9]|[5-9]\.?|1[0-9]\.?)', \
42 g++ -dumpversion | grep -E '^(4\.[8-9]|[5-9]\.?|1[0-9]\.?)', \
43 g++ --version | grep -E 'Apple.(LLVM|clang)' ))
44
45 $(eval $(call TestHostCommand,working-g++, \
46 \nPlease reinstall the GNU C++ Compiler (4.8 or later) - \
47 it appears to be broken, \
48 echo 'int main(int argc, char **argv) { return 0; }' | \
49 g++ -x c++ -o $(TMP_DIR)/a.out - -lstdc++ && \
50 $(TMP_DIR)/a.out))
51
52 $(eval $(call TestHostCommand,ncurses, \
53 Please install ncurses. (Missing libncurses.so or ncurses.h), \
54 echo 'int main(int argc, char **argv) { initscr(); return 0; }' | \
55 gcc -include ncurses.h -x c -o $(TMP_DIR)/a.out - -lncurses))
56 endif # IB
57
58 ifeq ($(HOST_OS),Linux)
59 zlib_link_flags := -Wl,-Bstatic -lz -Wl,-Bdynamic
60 else
61 zlib_link_flags := -lz
62 endif
63
64 $(eval $(call TestHostCommand,perl-data-dumper, \
65 Please install the Perl Data::Dumper module, \
66 perl -MData::Dumper -e 1))
67
68 $(eval $(call TestHostCommand,perl-thread-queue, \
69 Please install the Perl Thread::Queue module, \
70 perl -MThread::Queue -e 1))
71
72
73 $(eval $(call SetupHostCommand,tar,Please install GNU 'tar', \
74 gtar --version 2>&1 | grep GNU, \
75 gnutar --version 2>&1 | grep GNU, \
76 tar --version 2>&1 | grep GNU))
77
78 $(eval $(call SetupHostCommand,find,Please install GNU 'find', \
79 gfind --version 2>&1 | grep GNU, \
80 find --version 2>&1 | grep GNU))
81
82 $(eval $(call SetupHostCommand,bash,Please install GNU 'bash', \
83 bash --version 2>&1 | grep GNU))
84
85 $(eval $(call SetupHostCommand,xargs, \
86 Please install 'xargs' that supports '-r/--no-run-if-empty', \
87 gxargs -r --version, \
88 xargs -r --version))
89
90 $(eval $(call SetupHostCommand,patch,Please install GNU 'patch', \
91 gpatch --version 2>&1 | grep 'Free Software Foundation', \
92 patch --version 2>&1 | grep 'Free Software Foundation'))
93
94 $(eval $(call SetupHostCommand,diff,Please install diffutils, \
95 gdiff --version 2>&1 | grep diff, \
96 diff --version 2>&1 | grep diff))
97
98 $(eval $(call SetupHostCommand,cp,Please install GNU fileutils, \
99 gcp --help 2>&1 | grep 'Copy SOURCE', \
100 cp --help 2>&1 | grep 'Copy SOURCE'))
101
102 $(eval $(call SetupHostCommand,seq,Please install seq, \
103 gseq --version, \
104 seq --version 2>&1 | grep seq))
105
106 $(eval $(call SetupHostCommand,awk,Please install GNU 'awk', \
107 gawk --version 2>&1 | grep GNU, \
108 awk --version 2>&1 | grep GNU))
109
110 $(eval $(call SetupHostCommand,grep,Please install GNU 'grep', \
111 ggrep --version 2>&1 | grep GNU, \
112 grep --version 2>&1 | grep GNU))
113
114 $(eval $(call SetupHostCommand,egrep,Please install GNU 'grep', \
115 gegrep --version 2>&1 | grep GNU, \
116 egrep --version 2>&1 | grep GNU))
117
118 $(eval $(call SetupHostCommand,getopt, \
119 Please install an extended getopt version that supports --long, \
120 gnugetopt -o t --long test -- --test | grep '^ *--test *--', \
121 getopt -o t --long test -- --test | grep '^ *--test *--', \
122 /usr/local/opt/gnu-getopt/bin/getopt -o t --long test -- --test | grep '^ *--test *--'))
123
124 $(eval $(call SetupHostCommand,stat,Cannot find a file stat utility, \
125 gnustat -c%s $(TOPDIR)/Makefile, \
126 gstat -c%s $(TOPDIR)/Makefile, \
127 stat -c%s $(TOPDIR)/Makefile))
128
129 $(eval $(call SetupHostCommand,unzip,Please install 'unzip', \
130 unzip 2>&1 | grep zipfile, \
131 unzip))
132
133 $(eval $(call SetupHostCommand,bzip2,Please install 'bzip2', \
134 bzip2 --version </dev/null))
135
136 $(eval $(call SetupHostCommand,wget,Please install GNU 'wget', \
137 wget --version | grep GNU))
138
139 $(eval $(call SetupHostCommand,perl,Please install Perl 5.x, \
140 perl --version | grep "perl.*v5"))
141
142 $(eval $(call CleanupPython2))
143
144 $(eval $(call SetupHostCommand,python,Please install Python >= 3.5, \
145 python3.9 -V 2>&1 | grep 'Python 3', \
146 python3.8 -V 2>&1 | grep 'Python 3', \
147 python3.7 -V 2>&1 | grep 'Python 3', \
148 python3.6 -V 2>&1 | grep 'Python 3', \
149 python3.5 -V 2>&1 | grep 'Python 3', \
150 python3 -V 2>&1 | grep -E 'Python 3\.[5-9]\.?'))
151
152 $(eval $(call SetupHostCommand,python3,Please install Python >= 3.5, \
153 python3.9 -V 2>&1 | grep 'Python 3', \
154 python3.8 -V 2>&1 | grep 'Python 3', \
155 python3.7 -V 2>&1 | grep 'Python 3', \
156 python3.6 -V 2>&1 | grep 'Python 3', \
157 python3.5 -V 2>&1 | grep 'Python 3', \
158 python3 -V 2>&1 | grep -E 'Python 3\.[5-9]\.?'))
159
160 $(eval $(call SetupHostCommand,git,Please install Git (git-core) >= 1.7.12.2, \
161 git --exec-path | xargs -I % -- grep -q -- --recursive %/git-submodule))
162
163 $(eval $(call SetupHostCommand,file,Please install the 'file' package, \
164 file --version 2>&1 | grep file))
165
166 $(eval $(call SetupHostCommand,rsync,Please install 'rsync', \
167 rsync --version </dev/null))
168
169 $(eval $(call SetupHostCommand,which,Please install 'which', \
170 which which | grep which))
171
172 $(STAGING_DIR_HOST)/bin/mkhash: $(SCRIPT_DIR)/mkhash.c
173 mkdir -p $(dir $@)
174 $(CC) -O2 -I$(TOPDIR)/tools/include -o $@ $<
175
176 prereq: $(STAGING_DIR_HOST)/bin/mkhash
177
178 # Install ldconfig stub
179 $(eval $(call TestHostCommand,ldconfig-stub,Failed to install stub, \
180 touch $(STAGING_DIR_HOST)/bin/ldconfig && \
181 chmod +x $(STAGING_DIR_HOST)/bin/ldconfig))