#/bin/bash

# * Copyright (C) 2004, 2005 Michael Dominic K. (http://www.mdk.org.pl)
# *
# * 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., 59 Temple Place - Suite 330,
# * Boston, MA 02111-1307, USA.

# This file is built automatically from parts.
# Sources live in:
# http://forge.novell.com/modules/xfmod/project/?monotheka

VERSION=0.1.0

# Values reseting
BOIL_NOSLEEP=0
BOIL_DEBUG=0
#/bin/bash
# ----- BAILOUT -----

function BailOut {
    
    rm -f Makefile

    __Errorstring="$1

    This software was NOT configured! If you think this is a script error please report it to bugzilla (NovelForge, project Monotheka). You can obatin some more information how monoBOIL works by typing './configure --help' . A 'configure.log' file was created during the process, please attach it. "

    __ErrorNote=`fold -s -w 50 << EOF
$__Errorstring
EOF`;

    __ErrorNote=`sed 's/^/   | /'<<EOF
$__ErrorNote
EOF`;
    
    # FIXME: Colored error (RED)
    echo
    echo
    echo "   |--- ERROR ---"
    echo "$__ErrorNote";
    echo

    exit -1
}
#/bin/bash

# ----- PURGE -----

# This basically purges the project.
# Deletes all the temporary/autocreated files

function Purge {
    

    echo "Purging project..."

    # Check for custom script

    if [ -x "postconfigure" ] ; then
        ./postconfigure --purge
    fi

    # log file
    echo "   Removing configure log..."
    rm -f configure.log

    # First run make clean
    echo "   Running 'make clean'"
    make clean > /dev/null
    
    echo "   Deleting all the backup files..."
    
    # Now all the glade bak files...
    find ./ -name '*.bak' -exec rm -f '{}' ';'

    # Now all the gladep files... (we don't need them, but they get created)
    find ./ -name '*.gladep' -exec rm -f '{}' ';'

    echo "   Deleting all template-created files..."
    
    # Now we need to remove all the files that were created from the templates
    # We do this on the basis of the 'in' files

    OLDIFS=$IFS
    IFS=:
    _TemplateFiles=`find ./ -iname '*.in' -printf "%p$IFS"`
    
    _Count=1
    for _File in $_TemplateFiles
      do
      _Base=`basename "$_File"`
      _BaseTarget=`basename "$_Base" '.in'`
      _Dir=`dirname "$_File"`

      echo "      Removing $_Dir/$_BaseTarget"
      rm -f "$_Dir/$_BaseTarget"

      let "_Count=_Count+1"
    done
    let "_Count=_Count-1"
    echo   "      ($_Count files Removed)"

    # Now let's remove the Makefiles

    echo   "   Removing Makefiles (also stubs)"
    find ./ -name 'Makefile' -exec rm -f '{}' ';'
    echo "Done."
    
    echo 
    echo "Project purged and ready to commit/release."
    echo
    exit 0;

}

#/bin/bash

# ----- HELP -----

function Help {
    
    HELP_FILE="
*** ABOUT *** 
monoBOIL is a very simple autotools clone for the applications in
MONO. It was written because I found the typicall automake too
confusing and too clumsy. monoBOIL's purpose is to prepare
your application for compiling/making/installing. Basically it does
the following:

   - Checks for basic sanity of the system (and the ability to compile
     software)
   - Checks if the software dependencies are met
   - Parses the template files with some text/variable substitution
     (paths/version, etc.)
   - Creates a non-recursive Makefile for the project, based on the
     individual 'boil' files for the packages/modules
   - Creates a configure.log with the configuration history. You might
     want to attach it with a bug submission

*** USAGE ***
The following commandline params are accepted:

   --help          shows this help message 
   --purge         purges the project erasing the
   temporary/backup/autocreated files. After --purge you get a clean
   repository ready for distibution 
   
   --prefix=       same as --prefix in automake
   --bindir=       same as --bindir in automake
   --libdir=       same as --libdir in automake
   --datadir=      same as --datadir in automake
   --pkgconfig=    directory to store pkgconfig pc files

If you don't provide the paths, monoboil will try to guess them
automagically. 

Aditional options:

   --debug         compile software in debug mode
   --nosleep       skip the delay during configuration

Dependencies are resolved using the pkgconfig (also used in Makefile).
If you have problems check your pkgconfig configuration.

monoBOIL still has some limitations. It doesn't parse all the typicall
automake commandline variables (host, sysconfdir, liexecdir, etc.). If
you need that functionality, you can easily extend monoBOIL. It's
just a bash script.

The monoBOIL source files live in CVS along with the Monotheka on the
NovelForge:

   http://forge.novell.com/modules/xfmod/project/?monotheka

The module name (CVS) is monoboil. You can fetch it using something like:

   export CVS_RSH=ssh
   cvs -z3 -d:ext:anonymous@forgecvs1.novell.com:/cvsroot/monotheka co monoboil
   (password: anonymous)

If you wonder why non-recursive makefiles are good, please take a look on:

   http://www.canb.auug.org.au/~millerp/rmch/recu-make-cons-harm.html

Bugs/problems with this script should be also reported to Monotheka
project (bugzilla) on Novel Forge. 
"
    echo "$HELP_FILE"
    exit 0

}


#/bin/bash

# ----- START -----


# First serious action in the script
echo 
echo -e '* Running \e[1mmonoBOIL\e[m                                 ;,'"'"' '
echo '  Auto-configure tool for mono stuff       _o_    ;:;'"'"' '
echo '  GPL Licence, '"$VERSION"'                   ,-.'"'"'---`.__ ;   '
echo '  Copyright MDK <mdk@mdk.org.pl>      ((j`====='"'"',-'"'"'    '
echo '                                       `-\     /       '
echo '                                          `-=-'"'"'          '
echo


if [ "$1" == "--purge" ] ; then Purge; fi
if [ "$1" == "--help" ] ; then Help; fi


rm -f "configure.log"

echo -e "monoBOIL $VERSION\nSystem: " `uname -a` >> configure.log
echo "Params: $*" >> configure.log

# Basic sanity check

# Checks if a given tool/executable is present
# in a system.
function CheckTool {

    __ToolsPath=$PATH

    echo -n "Checking for $1" >> configure.log

    OLDIFS=$IFS
    IFS=:
    
    for _Path in $__ToolsPath
      do

      if [ -x "$_Path/$1" ] ; then
          echo " found $_Path/$1" >> configure.log
          IFS=$OLDIFS
          return 0;
      fi
    done
    
    IFS=$OLDIFS
    return -1
}

echo "Checking for sanity..."

__SanitySoft="make pkg-config sed awk mcs fold install" 
for _Soft in $__SanitySoft
do
  echo -n "      * $_Soft"
  CheckTool "$_Soft"
  if [ $? -eq 0 ] ; then echo -e " \E[1;32;40m[OK]\033[0m" ; else 
      echo -e " \E[1;31;40m[NOT FOUND!]\033[0m";
      BailOut "Basic sanity check failed! Please make sure that your system is suited to compile/develop software!"
  fi

done



# Config check
if [ ! -f "./monoboil.config" ] ; then BailOut "Can't find monoboil.config file!" ; fi

# Read config variables
source "./monoboil.config"

echo
echo "Configuring: $BOIL_SOFTWARE [$BOIL_VERSION \"$BOIL_CODENAME\"] ..."
echo

#log
echo "Configuring: $BOIL_SOFTWARE [$BOIL_VERSION \"$BOIL_CODENAME\"]" >> configure.log
#/bin/bash

# ----- COMMANDLINE PARAMETERS -----

echo "Parsing commandline parameters... "

__nparam=1
__ParamsNotRecognized=0

# For all command params...
while [ "$__nparam" -le "$#" ]
do

  # Get name of parameter
  __CurrentParam="${!__nparam}"
  __nparamnext=__nparam+1
  __NextParam="${!__nparamnext}"
  __Index=`expr index "$__CurrentParam" =`
  __ParamValue="${__CurrentParam:$__Index}"
  __ParamName="${__CurrentParam:0:$__Index}"

  # FIXME: Ok, I know... this is shit.
  # First check for = params
  if [ "$__ParamName" == "--prefix=" ] ; then BOIL_PREFIX="$__ParamValue" ; else
      if [ "$__ParamName" == "--bindir=" ] ; then BOIL_BINDIR="$__ParamValue" ; else
          if [ "$__ParamName" == "--libdir=" ] ; then BOIL_LIBDIR="$__ParamValue" ; else
              if [ "$__ParamName" == "--datadir=" ] ; then BOIL_DATADIR="$__ParamValue" ; else
                  if [ "$__ParamName" == "--pkgconfig=" ] ; then BOIL_PKGCONFIG="$__ParamValue" ; else
                      if [ "$__CurrentParam" == "--nosleep" ] ; then BOIL_NOSLEEP="1" ; else
                          if [ "$__CurrentParam" == "--debug" ] ; then BOIL_DEBUG="1" ; else
                              let "__ParamsNotRecognized=__ParamsNotRecognized+1"
                              echo -e "   $__CurrentParam is not a recognized option \E[1;33;33m[WARNING]\033[0m"
                          fi
                      fi
                  fi
              fi
          fi
      fi
  fi

  
  let "__nparam=__nparam+1"

done

# Check if we understood ANY of the params

if [ "$__ParamsNotRecognized" -eq "$#" ] && [ ! "$#" -eq 0 ] ; then 
    echo -e "   Not ANY of the params could be recognized \E[1;31;40m[ERROR!]\033[0m"
    BailOut "Not a single parameter from the ones specified could be understood! It's too risky to continue. Try 

   $> .//configure --help

... or just run the script without any parameters at all"
fi

echo 


#/bin/bash

# ----- DIRECTORIES -----

echo -e "Configuring install paths... "

#Prefix
echo -n "   PREFIX: "
if [ -z "$BOIL_PREFIX" ] ; then

    if [ -d "/usr/share/gnome" ] ; then 
        BOIL_PREFIX="/usr" 
    else 
        if [ -d "/opt/gnome" ] ; then 
            BOIL_PREFIX="/opt/gnome"  
        else 
            BOIL_PREFIX="/usr/local"
        fi
    fi

    echo -e "$BOIL_PREFIX \E[1;31;33m[auto]\033[0m "
    echo "Auto detecting PREFIX=$BOIL_PREFIX" >> configure.log
    else 
    echo "$BOIL_PREFIX"
fi

#Bindir
echo -n "   BINDIR: "
if [ -z "$BOIL_BINDIR" ] ; then
    BOIL_BINDIR="$BOIL_PREFIX/bin"
    echo -e "$BOIL_BINDIR \E[1;31;33m[auto]\033[0m "
    else 
    echo "$BOIL_BINDIR"
fi

#Libdir
echo -n "   LIBDIR: "
if [ -z "$BOIL_LIBDIR" ] ; then
    BOIL_LIBDIR="$BOIL_PREFIX/lib"
    echo -e "$BOIL_LIBDIR \E[1;31;33m[auto]\033[0m "
    else 
    echo "$BOIL_LIBDIR"
fi

#datadir
echo -n "   DATADIR: "
if [ -z "$BOIL_DATADIR" ] ; then
    BOIL_DATADIR="$BOIL_PREFIX/share"
    echo -e "$BOIL_DATADIR \E[1;31;33m[auto]\033[0m "
    else 
    echo "$BOIL_DATADIR"
fi

#Pkgconfig
echo -n "   PKGCONFIG: "
if [ -z "$BOIL_PKGCONFIG" ] ; then

    BOIL_PKGCONFIG="$BOIL_LIBDIR/pkgconfig"

    echo -e "$BOIL_PKGCONFIG \E[1;31;33m[auto]\033[0m "
    echo "Auto detecting PKGCONFIG=$BOIL_PKGCONFIG" >> configure.log
    else 
    echo "$BOIL_PKGCONFIG"
fi



# Log
echo "PREFIX: $BOIL_PREFIX" >> configure.log
echo "BINDIR: $BOIL_BINDIR" >> configure.log
echo "LIBDIR: $BOIL_LIBDIR" >> configure.log
echo "DATADIR: $BOIL_DATADIR" >> configure.log
echo "PKGCONFIG: $BOIL_PKGCONFIG" >> configure.log



echo 
# Sleep
if [ "$BOIL_NOSLEEP" -eq "0" ] ; then
    echo -n "Sleeping to let you see...5"
    sleep 1
    echo -n " 4"
    sleep 1
    echo -n " 3"
    sleep 1
    echo -n " 2"
    sleep 1
    echo -n " 1"
    sleep 1
    echo 
fi

echo 
#/bin/bash

# ----- DEPENDENCIES -----

function CheckPkg {
   
    DEP_VERSION=""
    __CURRENT="$1"
    __MATCH=0

    while [ ! `expr index "$__CURRENT" -` -eq 0 ]
    do
      __THISMATCH=`expr index "$__CURRENT" -`
      __CURRENT="${__CURRENT:$__THISMATCH}"
      let "__MATCH = __MATCH + __THISMATCH"
    done

    let "__MATCH2 = __MATCH - 1"
 
    __LEN=`expr length "$1"`
    
    # First let's get the version
    DEP_VERSION_REQ="${1:$__MATCH}"
   
    # Now the name
    DEP_NAME="${1:0:$__MATCH2}"
 
    #LOG
    echo -n "Checking for $DEP_NAME at least $DEP_VERSION_REQ" >> configure.log

    #Check if exist
    `pkg-config $DEP_NAME --exists`
    if [ ! $? -eq 0 ] ; then
        echo " DOESN'T EXIST!" >> configure.log
        return -1 ;
    fi
    
    # Get version number
    DEP_VERSION=`pkg-config $DEP_NAME --modversion`

    
    # Check if at least version...
    `pkg-config $DEP_NAME --atleast-version=$DEP_VERSION_REQ`
    if [ ! $? -eq 0 ] ; then
        echo " VERSION TOO OLD! ($DEP_VERSION)" >> configure.log
        return -1 ;
    fi

    #Log
    echo " found $DEP_VERSION" >> configure.log


    return 0;
}



echo "Checking for required components..."

echo "   Checking for pkg dependencies..."

# FIXME: Warning if no dependencies are specified. 
for _Dependency in $BOIL_DEPENDENCIES_PKG
do
  echo -n "      * $_Dependency"
  CheckPkg "$_Dependency"
  if [ $? -eq 0 ] ; then echo -e " \E[1;32;40m[OK]\033[0m ($DEP_VERSION)" ; 
      else 
      echo -e " \E[1;31;40m[NOT FOUND!]\033[0m ($DEP_VERSION)";
      BailOut "The required package could not be found in your system! Make sure it's installed and pkg-config'ed"
  fi

done
echo 



#/bin/bash

# ----- PARSE TEMPLATES -----

function ParseIn {
    
    _Base=`basename "$1"`
    _BaseTarget=`basename "$_Base" '.in'`
    _Dir=`dirname "$1"`
    
    #Change code
    #Copy
    cp -f "$_Dir/$_Base" "$_Dir/$_BaseTarget"
    if [ $? -ne 0 ] ; then 
        echo -e "\E[1;31;40m[FAILED!]\033[0m"
        BailOut "There was a problem while parsing file. Check permissions."
    fi

    # FIXME: Is this clean?  
    sed -i "s:@BOIL_VERSION@:$BOIL_VERSION:
            s:@BOIL_DEBUG@:$BOIL_DEBUG:
            s:@BOIL_CODENAME@:$BOIL_CODENAME:
            s:@BOILED@:1:
            s:@BOIL_BINDIR@:$BOIL_BINDIR:
            s:@BOIL_LIBDIR@:$BOIL_LIBDIR:
            s:@BOIL_DATADIR@:$BOIL_DATADIR:
            s:@BOIL_PKGCONFIG@:$BOIL_PKGCONFIG:" "$_Dir/$_BaseTarget"

}



echo "Creating target files from templates..."

OLDIFS=$IFS
IFS=:

_TemplateFiles=`find ./ -iname '*.in' -printf "%p$IFS"`

_Count=1
for _File in $_TemplateFiles
  do
  _Base=`basename "$_File"`
  _BaseTarget=`basename "$_Base" '.in'`
  _Dir=`dirname "$_File"`
  echo -n "   $_Dir/$_BaseTarget"
  ParseIn "$_File"
  echo 
  let "_Count=_Count+1"
done
let "_Count=_Count-1"
echo "$_Count files created."

IFS=$OLDIFS
echo 
#/bin/bash 

DEFAULTIFS=$IFS
OUTPUT_FILES=

# ----- AUTOMAKE (MAKEFILE) ----

# This pushes the package to the stack
function PushPackage {
    # Reset values
    NAME=
    TYPE=
    DEPENDS=
    SOURCES=
    REF_INTERNAL=
    REF_SYSTEM=
    REF_PKG=
    RESOURCES=
    RESOURCES_PATH=
    #Source
    source "$1"
    
    #FIXME: If source doesn't exist...

    # Some sanity check
    if [ -z "$NAME" ] ; then 
        BailOut "Broken package! It does not provide a valid name. Can't proceed."
    fi
}


function ParsePackage {
    PushPackage "$1"

    # Rewrite variables
    PACKAGE_NAME="$NAME"
    PACKAGE_TYPE="$TYPE"
    PACKAGE_DEPENDS="$DEPENDS"
    PACKAGE_SOURCES="$SOURCES"
    PACKAGE_REFERENCES_INTERNAL="$REF_INTERNAL"
    PACKAGE_REFERENCES_SYSTEM="$REF_SYSTEM"
    PACKAGE_REFERENCES_PKG="$REF_PKG"
    PACKAGE_RESOURCES="$RESOURCES"
    PACKAGE_RESOURCES_PATH="$RESOURCES_PATH"

    # Reset all the shit
    PACKAGE_INCLUDEPATHS=
    PACKAGE_PATH=
    PACKAGE_SOURCES_LIST=
    PACKAGE_DEPENDS_LIST=
    PACKAGE_TARGET=
    PACKAGE_REFERENCES_INTERNAL_LIST=
    PACKAGE_REFERENCES_SYSTEM_LIST=
    PACKAGE_REFERENCES_PKG_LIST=
    PACKAGE_RESOURCES_LIST=
    PACKAGE_RESOURCES_LIST2=
    
    # Write the name of the package...
    echo -n "      * $PACKAGE_NAME ($PACKAGE_TYPE)"

    # Parse all the dependencies...
    OLDIFS=$IFS
    IFS=$DEFAULTIFS
    echo "Package $PACKAGE_NAME depends on: $PACKAGE_DEPENDS" >> configure.log
    for _Dependency in $PACKAGE_DEPENDS
      do
      IFS=:
      # Parse all packages AGAIN to find this dependency
      for _DependsBoil in $_PackageBoils
        do
        PushPackage "$_DependsBoil"
        if [ "$NAME" == "$_Dependency" ] ; then break ; fi
      done
      IFS=$DEFAULTIFS

      if [ "$NAME" == "$_Dependency" ] ; then 
          PACKAGE_INCLUDEPATHS="$PACKAGE_INCLUDEPATHS"" -L "`dirname $_DependsBoil` 
          continue 
      fi
      
      # If we're here, we have problems...
      echo -e " \E[1;31;40m[FAILED!]\033[0m";
      BailOut "Couldn't satisfy a dependency for this package! Dependency: $_Dependency"
    
    done
    # Dependencies satisfied

    # Get package path
    PACKAGE_PATH=`dirname $1`
   
    # Get reources path
    if [ -z "$PACKAGE_RESOURCES_PATH" ] ; then PACKAGE_RESOURCES_PATH="$PACKAGE_PATH" ; fi

    # Make package target
    if [ "$PACKAGE_TYPE" == "exe" ] ; then
        PACKAGE_TARGET="$PACKAGE_PATH/$PACKAGE_NAME.exe"
    else if [ "$PACKAGE_TYPE" == "library" ] ; then
        PACKAGE_TARGET="$PACKAGE_PATH/$PACKAGE_NAME.dll"
    else
        PACKAGE_TARGET="$PACKAGE_PATH/$PACKAGE_NAME.collection"
    fi
    fi
    
    # Make sources list
    for _Source in $PACKAGE_SOURCES
      do 
      PACKAGE_SOURCES_LIST="$PACKAGE_SOURCES_LIST"" $PACKAGE_PATH/$_Source"
    done
    
    # Make depends list
    for _Depend in $PACKAGE_DEPENDS
      do 
      PACKAGE_DEPENDS_LIST="$PACKAGE_DEPENDS_LIST"" $_Depend"
    done

    # Make internal list
    for _Internal in $PACKAGE_REFERENCES_INTERNAL
      do 
      PACKAGE_REFERENCES_INTERNAL_LIST="$PACKAGE_REFERENCES_INTERNAL_LIST"" -r:$_Internal"
    done

    # Make system list
    for _System in $PACKAGE_REFERENCES_SYSTEM
      do 
      PACKAGE_REFERENCES_SYSTEM_LIST="$PACKAGE_REFERENCES_SYSTEM_LIST"" -r:$_System"
    done

    # Make pkg list
    for _Pkg in $PACKAGE_REFERENCES_PKG
      do 
      PACKAGE_REFERENCES_PKG_LIST="$PACKAGE_REFERENCES_PKG_LIST"" -pkg:$_Pkg"
    done

    # Make resources list
    for _Res in $PACKAGE_RESOURCES
      do 
      PACKAGE_RESOURCES_LIST="$PACKAGE_RESOURCES_LIST"" -resource:$PACKAGE_RESOURCES_PATH/$_Res"
      PACKAGE_RESOURCES_LIST2="$PACKAGE_RESOURCES_LIST2"" $PACKAGE_RESOURCES_PATH/$_Res"
    done

    
    # Write Makefile
    
    # Stub target
    echo -e "$PACKAGE_NAME: $PACKAGE_TARGET\n" >> Makefile

    # Actual target
    echo -e "$PACKAGE_TARGET: $PACKAGE_DEPENDS_LIST $PACKAGE_SOURCES_LIST $PACKAGE_RESOURCES_LIST2" >> Makefile
    
    # The rest depends on type...
    if [ "$PACKAGE_TYPE" == "exe" -o "$PACKAGE_TYPE" == "library" ] ; then
        __String="\t@echo \"(MCS) $PACKAGE_TARGET\"\n\t@mcs "'$(MCS_OPTIONS)'" $PACKAGE_INCLUDEPATHS -target:$PACKAGE_TYPE  -out:$PACKAGE_TARGET $PACKAGE_REFERENCES_INTERNAL_LIST $PACKAGE_REFERENCES_SYSTEM_LIST $PACKAGE_REFERENCES_PKG_LIST $PACKAGE_RESOURCES_LIST $PACKAGE_SOURCES_LIST\n"
        echo -e "$__String" >> Makefile

        OUTPUT_FILES="$OUTPUT_FILES""$PACKAGE_TARGET "
        else echo -e "\n" >> Makefile
    fi

    IFS=$OLDIFS
    echo -e " \E[1;32;40m[OK]\033[0m"
}

rm -f Makefile

echo "Auto-generating non-recursive Makefile..."
echo "   Parsing all package 'boil' files..."

# Header 
echo "# This file was auto-generated by monoBOIL. DO NOT EDIT IT!" >> Makefile
echo "# Instead, you should edit the individual 'boil' files that are used to form a Makefile." >> Makefile
echo >> Makefile

# By default we optimize all the code. 
if [ "$BOIL_DEBUG" -eq 0 ] ; then 
    echo "MCS_OPTIONS=/optimize" >> Makefile
else
    echo "MCS_OPTIONS=" >> Makefile
fi
echo >> Makefile


# IFS so we can easily parse ALL kinds of files (spaces)
IFS=:

# Find all the package files (except for the root package!)
_PackageBoils=`find ./ -mindepth 2 -iname 'boil' -printf "%p$IFS"`
_PackageCount=1

# Parse main package
if [ ! -f "boil" ] ; then BailOut "Can't find the root package! (./boil)" ; fi
ParsePackage "boil"

# Parse all the packages
for _Boil in $_PackageBoils
  do
  ParsePackage "$_Boil"
  let "_PackageCount=_PackageCount+1"
done

IFS=$DEFAULTIFS

# Let's create the "clean" object
echo "   Creating the clean object..."
echo "clean:" >> Makefile

for _TargetFile in $OUTPUT_FILES
do
  echo -e "\trm -f $_TargetFile" >> Makefile
done
echo >> Makefile

# Let's create the "install" object
echo "   Creating the install object..."

if [ ! -f "install" ] ; then 
    echo -e "      Install script not present, ignoring... \E[1;33;33m[WARNING]\033[0m"
    else

    echo "install: all" >> Makefile
    echo -e "\t./install "'$(DESTDIR)'"\n" >> Makefile
fi    

echo "$_PackageCount packages processed."
echo

# Just to be smooth...
IFS=$DEFAULTIFS
#/bin/bash

# ----- END -----

# Check for custom script

if [ -x "postconfigure" ] ; then
    echo "Running custom post configure script..."
    ./postconfigure --configure

    if [ ! $? -eq 0 ] ; then
        BailOut "Post install script failed!"
    fi
fi
       
echo
echo "Everything done! You should now type:"
echo "   $> make"
echo "   $> make install"
echo 
echo "... to compile & install it in your system. Happy hunting!"
echo
echo

#log
echo -e "Configure completed succesfully\nEND" >> configure.log

exit 0
