source: freewrt/scripts/scan-tools.sh@ 655dec8

Last change on this file since 655dec8 was 32396b1, checked in by Thorsten Glaser <tg@…>, 19 years ago

if a build system has a non-GNU make, or a too old gmake, just
build our own

tested on MirBSD odem.66h.42h.de 10 Kv#10n11-20070318 GENERIC#1014 i386
without gmake installed

if this is not working for you for the one or other reason,
please drop me a private mail with a detailled error description.

this procedure was explicitly ok'd by wbx@

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

  • Property mode set to 100644
File size: 9.5 KB
Line 
1#!/usr/bin/env bash
2# $FreeWRT: src/share/misc/licence.template,v 1.20 2006/12/11 21:04:56 tg Rel $
3#-
4# Copyright (c) 2006, 2007
5# Thorsten Glaser <tg@mirbsd.de>
6#
7# Provided that these terms and disclaimer and all copyright notices
8# are retained or reproduced in an accompanying document, permission
9# is granted to deal in this work without restriction, including un-
10# limited rights to use, publicly perform, distribute, sell, modify,
11# merge, give away, or sublicence.
12#
13# Advertising materials mentioning features or use of this work must
14# display the following acknowledgement:
15# This product includes material provided by Thorsten Glaser.
16# This acknowledgement does not need to be reprinted if this work is
17# linked into a bigger work whose licence does not allow such clause
18# and the author of this work is given due credit in the bigger work
19# or its accompanying documents, where such information is generally
20# kept, provided that said credits are retained.
21#
22# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
23# the utmost extent permitted by applicable law, neither express nor
24# implied; without malicious intent or gross negligence. In no event
25# may a licensor, author or contributor be held liable for indirect,
26# direct, other damage, loss, or other issues arising in any way out
27# of dealing in the work, even if advised of the possibility of such
28# damage or existence of a defect, except proven that it results out
29# of said person's immediate fault when using the work as intended.
30#-
31# Scan for prerequisite host tools.
32
33if test -z "$BASH_VERSION"; then
34 echo FreeWRT requires GNU bash to be installed, sorry.
35 exit 1
36fi
37
38shopt -s extglob
39topdir=$(pwd)
40opath=$PATH
41out=0
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 ;;
74*)
75 # unsupported
76 echo "Building FreeWRT on $os is currently unsupported."
77 echo "Sorry."
78 echo
79 case $os in
80 Darwin|Cyg*)
81 echo "The most prominent issue is that filesystems"
82 echo "can be case-insensitive. Some macros are missing."
83 echo
84 ;;
85 NetBSD|FreeBSD|DragonFly)
86 echo "Building should succeed with relatively few"
87 echo "patches, but perl must live in /usr/bin for"
88 echo "now in FreeWRT, which should indeed be fixed."
89 echo
90 ;;
91 esac
92 echo "If you need FreeWRT building on $os, please contact"
93 echo "the development team; there may be contractors available"
94 echo "for this task. If you intend on turning $os into one of"
95 echo "the supported build OSes, please contact us as well so"
96 echo "that we can feed back your enhancements into FreeWRT."
97 exit 1
98 ;;
99esac
100
101set +e
102
103if [[ ! -e $topdir/lbin/gmake ]]; then
104 for f in $topdir/tools_build/gmake/make \
105 "$($topdir/lbin/which gmake)" "$($topdir/lbin/which make)"; do
106 [[ -e $f ]] || continue
107 if [[ $f = $topdir/tools_build/gmake/make ]]; then
108 install -c -s -m 555 $f $topdir/lbin/gmake
109 else
110 ln -s "$f" $topdir/lbin/gmake
111 fi
112 break
113 done
114fi
115X=$($topdir/lbin/gmake --version 2>&1 | grep '^GNU Make' | \
116 sed -e 's/GNU Make //' -e 's/version //' -e 's/, by.*$//')
117[[ $X = +([0-9]).+([0-9]).+([0-9]) ]] && X=${X%.*}
118if [[ $X = +([0-9]).+([0-9]) ]]; then
119 let major=${X%.*}
120 let minor=${X#*.}
121elif [[ $X = +([0-9]).+([0-9])beta* ]]; then
122 # Beta version is not "the real thing"
123 let major=${X%.*}
124 X=${X%beta*}
125 let minor=${X#*.}-1
126else
127 let major=0
128fi
129if (( (major < 3) || ((major == 3) && (minor < 81)) )); then
130 echo "---> building GNU make 3.81"
131 rm -rf $topdir/tools_build/gmake $topdir/lbin/gmake
132 set -e
133 mkdir -p $topdir/tools_build/gmake
134 cd $topdir/tools_build/gmake
135 env CPPFLAGS="$CPPFLAGS -Dstrcmpi=strcasecmp" \
136 CFLAGS="$(grep '^HOSTCFLAGS' $topdir/lbin/prereq.mk | \
137 sed 's/HOSTCFLAGS:=//')" \
138 $BASH $topdir/tools/gmake/configure \
139 --program-prefix=g \
140 --disable-dependency-tracking \
141 --disable-nls \
142 --without-libiconv-prefix \
143 --without-libintl-prefix
144 make all
145 install -c -s -m 555 make $topdir/lbin/gmake
146 set +e
147 cd $topdir/lbin; ls -l gmake
148 cd $topdir/lbin/tmp
149fi
150export PATH=$topdir/lbin:$PATH
151
152cat >Makefile <<'EOF'
153include ${TOPDIR}/lbin/prereq.mk
154HOSTCFLAGS+= ${FLAG_TEST}
155all: run-test
156
157test: test.c
158 ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
159
160run-test: test
161 ./test
162EOF
163cat >test.c <<-'EOF'
164 #include <stdio.h>
165 int
166 main()
167 {
168 printf("Yay! Native compiler works.\n");
169 return (0);
170 }
171EOF
172X=$(gmake TOPDIR=$topdir 2>&1)
173if [[ $X != *@(Native compiler works)* ]]; then
174 echo "$X" | sed 's/^/| /'
175 echo Cannot compile a simple test programme.
176 echo You must install a host make and C compiler,
177 echo usually GCC, to proceed.
178 echo
179 out=1
180fi
181rm test
182
183X=$(gmake FLAG_TEST=-fwrapv TOPDIR=$topdir 2>&1)
184grep '^HOSTCFLAGS.*-fwrapv' ../prereq.mk >/dev/null 2>&1 || \
185 if [[ $X = *@(Native compiler works)* ]]; then
186 printf '/^HOSTCFLAGS/s/$/ -fwrapv/\nwq\n' | ed -s ../prereq.mk
187else
188 echo "$X" | sed 's/^/| /'
189fi
190rm test
191
192need_fnotreevrp=0
193X=$(gmake FLAG_TEST=-fno-tree-vrp TOPDIR=$topdir 2>&1)
194grep '^HOSTCFLAGS.*-fno-tree-vrp' ../prereq.mk >/dev/null 2>&1 || \
195 if [[ $X = *@(Native compiler works)* ]]; then
196 need_fnotreevrp=1
197else
198 #echo "$X" | sed 's/^/| /'
199 :
200fi
201rm test*
202if [[ $need_fnotreevrp = 1 ]]; then
203 cat >test.c <<-'EOF'
204 typedef unsigned size_t;
205 char *strncpy(char *, const char *, size_t);
206 char *
207 strncpy(char *d, const char *s, size_t n)
208 {
209 if (!d || !s) {
210 if (d)
211 *d = n;
212 return (d);
213 }
214 return (*d = 1, d);
215 }
216 int
217 main(void)
218 {
219 char a[] = "t";
220 strncpy(a, (void *)0, 2);
221 return (*a);
222 }
223 EOF
224 X=$(gmake test TOPDIR=$topdir 2>&1)
225 if [[ -x test ]]; then
226 ./test >/dev/null 2>&1
227 [[ $? = 2 ]] && need_fnotreevrp=0
228 fi
229 rm test*
230fi
231[[ $need_fnotreevrp = 1 ]] && \
232 printf '/^HOSTCFLAGS/s/$/ -fno-tree-vrp/\nwq\n' | ed -s ../prereq.mk
233
234if ! which flex >/dev/null 2>&1; then
235 echo You must install flex to continue.
236 echo
237 out=1
238else
239 echo '%%' | flex -
240 if fgrep _POSIX_SOURCE lex.yy.c; then
241 echo Your lexer \(flex\) contains a broken skeleton.
242 if [[ $NO_ERROR = 1 ]]; then
243 echo WARNING: continue at your own risk.
244 echo Some packages may be broken.
245 else
246 echo You can continue the build by issuing \'make prereq-noerror\'
247 echo However, several packages may faild to build correctly.
248 out=1
249 fi
250 echo
251 fi
252fi
253
254if ! which bison >/dev/null 2>&1; then
255 echo You must install GNU Bison to continue.
256 echo While you can install any version, it is '*STRONGLY*' suggested
257 echo to install GNU Bison version 2.3 because of its bug fixes.
258 echo
259 out=1
260fi
261X=$(bison --version 2>&1 | fgrep 'GNU Bison' | sed 's/^[^0-9]*//')
262V=old
263if [[ $X = +([0-9]).+([0-9]) ]]; then
264 let major=${X%.*}
265 let minor=${X#*.}
266 if (( (major > 2) || ((major == 2) && (minor >= 3)) )); then
267 V=new
268 fi
269fi
270if [[ $V = old ]]; then
271 echo It is suggested to upgrade your copy of bison to
272 echo GNU Bison 2.3 because of its bug fixes.
273fi
274
275if ! which gzip >/dev/null 2>&1; then
276 echo You must install gzip to continue.
277 echo
278 out=1
279fi
280
281if ! which bzip2 >/dev/null 2>&1; then
282 echo You must install bzip2 to continue.
283 echo
284 out=1
285fi
286
287if ! which unzip >/dev/null 2>&1; then
288 echo You must install unzip to continue, sorry.
289 echo
290 out=1
291fi
292
293if ! which patch >/dev/null 2>&1; then
294 echo You must install patch \(from Larry Wall\) to continue.
295 echo
296 out=1
297fi
298
299cat >test.c <<-'EOF'
300 #include <stdio.h>
301 #include <zlib.h>
302
303 #ifndef STDIN_FILENO
304 #define STDIN_FILENO 0
305 #endif
306
307 int
308 main()
309 {
310 gzFile zstdin;
311 char buf[1024];
312 int i;
313
314 zstdin = gzdopen(STDIN_FILENO, "rb");
315 i = gzread(zstdin, buf, sizeof (buf));
316 if ((i > 0) && (i < sizeof (buf)))
317 buf[i] = '\0';
318 buf[sizeof (buf) - 1] = '\0';
319 printf("%s\n", buf);
320 return (0);
321 }
322EOF
323X=$(echo 'Yay! Native compiler works.' | gzip | \
324 gmake TOPDIR=$topdir LDADD=-lz 2>&1)
325if [[ $X != *@(Native compiler works)* ]]; then
326 echo "$X" | sed 's/^/| /'
327 echo Cannot compile a libz test programme.
328 echo You must install the zlib development package,
329 echo usually called libz-dev, and the run-time library.
330 echo
331 out=1
332fi
333
334if [[ ! -s /usr/include/ncurses.h ]]; then
335 echo Install ncurses header files, please.
336 echo
337 out=1
338fi
339
340if ! which g++ >/dev/null 2>&1; then
341 echo You must install the host GNU C++ compiler to continue.
342 echo
343 out=1
344fi
345
346#if ! which perl >/dev/null 2>&1; then
347if [[ "$(which perl 2>/dev/null)" != /usr/bin/perl ]]; then
348 echo You must install Perl in /usr/bin to continue.
349 echo
350 out=1
351fi
352
353if ! which wget >/dev/null 2>&1; then
354 echo You must install GNU wget to continue.
355 echo
356 out=1
357fi
358
359if ! which makeinfo >/dev/null 2>&1; then
360 echo You must install GNU texinfo to continue.
361 echo
362 out=1
363fi
364
365if ! which ed >/dev/null 2>&1; then
366 echo Why does your distribution not package the standard
367 echo text editor, ed? Please install it to continue.
368 echo
369 out=1
370elif [[ "$(PATH=/bin:$PATH which ed 2>/dev/null)" != /bin/ed ]]; then
371 echo Your operating system installs ed, the standard text
372 echo editor, not as /bin/ed. While you can build FreeWRT
373 echo with this, ask your vendor to fix it, point to the
374 echo FHS if needed.
375 echo
376fi
377
378
379cd $topdir
380rm -rf lbin/tmp
381exit $out
Note: See TracBrowser for help on using the repository browser.