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

Revision 3771, 12.6 kB (checked in by tg, 5 months ago)

some GNU/Linux distributions don’t have a dependency gcc ← cpp, it seems
Message-ID: <20080625194019.46811dc5.ms@freewrt.org>

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