Merge branch 'master' of github.com:OpenFOAM/OpenFOAM-2.0.x
[OpenFOAM-2.0.x.git] / wmake / wmakeLnInclude
blobfa8dc97fe060f3ad97fd47e1546eb855e89a1377
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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 # wmakeLnInclude
28 # Description
29 # Link all the source files in the <dir> directory into <dir>/lnInclude
31 # Usage: wmakeLnInclude [-f] <dir>
33 # The desired source files:
34 # *.C *.H *.h *.cpp *.cxx *.hpp *.hxx
36 # Avoid
37 # *.c (C source)
38 # .#* (cvs recovered files)
39 #------------------------------------------------------------------------------
40 Script=${0##*/}
42 usage() {
43 exec 1>&2
44 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
45 cat<<USAGE
47 Usage: $Script [OPTION] dir
49 options:
50 -f | -force force update
51 -s | -silent use 'silent' mode (do not echo command)
52 -help print the usage
54 Link all the source files in the <dir> into <dir>/lnInclude
56 Note
57 The '-f' option forces an update when the lnInclude directory already exists
58 and changes the default linking from 'ln -s' to 'ln -sf'.
60 USAGE
61 exit 1
64 #------------------------------------------------------------------------------
66 # default 'find' option
67 unset findOpt
69 # default 'ln' option
70 lnOpt="-s"
72 unset forceUpdate silentOpt
74 # simple parse options
75 while [ "$#" -gt 0 ]
77 case "$1" in
78 -h | -help) # provide immediate help
79 usage
81 -f | -force)
82 forceUpdate=true
83 lnOpt="-sf"
84 shift
86 -s | -silent)
87 silentOpt=true
88 shift
90 -*)
91 usage "unknown option: '$*'"
94 break
96 esac
97 done
99 if [ $# -eq 1 ]
100 then
101 baseDir=$1
102 else
103 usage "ERROR: incorrect number of arguments"
107 # convert incorrect path/dir/lnInclude to something sensible
108 while [ "${baseDir##*/}" = lnInclude ]
110 baseDir="${baseDir%/*}"
111 if [ "$baseDir" = lnInclude ]
112 then
113 baseDir="."
115 done
116 incDir=$baseDir/lnInclude
119 [ -d $baseDir ] || {
120 echo "$Script error: base directory $baseDir does not exist" 1>&2
121 exit 2
124 if [ -d $incDir ]
125 then
126 [ "$forceUpdate" = true ] || {
127 # echo "$Script error: include directory $incDir already exists" 1>&2
128 exit 0
130 else
131 mkdir $incDir
134 [ -d $incDir ] || {
135 echo "$Script error: failed to create include directory $incDir" 1>&2
136 exit 0
139 cd $incDir || exit 1
141 #------------------------------------------------------------------------------
143 if [ "$silentOpt" != true ]
144 then
145 echo "$Script: linking include files to $incDir" 1>&2
149 # remove any broken links first (this helps when file locations have moved)
151 find -L . -type l -exec rm {} \;
154 # create links, avoid recreating links unless necessary
155 # things placed in the 'noLink' directory are skipped
157 find .. $findOpt \
158 \( -name lnInclude -o -name Make -o -name config -o -name noLink \) -prune \
159 -o \( -name '*.[CHh]' -o -name '*.[ch]xx' -o -name '*.[ch]pp' -o -name '*.type' \) \
160 -exec ln $lnOpt {} . \;
162 #------------------------------------------------------------------------------