Merge branch 'master' of github.com:OpenCFD/OpenFOAM-2.0.x
[OpenFOAM-2.0.x.git] / bin / rmdepold
blobbb83bbd9b6b06063ba00748d38536531778b8c3b
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #-------------------------------------------------------------------------------
9 # License
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # rmdepold
28 # Description
29 # Usage: rmdepold [dir1 .. dirN]
31 # Remove *.dep files that are without a corresponding .C or .L file.
32 # This often occurs when a directory has been moved.
33 # - print questionable directory and the *.dep file
34 # - optionally remove empty directories
35 #------------------------------------------------------------------------------
36 usage() {
37 exec 1>&2
38 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
39 cat<<USAGE
40 Usage: ${0##*/} [OPTION] [dir1 .. dirN]
41 options:
42 -rmdir find and remove empty directories (recursively)
44 Remove *.dep files that are without a corresponding .C or .L file.
45 This often occurs when a directory has been moved.
46 - print questionable directory and file
47 - optionally remove empty directories
49 USAGE
50 exit 1
53 unset optRmdir
55 # parse options
56 while [ "$#" -gt 0 ]
58 case "$1" in
59 -h | -help)
60 usage
62 -rmdir)
63 optRmdir=true
64 shift
66 -*)
67 usage "unknown option: '$*'"
70 break
72 esac
73 done
75 # default is the current directory
76 [ "$#" -gt 0 ] || set -- .
78 for checkDir
80 if [ -d $checkDir ]
81 then
82 echo "searching: $checkDir"
83 else
84 echo "skipping non-dir: $checkDir"
85 continue
88 find $checkDir -name '*.dep' -print | while read depFile
90 # check C++ and Flex files
91 if [ ! -r "${depFile%dep}C" -a ! -r "${depFile%dep}L" ];
92 then
93 echo "rm $depFile"
94 rm -f $depFile 2>/dev/null
96 done
98 # remove empty dirs
99 if [ "$optRmdir" ]
100 then
101 # get subdirs ourselves so we can avoid particular directories
102 for dir in $(find $checkDir -mindepth 1 -maxdepth 1 -type d \( -name .git -prune -o -print \) )
104 echo "check dir: $dir"
105 find $dir -depth -type d -empty -exec rmdir {} \; -print
106 done
108 done
109 # -----------------------------------------------------------------------------