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
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
32if test -z "$BASH_VERSION"; then
33 echo FreeWRT requires GNU bash to be installed, sorry.
34 exit 1
35fi
36
37shopt -s extglob
38topdir=$(pwd)
39opath=$PATH
40out=0
41bmake=
42
43if [[ $NO_ERROR != @(0|1) ]]; then
44 echo Please do not invoke this script directly!
45 exit 1
46fi
47
48set -e
49rm -rf $topdir/lbin/tmp
50mkdir -p $topdir/lbin/tmp
51cd $topdir/lbin/tmp
52
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
66os=$(uname)
67case $os in
68Darwin)
69 # needs a bunch of quirks, but seems to compile
70 echo Warning: Darwin support is highly experimental.
71 echo
72 ;;
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
91 bmake=/usr/bin/make
92 ;;
93*)
94 # unsupported
95 echo "Building FreeWRT on $os is currently unsupported."
96 echo "Sorry."
97 echo
98 case $os in
99 Cyg*)
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
120set +e
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
171cat >Makefile <<'EOF'
172include ${TOPDIR}/lbin/prereq.mk
173HOSTCFLAGS+= ${FLAG_TEST}
174all: run-test
175
176test: test.c
177 ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
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
193 echo "$X" | sed 's/^/| /'
194 echo Cannot compile a simple test programme.
195 echo You must install a host make and C compiler,
196 echo usually GCC, to proceed.
197 echo
198 out=1
199fi
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
209rm test
210
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
217 #echo "$X" | sed 's/^/| /'
218 :
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
253if ! which flex >/dev/null 2>&1; then
254 echo You must install flex to continue.
255 echo
256 out=1
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
269 echo
270 fi
271fi
272
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.
277 echo
278 out=1
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
294if ! which gzip >/dev/null 2>&1; then
295 echo You must install gzip to continue.
296 echo
297 out=1
298fi
299
300if ! which bzip2 >/dev/null 2>&1; then
301 echo You must install bzip2 to continue.
302 echo
303 out=1
304fi
305
306if ! which unzip >/dev/null 2>&1; then
307 echo You must install unzip to continue, sorry.
308 echo
309 out=1
310fi
311
312if ! which zip >/dev/null 2>&1; then
313 echo You must install zip to continue, sorry.
314 echo
315 out=1
316fi
317
318if ! which patch >/dev/null 2>&1; then
319 echo You must install patch \(from Larry Wall\) to continue.
320 echo
321 out=1
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
348X=$(echo 'Yay! Native compiler works.' | gzip | \
349 gmake TOPDIR=$topdir LDADD=-lz 2>&1)
350if [[ $X != *@(Native compiler works)* ]]; then
351 echo "$X" | sed 's/^/| /'
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.
355 echo
356 out=1
357fi
358
359if [[ ! -s /usr/include/ncurses.h ]]; then
360 echo Install ncurses header files, please.
361 echo
362 out=1
363fi
364
365if ! which g++ >/dev/null 2>&1; then
366 echo You must install the host GNU C++ compiler to continue.
367 echo
368 out=1
369fi
370
371#if ! which perl >/dev/null 2>&1; then
372if [[ "$(which perl 2>/dev/null)" != /usr/bin/perl ]]; then
373 echo You must install Perl in /usr/bin to continue.
374 echo
375 out=1
376fi
377
378if ! which wget >/dev/null 2>&1; then
379 echo You must install GNU wget to continue.
380 echo
381 out=1
382fi
383
384if ! which makeinfo >/dev/null 2>&1; then
385 echo You must install GNU texinfo to continue.
386 echo
387 out=1
388fi
389
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.
393 echo
394 out=1
395elif [[ "$(PATH=/bin:$PATH which ed 2>/dev/null)" != /bin/ed ]]; then
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.
400 echo
401fi
402
403if ! which file >/dev/null 2>&1; then
404 echo You must install \"file\" to continue.
405 echo
406 out=1
407fi
408
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
413fi
414
415if [[ $have_tsort = 0 ]]; then
416 bmake=
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)
422 [[ $y = +([0-9]) ]] || continue
423 [[ $y < 20070626 ]] && continue
424 bmake=$x
425 break
426 done
427fi
428[[ $bmake = $topdir/lbin/bmake ]] && bmake=
429
430if [[ $have_tsort = 0 || -z $bmake ]]; then
431 echo USE_TOOLS_MIRMAKE=1 >>$topdir/lbin/prereq.mk
432 bmake=$topdir/lbin/bmake
433 if ! which mksh >/dev/null 2>&1; then
434 echo USE_TOOLS_MKSH=1 >>$topdir/lbin/prereq.mk
435 fi
436fi
437
438echo "BMAKE='$bmake'" >>$topdir/lbin/prereq.mk
439
440if grep USE_TOOLS_MKSH=1 $topdir/lbin/prereq.mk >/dev/null 2>&1; then
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
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
458
459cd $topdir
460rm -rf lbin/tmp
461
462# populate some more tools
463cat >lbin/autoconf <<-EOF
464 #!$BASH
465 echo '===> Warning: this package calls autoconf!'
466 exit 0
467EOF
468cp lbin/autoconf lbin/autoheader
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
473cat >lbin/automake <<-EOF
474 #!$BASH
475 echo '===> Warning: this package calls automake!'
476 exit 0
477EOF
478cp lbin/automake lbin/aclocal
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}*
484
485exit $out
Note: See TracBrowser for help on using the repository browser.