mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
114 lines
2.7 KiB
Bash
Executable File
114 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
#------------------------------------------------------------------------------
|
|
# ========= |
|
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
# \\ / O peration |
|
|
# \\ / A nd | Copyright (C) 2019 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
# Script
|
|
# wmakeRoot
|
|
#
|
|
# Description
|
|
# Locate the root directory that has a Make/ directory.
|
|
#
|
|
# See Also
|
|
# wmake
|
|
#
|
|
#------------------------------------------------------------------------------
|
|
Script="${0##*/}" # Use 'Script' for error messages in wmakeFunctions
|
|
. "${0%/*}/scripts/wmakeFunctions" # Source wmake functions
|
|
|
|
usage() {
|
|
exec 1>&2
|
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
cat<<USAGE
|
|
|
|
Usage: $Script [OPTION] [dir]
|
|
|
|
options:
|
|
-h | -help Print the usage
|
|
|
|
Locate the root directory that has a Make/ directory.
|
|
|
|
USAGE
|
|
exit 1
|
|
}
|
|
|
|
#------------------------------------------------------------------------------
|
|
# Parse arguments and options
|
|
#------------------------------------------------------------------------------
|
|
|
|
while [ "$#" -gt 0 ]
|
|
do
|
|
case "$1" in
|
|
-h | -help*)
|
|
usage
|
|
;;
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
-*)
|
|
usage "unknown option: '$1'"
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
unset dir
|
|
|
|
if [ $# -ge 1 ]
|
|
then
|
|
if [ -d "$1" ]
|
|
then
|
|
dir="${1%/}"
|
|
elif [ -f "$1" ]
|
|
then
|
|
dir="${1%/*}"
|
|
: "${dir:=.}"
|
|
else
|
|
echo "$Script error: not a file or directory" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
cd "$dir" 2>/dev/null || {
|
|
echo "$Script error: could not change to directory '$dir'" 1>&2
|
|
exit 1
|
|
}
|
|
fi
|
|
|
|
|
|
# Locate target with Make/ directory
|
|
|
|
if dir="$(findTarget .)"
|
|
then
|
|
(cd "$dir" && pwd -L)
|
|
else
|
|
exit 2
|
|
fi
|
|
|
|
|
|
#------------------------------------------------------------------------------
|