source: freewrt/scripts/scan-tools.sh@ 0576dbb

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

netbsd® is more cruel™

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

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