2 #------------------------------------------------------------------------------
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
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
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/>.
29 # General, easy to use make system for multi-platform development.
31 #------------------------------------------------------------------------------
36 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
39 Usage: $Script [OPTION] [dir]
40 $Script [OPTION] target [dir [MakeDir]]
43 -s | -silent invoke make in 'silent' mode (do not echo commands)
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
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)
79 usage
"unknown option: '$*'"
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
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
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" ]
116 WM_NCOMPPROCS
=$
(wmakeScheduler
-count)
117 [ $?
-eq 0 ] ||
unset WM_NCOMPPROCS
120 if [ "$WM_NCOMPPROCS" ]
122 if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ]
124 lockDir
=$HOME/.
$WM_PROJECT/.wmake
133 make="$make --no-print-directory -j "$WM_NCOMPPROCS
138 #------------------------------------------------------------------------------
139 # check arguments and change to the directory in which to run wmake
140 #------------------------------------------------------------------------------
154 # specified directory name:
155 [ $# -ge 2 ] && dir
=$2
157 # specified alternative name for the Make sub-directory:
158 [ $# -ge 3 ] && MakeDir
=$3
162 cd $dir 2>/dev
/null ||
{
163 echo "$Script error: could not change to directory '$dir'" 1>&2
170 #------------------------------------------------------------------------------
171 # Recurse the application directories tree
172 #------------------------------------------------------------------------------
174 if [ "$makeType" = all
]
180 elif [ ! -d $MakeDir ]
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"
191 #------------------------------------------------------------------------------
192 # Require the existence of the 'Make' directory and 'files' file
193 #------------------------------------------------------------------------------
196 echo "$Script error: '$MakeDir' directory does not exist in $PWD" 1>&2
200 [ -r $MakeDir/files
] ||
{
201 echo "$Script error: file '$MakeDir/files' does not exist in $PWD" 1>&2
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
]
210 if grep -e '^ *LIB *=' "$MakeDir/files" >/dev
/null
2>&1
217 # Spawn a sub-shell and unset MAKEFLAGS in that sub-shell to avoid
218 # files and options being built in parallel
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
240 #------------------------------------------------------------------------------
241 # Make the dependency files
242 #------------------------------------------------------------------------------
244 touch $OBJECTS_DIR/dontIncludeDeps
248 $make -s -f $WM_DIR/Makefile MAKE_DIR
=$MakeDir INCLUDE_DEPS
=$OBJECTS_DIR/dontIncludeDeps lnInclude
/uptodate
252 $make -s -f $WM_DIR/Makefile MAKE_DIR
=$MakeDir INCLUDE_DEPS
=$OBJECTS_DIR/dontIncludeDeps
$OBJECTS_DIR/dependencies
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"
265 #------------------------------------------------------------------------------