BUG: potentialFoam/cylinder: indexing into non-existing patch in parallel
[OpenFOAM-2.0.x.git] / wmake / wmake
blobced70188cca8f69fa3af027b0387ab0cb9c72c7b
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 # wmake
28 # Description
29 # General, easy to use make system for multi-platform development.
31 #------------------------------------------------------------------------------
32 Script=${0##*/}
34 usage() {
35 exec 1>&2
36 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
37 cat<<USAGE
39 Usage: $Script [OPTION] [dir]
40 $Script [OPTION] target [dir [MakeDir]]
42 options:
43 -s | -silent invoke make in 'silent' mode (do not echo commands)
44 -help print the usage
47 A general, easy-to-use make system for multi-platform development
49 The 'target' is a Makefile target:
50 e.g., Make/linux64GccDPOpt/fvMesh.o
52 or a special target:
53 all all subdirectories, uses any Allwmake files if they exist
54 exe build statically linked executable
55 lib build statically linked archive lib (.a)
56 libo build statically linked lib (.o)
57 libso build dynamically linked lib (.so)
58 jar build Java jar
60 USAGE
61 exit 1
64 # normally use "make"
65 make="make"
67 # parse options
68 while [ "$#" -gt 0 ]
70 case "$1" in
71 -h | -help)
72 usage
74 -s | -silent)
75 make="$make -s"
76 shift
78 -*)
79 usage "unknown option: '$*'"
82 break
84 esac
85 done
88 # check environment variables
90 for check in WM_OPTIONS WM_LINK_LANGUAGE WM_DIR
92 eval test "\$$check" || {
93 echo "$Script error: environment variable \$$check not set" 1>&2
94 exit 1
96 done
99 # when compiling anything but a standalone exe:
100 # WM_PROJECT and WM_PROJECT_DIR must be set
101 [ "$1" = exe -o \( "$WM_PROJECT" -a "$WM_PROJECT_DIR" \) ] || {
102 echo "$Script error:" 1>&2
103 echo " environment variable \$WM_PROJECT or \$WM_PROJECT_DIR not set" 1>&2
104 echo " while building project library" 1>&2
105 exit 1
109 #------------------------------------------------------------------------------
110 # Select the version of make to be used
111 #------------------------------------------------------------------------------
113 # set WM_NCOMPPROCS automatically when both WM_HOSTS and WM_SCHEDULER are set
114 if [ -z "$WM_NCOMPPROCS" -a -n "$WM_HOSTS" -a -n "$WM_SCHEDULER" ]
115 then
116 WM_NCOMPPROCS=$(wmakeScheduler -count)
117 [ $? -eq 0 ] || unset WM_NCOMPPROCS
120 if [ "$WM_NCOMPPROCS" ]
121 then
122 if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ]
123 then
124 lockDir=$HOME/.$WM_PROJECT/.wmake
126 if [ -d $lockDir ]
127 then
128 rm -f $lockDir/*
129 else
130 mkdir -p $lockDir
133 make="$make --no-print-directory -j "$WM_NCOMPPROCS
138 #------------------------------------------------------------------------------
139 # check arguments and change to the directory in which to run wmake
140 #------------------------------------------------------------------------------
142 unset dir makeType
143 MakeDir=Make
145 if [ $# -ge 1 ]
146 then
147 if [ -d "$1" ]
148 then
149 dir=$1
150 else
151 makeType=$1
154 # specified directory name:
155 [ $# -ge 2 ] && dir=$2
157 # specified alternative name for the Make sub-directory:
158 [ $# -ge 3 ] && MakeDir=$3
160 if [ "$dir" ]
161 then
162 cd $dir 2>/dev/null || {
163 echo "$Script error: could not change to directory '$dir'" 1>&2
164 exit 1
170 #------------------------------------------------------------------------------
171 # Recurse the application directories tree
172 #------------------------------------------------------------------------------
174 if [ "$makeType" = all ]
175 then
176 if [ -e Allwmake ]
177 then
178 ./Allwmake
179 exit $?
180 elif [ ! -d $MakeDir ]
181 then
182 # FOAM_APPS=$(find . -maxdepth 1 \( -type d -a ! -name "." -a ! -name Optional -a ! -name Make \) -printf "%f ")
183 # avoid 'find' with '-printf' ... not entirely portable
184 FOAM_APPS=$(for d in *; do [ -d "$d" -a "$d" != Optional -a "$d" != Make ] && echo "$d"; done | xargs)
185 $make -k -f $WM_DIR/MakefileApps FOAM_APPS="$FOAM_APPS"
186 exit $?
191 #------------------------------------------------------------------------------
192 # Require the existence of the 'Make' directory and 'files' file
193 #------------------------------------------------------------------------------
195 [ -d $MakeDir ] || {
196 echo "$Script error: '$MakeDir' directory does not exist in $PWD" 1>&2
197 exit 1
200 [ -r $MakeDir/files ] || {
201 echo "$Script error: file '$MakeDir/files' does not exist in $PWD" 1>&2
202 exit 1
205 # transform "all" option to "libso" if that looks appropriate or remove it
206 # so that the call to make builds the application
207 if [ "$makeType" = all ]
208 then
209 unset makeType
210 if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1
211 then
212 makeType=libso
217 # Spawn a sub-shell and unset MAKEFLAGS in that sub-shell to avoid
218 # files and options being built in parallel
220 cd $MakeDir
221 unset MAKEFLAGS
222 make -s -f $WM_DIR/MakefileOptions
223 make -s -f $WM_DIR/MakefileFiles allFiles
227 #------------------------------------------------------------------------------
228 # Check the $OBJECTS_DIR = $MakeDir/$WM_OPTIONS/objectFiles file
229 # was created successfully
230 #------------------------------------------------------------------------------
232 OBJECTS_DIR=$MakeDir/$WM_OPTIONS
234 [ -r $OBJECTS_DIR/objectFiles ] || {
235 echo "$Script error: file '$OBJECTS_DIR/objectFiles' could not be created in $PWD" 1>&2
236 exit 1
240 #------------------------------------------------------------------------------
241 # Make the dependency files
242 #------------------------------------------------------------------------------
244 touch $OBJECTS_DIR/dontIncludeDeps
246 case "$makeType" in
247 lib | libo | libso )
248 $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps lnInclude/uptodate
250 esac
252 $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps $OBJECTS_DIR/dependencies
254 rc=$?
255 [ $rc -eq 0 ] || exit $rc
257 #------------------------------------------------------------------------------
258 # make the object files and link
259 #------------------------------------------------------------------------------
261 cmd="$make -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/includeDeps $makeType"
262 # echo "cmd=$cmd"
263 exec $cmd
265 #------------------------------------------------------------------------------