#!/bin/bash
echo "Этот скрипт настроит среду для сборки Open PS2 Loader"
echo "---------------"
echo "Сначала установим нужные библиотеки и т.п."
sudo apt-get -y install git
sudo apt-get -y install mercurial
sudo apt-get -y install zlib1g-dev
sudo apt-get -y install libucl-dev

#
echo "Создаем каталог, в котором все будет компилироваться"
mkdir ~/OPL
echo "Добавляем пути в PATH, чтоб скрипты знали где лежит компилятор и т.п."
echo "добавляем все просто в .bashrc"
echo "export PS2DEV=~/OPL/ps2dev" >> ~/.bashrc
echo "export PATH=$PATH:$PS2DEV/bin" >> ~/.bashrc
echo "export PATH=$PATH:$PS2DEV/ee/bin" >> ~/.bashrc
echo "export PATH=$PATH:$PS2DEV/iop/bin" >> ~/.bashrc
echo "export PATH=$PATH:$PS2DEV/dvp/bin" >> ~/.bashrc
echo "export PS2SDK=$PS2DEV/ps2sdk" >> ~/.bashrc
echo "export PATH=$PATH:$PS2SDK/bin" >> ~/.bashrc
echo "export GSKIT=$PS2DEV/gskit" >> ~/.bashrc
echo "-------------------------------"
echo "актуализируем те пути, что выше ввели"
source ~/.bashrc
echo "-------------------------------"
echo "Теперь качаем toolchain, gskit, ps2sdk-ports, ps2eth, ps2-packer, ps2link, ps2client ну и собственно сам OPL"
mkdir ~/OPL/install
cd ~/OPL/install
git clone https://github.com/ps2dev/ps2toolchain.git
git clone https://github.com/ps2dev/gsKit.git
git clone https://github.com/ps2dev/ps2sdk-ports.git
git clone https://github.com/ps2dev/ps2eth.git
git clone https://github.com/ps2dev/ps2-packer.git
git clone https://github.com/ps2dev/ps2link.git
git clone https://github.com/ps2dev/ps2client.git
cd ~/OPL/
hg clone https://bitbucket.org/ifcaro/open-ps2-loader

echo "-------------------------------"
echo "-------------------------------"
echo "теперь компилируем нужные библотеки и т.п."
cd ~/OPL/install/ps2sdk-ports/zlib
make
make install

cd ~/OPL/install/ps2sdk-ports/ucl
make
make install

cd ~/OPL/install/ps2sdk-ports/stlport
make
make install

cd ~/OPL/install/ps2sdk-ports/libtiff
make
make install

cd ~/OPL/install/ps2sdk-ports/libjpeg
make
make install

cd ~/OPL/install/ps2sdk-ports/libpng
make
make install

cd ~/OPL/install/ps2sdk-ports/libconfig-1.4.5
make
make install

cd ~/OPL/install/ps2sdk-ports/freetype-2.4.12
./configure
./SetupPS2.sh

cd ~/OPL/install/ps2sdk-ports/expat
make
make install

cd ~/OPL/install/gsKit
./setup

cd ~/OPL/install/
cp -R ps2eth ~/OPL/ps2dev/

OPL/install/ps2client
make
make install

OPL/install/ps2-packer
make
make install


/OPL/install/ps2link
make
make install

echo "---------------------------------"
echo "---------------------------------"
echo "Это собственно компиляция OPL"
cd ~/OPL/open-ps2-loader
make
mv OPNPS2LD.ELF OPNPS2LD_$(hg identify -n).ELF

