b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 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) 8 or later, \ |
| 36 | $(CC) -dumpversion | grep -E '^([8-9]\.?|1[0-9]\.?)', \ |
| 37 | gcc -dumpversion | grep -E '^([8-9]\.?|1[0-9]\.?)', \ |
| 38 | gcc-8 -dumpversion | grep -E '^([8-9]\.?|1[0-9]\.?)', \ |
| 39 | gcc --version | grep -E 'Apple.(LLVM|clang)' )) |
| 40 | |
| 41 | $(eval $(call TestHostCommand,working-gcc, \ |
| 42 | Please reinstall the GNU C Compiler (8 or later) - \ |
| 43 | it appears to be broken, \ |
| 44 | echo 'int main(int argc, char **argv) { return 0; }' | \ |
| 45 | $(STAGING_DIR_HOST)/bin/gcc -x c -o $(TMP_DIR)/a.out -)) |
| 46 | |
| 47 | $(eval $(call SetupHostCommand,g++, \ |
| 48 | Please install the GNU C++ Compiler (g++) 8 or later, \ |
| 49 | $(CXX) -dumpversion | grep -E '^([8-9]\.?|1[0-9]\.?)', \ |
| 50 | g++ -dumpversion | grep -E '^([8-9]\.?|1[0-9]\.?)', \ |
| 51 | g++-8 -dumpversion | grep -E '^([8-9]\.?|1[0-9]\.?)', \ |
| 52 | g++ --version | grep -E 'Apple.(LLVM|clang)' )) |
| 53 | |
| 54 | $(eval $(call TestHostCommand,working-g++, \ |
| 55 | Please reinstall the GNU C++ Compiler (8 or later) - \ |
| 56 | it appears to be broken, \ |
| 57 | echo 'int main(int argc, char **argv) { return 0; }' | \ |
| 58 | $(STAGING_DIR_HOST)/bin/g++ -x c++ -o $(TMP_DIR)/a.out - -lstdc++ && \ |
| 59 | $(TMP_DIR)/a.out)) |
| 60 | |
| 61 | $(eval $(call RequireCHeader,ncurses.h, \ |
| 62 | Please install ncurses. (Missing libncurses.so or ncurses.h), \ |
| 63 | initscr(), -lncurses)) |
| 64 | |
| 65 | $(eval $(call SetupHostCommand,git,Please install Git (git-core) >= 1.7.12.2, \ |
| 66 | git --exec-path | xargs -I % -- grep -q -- --recursive %/git-submodule, \ |
| 67 | git submodule --help | grep -- --recursive)) |
| 68 | |
| 69 | $(eval $(call SetupHostCommand,rsync,Please install 'rsync', \ |
| 70 | rsync --version </dev/null)) |
| 71 | endif # IB |
| 72 | |
| 73 | ifeq ($(HOST_OS),Linux) |
| 74 | zlib_link_flags := -Wl,-Bstatic -lz -Wl,-Bdynamic |
| 75 | else |
| 76 | zlib_link_flags := -lz |
| 77 | endif |
| 78 | |
| 79 | $(eval $(call TestHostCommand,perl-data-dumper, \ |
| 80 | Please install the Perl Data::Dumper module, \ |
| 81 | perl -MData::Dumper -e 1)) |
| 82 | |
| 83 | $(eval $(call TestHostCommand,perl-findbin, \ |
| 84 | Please install the Perl FindBin module, \ |
| 85 | perl -MFindBin -e 1)) |
| 86 | |
| 87 | $(eval $(call TestHostCommand,perl-file-copy, \ |
| 88 | Please install the Perl File::Copy module, \ |
| 89 | perl -MFile::Copy -e 1)) |
| 90 | |
| 91 | $(eval $(call TestHostCommand,perl-file-compare, \ |
| 92 | Please install the Perl File::Compare module, \ |
| 93 | perl -MFile::Compare -e 1)) |
| 94 | |
| 95 | $(eval $(call TestHostCommand,perl-thread-queue, \ |
| 96 | Please install the Perl Thread::Queue module, \ |
| 97 | perl -MThread::Queue -e 1)) |
| 98 | |
| 99 | $(eval $(call TestHostCommand,perl-ipc-cmd, \ |
| 100 | Please install the Perl IPC:Cmd module, \ |
| 101 | perl -MIPC::Cmd -e 1)) |
| 102 | |
| 103 | $(eval $(call SetupHostCommand,tar,Please install GNU 'tar', \ |
| 104 | gtar --version 2>&1 | grep GNU, \ |
| 105 | gnutar --version 2>&1 | grep GNU, \ |
| 106 | tar --version 2>&1 | grep GNU)) |
| 107 | |
| 108 | $(eval $(call SetupHostCommand,find,Please install GNU 'find', \ |
| 109 | gfind --version 2>&1 | grep GNU, \ |
| 110 | find --version 2>&1 | grep GNU)) |
| 111 | |
| 112 | $(eval $(call SetupHostCommand,bash,Please install GNU 'bash', \ |
| 113 | bash --version 2>&1 | grep GNU)) |
| 114 | |
| 115 | $(eval $(call SetupHostCommand,xargs, \ |
| 116 | Please install 'xargs' that supports '-r/--no-run-if-empty', \ |
| 117 | gxargs -r --version, \ |
| 118 | xargs -r --version)) |
| 119 | |
| 120 | $(eval $(call SetupHostCommand,patch,Please install GNU 'patch', \ |
| 121 | gpatch --version 2>&1 | grep 'Free Software Foundation', \ |
| 122 | patch --version 2>&1 | grep 'Free Software Foundation')) |
| 123 | |
| 124 | $(eval $(call SetupHostCommand,diff,Please install GNU diffutils, \ |
| 125 | gdiff --version 2>&1 | grep GNU, \ |
| 126 | diff --version 2>&1 | grep GNU)) |
| 127 | |
| 128 | $(eval $(call SetupHostCommand,cp,Please install GNU fileutils, \ |
| 129 | gcp --help 2>&1 | grep 'Copy SOURCE', \ |
| 130 | cp --help 2>&1 | grep 'Copy SOURCE')) |
| 131 | |
| 132 | $(eval $(call SetupHostCommand,seq,Please install seq, \ |
| 133 | gseq --version, \ |
| 134 | seq --version 2>&1 | grep seq)) |
| 135 | |
| 136 | $(eval $(call SetupHostCommand,awk,Please install GNU 'awk', \ |
| 137 | gawk --version 2>&1 | grep GNU, \ |
| 138 | awk --version 2>&1 | grep GNU)) |
| 139 | |
| 140 | $(eval $(call SetupHostCommand,grep,Please install GNU 'grep', \ |
| 141 | ggrep --version 2>&1 | grep GNU, \ |
| 142 | grep --version 2>&1 | grep GNU)) |
| 143 | |
| 144 | $(eval $(call SetupHostCommand,egrep,Please install GNU 'grep', \ |
| 145 | gegrep --version 2>&1 | grep GNU, \ |
| 146 | egrep --version 2>&1 | grep GNU)) |
| 147 | |
| 148 | $(eval $(call SetupHostCommand,getopt, \ |
| 149 | Please install an extended getopt version that supports --long, \ |
| 150 | gnugetopt -o t --long test -- --test | grep '^ *--test *--', \ |
| 151 | getopt -o t --long test -- --test | grep '^ *--test *--', \ |
| 152 | /usr/local/opt/gnu-getopt/bin/getopt -o t --long test -- --test | grep '^ *--test *--', \ |
| 153 | /opt/local/bin/getopt -o t --long test -- --test | grep '^ *--test *--')) |
| 154 | |
| 155 | $(eval $(call SetupHostCommand,realpath,Please install a 'realpath' utility, \ |
| 156 | grealpath /, \ |
| 157 | realpath /)) |
| 158 | |
| 159 | $(eval $(call SetupHostCommand,stat,Cannot find a file stat utility, \ |
| 160 | gnustat -c%s $(TOPDIR)/Makefile, \ |
| 161 | gstat -c%s $(TOPDIR)/Makefile, \ |
| 162 | stat -c%s $(TOPDIR)/Makefile)) |
| 163 | |
| 164 | $(eval $(call SetupHostCommand,gzip,Please install 'gzip', \ |
| 165 | gzip --version </dev/null)) |
| 166 | |
| 167 | $(eval $(call SetupHostCommand,unzip,Please install 'unzip', \ |
| 168 | unzip 2>&1 | grep zipfile, \ |
| 169 | unzip)) |
| 170 | |
| 171 | $(eval $(call SetupHostCommand,bzip2,Please install 'bzip2', \ |
| 172 | bzip2 --version </dev/null)) |
| 173 | |
| 174 | $(eval $(call SetupHostCommand,wget,Please install GNU 'wget', \ |
| 175 | wget --version | grep GNU)) |
| 176 | |
| 177 | $(eval $(call SetupHostCommand,install,Please install GNU 'install', \ |
| 178 | install --version | grep GNU, \ |
| 179 | ginstall --version | grep GNU)) |
| 180 | |
| 181 | $(eval $(call SetupHostCommand,perl,Please install Perl 5.x, \ |
| 182 | perl --version | grep "perl.*v5")) |
| 183 | |
| 184 | $(eval $(call SetupHostCommand,python,Please install Python >= 3.7, \ |
| 185 | python3.12 -V 2>&1 | grep 'Python 3', \ |
| 186 | python3.11 -V 2>&1 | grep 'Python 3', \ |
| 187 | python3.10 -V 2>&1 | grep 'Python 3', \ |
| 188 | python3.9 -V 2>&1 | grep 'Python 3', \ |
| 189 | python3.8 -V 2>&1 | grep 'Python 3', \ |
| 190 | python3.7 -V 2>&1 | grep 'Python 3', \ |
| 191 | python3 -V 2>&1 | grep -E 'Python 3\.([7-9]|[0-9][0-9])\.?')) |
| 192 | |
| 193 | $(eval $(call SetupHostCommand,python3,Please install Python >= 3.7, \ |
| 194 | python3.12 -V 2>&1 | grep 'Python 3', \ |
| 195 | python3.11 -V 2>&1 | grep 'Python 3', \ |
| 196 | python3.10 -V 2>&1 | grep 'Python 3', \ |
| 197 | python3.9 -V 2>&1 | grep 'Python 3', \ |
| 198 | python3.8 -V 2>&1 | grep 'Python 3', \ |
| 199 | python3.7 -V 2>&1 | grep 'Python 3', \ |
| 200 | python3 -V 2>&1 | grep -E 'Python 3\.([7-9]|[0-9][0-9])\.?')) |
| 201 | |
| 202 | $(eval $(call TestHostCommand,python3-distutils, \ |
| 203 | Please install the Python3 distutils module, \ |
| 204 | printf 'from sys import version_info\nif version_info < (3, 12):\n\tfrom distutils import util' | \ |
| 205 | $(STAGING_DIR_HOST)/bin/python3 -)) |
| 206 | |
| 207 | $(eval $(call TestHostCommand,python3-stdlib, \ |
| 208 | Please install the Python3 stdlib module, \ |
| 209 | $(STAGING_DIR_HOST)/bin/python3 -c 'import ntpath')) |
| 210 | |
| 211 | $(eval $(call SetupHostCommand,file,Please install the 'file' package, \ |
| 212 | file --version 2>&1 | grep file)) |
| 213 | |
| 214 | $(eval $(call SetupHostCommand,which,Please install 'which', \ |
| 215 | /usr/bin/which which, \ |
| 216 | /bin/which which, \ |
| 217 | which which)) |
| 218 | |
| 219 | ifeq ($(HOST_OS),Linux) |
| 220 | $(eval $(call RequireCHeader,argp.h, \ |
| 221 | Missing argp.h Please install the argp-standalone package if musl libc)) |
| 222 | |
| 223 | $(eval $(call RequireCHeader,fts.h, \ |
| 224 | Missing fts.h Please install the musl-fts-dev package if musl libc)) |
| 225 | |
| 226 | $(eval $(call RequireCHeader,obstack.h, \ |
| 227 | Missing obstack.h Please install the musl-obstack-dev package if musl libc)) |
| 228 | |
| 229 | $(eval $(call RequireCHeader,libintl.h, \ |
| 230 | Missing libintl.h Please install the musl-libintl package if musl libc)) |
| 231 | endif |
| 232 | |
| 233 | $(STAGING_DIR_HOST)/bin/mkhash: $(SCRIPT_DIR)/mkhash.c |
| 234 | mkdir -p $(dir $@) |
| 235 | $(CC) -O2 -I$(TOPDIR)/tools/include -o $@ $< |
| 236 | |
| 237 | $(STAGING_DIR_HOST)/bin/xxd: $(SCRIPT_DIR)/xxdi.pl |
| 238 | $(LN) $< $@ |
| 239 | |
| 240 | prereq: $(STAGING_DIR_HOST)/bin/mkhash $(STAGING_DIR_HOST)/bin/xxd |
| 241 | |
| 242 | # Install ldconfig stub |
| 243 | $(eval $(call TestHostCommand,ldconfig-stub,Failed to install stub, \ |
| 244 | $(LN) $(SCRIPT_DIR)/noop.sh $(STAGING_DIR_HOST)/bin/ldconfig)) |