#!/bin/bash

# OpenSpades automatic build script
# by Anthony Zhang <azhang9@gmail.com>
# modified by Thomas <thomas.pp.ua>

# set up working directory
mkdir OpenSpades
cd OpenSpades

# install some packages first
sudo apt-get install libopenal-dev libpng-dev libtiff-dev cmake g++
sudo apt-get install pkg-config libglew-dev libcurl3-openssl-dev libsdl2-dev libsdl2-image-dev libalut-dev xdg-utils libfreetype6-dev libopus-dev libopusfile-dev

# install SDL
wget http://www.libsdl.org/release/SDL2-2.0.2.tar.gz
tar -zxvf SDL2-2.0.2.tar.gz
cd SDL2-2.0.2/
./configure
make clean
make
sudo make install
cd ../

# install SDL_image
wget https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.0.tar.gz
tar -zxvf SDL2_image-2.0.0.tar.gz
cd SDL2_image-2.0.0/
./configure --disable-png-shared
make clean
make
sudo make install
cd ../

# build OpenSpades
wget https://github.com/yvt/openspades/archive/v0.1.1c.tar.gz
tar -zxvf v0.1.1c.tar.gz
cd openspades-0.1.1c
cmake . -DCMAKE_BUILD_TYPE=Release
make

# install and run OpenSpades
sudo make install
openspades
