Commit 7bcf3dc9 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add -root option for wmakeLnInclude (convenience)

- finds the correct root directory location before creating
  the lnInclude directory

  Eg,

  from within something like src/finiteVolume/fields/fvPatchFields/..

      wmakeLnInclude -update -root

  it backtracks to find the top-level directory with Make/
  and makes the lnInclude directory there:

    Using /home/mark/openfoam/OpenFOAM-plus/src/finiteVolume
        ln: /home/mark/openfoam/OpenFOAM-plus/src/finiteVolume/lnInclude
parent e84345cc
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM. # This file is part of OpenFOAM.
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# wmakeLnInclude # wmakeLnInclude
# #
# Usage # Usage
# wmakeLnInclude [-u | -update] [-s | -silent] <dir> # wmakeLnInclude [OPTION] [-root | <dir>]
# #
# Description # Description
# Link all the source files in the <dir> directory into <dir>/lnInclude # Link all the source files in the <dir> directory into <dir>/lnInclude
...@@ -38,21 +38,23 @@ ...@@ -38,21 +38,23 @@
# *.c (C source) # *.c (C source)
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
Script=${0##*/} Script="${0##*/}" # Use 'Script' for error messages in wmakeFunctions
. "${0%/*}/scripts/wmakeFunctions" # Source wmake functions
usage() { usage() {
exec 1>&2 exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE cat<<USAGE
Usage: $Script [OPTION] dir Usage: $Script [OPTION] [-root | dir]
options: options:
-u | -update update -u | -update Update
-s | -silent use 'silent' mode (do not echo command) -s | -silent Use 'silent' mode (do not echo command)
-help print the usage -root Locate root directory containing a Make/ directory.
-h | -help Print the usage
Link all the source files in the <dir> into <dir>/lnInclude Link all the source files in the <dir> into <dir>/lnInclude
Note Note
The '-u' option forces an update when the lnInclude directory already exists The '-u' option forces an update when the lnInclude directory already exists
...@@ -68,9 +70,9 @@ USAGE ...@@ -68,9 +70,9 @@ USAGE
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Option for 'ln' # Option for 'ln'
lnOpt="-s" optLink="-s"
unset update silentOpt unset update optQuiet optRoot
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
...@@ -80,12 +82,13 @@ do ...@@ -80,12 +82,13 @@ do
;; ;;
-u | -update) -u | -update)
update=true update=true
lnOpt="-sf" optLink="-sf"
shift
;; ;;
-s | -silent) -s | -silent)
silentOpt=true optQuiet=true
shift ;;
-root)
optRoot=true
;; ;;
-*) -*)
usage "unknown option: '$1'" usage "unknown option: '$1'"
...@@ -94,13 +97,50 @@ do ...@@ -94,13 +97,50 @@ do
break break
;; ;;
esac esac
shift
done done
if [ $# -eq 1 ] [ "$optRoot" = true ] || [ "$#" -eq 1 ] || \
then
baseDir=$1
else
usage "Error: incorrect number of arguments" usage "Error: incorrect number of arguments"
#------------------------------------------------------------------------------
unset dir
baseDir="$1"
# With -root, go on discovery
if [ "$optRoot" = true ]
then
if [ -n "$baseDir" ]
then
dir="$baseDir"
if [ -d "$dir" ]
then
dir="${dir%/}"
elif [ -f "$dir" ]
then
dir="${dir%/*}"
: "${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
baseDir="$(cd "$dir" && pwd -L)"
else
exit 2
fi
echo "Using $baseDir" 1>&2
fi fi
...@@ -113,34 +153,30 @@ do ...@@ -113,34 +153,30 @@ do
baseDir="." baseDir="."
fi fi
done done
incDir=$baseDir/lnInclude incDir="$baseDir/lnInclude"
[ -d $baseDir ] || { [ -d "$baseDir" ] || {
echo "$Script error: base directory $baseDir does not exist" 1>&2 echo "$Script error: base directory $baseDir does not exist" 1>&2
exit 2 exit 2
} }
if [ -d $incDir ] if [ -d "$incDir" ]
then then
[ "$update" = true ] || exit 0 [ "$update" = true ] || exit 0
else else
mkdir $incDir mkdir "$incDir"
fi fi
[ -d $incDir ] || { [ -d "$incDir" ] || {
echo "$Script error: failed to create include directory $incDir" 1>&2 echo "$Script error: failed to create include directory $incDir" 1>&2
exit 0 exit 0
} }
cd $incDir || exit 1 cd "$incDir" || exit 1
if [ "$silentOpt" = true -o -n "$WM_QUIET" ] # Always just display compact info
then echo " ln: $incDir" 1>&2
echo " ln: $incDir" 1>&2
else
echo "$Script: linking include files to $incDir" 1>&2
fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
...@@ -148,10 +184,10 @@ fi ...@@ -148,10 +184,10 @@ fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
case "$WM_ARCH" in case "$WM_ARCH" in
darwin*) (darwin*)
find -L . -type l -exec rm -- {} \+ find -L . -type l -exec rm -- {} \+
;; ;;
*) (*)
find -L . -type l -delete find -L . -type l -delete
;; ;;
esac esac
...@@ -170,7 +206,7 @@ find .. \ ...@@ -170,7 +206,7 @@ find .. \
-o -name '*.[ch]pp' \ -o -name '*.[ch]pp' \
-o -name '*.type' \ -o -name '*.type' \
\) \ \) \
-exec ln $lnOpt {} . \; -exec ln "$optLink" {} . \;
exit 0 # clean exit exit 0 # clean exit
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment