| 1 | #!/usr/bin/env bash
|
|---|
| 2 | # $FreeWRT: src/share/misc/licence.template,v 1.8 2006/06/16 23:03:39 tg Rel $
|
|---|
| 3 | #-
|
|---|
| 4 | # Copyright (c) 2006
|
|---|
| 5 | # Thorsten Glaser <tg@mirbsd.de>
|
|---|
| 6 | #
|
|---|
| 7 | # Licensee is hereby permitted to deal in this work without restric-
|
|---|
| 8 | # tion, including unlimited rights to use, publicly perform, modify,
|
|---|
| 9 | # merge, distribute, sell, give away or sublicence, provided all co-
|
|---|
| 10 | # pyright notices above, these terms and the disclaimer are retained
|
|---|
| 11 | # in all redistributions or reproduced in accompanying documentation
|
|---|
| 12 | # or other materials provided with binary redistributions.
|
|---|
| 13 | #
|
|---|
| 14 | # All advertising materials mentioning features or use of this soft-
|
|---|
| 15 | # ware must display the following acknowledgement:
|
|---|
| 16 | # This product includes material provided by Thorsten Glaser.
|
|---|
| 17 | # This acknowledgement does not need to be reprinted if this work is
|
|---|
| 18 | # linked into a bigger work whose licence does not allow such clause
|
|---|
| 19 | # and the author of this work is given due credit in the bigger work
|
|---|
| 20 | # or its documentation.
|
|---|
| 21 | #
|
|---|
| 22 | # Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
|
|---|
| 23 | # express, or implied, to the maximum extent permitted by applicable
|
|---|
| 24 | # law, without malicious intent or gross negligence; in no event may
|
|---|
| 25 | # licensor, an author or contributor be held liable for any indirect
|
|---|
| 26 | # or other damage, or direct damage except proven a consequence of a
|
|---|
| 27 | # direct error of said person and intended use of this work, loss or
|
|---|
| 28 | # other issues arising in any way out of its use, even if advised of
|
|---|
| 29 | # the possibility of such damage or existence of a nontrivial bug.
|
|---|
| 30 | #-
|
|---|
| 31 | # Scan for prerequisite host tools.
|
|---|
| 32 |
|
|---|
| 33 | if test -z "$BASH_VERSION"; then
|
|---|
| 34 | echo FreeWRT requires GNU bash to be installed, sorry.
|
|---|
| 35 | exit 1
|
|---|
| 36 | fi
|
|---|
| 37 |
|
|---|
| 38 | shopt -s extglob
|
|---|
| 39 | topdir=$(pwd)
|
|---|
| 40 | export PATH=$topdir/lbin:$PATH
|
|---|
| 41 | out=0
|
|---|
| 42 |
|
|---|
| 43 | if [[ $NO_ERROR != @(0|1) ]]; then
|
|---|
| 44 | echo Please do not invoke this script directly!
|
|---|
| 45 | exit 1
|
|---|
| 46 | fi
|
|---|
| 47 |
|
|---|
| 48 | set -e
|
|---|
| 49 | rm -rf $topdir/lbin/tmp
|
|---|
| 50 | mkdir -p $topdir/lbin/tmp
|
|---|
| 51 | cd $topdir/lbin/tmp
|
|---|
| 52 | set +e
|
|---|
| 53 | cat >Makefile <<'EOF'
|
|---|
| 54 | include $(TOPDIR)/lbin/prereq.mk
|
|---|
| 55 | all: run-test
|
|---|
| 56 |
|
|---|
| 57 | test: test.c
|
|---|
| 58 | ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
|
|---|
| 59 |
|
|---|
| 60 | run-test: test
|
|---|
| 61 | ./test
|
|---|
| 62 | EOF
|
|---|
| 63 | cat >test.c <<-'EOF'
|
|---|
| 64 | #include <stdio.h>
|
|---|
| 65 | int
|
|---|
| 66 | main()
|
|---|
| 67 | {
|
|---|
| 68 | printf("Yay! Native compiler works.\n");
|
|---|
| 69 | return (0);
|
|---|
| 70 | }
|
|---|
| 71 | EOF
|
|---|
| 72 | X=$(gmake TOPDIR=$topdir 2>&1)
|
|---|
| 73 | if [[ $X != *@(Native compiler works)* ]]; then
|
|---|
| 74 | echo Cannot compile a simple test programme.
|
|---|
| 75 | echo You must install GNU make and a host C compiler,
|
|---|
| 76 | echo usually GCC, to proceed.
|
|---|
| 77 | out=1
|
|---|
| 78 | fi
|
|---|
| 79 | rm test*
|
|---|
| 80 |
|
|---|
| 81 | X=$(gmake --version 2>&1 | grep '^GNU Make' | \
|
|---|
| 82 | sed -e 's/GNU Make //' -e 's/version //' -e 's/, by.*$//')
|
|---|
| 83 | [[ $X = +([0-9]).+([0-9]).+([0-9]) ]] && X=${X%.*}
|
|---|
| 84 | if [[ $X = +([0-9]).+([0-9]) ]]; then
|
|---|
| 85 | let major=${X%.*}
|
|---|
| 86 | let minor=${X#*.}
|
|---|
| 87 | elif [[ $X = +([0-9]).+([0-9])beta* ]]; then
|
|---|
| 88 | # Beta version is not "the real thing"
|
|---|
| 89 | let major=${X%.*}
|
|---|
| 90 | X=${X%beta*}
|
|---|
| 91 | let minor=${X#*.}-1
|
|---|
| 92 | else
|
|---|
| 93 | echo Cannot determine GNU make version number.
|
|---|
| 94 | out=1
|
|---|
| 95 | fi
|
|---|
| 96 | if (( (major < 3) || ((major == 3) && (minor < 81)) )); then
|
|---|
| 97 | echo GNU make $major.$minor too old.
|
|---|
| 98 | echo Please install GNU make 3.81 or higher to continue.
|
|---|
| 99 | if [[ $NO_ERROR = 1 || -s /etc/debian_version ]]; then
|
|---|
| 100 | echo WARNING: should abort here, continuing...
|
|---|
| 101 | else
|
|---|
| 102 | echo You can override this check, see http://www.freewrt.org/faq for details.
|
|---|
| 103 | out=1
|
|---|
| 104 | fi
|
|---|
| 105 | fi
|
|---|
| 106 |
|
|---|
| 107 | if ! which flex >/dev/null 2>&1; then
|
|---|
| 108 | echo You must install flex to continue.
|
|---|
| 109 | out=1
|
|---|
| 110 | fi
|
|---|
| 111 |
|
|---|
| 112 | echo '%%' | flex -
|
|---|
| 113 | if fgrep _POSIX_SOURCE lex.yy.c; then
|
|---|
| 114 | echo Your lexer \(flex\) contains a broken skeleton.
|
|---|
| 115 | if [[ $NO_ERROR = 1 ]]; then
|
|---|
| 116 | echo WARNING: continue at your own risk.
|
|---|
| 117 | echo Some packages may be broken.
|
|---|
| 118 | else
|
|---|
| 119 | echo You can continue the build by issuing \'make prereq-noerror\'
|
|---|
| 120 | echo However, several packages may faild to build correctly.
|
|---|
| 121 | out=1
|
|---|
| 122 | fi
|
|---|
| 123 | fi
|
|---|
| 124 |
|
|---|
| 125 | if ! which bison >/dev/null 2>&1; then
|
|---|
| 126 | echo You must install GNU Bison to continue.
|
|---|
| 127 | echo While you can install any version, it is '*STRONGLY*' suggested
|
|---|
| 128 | echo to install GNU Bison version 2.3 because of its bug fixes.
|
|---|
| 129 | out=1
|
|---|
| 130 | fi
|
|---|
| 131 | X=$(bison --version 2>&1 | fgrep 'GNU Bison' | sed 's/^[^0-9]*//')
|
|---|
| 132 | V=old
|
|---|
| 133 | if [[ $X = +([0-9]).+([0-9]) ]]; then
|
|---|
| 134 | let major=${X%.*}
|
|---|
| 135 | let minor=${X#*.}
|
|---|
| 136 | if (( (major > 2) || ((major == 2) && (minor >= 3)) )); then
|
|---|
| 137 | V=new
|
|---|
| 138 | fi
|
|---|
| 139 | fi
|
|---|
| 140 | if [[ $V = old ]]; then
|
|---|
| 141 | echo It is suggested to upgrade your copy of bison to
|
|---|
| 142 | echo GNU Bison 2.3 because of its bug fixes.
|
|---|
| 143 | fi
|
|---|
| 144 |
|
|---|
| 145 | if ! which gzip >/dev/null 2>&1; then
|
|---|
| 146 | echo You must install gzip to continue.
|
|---|
| 147 | out=1
|
|---|
| 148 | fi
|
|---|
| 149 |
|
|---|
| 150 | if ! which bzip2 >/dev/null 2>&1; then
|
|---|
| 151 | echo You must install bzip2 to continue.
|
|---|
| 152 | out=1
|
|---|
| 153 | fi
|
|---|
| 154 |
|
|---|
| 155 | if ! which unzip >/dev/null 2>&1; then
|
|---|
| 156 | echo You must install unzip to continue, sorry.
|
|---|
| 157 | out=1
|
|---|
| 158 | fi
|
|---|
| 159 |
|
|---|
| 160 | if ! which patch >/dev/null 2>&1; then
|
|---|
| 161 | echo You must install patch \(from Larry Wall\) to continue.
|
|---|
| 162 | out=1
|
|---|
| 163 | fi
|
|---|
| 164 |
|
|---|
| 165 | cat >test.c <<-'EOF'
|
|---|
| 166 | #include <stdio.h>
|
|---|
| 167 | #include <zlib.h>
|
|---|
| 168 |
|
|---|
| 169 | #ifndef STDIN_FILENO
|
|---|
| 170 | #define STDIN_FILENO 0
|
|---|
| 171 | #endif
|
|---|
| 172 |
|
|---|
| 173 | int
|
|---|
| 174 | main()
|
|---|
| 175 | {
|
|---|
| 176 | gzFile zstdin;
|
|---|
| 177 | char buf[1024];
|
|---|
| 178 | int i;
|
|---|
| 179 |
|
|---|
| 180 | zstdin = gzdopen(STDIN_FILENO, "rb");
|
|---|
| 181 | i = gzread(zstdin, buf, sizeof (buf));
|
|---|
| 182 | if ((i > 0) && (i < sizeof (buf)))
|
|---|
| 183 | buf[i] = '\0';
|
|---|
| 184 | buf[sizeof (buf) - 1] = '\0';
|
|---|
| 185 | printf("%s\n", buf);
|
|---|
| 186 | return (0);
|
|---|
| 187 | }
|
|---|
| 188 | EOF
|
|---|
| 189 | X=$(echo 'Yay! Native compiler works.' | gzip | \
|
|---|
| 190 | gmake TOPDIR=$topdir LDADD=-lz 2>&1)
|
|---|
| 191 | if [[ $X != *@(Native compiler works)* ]]; then
|
|---|
| 192 | echo Cannot compile a libz test programme.
|
|---|
| 193 | echo You must install the zlib development package,
|
|---|
| 194 | echo usually called libz-dev, and the run-time library.
|
|---|
| 195 | out=1
|
|---|
| 196 | fi
|
|---|
| 197 |
|
|---|
| 198 | if ! which g++ >/dev/null 2>&1; then
|
|---|
| 199 | echo You must install the host GNU C++ compiler to continue.
|
|---|
| 200 | out=1
|
|---|
| 201 | fi
|
|---|
| 202 |
|
|---|
| 203 | #if ! which perl >/dev/null 2>&1; then
|
|---|
| 204 | if [[ "$(which perl 2>/dev/null)" != /usr/bin/perl ]]; then
|
|---|
| 205 | echo You must install Perl in /usr/bin to continue.
|
|---|
| 206 | out=1
|
|---|
| 207 | fi
|
|---|
| 208 |
|
|---|
| 209 | if ! which python >/dev/null 2>&1; then
|
|---|
| 210 | echo You must install Python to continue, sorry.
|
|---|
| 211 | out=1
|
|---|
| 212 | fi
|
|---|
| 213 |
|
|---|
| 214 | if ! which wget >/dev/null 2>&1; then
|
|---|
| 215 | echo You must install GNU wget to continue.
|
|---|
| 216 | out=1
|
|---|
| 217 | fi
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 | cd $topdir
|
|---|
| 221 | rm -rf lbin/tmp
|
|---|
| 222 | exit $out
|
|---|