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