1#!/bin/bash
2ok=1
3for i in fxc.exe D3DCompiler_43.dll d3dx9_43.dll d3dx10_43.dll d3dx11_43.dll; do
4	if ! test -e "$i"; then
5		ok=
6	fi
7done
8
9if test -n "$ok"; then
10	exit 0
11fi
12
13echo "To compile HLSL shaders, the Microsoft HLSL compiler needs to be downloaded."
14echo
15echo "Downloading Microsoft DirectX June 2010 SDK and extracting files..."
16echo "Please wait, this will need to download and unpack a 600 MB file..."
17echo
18echo "The contribution of a free HLSL compiler would be greatly appreciated!"
19echo
20
21ok=1
22if ! which wget >/dev/null; then
23        echo "Error: wget is required to download the files"
24        echo "On Debian or Ubuntu, run the following command to install it:"
25        echo "sudo apt-get install wget"
26	echo
27	ok=
28fi
29
30if ! which cabextract >/dev/null; then
31	echo "Error: cabextract is required to unpack the files"
32	echo "On Debian or Ubuntu, run the following command to install it:"
33	echo "sudo apt-get install cabextract"
34	echo
35	ok=
36fi
37
38if test -z "$ok"; then
39	exit 1
40fi
41
42dxsdk_file="DXSDK_Jun10.exe"
43dxsdk_url="http://download.microsoft.com/download/A/E/7/AE743F1F-632B-4809-87A9-AA1BB3458E31/DXSDK_Jun10.exe"
44dxsdk_size=599452800
45
46fxc_path="DXSDK/Utilities/bin/x86/fxc.exe"
47d3dcompiler_cab_path="DXSDK/Redist/Jun2010_D3DCompiler_43_x86.cab"
48d3dx9_cab_path="DXSDK/Redist/Jun2010_d3dx9_43_x86.cab"
49d3dx10_cab_path="DXSDK/Redist/Jun2010_d3dx10_43_x86.cab"
50d3dx11_cab_path="DXSDK/Redist/Jun2010_d3dx11_43_x86.cab"
51
52if test "$(stat -c '%s' "$dxsdk_file" 2>/dev/null)" != $dxsdk_size; then
53	wget --continue "$dxsdk_url"
54	if test "$(stat -c '%s' "$dxsdk_file" 2>/dev/null)" != $dxsdk_size; then
55		echo "Failed to download DirectX SDK: expected $dxsdk_file with size $dxsdk_size"
56		echo "Download manually from $dxsdk_url"
57		exit 1
58	fi
59fi
60
61for i in "$fxc_path" "$d3dcompiler_cab_path" "$d3dx9_cab_path" "$d3dx10_cab_path" "$d3dx11_cab_path"; do
62	if ! test -e "$i"; then
63		echo "Please wait, this may take several minutes because a 600 MB archive may need to be fully decompressed..."
64		cabextract -F "$i" "$dxsdk_file"
65	fi
66done
67
68for i in "$d3dcompiler_cab_path" "$d3dx9_cab_path" "$d3dx10_cab_path" "$d3dx11_cab_path"; do
69	cabextract -F "*.dll" "$i"
70done
71
72/bin/cp -dpf "$fxc_path" .
73
74