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

Last change on this file since f855d85 was 2a734b1, checked in by Thorsten Glaser <tg@…>, 19 years ago

rstrip.sh already requires "file"

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

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