STYLE: sampledPlane : added comment about calling update() after construction
[OpenFOAM-1.6.x.git] / wmake / wmake
blob473119fd01eb7db0834442c4b790fa385a8d2721
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2009 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 the
14 # Free Software Foundation; either version 2 of the License, or (at your
15 # 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, write to the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 # Script
27 # wmake
29 # Description
30 # General, easy to use make system for multi-platform development.
32 #------------------------------------------------------------------------------
33 Script=${0##*/}
35 usage() {
36 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
37 cat<<USAGE
38 usage: $Script [dir]
39 $Script target [dir [MakeDir]]
41 A general, easy-to-use make system for multi-platform development
43 The 'target' is a Makefile target:
44 e.g., Make/linux64GccDPOpt/fvMesh.o
46 or a special target:
47 all all subdirectories
48 exe build statically linked executable
49 lib build statically linked archive lib (.a)
50 libso build dynamically linked lib (.so)
51 libo build statically linked lib (.o)
52 jar build Java jar
54 USAGE
55 exit 1
58 # provide immediate help, even if none of the environment is set
59 if [ "$1" = "-h" -o "$1" = "-help" ]
60 then
61 usage
66 # check environment variables
68 for check in WM_OPTIONS WM_LINK_LANGUAGE WM_DIR
70 eval test "\$$check" || {
71 echo "$Script error: environment variable \$$check not set" 1>&2
72 exit 1
74 done
76 # when compiling anything but a standalone exe:
77 # WM_PROJECT and WM_PROJECT_DIR must be set
78 [ "$1" = exe -o \( "$WM_PROJECT" -a "$WM_PROJECT_DIR" \) ] || {
79 echo "$Script error:" 1>&2
80 echo " environment variable \$WM_PROJECT or \$WM_PROJECT_DIR not set" 1>&2
81 echo " while building project library" 1>&2
82 exit 1
86 #------------------------------------------------------------------------------
87 # Select the version of make to be used
88 #------------------------------------------------------------------------------
90 make="make"
92 # set WM_NCOMPPROCS automatically when both WM_HOSTS and WM_SCHEDULER are set
93 if [ -z "$WM_NCOMPPROCS" -a -n "$WM_HOSTS" -a -n "$WM_SCHEDULER" ]
94 then
95 WM_NCOMPPROCS=$(wmakeScheduler -count)
96 [ $? -eq 0 ] || unset WM_NCOMPPROCS
99 if [ "$WM_NCOMPPROCS" ]
100 then
101 if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ]
102 then
103 lockDir=$HOME/.wmakeScheduler
105 if [ -d $lockDir ]
106 then
107 rm -f $lockDir/*
108 else
109 mkdir -p $lockDir
112 make="make --no-print-directory -j "$WM_NCOMPPROCS
117 #------------------------------------------------------------------------------
118 # check arguments and change to the directory in which to run wmake
119 #------------------------------------------------------------------------------
121 unset dir makeOption
122 MakeDir=Make
124 if [ $# -ge 1 ]
125 then
126 if [ -d "$1" ]
127 then
128 dir=$1
129 else
130 makeOption=$1
133 if [ $# -ge 2 ]
134 then
135 dir=$2
138 # alternative name for the Make sub-directory
139 if [ $# -ge 3 ]
140 then
141 MakeDir=$3
144 if [ "$dir" ]
145 then
146 cd $dir 2>/dev/null || {
147 echo "$Script error: could not change to directory '$dir'" 1>&2
148 exit 1
154 #------------------------------------------------------------------------------
155 # Recurse the application directories tree
156 #------------------------------------------------------------------------------
158 if [ "$makeOption" = all ]
159 then
160 if [ -e Allwmake ]
161 then
162 ./Allwmake
163 exit $?
164 elif [ ! -d $MakeDir ]
165 then
166 # FOAM_APPS=$(find . -maxdepth 1 \( -type d -a ! -name "." -a ! -name Optional -a ! -name Make \) -printf "%f ")
167 # avoid 'find' with '-printf' ... not entirely portable
168 FOAM_APPS=$(for d in *; do [ -d "$d" -a "$d" != Optional -a "$d" != Make ] && echo "$d"; done | xargs)
169 $make -k -f $WM_DIR/MakefileApps FOAM_APPS="$FOAM_APPS"
170 exit $?
173 # This is the end of the recursion down the application directories tree
174 # so remove the "all" option so that the call to make builds the application
175 makeOption=
179 #------------------------------------------------------------------------------
180 # Check the existance of the Make directory and files file
181 # If both exist, make the wmake derived files
182 #------------------------------------------------------------------------------
184 [ -d $MakeDir ] || {
185 echo "$Script error: '$MakeDir' directory does not exist" 1>&2
186 exit 1
189 [ -r $MakeDir/files ] || {
190 echo "$Script error: file '$MakeDir/files' does not exist" 1>&2
191 exit 1
194 # Spawn a sub-shell and unset MAKEFLAGS in that sub-shell to avoid
195 # files and options being built in parallel
197 cd $MakeDir
198 unset MAKEFLAGS
199 make -s -f $WM_DIR/MakefileOptions
200 make -s -f $WM_DIR/MakefileFiles allFiles
204 #------------------------------------------------------------------------------
205 # Check the $OBJECTS_DIR = $MakeDir/$WM_OPTIONS/objectFiles file
206 # was created successfully
207 #------------------------------------------------------------------------------
209 OBJECTS_DIR=$MakeDir/$WM_OPTIONS
211 [ -r $OBJECTS_DIR/objectFiles ] || {
212 echo "$Script error: file '$OBJECTS_DIR/objectFiles' could not be created" 1>&2
213 exit 1
217 #------------------------------------------------------------------------------
218 # Make the dependency files
219 #------------------------------------------------------------------------------
221 touch $OBJECTS_DIR/dontIncludeDeps
223 case "$makeOption" in
224 lib | libso | libo )
225 $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps lnInclude/uptodate
227 esac
229 $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps $OBJECTS_DIR/dependencies
231 retVal=$?
232 if [ $retVal -ne 0 ]
233 then
234 exit $retVal
238 #------------------------------------------------------------------------------
239 # make the object files and link
240 #------------------------------------------------------------------------------
242 cmd="$make -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/includeDeps $makeOption"
243 # echo "cmd=$cmd"
244 exec $cmd
246 #------------------------------------------------------------------------------