1*4882a593Smuzhiyun#!/bin/sh 2*4882a593Smuzhiyun# vi: set sw=4 ts=4: 3*4882a593Smuzhiyun 4*4882a593Smuzhiyunexport LC_ALL=C 5*4882a593SmuzhiyunTAB="$(printf '\t')" 6*4882a593SmuzhiyunNL=" 7*4882a593Smuzhiyun" 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun# Verify that grep works 10*4882a593Smuzhiyunecho "WORKS" | grep "WORKS" >/dev/null 2>&1 11*4882a593Smuzhiyunif test $? != 0 ; then 12*4882a593Smuzhiyun echo 13*4882a593Smuzhiyun echo "grep doesn't work" 14*4882a593Smuzhiyun exit 1 15*4882a593Smuzhiyunfi 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun# Sanity check for CWD in LD_LIBRARY_PATH 18*4882a593Smuzhiyuncase ":${LD_LIBRARY_PATH:-unset}:" in 19*4882a593Smuzhiyun(*::*|*:.:*) 20*4882a593Smuzhiyun echo 21*4882a593Smuzhiyun echo "You seem to have the current working directory in your" 22*4882a593Smuzhiyun echo "LD_LIBRARY_PATH environment variable. This doesn't work." 23*4882a593Smuzhiyun exit 1 24*4882a593Smuzhiyun ;; 25*4882a593Smuzhiyunesac 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun# Sanity check for CWD in PATH. Having the current working directory 28*4882a593Smuzhiyun# in the PATH makes various packages (e.g. toolchain, coreutils...) 29*4882a593Smuzhiyun# build process break. 30*4882a593Smuzhiyun# PATH should not contain a newline, otherwise it fails in spectacular 31*4882a593Smuzhiyun# ways as soon as PATH is referenced in a package rule 32*4882a593Smuzhiyun# An empty PATH is technically possible, but in practice we would not 33*4882a593Smuzhiyun# even arrive here if that was the case. 34*4882a593Smuzhiyuncase ":${PATH:-unset}:" in 35*4882a593Smuzhiyun(*::*|*:.:*) 36*4882a593Smuzhiyun echo 37*4882a593Smuzhiyun echo "You seem to have the current working directory in your" 38*4882a593Smuzhiyun echo "PATH environment variable. This doesn't work." 39*4882a593Smuzhiyun exit 1 40*4882a593Smuzhiyun ;; 41*4882a593Smuzhiyun(*" "*|*"${TAB}"*|*"${NL}"*) 42*4882a593Smuzhiyun printf "\n" 43*4882a593Smuzhiyun printf "Your PATH contains spaces, TABs, and/or newline (\\\n) characters.\n" 44*4882a593Smuzhiyun printf "This doesn't work. Fix you PATH.\n" 45*4882a593Smuzhiyun exit 1 46*4882a593Smuzhiyun ;; 47*4882a593Smuzhiyunesac 48*4882a593Smuzhiyun 49*4882a593Smuzhiyunif test -n "$PERL_MM_OPT" ; then 50*4882a593Smuzhiyun echo 51*4882a593Smuzhiyun echo "You have PERL_MM_OPT defined because Perl local::lib" 52*4882a593Smuzhiyun echo "is installed on your system. Please unset this variable" 53*4882a593Smuzhiyun echo "before starting Buildroot, otherwise the compilation of" 54*4882a593Smuzhiyun echo "Perl related packages will fail" 55*4882a593Smuzhiyun exit 1 56*4882a593Smuzhiyunfi 57*4882a593Smuzhiyun 58*4882a593Smuzhiyuncheck_prog_host() 59*4882a593Smuzhiyun{ 60*4882a593Smuzhiyun prog="$1" 61*4882a593Smuzhiyun if ! which $prog > /dev/null ; then 62*4882a593Smuzhiyun echo >&2 63*4882a593Smuzhiyun echo "You must install '$prog' on your build machine" >&2 64*4882a593Smuzhiyun exit 1 65*4882a593Smuzhiyun fi 66*4882a593Smuzhiyun} 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun# Verify that which is installed 69*4882a593Smuzhiyuncheck_prog_host "which" 70*4882a593Smuzhiyun# Verify that sed is installed 71*4882a593Smuzhiyuncheck_prog_host "sed" 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun# 'file' must be present and must be exactly /usr/bin/file, 74*4882a593Smuzhiyun# otherwise libtool fails in incomprehensible ways. 75*4882a593Smuzhiyuncheck_prog_host "/usr/bin/file" 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun# Check make 78*4882a593SmuzhiyunMAKE=$(which make 2> /dev/null) 79*4882a593Smuzhiyunif [ -z "$MAKE" ] ; then 80*4882a593Smuzhiyun echo 81*4882a593Smuzhiyun echo "You must install 'make' on your build machine"; 82*4882a593Smuzhiyun exit 1; 83*4882a593Smuzhiyunfi; 84*4882a593SmuzhiyunMAKE_VERSION=$($MAKE --version 2>&1 | sed -e 's/^.* \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q') 85*4882a593Smuzhiyunif [ -z "$MAKE_VERSION" ] ; then 86*4882a593Smuzhiyun echo 87*4882a593Smuzhiyun echo "You must install 'make' on your build machine"; 88*4882a593Smuzhiyun exit 1; 89*4882a593Smuzhiyunfi; 90*4882a593SmuzhiyunMAKE_MAJOR=$(echo $MAKE_VERSION | sed -e "s/\..*//g") 91*4882a593SmuzhiyunMAKE_MINOR=$(echo $MAKE_VERSION | sed -e "s/^$MAKE_MAJOR\.//g" -e "s/\..*//g" -e "s/[a-zA-Z].*//g") 92*4882a593Smuzhiyunif [ $MAKE_MAJOR -lt 3 ] || [ $MAKE_MAJOR -eq 3 -a $MAKE_MINOR -lt 81 ] ; then 93*4882a593Smuzhiyun echo 94*4882a593Smuzhiyun echo "You have make '$MAKE_VERSION' installed. GNU make >=3.81 is required" 95*4882a593Smuzhiyun exit 1; 96*4882a593Smuzhiyunfi; 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun# Check host gcc 99*4882a593SmuzhiyunCOMPILER=$(which $HOSTCC_NOCCACHE 2> /dev/null) 100*4882a593Smuzhiyunif [ -z "$COMPILER" ] ; then 101*4882a593Smuzhiyun COMPILER=$(which cc 2> /dev/null) 102*4882a593Smuzhiyunfi; 103*4882a593Smuzhiyunif [ -z "$COMPILER" ] ; then 104*4882a593Smuzhiyun echo 105*4882a593Smuzhiyun echo "You must install 'gcc' on your build machine"; 106*4882a593Smuzhiyun exit 1; 107*4882a593Smuzhiyunfi; 108*4882a593Smuzhiyun 109*4882a593SmuzhiyunCOMPILER_VERSION=$($COMPILER -v 2>&1 | sed -n '/^gcc version/p' | 110*4882a593Smuzhiyun sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q') 111*4882a593Smuzhiyunif [ -z "$COMPILER_VERSION" ] ; then 112*4882a593Smuzhiyun echo 113*4882a593Smuzhiyun echo "You must install 'gcc' on your build machine"; 114*4882a593Smuzhiyun exit 1; 115*4882a593Smuzhiyunfi; 116*4882a593SmuzhiyunCOMPILER_MAJOR=$(echo $COMPILER_VERSION | sed -e "s/\..*//g") 117*4882a593SmuzhiyunCOMPILER_MINOR=$(echo $COMPILER_VERSION | sed -e "s/^$COMPILER_MAJOR\.//g" -e "s/\..*//g") 118*4882a593Smuzhiyunif [ $COMPILER_MAJOR -lt 4 -o $COMPILER_MAJOR -eq 4 -a $COMPILER_MINOR -lt 8 ] ; then 119*4882a593Smuzhiyun echo 120*4882a593Smuzhiyun echo "You have gcc '$COMPILER_VERSION' installed. gcc >= 4.8 is required" 121*4882a593Smuzhiyun exit 1; 122*4882a593Smuzhiyunfi; 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun# check for host CXX 125*4882a593SmuzhiyunCXXCOMPILER=$(which $HOSTCXX_NOCCACHE 2> /dev/null) 126*4882a593Smuzhiyunif [ -z "$CXXCOMPILER" ] ; then 127*4882a593Smuzhiyun CXXCOMPILER=$(which c++ 2> /dev/null) 128*4882a593Smuzhiyunfi 129*4882a593Smuzhiyun 130*4882a593Smuzhiyunif [ -z "$CXXCOMPILER" ] ; then 131*4882a593Smuzhiyun echo 132*4882a593Smuzhiyun echo "You may have to install 'g++' on your build machine" 133*4882a593Smuzhiyunfi 134*4882a593Smuzhiyunif [ ! -z "$CXXCOMPILER" ] ; then 135*4882a593Smuzhiyun CXXCOMPILER_VERSION=$($CXXCOMPILER -v 2>&1 | sed -n '/^gcc version/p' | 136*4882a593Smuzhiyun sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q') 137*4882a593Smuzhiyun if [ -z "$CXXCOMPILER_VERSION" ] ; then 138*4882a593Smuzhiyun echo 139*4882a593Smuzhiyun echo "You may have to install 'g++' on your build machine" 140*4882a593Smuzhiyun fi 141*4882a593Smuzhiyunfi 142*4882a593Smuzhiyun 143*4882a593Smuzhiyunif [ -n "$CXXCOMPILER_VERSION" ] ; then 144*4882a593Smuzhiyun CXXCOMPILER_MAJOR=$(echo $CXXCOMPILER_VERSION | sed -e "s/\..*//g") 145*4882a593Smuzhiyun CXXCOMPILER_MINOR=$(echo $CXXCOMPILER_VERSION | sed -e "s/^$CXXCOMPILER_MAJOR\.//g" -e "s/\..*//g") 146*4882a593Smuzhiyun if [ $CXXCOMPILER_MAJOR -lt 4 -o $CXXCOMPILER_MAJOR -eq 4 -a $CXXCOMPILER_MINOR -lt 8 ] ; then 147*4882a593Smuzhiyun echo 148*4882a593Smuzhiyun echo "You have g++ '$CXXCOMPILER_VERSION' installed. g++ >= 4.8 is required" 149*4882a593Smuzhiyun exit 1 150*4882a593Smuzhiyun fi 151*4882a593Smuzhiyunfi 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun# Check bash 154*4882a593Smuzhiyun# We only check bash is available, setting SHELL appropriately is done 155*4882a593Smuzhiyun# in the top-level Makefile, and we mimick the same sequence here 156*4882a593Smuzhiyunif [ -n "${BASH}" ]; then : 157*4882a593Smuzhiyunelif [ -x /bin/bash ]; then : 158*4882a593Smuzhiyunelif [ -z "$( sh -c 'echo $BASH' )" ]; then 159*4882a593Smuzhiyun echo 160*4882a593Smuzhiyun echo "You must install 'bash' on your build machine" 161*4882a593Smuzhiyun exit 1 162*4882a593Smuzhiyunfi 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun# Check that a few mandatory programs are installed 165*4882a593Smuzhiyunmissing_progs="no" 166*4882a593Smuzhiyunfor prog in perl tar wget cpio unzip rsync bc ${DL_TOOLS} ; do 167*4882a593Smuzhiyun if ! which $prog > /dev/null ; then 168*4882a593Smuzhiyun echo "You must install '$prog' on your build machine"; 169*4882a593Smuzhiyun missing_progs="yes" 170*4882a593Smuzhiyun if test $prog = "svn" ; then 171*4882a593Smuzhiyun echo " svn is usually part of the subversion package in your distribution" 172*4882a593Smuzhiyun elif test $prog = "hg" ; then 173*4882a593Smuzhiyun echo " hg is usually part of the mercurial package in your distribution" 174*4882a593Smuzhiyun elif test $prog = "zcat" ; then 175*4882a593Smuzhiyun echo " zcat is usually part of the gzip package in your distribution" 176*4882a593Smuzhiyun elif test $prog = "bzcat" ; then 177*4882a593Smuzhiyun echo " bzcat is usually part of the bzip2 package in your distribution" 178*4882a593Smuzhiyun fi 179*4882a593Smuzhiyun fi 180*4882a593Smuzhiyundone 181*4882a593Smuzhiyun 182*4882a593Smuzhiyunif test "${missing_progs}" = "yes" ; then 183*4882a593Smuzhiyun exit 1 184*4882a593Smuzhiyunfi 185*4882a593Smuzhiyun 186*4882a593SmuzhiyunPATCH_VERSION="$(patch -v 2>/dev/null | sed -n 's/^GNU patch \(.*\)/\1/p')" 187*4882a593Smuzhiyunif [ -z "${PATCH_VERSION}" ] ; then 188*4882a593Smuzhiyun echo 189*4882a593Smuzhiyun echo "You must install GNU patch" 190*4882a593Smuzhiyun exit 1 191*4882a593Smuzhiyunfi 192*4882a593SmuzhiyunPATCH_MAJOR="$(echo "${PATCH_VERSION}" | cut -d . -f 1)" 193*4882a593SmuzhiyunPATCH_MINOR="$(echo "${PATCH_VERSION}" | cut -d . -f 2)" 194*4882a593Smuzhiyunif [ "${PATCH_MAJOR}" -lt 2 ] || [ "${PATCH_MAJOR}" -eq 2 -a "${PATCH_MINOR}" -lt 7 ] ; then 195*4882a593Smuzhiyun echo 196*4882a593Smuzhiyun echo "You have GNU patch '${PATCH_VERSION}' installed. GNU patch >= 2.7 is required" 197*4882a593Smuzhiyun exit 1; 198*4882a593Smuzhiyunfi 199*4882a593Smuzhiyun 200*4882a593Smuzhiyunif grep ^BR2_NEEDS_HOST_UTF8_LOCALE=y $BR2_CONFIG > /dev/null; then 201*4882a593Smuzhiyun if ! which locale > /dev/null ; then 202*4882a593Smuzhiyun echo 203*4882a593Smuzhiyun echo "You need locale support on your build machine to build a toolchain supporting locales" 204*4882a593Smuzhiyun exit 1 ; 205*4882a593Smuzhiyun fi 206*4882a593Smuzhiyun if ! locale -a | grep -q -i -E 'utf-?8$' ; then 207*4882a593Smuzhiyun echo 208*4882a593Smuzhiyun echo "You need at least one UTF8 locale to build a toolchain supporting locales" 209*4882a593Smuzhiyun exit 1 ; 210*4882a593Smuzhiyun fi 211*4882a593Smuzhiyunfi 212*4882a593Smuzhiyun 213*4882a593Smuzhiyunif grep -q ^BR2_NEEDS_HOST_JAVA=y $BR2_CONFIG ; then 214*4882a593Smuzhiyun check_prog_host "java" 215*4882a593Smuzhiyun JAVA_GCJ=$(java -version 2>&1 | grep gcj) 216*4882a593Smuzhiyun if [ ! -z "$JAVA_GCJ" ] ; then 217*4882a593Smuzhiyun echo 218*4882a593Smuzhiyun echo "$JAVA_GCJ is not sufficient to compile your package selection." 219*4882a593Smuzhiyun echo "Please install an OpenJDK/IcedTea/Oracle Java." 220*4882a593Smuzhiyun exit 1 ; 221*4882a593Smuzhiyun fi 222*4882a593Smuzhiyunfi 223*4882a593Smuzhiyun 224*4882a593Smuzhiyunif grep -q ^BR2_HOSTARCH_NEEDS_IA32_LIBS=y $BR2_CONFIG ; then 225*4882a593Smuzhiyun if test ! -f /lib/ld-linux.so.2 ; then 226*4882a593Smuzhiyun echo 227*4882a593Smuzhiyun echo "Your Buildroot configuration uses pre-built tools for the x86 architecture," 228*4882a593Smuzhiyun echo "but your build machine uses the x86-64 architecture without the 32 bits compatibility" 229*4882a593Smuzhiyun echo "library." 230*4882a593Smuzhiyun echo "If you're running a Debian/Ubuntu distribution, install the libc6-i386," 231*4882a593Smuzhiyun echo "lib32stdc++6, and lib32z1 packages (or alternatively libc6:i386," 232*4882a593Smuzhiyun echo "libstdc++6:i386, and zlib1g:i386)." 233*4882a593Smuzhiyun echo "If you're running a RedHat/Fedora distribution, install the glibc.i686 and" 234*4882a593Smuzhiyun echo "zlib.i686 packages." 235*4882a593Smuzhiyun echo "If you're running an ArchLinux distribution, install lib32-glibc." 236*4882a593Smuzhiyun echo "For other distributions, refer to the documentation on how to install the 32 bits" 237*4882a593Smuzhiyun echo "compatibility libraries." 238*4882a593Smuzhiyun exit 1 239*4882a593Smuzhiyun fi 240*4882a593Smuzhiyunfi 241*4882a593Smuzhiyun 242*4882a593Smuzhiyunif grep -q ^BR2_HOSTARCH_NEEDS_IA32_COMPILER=y $BR2_CONFIG ; then 243*4882a593Smuzhiyun if ! echo "int main(void) {}" | gcc -m32 -x c - -o /dev/null 2>/dev/null; then 244*4882a593Smuzhiyun echo 245*4882a593Smuzhiyun echo "Your Buildroot configuration needs a compiler capable of building 32 bits binaries." 246*4882a593Smuzhiyun echo "If you're running a Debian/Ubuntu distribution, install the gcc-multilib package." 247*4882a593Smuzhiyun echo "For other distributions, refer to their documentation." 248*4882a593Smuzhiyun exit 1 249*4882a593Smuzhiyun fi 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun if ! echo "int main(void) {}" | g++ -m32 -x c++ - -o /dev/null 2>/dev/null; then 252*4882a593Smuzhiyun echo 253*4882a593Smuzhiyun echo "Your Buildroot configuration needs a compiler capable of building 32 bits binaries." 254*4882a593Smuzhiyun echo "If you're running a Debian/Ubuntu distribution, install the g++-multilib package." 255*4882a593Smuzhiyun echo "For other distributions, refer to their documentation." 256*4882a593Smuzhiyun exit 1 257*4882a593Smuzhiyun fi 258*4882a593Smuzhiyunfi 259*4882a593Smuzhiyun 260*4882a593Smuzhiyunif grep ^BR2_NEEDS_HOST_GCC_PLUGIN_SUPPORT=y $BR2_CONFIG ; then 261*4882a593Smuzhiyun if ! echo "#include <gcc-plugin.h>" | $HOSTCXX_NOCCACHE -I$($HOSTCXX_NOCCACHE -print-file-name=plugin)/include -x c++ -c - -o /dev/null ; then 262*4882a593Smuzhiyun echo 263*4882a593Smuzhiyun echo "Your Buildroot configuration needs a host compiler capable of building gcc plugins." 264*4882a593Smuzhiyun echo "If you're running a Debian/Ubuntu distribution, install gcc-X-plugin-dev package." 265*4882a593Smuzhiyun echo "For other distributions, refer to their documentation." 266*4882a593Smuzhiyun exit 1 ; 267*4882a593Smuzhiyun fi 268*4882a593Smuzhiyunfi 269*4882a593Smuzhiyun 270*4882a593Smuzhiyun# Check that the Perl installation is complete enough for Buildroot. 271*4882a593Smuzhiyunrequired_perl_modules="Data::Dumper" # Needed to build host-autoconf 272*4882a593Smuzhiyunrequired_perl_modules="$required_perl_modules ExtUtils::MakeMaker" # Used by host-libxml-parser-perl 273*4882a593Smuzhiyunrequired_perl_modules="$required_perl_modules Thread::Queue" # Used by host-automake 274*4882a593Smuzhiyun 275*4882a593Smuzhiyunif grep -q ^BR2_PACKAGE_MPV=y $BR2_CONFIG ; then 276*4882a593Smuzhiyun required_perl_modules="$required_perl_modules Math::BigInt" 277*4882a593Smuzhiyun required_perl_modules="$required_perl_modules Math::BigRat" 278*4882a593Smuzhiyunfi 279*4882a593Smuzhiyun 280*4882a593Smuzhiyunif grep -q ^BR2_PACKAGE_WHOIS=y $BR2_CONFIG ; then 281*4882a593Smuzhiyun required_perl_modules="$required_perl_modules autodie" 282*4882a593Smuzhiyunfi 283*4882a593Smuzhiyun 284*4882a593Smuzhiyunif grep -q -E '^BR2_PACKAGE_(WEBKITGTK|WPEWEBKIT)=y' $BR2_CONFIG ; then 285*4882a593Smuzhiyun required_perl_modules="${required_perl_modules} JSON::PP" 286*4882a593Smuzhiyunfi 287*4882a593Smuzhiyun 288*4882a593Smuzhiyun# This variable will keep the modules that are missing in your system. 289*4882a593Smuzhiyunmissing_perl_modules="" 290*4882a593Smuzhiyun 291*4882a593Smuzhiyunfor pm in $required_perl_modules ; do 292*4882a593Smuzhiyun if ! perl -e "require $pm" > /dev/null 2>&1 ; then 293*4882a593Smuzhiyun missing_perl_modules="$missing_perl_modules $pm" 294*4882a593Smuzhiyun fi 295*4882a593Smuzhiyundone 296*4882a593Smuzhiyun 297*4882a593Smuzhiyunif [ -n "$missing_perl_modules" ] ; then 298*4882a593Smuzhiyun echo "Your Perl installation is not complete enough; at least the following" 299*4882a593Smuzhiyun echo "modules are missing:" 300*4882a593Smuzhiyun echo 301*4882a593Smuzhiyun for pm in $missing_perl_modules ; do 302*4882a593Smuzhiyun printf "\t $pm\n" 303*4882a593Smuzhiyun done 304*4882a593Smuzhiyun echo 305*4882a593Smuzhiyun exit 1 306*4882a593Smuzhiyunfi 307