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

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

fix bmake detection

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

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