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