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

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

add a prereq check for a case-sensitive fs, 10x for the idea nbd@openwrt

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

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