#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
#    \\/     M anipulation  |
#-------------------------------------------------------------------------------
# License
#     This file is part of OpenFOAM.
#
#     OpenFOAM 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.
#
#     OpenFOAM 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 OpenFOAM; if not, write to the Free Software Foundation,
#     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Script
#     wclean
#
# Description
#     Clean up the wmake control directory Make and remove the include
#     directory generated for libraries.
#
#     Usage: 
#        wclean                         (cleans Make)
#        wclean lib??                   (cleans Make and lnInclude)
#
#        wclean <dir>                   (cleans dir/Make)
#        wclean exe <dir>               (cleans dir/Make)
#        wclean lib?? <dir>             (cleans dir/Make and lnInclude)
#        wclean exe <dir> <MakeDir>     (cleans dir/MakeDir)
#        wclean lib?? <dir> <MakeDir>   (cleans dir/MakeDir and lnInclude)
#
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# check arguments and change to the directory in which to run wmake
#------------------------------------------------------------------------------

curDir=`pwd`

makeOption=""
dir="_"

if [ $# -ge 1 ]
then
    if [ $1 = "lib" -o $1 = "libso" -o $1 = "libo" -o $1 = "exe" -o $1 = "project" ]
    then
        makeOption=$1
    else
        dir=$1
    fi
fi

if [ $# -ge 2 ]
then
    dir=$2
fi

if [ $dir != "_" ]
then
    if [ -d $dir ]
    then
        cd $dir
    else
        echo $0: directory $dir does not exist
        exit 1
    fi
fi

if [ $# = 3 ]
then
	MakeDir=$3
else
    MakeDir=Make
fi

if [ ! -d $MakeDir ]
then
    echo $0: $MakeDir directory does not exist, exiting !
    exit 0
fi


#------------------------------------------------------------------------------

rm -rf $MakeDir/$WM_OPTIONS $MakeDir/classes

find . -name "*.dep" -exec rm {} \;

if [ "$makeOption" = "lib" -o "$makeOption" = "libso" -o "$makeOption" = "libo" ]
then
    if [ -d "lnInclude" ]
    then
        rm -rf lnInclude
    fi
fi

rm -rf ii_files
rm -rf Templates.DB

rm -f so_locations


#------------------------------------------------------------------------------

cd $curDir

#------------------------------------------------------------------------------
