root/trunk/freewrt/scripts/scan-tools.sh

Revision 3908, 14.0 kB (checked in by tg, 2 years ago)

reformat some warnings and lessen the impact of some
r3907 can be built on a koala, all bugs reported by wbx@ are fixed
and even the mirmake-using programmes work despite the unused thing

  • Property svn:keywords set to FreeWRT=Id
Line 
1 # $FreeWRT: src/share/misc/licence.template,v 1.20 2006/12/11 21:04:56 tg Rel $
2 #-
3 # Copyright (c) 2006, 2007, 2009
4 #       Thorsten Glaser <tg@mirbsd.de>
5 #
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.
11 #
12 # Advertising materials mentioning features or use of this work must
13 # display the following acknowledgement:
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
18 # or its accompanying documents, where such information is generally
19 # kept, provided that said credits are retained.
20 #
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.
29 #-
30 # Scan for prerequisite host tools.
31
32 if test -z "$BASH_VERSION"; then
33         echo FreeWRT requires GNU bash to be installed, sorry.
34         exit 1
35 fi
36
37 shopt -s extglob
38 topdir=$(pwd)
39 opath=$PATH
40 out=0
41 slp=0
42
43 if [[ $NO_ERROR != @(0|1) ]]; then
44         echo Please do not invoke this script directly!
45         exit 1
46 fi
47
48 set -e
49 rm -rf $topdir/lbin/tmp
50 mkdir -p $topdir/lbin/tmp
51 cd $topdir/lbin/tmp
52
53 rm -f foo
54 echo >FOO
55 if [[ -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
63 fi
64 rm -f FOO
65
66 os=$(uname)
67 case $os in
68 Darwin)
69         # needs a bunch of quirks, but seems to compile
70         echo Warning: Darwin support is highly experimental.
71         echo
72         ;;
73 Linux)
74         # supported with no extra quirks at the moment
75         ;;
76 MirBSD)
77         # needs a little quirk, because the autoconf
78         # version of some packages doesn't recognise
79         # it as valid OS, and as build (not host) OS
80         # faking OpenBSD is close enough
81         rm -f $topdir/lbin/uname
82         sed -e 's!@@FromOS@@!MirBSD!g' -e 's!@@ToOS@@!OpenBSD!g' \
83             -e "s!@@PROG@@!$($topdir/lbin/which uname)!g" \
84             <$topdir/scripts/uname.fake >$topdir/lbin/uname
85         chmod 555 $topdir/lbin/uname
86         which cpp >/dev/null 2>&1 || ln -s /usr/bin/mcpp $topdir/lbin/cpp
87         ;;
88 NetBSD)
89         echo "Building FreeWRT on $os is currently unsupported."
90         echo "Sorry."
91         echo
92         echo There are unresolved issues relating to ncurses not
93         echo being included in NetBSD®, and these provided by pkgsrc®
94         echo lack important header files.
95         echo
96         ;;
97 OpenBSD)
98         # supported with no extra quirks at the moment
99         # although some packages' autoconf scripts may
100         # not properly recognise OpenBSD
101         ;;
102 *)
103         # unsupported
104         echo "Building FreeWRT on $os is currently unsupported."
105         echo "Sorry."
106         echo
107         case $os in
108         Cyg*)
109                 echo "The most prominent issue is that filesystems"
110                 echo "can be case-insensitive. Some macros are missing."
111                 echo
112                 ;;
113         FreeBSD|DragonFly)
114                 echo "Building should succeed with relatively few"
115                 echo "patches, but perl must live in /usr/bin for"
116                 echo "now in FreeWRT, which should indeed be fixed."
117                 echo
118                 ;;
119         esac
120         echo "If you need FreeWRT building on $os, please contact"
121         echo "the development team; there may be contractors available"
122         echo "for this task. If you intend on turning $os into one of"
123         echo "the supported build OSes, please contact us as well so"
124         echo "that we can feed back your enhancements into FreeWRT."
125         exit 1
126         ;;
127 esac
128
129 set +e
130
131 if [[ ! -e $topdir/lbin/gmake ]]; then
132         for f in $topdir/tools_build/gmake/make \
133             "$($topdir/lbin/which gmake)" "$($topdir/lbin/which make)"; do
134                 [[ -e $f ]] || continue
135                 if [[ $f = $topdir/tools_build/gmake/make ]]; then
136                         install -c -s -m 555 $f $topdir/lbin/gmake
137                 else
138                         ln -s "$f" $topdir/lbin/gmake
139                 fi
140                 break
141         done
142 fi
143 X=$($topdir/lbin/gmake --version 2>&1 | grep '^GNU Make' | \
144     sed -e 's/GNU Make //' -e 's/version //' -e 's/, by.*$//')
145 [[ $X = +([0-9]).+([0-9]).+([0-9]) ]] && X=${X%.*}
146 if [[ $X = +([0-9]).+([0-9]) ]]; then
147         let major=${X%.*}
148         let minor=${X#*.}
149 elif [[ $X = +([0-9]).+([0-9])beta* ]]; then
150         # Beta version is not "the real thing"
151         let major=${X%.*}
152         X=${X%beta*}
153         let minor=${X#*.}-1
154 else
155         let major=0
156 fi
157 if (( (major < 3) || ((major == 3) && (minor < 81)) )); then
158         echo "---> building GNU make 3.81"
159         rm -rf $topdir/tools_build/gmake $topdir/lbin/gmake
160         set -e
161         mkdir -p $topdir/tools_build/gmake
162         cd $topdir/tools_build/gmake
163         env CPPFLAGS="$CPPFLAGS -Dstrcmpi=strcasecmp" \
164             CFLAGS="$(grep '^HOSTCFLAGS' $topdir/lbin/prereq.mk | \
165                 sed 's/HOSTCFLAGS:=//')" \
166             $BASH $topdir/tools/gmake/configure \
167             --program-prefix=g \
168             --disable-dependency-tracking \
169             --disable-nls \
170             --without-libiconv-prefix \
171             --without-libintl-prefix
172         make all
173         install -c -s -m 555 make $topdir/lbin/gmake
174         set +e
175         cd $topdir/lbin; ls -l gmake
176         cd $topdir/lbin/tmp
177 fi
178 export PATH=$topdir/lbin:$PATH
179
180 cat >Makefile <<'EOF'
181 include ${TOPDIR}/lbin/prereq.mk
182 HOSTCFLAGS+=    ${FLAG_TEST}
183 all: run-test
184
185 test: test.c
186         ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
187
188 run-test: test
189         ./test
190 EOF
191 cat >test.c <<-'EOF'
192         #include <stdio.h>
193         int
194         main()
195         {
196                 printf("Yay! Native compiler works.\n");
197                 return (0);
198         }
199 EOF
200 X=$(gmake TOPDIR=$topdir 2>&1)
201 if [[ $X != *@(Native compiler works)* ]]; then
202         echo "$X" | sed 's/^/| /'
203         echo Cannot compile a simple test programme.
204         echo You must install a host make and C compiler,
205         echo usually GCC, to proceed.
206         echo
207         out=1
208 fi
209 rm test
210
211 X=$(gmake FLAG_TEST=-fwrapv TOPDIR=$topdir 2>&1)
212 grep '^HOSTCFLAGS.*-fwrapv' ../prereq.mk >/dev/null 2>&1 || \
213     if [[ $X = *@(Native compiler works)* ]]; then
214         printf '/^HOSTCFLAGS/s/$/ -fwrapv/\nwq\n' | ed -s ../prereq.mk
215 else
216         echo "$X" | sed 's/^/| /'
217 fi
218 rm test
219
220 need_fnotreevrp=0
221 X=$(gmake FLAG_TEST=-fno-tree-vrp TOPDIR=$topdir 2>&1)
222 grep '^HOSTCFLAGS.*-fno-tree-vrp' ../prereq.mk >/dev/null 2>&1 || \
223     if [[ $X = *@(Native compiler works)* ]]; then
224         need_fnotreevrp=1
225 else
226         #echo "$X" | sed 's/^/| /'
227         :
228 fi
229 rm test*
230 if [[ $need_fnotreevrp = 1 ]]; then
231         cat >test.c <<-'EOF'
232                 typedef unsigned size_t;
233                 char *strncpy(char *, const char *, size_t);
234                 char *
235                 strncpy(char *d, const char *s, size_t n)
236                 {
237                         if (!d || !s) {
238                                 if (d)
239                                         *d = n;
240                                 return (d);
241                         }
242                         return (*d = 1, d);
243                 }
244                 int
245                 main(void)
246                 {
247                         char a[] = "t";
248                         strncpy(a, (void *)0, 2);
249                         return (*a);
250                 }
251         EOF
252         X=$(gmake test TOPDIR=$topdir 2>&1)
253         if [[ -x test ]]; then
254                 ./test >/dev/null 2>&1
255                 [[ $? = 2 ]] && need_fnotreevrp=0
256         fi
257         rm test*
258 fi
259 [[ $need_fnotreevrp = 1 ]] && \
260     printf '/^HOSTCFLAGS/s/$/ -fno-tree-vrp/\nwq\n' | ed -s ../prereq.mk
261
262 if ! which cpp >/dev/null 2>&1; then
263         echo You must install a C præprocessor to continue.
264         echo
265         out=1
266 fi
267
268 if ! which flex >/dev/null 2>&1; then
269         echo You must install flex to continue.
270         echo
271         out=1
272 else
273         echo '%%' | flex -
274         if fgrep _POSIX_SOURCE lex.yy.c; then
275                 echo Your lexer \(flex\) contains a broken skeleton.
276                 if [[ $NO_ERROR = 1 ]]; then
277                         echo WARNING: continue at your own risk.
278                         echo Some packages may be broken.
279                 else
280                         echo You can continue the build by issuing \'make prereq-noerror\'
281                         echo However, several packages may faild to build correctly.
282                         out=1
283                 fi
284                 echo
285         fi
286 fi
287
288 if ! which bison >/dev/null 2>&1; then
289         echo You must install GNU Bison to continue.
290         echo While you can install any version, it is '*STRONGLY*' suggested
291         echo to install GNU Bison version 2.3 because of its bug fixes.
292         echo
293         out=1
294 fi
295 X=$(bison --version 2>&1 | fgrep 'GNU Bison' | sed 's/^[^0-9]*//')
296 V=old
297 if [[ $X = +([0-9]).+([0-9]) ]]; then
298         let major=${X%.*}
299         let minor=${X#*.}
300         if (( (major > 2) || ((major == 2) && (minor >= 3)) )); then
301                 V=new
302         fi
303 fi
304 if [[ $V = old ]]; then
305         echo It is suggested to upgrade your copy of bison to
306         echo GNU Bison 2.3 because of its bug fixes.
307         echo
308 fi
309
310 if ! which gzip >/dev/null 2>&1; then
311         echo You must install gzip to continue.
312         echo
313         out=1
314 fi
315
316 if ! which bzip2 >/dev/null 2>&1; then
317         echo You must install bzip2 to continue.
318         echo
319         out=1
320 fi
321
322 if ! which unzip >/dev/null 2>&1; then
323         echo You must install unzip to continue, sorry.
324         echo
325         out=1
326 fi
327
328 if ! which zip >/dev/null 2>&1; then
329         echo You must install zip to continue, sorry.
330         echo
331         out=1
332 fi
333
334 if ! which patch >/dev/null 2>&1; then
335         echo You must install patch \(from Larry Wall\) to continue.
336         echo
337         out=1
338 fi
339
340 cat >test.c <<-'EOF'
341         #include <stdio.h>
342         #include <zlib.h>
343
344         #ifndef STDIN_FILENO
345         #define STDIN_FILENO 0
346         #endif
347
348         int
349         main()
350         {
351                 gzFile zstdin;
352                 char buf[1024];
353                 int i;
354
355                 zstdin = gzdopen(STDIN_FILENO, "rb");
356                 i = gzread(zstdin, buf, sizeof (buf));
357                 if ((i > 0) && (i < sizeof (buf)))
358                         buf[i] = '\0';
359                 buf[sizeof (buf) - 1] = '\0';
360                 printf("%s\n", buf);
361                 return (0);
362         }
363 EOF
364 X=$(echo 'Yay! Native compiler works.' | gzip | \
365     gmake TOPDIR=$topdir LDADD=-lz 2>&1)
366 if [[ $X != *@(Native compiler works)* ]]; then
367         echo "$X" | sed 's/^/| /'
368         echo Cannot compile a libz test programme.
369         echo You must install the zlib development package,
370         echo usually called libz-dev, and the run-time library.
371         echo
372         out=1
373 fi
374
375 [[ -s /usr/include/ncurses.h ]] || if [[ -s /usr/pkg/include/ncurses.h ]]; then
376         echo 'HOSTCFLAGS+= -isystem /usr/pkg/include' >>$topdir/lbin/prereq.mk
377         echo 'HOSTLDFLAGS+=-L/usr/pkg/lib -Wl,-rpath -Wl,/usr/pkg/lib' >>$topdir/lbin/prereq.mk
378 else
379         echo Install ncurses header files, please.
380         echo
381         out=1
382 fi
383
384 if ! which g++ >/dev/null 2>&1; then
385         echo You must install the host GNU C++ compiler to continue.
386         echo The compiler must be available as both c++ and g++.
387         echo
388         out=1
389 fi
390
391 if ! which c++ >/dev/null 2>&1; then
392         echo You must install the host GNU C++ compiler to continue.
393         echo The compiler must be available as both c++ and g++.
394         echo
395         out=1
396 fi
397
398 if ! which perl >/dev/null 2>&1; then
399 #if [[ "$(which perl 2>/dev/null)" != /usr/bin/perl ]]; then
400         echo You must install Perl in /usr/bin to continue.
401         echo
402         out=1
403 fi
404
405 if ! which wget >/dev/null 2>&1; then
406         echo You must install GNU wget to continue.
407         echo
408         out=1
409 fi
410
411 if ! which makeinfo >/dev/null 2>&1; then
412         echo You must install GNU texinfo to continue.
413         echo
414         out=1
415 fi
416
417 unused_bug=0
418
419 if fgrep -w __unused /usr/include/asm/stat.h /usr/include/linux/sysctl.h \
420     >/dev/null 2>&1; then
421         echo 'Compiling MirMake, which is required by the ADK, may fail for'
422         echo 'your system due to incompatibilities in the Linux headers.'
423         echo 'This has been reported as Debian #522773 and forwarded to:'
424         echo 'http://bugzilla.kernel.org/show_bug.cgi?id=14186'
425         echo
426         unused_bug=1
427 fi
428
429 if fgrep -w __unused /usr/include/bits/stat.h /usr/include/netdb.h \
430     >/dev/null 2>&1; then
431         echo 'Compiling MirMake, which is required by the ADK, may fail for'
432         echo 'your system due to incompatibilities in the glibc headers. It'
433         echo 'is Debian #522774 and treated WONTFIX by eglibc maintainers.'
434         echo
435 fi
436
437 if (( unused_bug )); then
438         echo 'You can continue if you are totally sure that this is not an'
439         echo 'issue for your system. Otherwise you should replace all occu-'
440         echo 'rences of "__unused" (but not e.g. "__unused1") in your sy-'
441         echo 'stem headers with e.g. "__unused_" to work around this bug.'
442         echo
443         slp=1
444 fi
445
446 if [[ ${BASH_VERSION%%.*} -lt 2 || ${BASH_VERSION%%.*} -gt 3 ]]; then
447         echo '*WARNING* Your GNU bash is not version 2 or 3, which'
448         echo may lead to errors.
449         echo
450         slp=1
451 fi
452
453 if ! which ed >/dev/null 2>&1; then
454         echo Why does your distribution not package the standard
455         echo text editor, ed? Please install it to continue.
456         echo
457         out=1
458 elif [[ "$(PATH=/bin:$PATH which ed 2>/dev/null)" != /bin/ed ]]; then
459         echo Your operating system installs ed, the standard text
460         echo editor, not as /bin/ed. While you can build FreeWRT
461         echo with this, ask your vendor to fix it, point to the
462         echo FHS if needed.
463         echo
464 fi
465
466 if ! which file >/dev/null 2>&1; then
467         echo You must install \"file\" to continue.
468         echo
469         out=1
470 fi
471
472 if ! which mksh >/dev/null 2>&1; then
473         echo USE_TOOLS_MKSH=1 >>$topdir/lbin/prereq.mk
474         echo "MBSH:=$topdir/lbin/mkshw" >>$topdir/lbin/prereq.mk
475         rm -f $topdir/lbin/mkshw
476         cat >$topdir/lbin/mkshw <<-EOF
477                 #!/bin/sh
478                 if test -e '$topdir/lbin/mksh'; then
479                         exec '$topdir/lbin/mksh' "\$@"
480                 else
481                         exec '$BASH' "\$@"
482                 fi
483         EOF
484         chmod +x $topdir/lbin/mkshw
485         BSH=$BASH
486 else
487         BSH=$(which mksh)
488         echo "MBSH:=$BSH" >>$topdir/lbin/prereq.mk
489 fi
490
491 if which nroff >/dev/null 2>&1; then
492         if which nrcon >/dev/null 2>&1; then
493                 NROFF="nroff -Tcol \$\${MACROS} \$\${PAGES}"
494         elif [[ "$(echo | nroff -v 2>&1)" = *GNU* ]]; then
495                 NROFF="nroff -c -Tascii \$\${MACROS} \$\${PAGES}"
496         else
497                 NROFF="nroff \$\${MACROS} \$\${PAGES}"
498         fi
499 elif which gnroff >/dev/null 2>&1; then
500         NROFF="gnroff -c -Tascii \$\${MACROS} \$\${PAGES}"
501 elif which groff >/dev/null 2>&1; then
502         NROFF="groff -c -Tascii \$\${MACROS} \$\${PAGES}"
503 else
504         NROFF="cat -- \$\${PAGES}"
505         echo warning: no nroff found, install GNU groff please
506 fi
507 echo "NROFF:=$NROFF" >>$topdir/lbin/prereq.mk
508
509
510 cd $topdir
511 rm -rf lbin/tmp
512
513 # populate some more tools
514 cat >lbin/autoconf <<-EOF
515         #!$BSH
516         echo '===> Warning: this package calls autoconf!'
517         exit 0
518 EOF
519 cp lbin/autoconf lbin/autoheader
520 for 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
521         cp lbin/autoconf lbin/autoconf-$v
522         cp lbin/autoconf lbin/autoheader-$v
523 done
524 cat >lbin/automake <<-EOF
525         #!$BSH
526         echo '===> Warning: this package calls automake!'
527         exit 0
528 EOF
529 cp lbin/automake lbin/aclocal
530 for v in 1.4 1.5 1.6 1.7 1.8 1.9 1.10; do
531         cp lbin/automake lbin/automake-$v
532         cp lbin/automake lbin/aclocal-$v
533 done
534 cat >lbin/help2man <<-EOF
535         #!$BSH
536         echo '===> Warning: this package calls help2man!'
537         exit 0
538 EOF
539 chmod a+x lbin/{autoconf,autoheader,automake,aclocal,help2man}*
540
541 if (( slp && !out )); then
542         echo 'Please read the warnings above; I will wait a few seconds'
543         sleep 12
544 fi
545
546 exit $out
547
Note: See TracBrowser for help on using the browser.