#!/bin/bash

# Copyright (C) 2007 Pâris Quentin
#  		     Cassarin-Grand Arthur

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 

if [ "$PLAYONLINUX" = "" ]
then
exit 0
fi
source "$PLAYONLINUX/lib/sources"
cfg_check

message "$LNG_GIT_WELCOME1"
message "$LNG_GIT_WELCOME2"

# Check
check_one git
check_one gcc
check_one make
check_one flex
check_one bison

# Preparations
GIT_TEMP=$HOME/.PlayOnLinux/tmp/git/
GIT_WINEVERSION=$HOME/.PlayOnLinux/WineVersions/git/

if [ -e "$GIT_TEMP" ]; then
	attendre "$LNG_WAIT" "rm -rf $GIT_TEMP"
fi
if [ -e "$GIT_WINEVERSION" ]; then
	GIT_KEEP=$(champ "$LNG_GIT_KEEP" "N" ) ;
	if [ "$GIT_KEEP" == "Y" ]; then
		GIT_RENAME=$(champ "$LNG_GIT_RENAME" "" ) ;
		if [ "$GIT_RENAME" == "" ]; then
			erreur "$LNG_GIT_NAME_ERROR"
			exit 0
		else if [ -e "$GIT_RENAME" ]; then
			erreur "$LNG_GIT_NAME_DUPLICATE_ERROR"
			until [ ! -e "$GIT_RENAME" ];
			do
				GIT_RENAME=$(champ "$LNG_GIT_KEEP2" "" ) ;
			done
		else
			mv $GIT_WINEVERSION $HOME/.PlayOnLinux/WineVersions/$GIT_RENAME
			chmod 777 $HOME/.PlayOnLinux/WineVersions/$GIT_RENAME -R
		fi
		fi
	else
		rm -rf $GIT_WINEVERSION
	fi
fi
mkdir -p $GIT_TEMP
mkdir -p $GIT_WINEVERSION
mkdir -p $GIT_WINEVERSION/usr/
chmod 777 $GIT_TEMP -R
chmod 777 $GIT_WINEVERSION -R

cd $GIT_TEMP
attendre "$LNG_GIT_DOWNLOAD" "git clone git://source.winehq.org/git/wine.git wine"
cd wine
(
	./configure --prefix=$GIT_WINEVERSION/usr/
	make depend && make
	make install
) | attendre_multiple "$LNG_GIT_COMPILATION"

message "$LNG_GIT_FINISHED"
