#!/bin/bash
#
#
#    See the file COPYING.GPL.txt, included in this distribution,
#    for details about the copyright.
#
#    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.
#
#    "compile" Copyright (c) by "Fedoramedia team". Is free software,  This
#    works in GNU/Linux, FreeBSD and others, is freed under the terms of the
#    GPL (GNU GENERAL PUBLIC LICENSE). More information can be found in :
#
#    http://www.fedoramedia.cf
#    _________________________________________________________
#
#    You can support this project by sending a donation to :
#
#    Paypal [http://mklauncher.osdn.io/en/donate.html]
#
#

##### Vars #####

Error=""
Platform_folder="$(pwd)"

##### Functions #####

previous_folder()
{
    ##### Change to previous folder #####

    cd ..
}

platform_folder()
{
    ##### Change to platform folder #####

    cd $Platform_folder    
}

check_dependencies()
{
    echo "--- Check dependencies ---"
    
    ##### fpc #####

    if which fpc; then
    
       echo "- OK Package \"fpc\" found"
    else
       echo "Error: It is necessary to install the \"fpc\" package in order to compile"
       echo "note that some distributions use \"fpc-laz\" instead of \"fpc\"."
       exit 1
    fi
    
    ##### binutils #####
    
    if which strip; then
    
       echo "- OK Package \"binutils\" found"
    else
       echo "Error: It is necessary to install the \"binutils\" package in order to compile."
       exit 1
    fi    
}

precompile()
{
    echo "--- Precompile tasks ---"
    check_dependencies
}

compile()
{
    echo "--- Compile ---"
    fpc @mklauncher.cfg mklauncher.pp
    strip -s ./mklauncher
    chmod +x ./mklauncher
}

poscompile()
{
    echo "--- Poscompile tasks ---"

    ##### ./mklauncher #####

    if test -e "./mklauncher"; then
    
       echo "- OK \"mklauncher\" was compiled correctly."
    else
       echo "Error: \"mklauncher\" could not be compiled."
       exit 1
    fi
}

##### Main #####

previous_folder
precompile
compile
poscompile
platform_folder

