Avoid file copy on Windows lnInclude
[foam-extend-4.0.git] / wmake / wmakeLnInclude
blob67e2d8cdc097c026f0e89e8b347a2248046f4083
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration | Version: 3.2
6 # \\ / A nd | Web: http://www.foam-extend.org
7 # \\/ M anipulation | For copyright notice see file Copyright
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of foam-extend.
12 # foam-extend is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by the
14 # Free Software Foundation, either version 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. 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> [-lnOption]
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 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
44 cat<<USAGE
46 usage: $Script [-f] <dir> [-lnOption]
48 Link all the source files in the <dir> into <dir>/lnInclude
50 Note
51 The '-f' option forces an update when the lnInclude directory already exists
52 and also changes the default linking from 'ln -s' to 'ln -sf'.
54 USAGE
55 exit 1
58 #------------------------------------------------------------------------------
60 # simple option parsing
61 unset forceUpdate
62 unset findOpt
64 # default ln option
65 lnOpt="-s"
67 # simple parse options
68 while [ "$#" -gt 0 ]
70 case "$1" in
71 -h | -help) # provide immediate help
72 usage
74 -f)
75 shift
76 forceUpdate=1
77 lnOpt="-sf"
79 -*)
80 usage "unknown option: '$*'"
83 break
85 esac
86 done
88 if [ $# -eq 1 ]
89 then
90 baseDir=$1
91 elif [ $# -eq 2 ]
92 then
93 baseDir=$1
94 lnOpt="$2"
95 else
96 usage "ERROR: incorrect number of arguments"
100 # convert incorrect path/dir/lnInclude to something sensible
101 while [ "${baseDir##*/}" = lnInclude ]
103 baseDir="${baseDir%/*}"
104 if [ "$baseDir" = lnInclude ]
105 then
106 baseDir="."
108 done
109 incDir=$baseDir/lnInclude
112 if [ ! -d $baseDir ]
113 then
114 echo "$Script error: base directory $baseDir does not exist" 1>&2
115 exit 2
118 if [ -d $incDir ]
119 then
120 if [ ! "$forceUpdate" ]
121 then
122 # echo "$Script error: include directory $incDir already exists" 1>&2
123 exit 0
125 else
126 mkdir $incDir
129 if [ ! -d $incDir ]
130 then
131 echo "$Script error: failed to create include directory $incDir" 1>&2
132 exit 0
135 cd $incDir || exit 1
138 # Link include files
139 # ~~~~~~~~~~~~~~~~~~
140 echo "$Script: linking include files to $incDir"
143 # remove any broken links first (this helps when file locations have moved)
145 find -L . -type l -exec rm {} \;
148 # create links, avoid recreating links unless necessary
149 # things placed in the 'noLink' directory are skipped
151 if [ "$WM_ARCH_BASE" == "mingw" ] ; then
152 lnCmd="genInclude.pl"
153 else
154 lnCmd="ln $lnOpt"
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 $lnCmd {} . \;
162 #------------------------------------------------------------------------------