prereq-build.mk 8.6 KB

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