2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright held by original author
8 #------------------------------------------------------------------------------
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
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
30 # General, easy to use make system for multi-platform development.
32 #------------------------------------------------------------------------------
36 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
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
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)
58 # provide immediate help, even if none of the environment is set
59 if [ "$1" = "-h" -o "$1" = "-help" ]
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
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
86 #------------------------------------------------------------------------------
87 # Select the version of make to be used
88 #------------------------------------------------------------------------------
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" ]
95 WM_NCOMPPROCS
=$
(wmakeScheduler
-count)
96 [ $?
-eq 0 ] ||
unset WM_NCOMPPROCS
99 if [ "$WM_NCOMPPROCS" ]
101 if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ]
103 lockDir
=$HOME/.wmakeScheduler
112 make="make --no-print-directory -j "$WM_NCOMPPROCS
117 #------------------------------------------------------------------------------
118 # check arguments and change to the directory in which to run wmake
119 #------------------------------------------------------------------------------
138 # alternative name for the Make sub-directory
146 cd $dir 2>/dev
/null ||
{
147 echo "$Script error: could not change to directory '$dir'" 1>&2
154 #------------------------------------------------------------------------------
155 # Recurse the application directories tree
156 #------------------------------------------------------------------------------
158 if [ "$makeOption" = all
]
164 elif [ ! -d $MakeDir ]
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"
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
179 #------------------------------------------------------------------------------
180 # Check the existance of the Make directory and files file
181 # If both exist, make the wmake derived files
182 #------------------------------------------------------------------------------
185 echo "$Script error: '$MakeDir' directory does not exist" 1>&2
189 [ -r $MakeDir/files
] ||
{
190 echo "$Script error: file '$MakeDir/files' does not exist" 1>&2
194 # Spawn a sub-shell and unset MAKEFLAGS in that sub-shell to avoid
195 # files and options being built in parallel
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
217 #------------------------------------------------------------------------------
218 # Make the dependency files
219 #------------------------------------------------------------------------------
221 touch $OBJECTS_DIR/dontIncludeDeps
223 case "$makeOption" in
225 $make -s -f $WM_DIR/Makefile MAKE_DIR
=$MakeDir INCLUDE_DEPS
=$OBJECTS_DIR/dontIncludeDeps lnInclude
/uptodate
229 $make -s -f $WM_DIR/Makefile MAKE_DIR
=$MakeDir INCLUDE_DEPS
=$OBJECTS_DIR/dontIncludeDeps
$OBJECTS_DIR/dependencies
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"
246 #------------------------------------------------------------------------------