192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#!/bin/bash
292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriok=1
392617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifor i in fxc.exe D3DCompiler_43.dll d3dx9_43.dll d3dx10_43.dll d3dx11_43.dll; do
492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	if ! test -e "$i"; then
592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri		ok=
692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	fi
792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieridone
892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriif test -n "$ok"; then
1092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	exit 0
1192617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifi
1292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
1392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriecho "To compile HLSL shaders, the Microsoft HLSL compiler needs to be downloaded."
1492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriecho
1592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriecho "Downloading Microsoft DirectX June 2010 SDK and extracting files..."
1692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriecho "Please wait, this will need to download and unpack a 600 MB file..."
1792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriecho
1892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriecho "The contribution of a free HLSL compiler would be greatly appreciated!"
1992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriecho
2092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
2192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriok=1
2292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriif ! which wget >/dev/null; then
2392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri        echo "Error: wget is required to download the files"
2492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri        echo "On Debian or Ubuntu, run the following command to install it:"
2592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri        echo "sudo apt-get install wget"
2692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	echo
2792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	ok=
2892617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifi
2992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
3092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriif ! which cabextract >/dev/null; then
3192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	echo "Error: cabextract is required to unpack the files"
3292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	echo "On Debian or Ubuntu, run the following command to install it:"
3392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	echo "sudo apt-get install cabextract"
3492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	echo
3592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	ok=
3692617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifi
3792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
3892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriif test -z "$ok"; then
3992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	exit 1
4092617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifi
4192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
4292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieridxsdk_file="DXSDK_Jun10.exe"
4392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieridxsdk_url="http://download.microsoft.com/download/A/E/7/AE743F1F-632B-4809-87A9-AA1BB3458E31/DXSDK_Jun10.exe"
4492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieridxsdk_size=599452800
4592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
4692617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifxc_path="DXSDK/Utilities/bin/x86/fxc.exe"
4792617aeac109481258f0c3863d09c1b8903d438bLuca Barbierid3dcompiler_cab_path="DXSDK/Redist/Jun2010_D3DCompiler_43_x86.cab"
4892617aeac109481258f0c3863d09c1b8903d438bLuca Barbierid3dx9_cab_path="DXSDK/Redist/Jun2010_d3dx9_43_x86.cab"
4992617aeac109481258f0c3863d09c1b8903d438bLuca Barbierid3dx10_cab_path="DXSDK/Redist/Jun2010_d3dx10_43_x86.cab"
5092617aeac109481258f0c3863d09c1b8903d438bLuca Barbierid3dx11_cab_path="DXSDK/Redist/Jun2010_d3dx11_43_x86.cab"
5192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
5292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieriif test "$(stat -c '%s' "$dxsdk_file" 2>/dev/null)" != $dxsdk_size; then
5392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	wget --continue "$dxsdk_url"
5492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	if test "$(stat -c '%s' "$dxsdk_file" 2>/dev/null)" != $dxsdk_size; then
5592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri		echo "Failed to download DirectX SDK: expected $dxsdk_file with size $dxsdk_size"
5692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri		echo "Download manually from $dxsdk_url"
5792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri		exit 1
5892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	fi
5992617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifi
6092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
6192617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifor i in "$fxc_path" "$d3dcompiler_cab_path" "$d3dx9_cab_path" "$d3dx10_cab_path" "$d3dx11_cab_path"; do
6292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	if ! test -e "$i"; then
6392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri		echo "Please wait, this may take several minutes because a 600 MB archive may need to be fully decompressed..."
6492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri		cabextract -F "$i" "$dxsdk_file"
6592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	fi
6692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieridone
6792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
6892617aeac109481258f0c3863d09c1b8903d438bLuca Barbierifor i in "$d3dcompiler_cab_path" "$d3dx9_cab_path" "$d3dx10_cab_path" "$d3dx11_cab_path"; do
6992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri	cabextract -F "*.dll" "$i"
7092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieridone
7192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
7292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri/bin/cp -dpf "$fxc_path" .
7392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri
74