From e66cd871b5fc19e88b3a4442115b30fdaeaa2b84 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 11 Jun 2013 12:58:19 +0100 Subject: [PATCH] wmake: add "dwim" target dwim (do what I mean): search up directories tree for Make sub-directory and build the target specified in Make/files --- wmake/wmake | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/wmake/wmake b/wmake/wmake index ebcd38cb6e..b9977fa7e1 100755 --- a/wmake/wmake +++ b/wmake/wmake @@ -50,6 +50,7 @@ The 'target' is a Makefile target: e.g., Make/linux64GccDPOpt/fvMesh.o or a special target: + dwim search up directories tree for Make sub-directory and build all all subdirectories, uses any Allwmake files if they exist exe build statically linked executable lib build statically linked archive lib (.a) @@ -136,7 +137,7 @@ fi #------------------------------------------------------------------------------ -# check arguments and change to the directory in which to run wmake +# Check arguments and change to the directory in which to run wmake #------------------------------------------------------------------------------ unset dir makeType @@ -167,6 +168,51 @@ then fi +#------------------------------------------------------------------------------ +# Search up directories tree for the Make sub-directory and build there +#------------------------------------------------------------------------------ + +unset dir +MakeDir=Make + +expandpath() +{ + dir=`dirname $1` + cwd=$PWD + cd $dir + exPath=$PWD + cd $cwd +} + +find_target() +{ + expandpath $1 + + if [ "$exPath" = "$WM_PROJECT_DIR" -o "$exPath" = "$HOME" -o "$exPath" = "/" ]; then + echo "$Script error: could not find Make directory" + elif [ -d "$1/Make" ]; then + echo Target $1 + dir=$1 + else + find_target "$1/.." + fi +} + +if [ "$makeType" = dwim ] +then + find_target . + makeType= + + if [ "$dir" ] + then + cd $dir 2>/dev/null || { + echo "$Script error: could not change to directory '$dir'" 1>&2 + exit 1 + } + fi +fi + + #------------------------------------------------------------------------------ # Recurse the application directories tree #------------------------------------------------------------------------------ @@ -254,8 +300,9 @@ $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontInc rc=$? [ $rc -eq 0 ] || exit $rc + #------------------------------------------------------------------------------ -# make the object files and link +# Make the object files and link #------------------------------------------------------------------------------ cmd="$make -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/includeDeps $makeType"