| 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 |
|
|---|
| 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 |
|
|---|
| 53 | os=$(uname)
|
|---|
| 54 | case $os in
|
|---|
| 55 | Linux)
|
|---|
| 56 | # supported with no extra quirks at the moment
|
|---|
| 57 | ;;
|
|---|
| 58 | OpenBSD)
|
|---|
| 59 | # supported with no extra quirks at the moment
|
|---|
| 60 | # although some packages' autoconf scripts may
|
|---|
| 61 | # not properly recognise OpenBSD
|
|---|
| 62 | ;;
|
|---|
| 63 | MirBSD)
|
|---|
| 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 | ;;
|
|---|
| 99 | esac
|
|---|
| 100 |
|
|---|
| 101 | set +e
|
|---|
| 102 | cat >Makefile <<'EOF'
|
|---|
| 103 | include $(TOPDIR)/lbin/prereq.mk
|
|---|
| 104 | all: run-test
|
|---|
| 105 |
|
|---|
| 106 | test: test.c
|
|---|
| 107 | ${HOSTCC} ${HOSTCFLAGS} -o $@ $^ ${LDADD}
|
|---|
| 108 |
|
|---|
| 109 | run-test: test
|
|---|
| 110 | ./test
|
|---|
| 111 | EOF
|
|---|
| 112 | cat >test.c <<-'EOF'
|
|---|
| 113 | #include <stdio.h>
|
|---|
| 114 | int
|
|---|
| 115 | main()
|
|---|
| 116 | {
|
|---|
| 117 | printf("Yay! Native compiler works.\n");
|
|---|
| 118 | return (0);
|
|---|
| 119 | }
|
|---|
| 120 | EOF
|
|---|
| 121 | X=$(gmake TOPDIR=$topdir 2>&1)
|
|---|
| 122 | if [[ $X != *@(Native compiler works)* ]]; then
|
|---|
| 123 | echo Cannot compile a simple test programme.
|
|---|
| 124 | echo You must install GNU make and a host C compiler,
|
|---|
| 125 | echo usually GCC, to proceed.
|
|---|
| 126 | out=1
|
|---|
| 127 | fi
|
|---|
| 128 | rm test*
|
|---|
| 129 |
|
|---|
| 130 | X=$(gmake --version 2>&1 | grep '^GNU Make' | \
|
|---|
| 131 | sed -e 's/GNU Make //' -e 's/version //' -e 's/, by.*$//')
|
|---|
| 132 | [[ $X = +([0-9]).+([0-9]).+([0-9]) ]] && X=${X%.*}
|
|---|
| 133 | if [[ $X = +([0-9]).+([0-9]) ]]; then
|
|---|
| 134 | let major=${X%.*}
|
|---|
| 135 | let minor=${X#*.}
|
|---|
| 136 | elif [[ $X = +([0-9]).+([0-9])beta* ]]; then
|
|---|
| 137 | # Beta version is not "the real thing"
|
|---|
| 138 | let major=${X%.*}
|
|---|
| 139 | X=${X%beta*}
|
|---|
| 140 | let minor=${X#*.}-1
|
|---|
| 141 | else
|
|---|
| 142 | echo Cannot determine GNU make version number.
|
|---|
| 143 | out=1
|
|---|
| 144 | fi
|
|---|
| 145 | if (( (major < 3) || ((major == 3) && (minor < 81)) )); then
|
|---|
| 146 | echo GNU make $major.$minor too old.
|
|---|
| 147 | echo Please install GNU make 3.81 or higher to continue.
|
|---|
| 148 | if [[ $NO_ERROR = 1 || -s /etc/debian_version || \
|
|---|
| 149 | -s /etc/fedora-release ]]; then
|
|---|
| 150 | echo WARNING: should abort here, continuing...
|
|---|
| 151 | else
|
|---|
| 152 | echo You can override this check, see http://www.freewrt.org/trac/wiki/Documentation/FAQ for details.
|
|---|
| 153 | out=1
|
|---|
| 154 | fi
|
|---|
| 155 | fi
|
|---|
| 156 |
|
|---|
| 157 | if ! which flex >/dev/null 2>&1; then
|
|---|
| 158 | echo You must install flex to continue.
|
|---|
| 159 | out=1
|
|---|
| 160 | else
|
|---|
| 161 | echo '%%' | flex -
|
|---|
| 162 | if fgrep _POSIX_SOURCE lex.yy.c; then
|
|---|
| 163 | echo Your lexer \(flex\) contains a broken skeleton.
|
|---|
| 164 | if [[ $NO_ERROR = 1 ]]; then
|
|---|
| 165 | echo WARNING: continue at your own risk.
|
|---|
| 166 | echo Some packages may be broken.
|
|---|
| 167 | else
|
|---|
| 168 | echo You can continue the build by issuing \'make prereq-noerror\'
|
|---|
| 169 | echo However, several packages may faild to build correctly.
|
|---|
| 170 | out=1
|
|---|
| 171 | fi
|
|---|
| 172 | fi
|
|---|
| 173 | fi
|
|---|
| 174 |
|
|---|
| 175 | if ! which bison >/dev/null 2>&1; then
|
|---|
| 176 | echo You must install GNU Bison to continue.
|
|---|
| 177 | echo While you can install any version, it is '*STRONGLY*' suggested
|
|---|
| 178 | echo to install GNU Bison version 2.3 because of its bug fixes.
|
|---|
| 179 | out=1
|
|---|
| 180 | fi
|
|---|
| 181 | X=$(bison --version 2>&1 | fgrep 'GNU Bison' | sed 's/^[^0-9]*//')
|
|---|
| 182 | V=old
|
|---|
| 183 | if [[ $X = +([0-9]).+([0-9]) ]]; then
|
|---|
| 184 | let major=${X%.*}
|
|---|
| 185 | let minor=${X#*.}
|
|---|
| 186 | if (( (major > 2) || ((major == 2) && (minor >= 3)) )); then
|
|---|
| 187 | V=new
|
|---|
| 188 | fi
|
|---|
| 189 | fi
|
|---|
| 190 | if [[ $V = old ]]; then
|
|---|
| 191 | echo It is suggested to upgrade your copy of bison to
|
|---|
| 192 | echo GNU Bison 2.3 because of its bug fixes.
|
|---|
| 193 | fi
|
|---|
| 194 |
|
|---|
| 195 | if ! which gzip >/dev/null 2>&1; then
|
|---|
| 196 | echo You must install gzip to continue.
|
|---|
| 197 | out=1
|
|---|
| 198 | fi
|
|---|
| 199 |
|
|---|
| 200 | if ! which bzip2 >/dev/null 2>&1; then
|
|---|
| 201 | echo You must install bzip2 to continue.
|
|---|
| 202 | out=1
|
|---|
| 203 | fi
|
|---|
| 204 |
|
|---|
| 205 | if ! which unzip >/dev/null 2>&1; then
|
|---|
| 206 | echo You must install unzip to continue, sorry.
|
|---|
| 207 | out=1
|
|---|
| 208 | fi
|
|---|
| 209 |
|
|---|
| 210 | if ! which patch >/dev/null 2>&1; then
|
|---|
| 211 | echo You must install patch \(from Larry Wall\) to continue.
|
|---|
| 212 | out=1
|
|---|
| 213 | fi
|
|---|
| 214 |
|
|---|
| 215 | cat >test.c <<-'EOF'
|
|---|
| 216 | #include <stdio.h>
|
|---|
| 217 | #include <zlib.h>
|
|---|
| 218 |
|
|---|
| 219 | #ifndef STDIN_FILENO
|
|---|
| 220 | #define STDIN_FILENO 0
|
|---|
| 221 | #endif
|
|---|
| 222 |
|
|---|
| 223 | int
|
|---|
| 224 | main()
|
|---|
| 225 | {
|
|---|
| 226 | gzFile zstdin;
|
|---|
| 227 | char buf[1024];
|
|---|
| 228 | int i;
|
|---|
| 229 |
|
|---|
| 230 | zstdin = gzdopen(STDIN_FILENO, "rb");
|
|---|
| 231 | i = gzread(zstdin, buf, sizeof (buf));
|
|---|
| 232 | if ((i > 0) && (i < sizeof (buf)))
|
|---|
| 233 | buf[i] = '\0';
|
|---|
| 234 | buf[sizeof (buf) - 1] = '\0';
|
|---|
| 235 | printf("%s\n", buf);
|
|---|
| 236 | return (0);
|
|---|
| 237 | }
|
|---|
| 238 | EOF
|
|---|
| 239 | X=$(echo 'Yay! Native compiler works.' | gzip | \
|
|---|
| 240 | gmake TOPDIR=$topdir LDADD=-lz 2>&1)
|
|---|
| 241 | if [[ $X != *@(Native compiler works)* ]]; then
|
|---|
| 242 | echo Cannot compile a libz test programme.
|
|---|
| 243 | echo You must install the zlib development package,
|
|---|
| 244 | echo usually called libz-dev, and the run-time library.
|
|---|
| 245 | out=1
|
|---|
| 246 | fi
|
|---|
| 247 |
|
|---|
| 248 | if [[ ! -s /usr/include/ncurses.h ]]; then
|
|---|
| 249 | echo Install ncurses header files, please.
|
|---|
| 250 | out=1
|
|---|
| 251 | fi
|
|---|
| 252 |
|
|---|
| 253 | if ! which g++ >/dev/null 2>&1; then
|
|---|
| 254 | echo You must install the host GNU C++ compiler to continue.
|
|---|
| 255 | out=1
|
|---|
| 256 | fi
|
|---|
| 257 |
|
|---|
| 258 | #if ! which perl >/dev/null 2>&1; then
|
|---|
| 259 | if [[ "$(which perl 2>/dev/null)" != /usr/bin/perl ]]; then
|
|---|
| 260 | echo You must install Perl in /usr/bin to continue.
|
|---|
| 261 | out=1
|
|---|
| 262 | fi
|
|---|
| 263 |
|
|---|
| 264 | if ! which wget >/dev/null 2>&1; then
|
|---|
| 265 | echo You must install GNU wget to continue.
|
|---|
| 266 | out=1
|
|---|
| 267 | fi
|
|---|
| 268 |
|
|---|
| 269 | if ! which makeinfo >/dev/null 2>&1; then
|
|---|
| 270 | echo You must install GNU texinfo to continue.
|
|---|
| 271 | out=1
|
|---|
| 272 | fi
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 | cd $topdir
|
|---|
| 276 | rm -rf lbin/tmp
|
|---|
| 277 | exit $out
|
|---|