| 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. Specifically, re-using this code in any work
|
|---|
| 21 | # covered by the GNU General Public License version 1 or Library Ge-
|
|---|
| 22 | # neral Public License (any version) is permitted.
|
|---|
| 23 | #
|
|---|
| 24 | # Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
|
|---|
| 25 | # express, or implied, to the maximum extent permitted by applicable
|
|---|
| 26 | # law, without malicious intent or gross negligence; in no event may
|
|---|
| 27 | # licensor, an author or contributor be held liable for any indirect
|
|---|
| 28 | # or other damage, or direct damage except proven a consequence of a
|
|---|
| 29 | # direct error of said person and intended use of this work, loss or
|
|---|
| 30 | # other issues arising in any way out of its use, even if advised of
|
|---|
| 31 | # the possibility of such damage or existence of a nontrivial bug.
|
|---|
| 32 | #-
|
|---|
| 33 | # Scan for prerequisite host tools.
|
|---|
| 34 |
|
|---|
| 35 | if test -z "$BASH_VERSION"; then
|
|---|
| 36 | echo FreeWRT requires GNU bash to be installed, sorry.
|
|---|
| 37 | exit 1
|
|---|
| 38 | fi
|
|---|
| 39 |
|
|---|
| 40 | shopt -s extglob
|
|---|
| 41 | topdir=$(pwd)
|
|---|
| 42 | export PATH=$topdir/lbin:$PATH
|
|---|
| 43 |
|
|---|
| 44 | if [[ $NO_ERROR != @(0|1) ]]; then
|
|---|
| 45 | echo Please do not invoke this script directly!
|
|---|
| 46 | exit 1
|
|---|
| 47 | fi
|
|---|
| 48 |
|
|---|
| 49 | set -e
|
|---|
| 50 | rm -rf $topdir/lbin/tmp
|
|---|
| 51 | mkdir -p $topdir/lbin/tmp
|
|---|
| 52 | cd $topdir/lbin/tmp
|
|---|
| 53 | set +e
|
|---|
| 54 | cat >Makefile <<'EOF'
|
|---|
| 55 | include $(TOPDIR)/lbin/prereq.mk
|
|---|
| 56 | all: run-test
|
|---|
| 57 |
|
|---|
| 58 | test: test.c
|
|---|
| 59 | ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
|
|---|
| 60 |
|
|---|
| 61 | run-test: test
|
|---|
| 62 | ./test
|
|---|
| 63 | EOF
|
|---|
| 64 | cat >test.c <<-'EOF'
|
|---|
| 65 | #include <stdio.h>
|
|---|
| 66 | int
|
|---|
| 67 | main()
|
|---|
| 68 | {
|
|---|
| 69 | printf("Yay! Native compiler works.\n");
|
|---|
| 70 | return (0);
|
|---|
| 71 | }
|
|---|
| 72 | EOF
|
|---|
| 73 | X=$(gmake TOPDIR=$topdir 2>&1)
|
|---|
| 74 | if [[ $X != *@(Native compiler works)* ]]; then
|
|---|
| 75 | echo Cannot compile a simple test programme.
|
|---|
| 76 | echo You must install GNU make and a host C compiler,
|
|---|
| 77 | echo usually GCC, to proceed.
|
|---|
| 78 | exit 1
|
|---|
| 79 | fi
|
|---|
| 80 | rm test*
|
|---|
| 81 |
|
|---|
| 82 | X=$(gmake --version 2>&1 | grep '^GNU Make' | sed 's/GNU Make //')
|
|---|
| 83 | if [[ $X != +([0-9]).+([0-9]) ]]; then
|
|---|
| 84 | echo Cannot determine GNU make version number.
|
|---|
| 85 | exit 1
|
|---|
| 86 | fi
|
|---|
| 87 | let major=${X%.*}
|
|---|
| 88 | let minor=${X#*.}
|
|---|
| 89 | if (( (major < 3) || ((major == 3) && (minor < 81)) )); then
|
|---|
| 90 | echo GNU make too old.
|
|---|
| 91 | echo Please install GNU make 3.81 or higher to continue.
|
|---|
| 92 | if [[ $NO_ERROR = 1 ]]; then
|
|---|
| 93 | echo WARNING: should abort here, continuing...
|
|---|
| 94 | else
|
|---|
| 95 | echo You can override this check, see http://www.freewrt.org/faq for details.
|
|---|
| 96 | exit 1
|
|---|
| 97 | fi
|
|---|
| 98 | fi
|
|---|
| 99 |
|
|---|
| 100 | if ! which flex >/dev/null 2>&1; then
|
|---|
| 101 | echo You must install flex to continue.
|
|---|
| 102 | exit 1
|
|---|
| 103 | fi
|
|---|
| 104 |
|
|---|
| 105 | if ! which bison >/dev/null 2>&1; then
|
|---|
| 106 | echo You must install GNU Bison to continue.
|
|---|
| 107 | echo While you can install any version, it is '*STRONGLY*' suggested
|
|---|
| 108 | echo to install GNU Bison version 2.3 because of its bug fixes.
|
|---|
| 109 | exit 1
|
|---|
| 110 | fi
|
|---|
| 111 | X=$(bison --version 2>&1 | fgrep 'GNU Bison' | sed 's/^[^0-9]*//')
|
|---|
| 112 | V=old
|
|---|
| 113 | if [[ $X = +([0-9]).+([0-9]) ]]; then
|
|---|
| 114 | let major=${X%.*}
|
|---|
| 115 | let minor=${X#*.}
|
|---|
| 116 | if (( (major > 2) || ((major == 2) && (minor >= 3)) )); then
|
|---|
| 117 | V=new
|
|---|
| 118 | fi
|
|---|
| 119 | fi
|
|---|
| 120 | if [[ $V = old ]]; then
|
|---|
| 121 | echo It is suggested to upgrade your copy of bison to
|
|---|
| 122 | echo GNU Bison 2.3 because of its bug fixes.
|
|---|
| 123 | fi
|
|---|
| 124 |
|
|---|
| 125 | if ! which bzip2 >/dev/null 2>&1; then
|
|---|
| 126 | echo You must install bzip2 to continue.
|
|---|
| 127 | exit 1
|
|---|
| 128 | fi
|
|---|
| 129 |
|
|---|
| 130 | if ! which unzip >/dev/null 2>&1; then
|
|---|
| 131 | echo You must install unzip to continue, sorry.
|
|---|
| 132 | exit 1
|
|---|
| 133 | fi
|
|---|
| 134 |
|
|---|
| 135 | if ! which patch >/dev/null 2>&1; then
|
|---|
| 136 | echo You must install patch \(from Larry Wall\) to continue.
|
|---|
| 137 | exit 1
|
|---|
| 138 | fi
|
|---|
| 139 |
|
|---|
| 140 | cat >test.c <<-'EOF'
|
|---|
| 141 | #include <stdio.h>
|
|---|
| 142 | #include <zlib.h>
|
|---|
| 143 |
|
|---|
| 144 | #ifndef STDIN_FILENO
|
|---|
| 145 | #define STDIN_FILENO 0
|
|---|
| 146 | #endif
|
|---|
| 147 |
|
|---|
| 148 | int
|
|---|
| 149 | main()
|
|---|
| 150 | {
|
|---|
| 151 | gzFile zstdin;
|
|---|
| 152 | char buf[1024];
|
|---|
| 153 | int i;
|
|---|
| 154 |
|
|---|
| 155 | zstdin = gzdopen(STDIN_FILENO, "rb");
|
|---|
| 156 | i = gzread(zstdin, buf, sizeof (buf));
|
|---|
| 157 | if ((i > 0) && (i < sizeof (buf)))
|
|---|
| 158 | buf[i] = '\0';
|
|---|
| 159 | buf[sizeof (buf) - 1] = '\0';
|
|---|
| 160 | printf("%s\n", buf);
|
|---|
| 161 | return (0);
|
|---|
| 162 | }
|
|---|
| 163 | EOF
|
|---|
| 164 | X=$(echo 'Yay! Native compiler works.' | gmake TOPDIR=$topdir LDADD=-lz 2>&1)
|
|---|
| 165 | if [[ $X != *@(Native compiler works)* ]]; then
|
|---|
| 166 | echo Cannot compile a libz test programme.
|
|---|
| 167 | echo You must install the zlib development package,
|
|---|
| 168 | echo usually called libz-dev, and the run-time library.
|
|---|
| 169 | exit 1
|
|---|
| 170 | fi
|
|---|
| 171 |
|
|---|
| 172 | if ! which g++ >/dev/null 2>&1; then
|
|---|
| 173 | echo You must install the host GNU C++ compiler to continue.
|
|---|
| 174 | exit 1
|
|---|
| 175 | fi
|
|---|
| 176 |
|
|---|
| 177 | if ! tar --version 2>&1 | fgrep 'GNU tar' >/dev/null 2>&1; then
|
|---|
| 178 | echo You must install GNU tar for now, sorry...
|
|---|
| 179 | echo this is horrid, I know, but it will be fixed RSN.
|
|---|
| 180 | exit 1
|
|---|
| 181 | fi
|
|---|
| 182 |
|
|---|
| 183 | cd $topdir
|
|---|
| 184 | rm -rf lbin/tmp
|
|---|
| 185 | exit 0
|
|---|