source: freewrt/scripts/scan-tools.sh@ bbe41f83

Last change on this file since bbe41f83 was bbe41f83, checked in by Thorsten Glaser <tg@…>, 18 years ago

better

git-svn-id: svn://www.freewrt.org/trunk/freewrt@3086 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 12.0 KB
RevLine 
[2dcc12b]1# $FreeWRT: src/share/misc/licence.template,v 1.20 2006/12/11 21:04:56 tg Rel $
[959aa50]2#-
[5486644]3# Copyright (c) 2006, 2007
[959aa50]4# Thorsten Glaser <tg@mirbsd.de>
5#
[2dcc12b]6# Provided that these terms and disclaimer and all copyright notices
7# are retained or reproduced in an accompanying document, permission
8# is granted to deal in this work without restriction, including un-
9# limited rights to use, publicly perform, distribute, sell, modify,
10# merge, give away, or sublicence.
[959aa50]11#
[61acfd0]12# Advertising materials mentioning features or use of this work must
13# display the following acknowledgement:
[959aa50]14# This product includes material provided by Thorsten Glaser.
15# This acknowledgement does not need to be reprinted if this work is
16# linked into a bigger work whose licence does not allow such clause
17# and the author of this work is given due credit in the bigger work
[2dcc12b]18# or its accompanying documents, where such information is generally
19# kept, provided that said credits are retained.
[959aa50]20#
[2dcc12b]21# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
22# the utmost extent permitted by applicable law, neither express nor
23# implied; without malicious intent or gross negligence. In no event
24# may a licensor, author or contributor be held liable for indirect,
25# direct, other damage, loss, or other issues arising in any way out
26# of dealing in the work, even if advised of the possibility of such
27# damage or existence of a defect, except proven that it results out
28# of said person's immediate fault when using the work as intended.
[959aa50]29#-
30# Scan for prerequisite host tools.
31
32if test -z "$BASH_VERSION"; then
33 echo FreeWRT requires GNU bash to be installed, sorry.
34 exit 1
35fi
36
37shopt -s extglob
[50275dc]38topdir=$(pwd)
[32396b1]39opath=$PATH
[fa281a9]40out=0
[2832e46]41bmake=
[959aa50]42
[4ed535c]43if [[ $NO_ERROR != @(0|1) ]]; then
44 echo Please do not invoke this script directly!
45 exit 1
46fi
47
[959aa50]48set -e
49rm -rf $topdir/lbin/tmp
50mkdir -p $topdir/lbin/tmp
51cd $topdir/lbin/tmp
[2dcc12b]52
[f0b8a0f]53rm -f foo
54echo >FOO
55if [[ -e foo ]]; then
56 cat >&2 <<-EOF
57 ERROR: FreeWRT cannot be built in a case-insensitive
58 file system. Please use scripts/darwindiskimage on a
59 Macintosh to create a case-sensitive filesystem image,
60 or reconfigure your Windows system approprately.
61 EOF
62 exit 1
63fi
64rm -f FOO
65
[2dcc12b]66os=$(uname)
67case $os in
[914e1e8]68Darwin)
69 # needs a bunch of quirks, but seems to compile
70 echo Warning: Darwin support is highly experimental.
71 echo
72 ;;
[2dcc12b]73Linux)
74 # supported with no extra quirks at the moment
75 ;;
76OpenBSD)
77 # supported with no extra quirks at the moment
78 # although some packages' autoconf scripts may
79 # not properly recognise OpenBSD
80 ;;
81MirBSD)
82 # needs a little quirk, because the autoconf
83 # version of some packages doesn't recognise
84 # it as valid OS, and as build (not host) OS
85 # faking OpenBSD is close enough
86 rm -f $topdir/lbin/uname
87 sed -e 's!@@FromOS@@!MirBSD!g' -e 's!@@ToOS@@!OpenBSD!g' \
88 -e "s!@@PROG@@!$($topdir/lbin/which uname)!g" \
89 <$topdir/scripts/uname.fake >$topdir/lbin/uname
90 chmod 555 $topdir/lbin/uname
[2832e46]91 bmake=/usr/bin/make
[2dcc12b]92 ;;
93*)
94 # unsupported
95 echo "Building FreeWRT on $os is currently unsupported."
96 echo "Sorry."
97 echo
98 case $os in
[914e1e8]99 Cyg*)
[2dcc12b]100 echo "The most prominent issue is that filesystems"
101 echo "can be case-insensitive. Some macros are missing."
102 echo
103 ;;
104 NetBSD|FreeBSD|DragonFly)
105 echo "Building should succeed with relatively few"
106 echo "patches, but perl must live in /usr/bin for"
107 echo "now in FreeWRT, which should indeed be fixed."
108 echo
109 ;;
110 esac
111 echo "If you need FreeWRT building on $os, please contact"
112 echo "the development team; there may be contractors available"
113 echo "for this task. If you intend on turning $os into one of"
114 echo "the supported build OSes, please contact us as well so"
115 echo "that we can feed back your enhancements into FreeWRT."
116 exit 1
117 ;;
118esac
119
[959aa50]120set +e
[32396b1]121
122if [[ ! -e $topdir/lbin/gmake ]]; then
123 for f in $topdir/tools_build/gmake/make \
124 "$($topdir/lbin/which gmake)" "$($topdir/lbin/which make)"; do
125 [[ -e $f ]] || continue
126 if [[ $f = $topdir/tools_build/gmake/make ]]; then
127 install -c -s -m 555 $f $topdir/lbin/gmake
128 else
129 ln -s "$f" $topdir/lbin/gmake
130 fi
131 break
132 done
133fi
134X=$($topdir/lbin/gmake --version 2>&1 | grep '^GNU Make' | \
135 sed -e 's/GNU Make //' -e 's/version //' -e 's/, by.*$//')
136[[ $X = +([0-9]).+([0-9]).+([0-9]) ]] && X=${X%.*}
137if [[ $X = +([0-9]).+([0-9]) ]]; then
138 let major=${X%.*}
139 let minor=${X#*.}
140elif [[ $X = +([0-9]).+([0-9])beta* ]]; then
141 # Beta version is not "the real thing"
142 let major=${X%.*}
143 X=${X%beta*}
144 let minor=${X#*.}-1
145else
146 let major=0
147fi
148if (( (major < 3) || ((major == 3) && (minor < 81)) )); then
149 echo "---> building GNU make 3.81"
150 rm -rf $topdir/tools_build/gmake $topdir/lbin/gmake
151 set -e
152 mkdir -p $topdir/tools_build/gmake
153 cd $topdir/tools_build/gmake
154 env CPPFLAGS="$CPPFLAGS -Dstrcmpi=strcasecmp" \
155 CFLAGS="$(grep '^HOSTCFLAGS' $topdir/lbin/prereq.mk | \
156 sed 's/HOSTCFLAGS:=//')" \
157 $BASH $topdir/tools/gmake/configure \
158 --program-prefix=g \
159 --disable-dependency-tracking \
160 --disable-nls \
161 --without-libiconv-prefix \
162 --without-libintl-prefix
163 make all
164 install -c -s -m 555 make $topdir/lbin/gmake
165 set +e
166 cd $topdir/lbin; ls -l gmake
167 cd $topdir/lbin/tmp
168fi
169export PATH=$topdir/lbin:$PATH
170
[959aa50]171cat >Makefile <<'EOF'
[8e62bd6]172include ${TOPDIR}/lbin/prereq.mk
173HOSTCFLAGS+= ${FLAG_TEST}
[959aa50]174all: run-test
175
176test: test.c
[4e5b696]177 ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
[959aa50]178
179run-test: test
180 ./test
181EOF
182cat >test.c <<-'EOF'
183 #include <stdio.h>
184 int
185 main()
186 {
187 printf("Yay! Native compiler works.\n");
188 return (0);
189 }
190EOF
191X=$(gmake TOPDIR=$topdir 2>&1)
192if [[ $X != *@(Native compiler works)* ]]; then
[2f13d9a]193 echo "$X" | sed 's/^/| /'
[959aa50]194 echo Cannot compile a simple test programme.
[32396b1]195 echo You must install a host make and C compiler,
[959aa50]196 echo usually GCC, to proceed.
[2f13d9a]197 echo
[fa281a9]198 out=1
[959aa50]199fi
[8e62bd6]200rm test
201
202X=$(gmake FLAG_TEST=-fwrapv TOPDIR=$topdir 2>&1)
203grep '^HOSTCFLAGS.*-fwrapv' ../prereq.mk >/dev/null 2>&1 || \
204 if [[ $X = *@(Native compiler works)* ]]; then
205 printf '/^HOSTCFLAGS/s/$/ -fwrapv/\nwq\n' | ed -s ../prereq.mk
206else
207 echo "$X" | sed 's/^/| /'
208fi
[edea0b2]209rm test
[959aa50]210
[b803791]211need_fnotreevrp=0
212X=$(gmake FLAG_TEST=-fno-tree-vrp TOPDIR=$topdir 2>&1)
213grep '^HOSTCFLAGS.*-fno-tree-vrp' ../prereq.mk >/dev/null 2>&1 || \
214 if [[ $X = *@(Native compiler works)* ]]; then
215 need_fnotreevrp=1
216else
[4a86091]217 #echo "$X" | sed 's/^/| /'
[bcacd7d]218 :
[b803791]219fi
220rm test*
221if [[ $need_fnotreevrp = 1 ]]; then
222 cat >test.c <<-'EOF'
223 typedef unsigned size_t;
224 char *strncpy(char *, const char *, size_t);
225 char *
226 strncpy(char *d, const char *s, size_t n)
227 {
228 if (!d || !s) {
229 if (d)
230 *d = n;
231 return (d);
232 }
233 return (*d = 1, d);
234 }
235 int
236 main(void)
237 {
238 char a[] = "t";
239 strncpy(a, (void *)0, 2);
240 return (*a);
241 }
242 EOF
243 X=$(gmake test TOPDIR=$topdir 2>&1)
244 if [[ -x test ]]; then
245 ./test >/dev/null 2>&1
246 [[ $? = 2 ]] && need_fnotreevrp=0
247 fi
248 rm test*
249fi
250[[ $need_fnotreevrp = 1 ]] && \
251 printf '/^HOSTCFLAGS/s/$/ -fno-tree-vrp/\nwq\n' | ed -s ../prereq.mk
252
[8d0b68e]253if ! which flex >/dev/null 2>&1; then
254 echo You must install flex to continue.
[2f13d9a]255 echo
[fa281a9]256 out=1
[af632b3]257else
258 echo '%%' | flex -
259 if fgrep _POSIX_SOURCE lex.yy.c; then
260 echo Your lexer \(flex\) contains a broken skeleton.
261 if [[ $NO_ERROR = 1 ]]; then
262 echo WARNING: continue at your own risk.
263 echo Some packages may be broken.
264 else
265 echo You can continue the build by issuing \'make prereq-noerror\'
266 echo However, several packages may faild to build correctly.
267 out=1
268 fi
[2f13d9a]269 echo
[e722055]270 fi
271fi
272
[8d0b68e]273if ! which bison >/dev/null 2>&1; then
274 echo You must install GNU Bison to continue.
275 echo While you can install any version, it is '*STRONGLY*' suggested
276 echo to install GNU Bison version 2.3 because of its bug fixes.
[2f13d9a]277 echo
[fa281a9]278 out=1
[8d0b68e]279fi
280X=$(bison --version 2>&1 | fgrep 'GNU Bison' | sed 's/^[^0-9]*//')
281V=old
282if [[ $X = +([0-9]).+([0-9]) ]]; then
283 let major=${X%.*}
284 let minor=${X#*.}
285 if (( (major > 2) || ((major == 2) && (minor >= 3)) )); then
286 V=new
287 fi
288fi
289if [[ $V = old ]]; then
290 echo It is suggested to upgrade your copy of bison to
291 echo GNU Bison 2.3 because of its bug fixes.
292fi
293
[99d4f9d3]294if ! which gzip >/dev/null 2>&1; then
295 echo You must install gzip to continue.
[2f13d9a]296 echo
[fa281a9]297 out=1
[99d4f9d3]298fi
299
[4e5b696]300if ! which bzip2 >/dev/null 2>&1; then
301 echo You must install bzip2 to continue.
[2f13d9a]302 echo
[fa281a9]303 out=1
[4e5b696]304fi
305
306if ! which unzip >/dev/null 2>&1; then
307 echo You must install unzip to continue, sorry.
[2f13d9a]308 echo
[fa281a9]309 out=1
[4e5b696]310fi
311
[44dd5e42]312if ! which zip >/dev/null 2>&1; then
313 echo You must install zip to continue, sorry.
314 echo
315 out=1
316fi
317
[4e5b696]318if ! which patch >/dev/null 2>&1; then
319 echo You must install patch \(from Larry Wall\) to continue.
[2f13d9a]320 echo
[fa281a9]321 out=1
[4e5b696]322fi
323
324cat >test.c <<-'EOF'
325 #include <stdio.h>
326 #include <zlib.h>
327
328 #ifndef STDIN_FILENO
329 #define STDIN_FILENO 0
330 #endif
331
332 int
333 main()
334 {
335 gzFile zstdin;
336 char buf[1024];
337 int i;
338
339 zstdin = gzdopen(STDIN_FILENO, "rb");
340 i = gzread(zstdin, buf, sizeof (buf));
341 if ((i > 0) && (i < sizeof (buf)))
342 buf[i] = '\0';
343 buf[sizeof (buf) - 1] = '\0';
344 printf("%s\n", buf);
345 return (0);
346 }
347EOF
[99d4f9d3]348X=$(echo 'Yay! Native compiler works.' | gzip | \
349 gmake TOPDIR=$topdir LDADD=-lz 2>&1)
[4e5b696]350if [[ $X != *@(Native compiler works)* ]]; then
[2f13d9a]351 echo "$X" | sed 's/^/| /'
[4e5b696]352 echo Cannot compile a libz test programme.
353 echo You must install the zlib development package,
354 echo usually called libz-dev, and the run-time library.
[2f13d9a]355 echo
[fa281a9]356 out=1
[4e5b696]357fi
358
[b2dd798d]359if [[ ! -s /usr/include/ncurses.h ]]; then
360 echo Install ncurses header files, please.
[2f13d9a]361 echo
[b2dd798d]362 out=1
363fi
364
[e7119e1]365if ! which g++ >/dev/null 2>&1; then
366 echo You must install the host GNU C++ compiler to continue.
[2f13d9a]367 echo
[fa281a9]368 out=1
[e7119e1]369fi
370
[0a5b5d1]371#if ! which perl >/dev/null 2>&1; then
[38c7e913]372if [[ "$(which perl 2>/dev/null)" != /usr/bin/perl ]]; then
373 echo You must install Perl in /usr/bin to continue.
[2f13d9a]374 echo
[fa281a9]375 out=1
[f2bcc47]376fi
377
[8c028e7]378if ! which wget >/dev/null 2>&1; then
379 echo You must install GNU wget to continue.
[2f13d9a]380 echo
[fa281a9]381 out=1
[8c028e7]382fi
383
[5486644]384if ! which makeinfo >/dev/null 2>&1; then
385 echo You must install GNU texinfo to continue.
[2f13d9a]386 echo
[5486644]387 out=1
388fi
389
[b9492d5]390if ! which ed >/dev/null 2>&1; then
391 echo Why does your distribution not package the standard
392 echo text editor, ed? Please install it to continue.
[2f13d9a]393 echo
[b9492d5]394 out=1
[b65ac45]395elif [[ "$(PATH=/bin:$PATH which ed 2>/dev/null)" != /bin/ed ]]; then
[b9492d5]396 echo Your operating system installs ed, the standard text
397 echo editor, not as /bin/ed. While you can build FreeWRT
398 echo with this, ask your vendor to fix it, point to the
399 echo FHS if needed.
[2f13d9a]400 echo
[b9492d5]401fi
402
[2a734b1]403if ! which file >/dev/null 2>&1; then
404 echo You must install \"file\" to continue.
405 echo
406 out=1
407fi
408
[f1b0356]409have_tsort=0
410if which tsort >/dev/null 2>&1; then
411 v=$(printf 'a b\nb c\n' | tsort -r 2>/dev/null | md5sum)
412 [[ ${v%% *} = 0617bc44e824dd65da71d04b29c85e63 ]] && have_tsort=1
[5ecbb4f4]413fi
[f1b0356]414
[efd2732]415if [[ $have_tsort = 0 ]]; then
[2832e46]416 bmake=
[efd2732]417else
418 for x in $bmake $(which mmake) $(which bmake) /usr/bin/make; do
419 bmake=
420 y=$(printf 't:\n\t@echo ${_MIRMAKE_VER}\n' | \
421 $x -f - t 2>/dev/null)
[6b5052df]422 [[ $y = +([0-9]) ]] || continue
[efd2732]423 [[ $y < 20070626 ]] && continue
424 bmake=$x
425 break
426 done
427fi
428[[ $bmake = $topdir/lbin/bmake ]] && bmake=
[2832e46]429
430if [[ $have_tsort = 0 || -z $bmake ]]; then
[f1b0356]431 echo USE_TOOLS_MIRMAKE=1 >>$topdir/lbin/prereq.mk
[2832e46]432 bmake=$topdir/lbin/bmake
[f1b0356]433 if ! which mksh >/dev/null 2>&1; then
434 echo USE_TOOLS_MKSH=1 >>$topdir/lbin/prereq.mk
435 fi
[c534048]436fi
[f2bcc47]437
[2832e46]438echo "BMAKE='$bmake'" >>$topdir/lbin/prereq.mk
439
[727dae0d]440if grep USE_TOOLS_MKSH=1 $topdir/lbin/prereq.mk >/dev/null 2>&1; then
[bbe41f83]441 echo "MBSH:=$topdir/lbin/mkshw" >>$topdir/lbin/prereq.mk
442 rm -f $topdir/lbin/mkshw
443 cat >$topdir/lbin/mkshw <<-EOF
444 #!/bin/sh
445 if [[ -x $topdir/lbin/mksh ]]; then
446 exec $topdir/lbin/mkshw "\$@"
447 else
448 exec bash "\$@"
449 fi
450 EOF
451 chmod +x $topdir/lbin/mkshw
[727dae0d]452elif which mksh >/dev/null 2>&1; then
453 echo "MBSH:=$(which mksh)" >>$topdir/lbin/prereq.mk
454else
455 echo "MBSH:=$${BASH}" >>$topdir/lbin/prereq.mk
456fi
457
[f1b0356]458
[959aa50]459cd $topdir
460rm -rf lbin/tmp
[c116dcc]461
462# populate some more tools
463cat >lbin/autoconf <<-EOF
464 #!$BASH
[de9aae5]465 echo '===> Warning: this package calls autoconf!'
[372c556]466 exit 0
[c116dcc]467EOF
[b18839a]468cp lbin/autoconf lbin/autoheader
[6fe2e9c]469for v in 2.13 2.52 2.53 2.54 2.55 2.56 2.57 2.58 2.59 2.60 2.61; do
470 cp lbin/autoconf lbin/autoconf-$v
471 cp lbin/autoconf lbin/autoheader-$v
472done
[c116dcc]473cat >lbin/automake <<-EOF
474 #!$BASH
[372c556]475 echo '===> Warning: this package calls automake!'
476 exit 0
[c116dcc]477EOF
[b18839a]478cp lbin/automake lbin/aclocal
[6fe2e9c]479for v in 1.4 1.5 1.6 1.7 1.8 1.9 1.10; do
480 cp lbin/automake lbin/automake-$v
481 cp lbin/automake lbin/aclocal-$v
482done
483chmod a+x lbin/{autoconf,autoheader,automake,aclocal}*
[c116dcc]484
[fa281a9]485exit $out
Note: See TracBrowser for help on using the repository browser.