Merged in f5soh/librepilot/laurent/LP-98_SystemHealth_refresh (pull request #36)
[librepilot.git] / make / scripts / win_sdk_install.sh
blob45d91cef96824b8c3f3bd0ab031f92827fac3d96
1 #!/bin/bash
3 # win_sdk_install.sh - Windows toolchain install script.
4 # Copyright (C) 2015, The LibrePilot Project, http://www.librepilot.org
5 # Copyright (c) 2013, The OpenPilot Team, http://www.openpilot.org
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # This script should be launched from git bash prompt. It assumes MSYS
23 # environment and expects path names in the form of /C/some/path, where
24 # C is a drive letter, and paths are in MSYS format. It probably won't
25 # work under cygwin.
27 SCRIPT_PATH="`echo "$BASH_SOURCE" | sed 's|\\\\|/|g; s|^\(.\):|/\1|'`"
28 SCRIPT_NAME="`basename \"$SCRIPT_PATH\"`"
29 SCRIPT_DIR="`dirname \"$SCRIPT_PATH\"`"
30 ROOT_DIR="`pushd \"$SCRIPT_DIR/../..\" >/dev/null && pwd && popd >/dev/null`"
31 TOOLS_DIR="$ROOT_DIR/tools"
32 if [ -x "$1" ]; then
33 TOOLS_DIR="$1"
36 # Tools URLs to fetch
37 WGET_URL="http://librepilot.github.io/tools/wget.exe"
38 MAKE_URL="http://librepilot.github.io/tools/make.exe"
39 SEVENZIP_URL="http://librepilot.github.io/tools/7za.exe"
41 # Expected tools paths
42 WGET="$TOOLS_DIR/bin/`basename \"$WGET_URL\"`"
43 MAKE="$TOOLS_DIR/bin/`basename \"$MAKE_URL\"`"
44 SEVENZIP="$TOOLS_DIR/bin/`basename \"$SEVENZIP_URL\"`"
46 # wget is necessary to fetch other files
47 WGET_NAME="`basename \"$WGET\"`"
48 if [ ! -x "$WGET" ]; then
49 echo "$SCRIPT_NAME: $WGET_NAME not found, fetching from $WGET_URL"
50 mkdir -p "`dirname \"$WGET\"`"
52 VBSCRIPT="$TOOLS_DIR/fetch.$$.vbs"
53 cat >"$VBSCRIPT" <<-EOF
54 url = WScript.Arguments.Item(0)
55 file = WScript.Arguments.Item(1)
57 Dim xHttp: Set xHttp = CreateObject("MSXML2.ServerXMLHTTP")
58 xHttp.Open "GET", url, False
59 xHttp.setOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
60 xHttp.Send
62 If xHttp.Status = 200 Then
63 Dim bStrm: Set bStrm = CreateObject("AdoDb.Stream")
64 With bStrm
65 .Type = 1 '// binary
66 .Open
67 .Write xHttp.ResponseBody
68 .SaveToFile file, 2 '// overwrite
69 .Close
70 End With
71 WScript.Quit(0)
72 Else
73 WScript.Quit(1)
74 End IF
75 EOF
77 cscript "$VBSCRIPT" "$WGET_URL" "$WGET"
78 rc=$?
79 rm "$VBSCRIPT"
81 if [ $rc -ne 0 ]; then
82 echo "$SCRIPT_NAME: $WGET_NAME fetch error, hope it's in the path..."
83 WGET="$WGET_NAME"
87 # make is necessary to fetch all SDKs
88 if [ ! -x "$MAKE" ]; then
89 echo "$SCRIPT_NAME: $MAKE_NAME not found, fetching from $MAKE_URL"
90 MAKE_DIR="`dirname \"$MAKE\"`"
91 mkdir -p "$MAKE_DIR"
92 $WGET --no-check-certificate -N --content-disposition -P "$MAKE_DIR" "$MAKE_URL"
93 if [ $? -ne 0 ]; then
94 echo "$SCRIPT_NAME: $MAKE_NAME fetch error, hope it's in the path..."
95 MAKE_NAME="`basename \"$MAKE\"`"
96 MAKE="$MAKE_NAME"
100 # 7-Zip is necessary to install some SDKs
101 if [ ! -x "$SEVENZIP" ]; then
102 echo "$SCRIPT_NAME: $SEVENZIP_NAME not found, fetching from $SEVENZIP_URL"
103 SEVENZIP_DIR="`dirname \"$SEVENZIP\"`"
104 mkdir -p "$SEVENZIP_DIR"
105 $WGET --no-check-certificate -N --content-disposition -P "$SEVENZIP_DIR" "$SEVENZIP_URL"
106 if [ $? -ne 0 ]; then
107 echo "$SCRIPT_NAME: $SEVENZIP_NAME fetch error, hope it's in the path..."
108 SEVENZIP_NAME="`basename \"$SEVENZIP\"`"
109 SEVENZIP="$SEVENZIP_NAME"
113 # Finally we can fetch all SDKs using top level Makefile
114 cd "$ROOT_DIR"
115 echo "Run 'tools/bin/make all_sdk_install' to install the other tools"
116 echo " or 'tools/bin/make help' for more info on make targets"