2 #------------------------------------------------------------------------------
4 # \\ / F ield | foam-extend: Open Source CFD
6 # \\ / A nd | For copyright notice see file Copyright
8 #------------------------------------------------------------------------------
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/>.
29 # General, easy to use make system for multi-platform development.
31 #------------------------------------------------------------------------------
35 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
38 $Script target [dir [MakeDir]]
40 A general, easy-to-use make system for multi-platform development
42 The 'target' is a Makefile target:
43 e.g., Make/linux64GccDPOpt/fvMesh.o
46 all all subdirectories
47 exe build statically linked executable
48 lib build statically linked archive lib (.a)
49 libso build dynamically linked lib (.so)
50 libo build statically linked lib (.o)
57 # provide immediate help, even if none of the environment is set
58 if [ "$1" = "-h" -o "$1" = "-help" ]
65 # check environment variables
67 for check
in WM_OPTIONS WM_LINK_LANGUAGE WM_DIR
69 eval test "\$$check" ||
{
70 echo "$Script error: environment variable \$$check not set" 1>&2
75 # when compiling anything but a standalone exe:
76 # WM_PROJECT and WM_PROJECT_DIR must be set
77 [ "$1" = exe
-o \
( "$WM_PROJECT" -a "$WM_PROJECT_DIR" \
) ] ||
{
78 echo "$Script error:" 1>&2
79 echo " environment variable \$WM_PROJECT or \$WM_PROJECT_DIR not set" 1>&2
80 echo " while building project library" 1>&2
85 #------------------------------------------------------------------------------
86 # Select the version of make to be used
87 #------------------------------------------------------------------------------
91 # set WM_NCOMPPROCS automatically when both WM_HOSTS and WM_SCHEDULER are set
92 if [ -z "$WM_NCOMPPROCS" -a -n "$WM_HOSTS" -a -n "$WM_SCHEDULER" ]
94 WM_NCOMPPROCS
=$
(wmakeScheduler
-count)
95 [ $?
-eq 0 ] ||
unset WM_NCOMPPROCS
98 if [ "$WM_NCOMPPROCS" ]
100 if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ]
102 lockDir
=$HOME/.wmakeScheduler
111 make="make --no-print-directory -j "$WM_NCOMPPROCS
116 #------------------------------------------------------------------------------
117 # check arguments and change to the directory in which to run wmake
118 #------------------------------------------------------------------------------
137 # alternative name for the Make sub-directory
145 cd $dir 2>/dev
/null ||
{
146 echo "$Script error: could not change to directory '$dir'" 1>&2
153 #------------------------------------------------------------------------------
154 # Recurse the application directories tree
155 #------------------------------------------------------------------------------
157 if [ "$makeOption" = all
]
163 elif [ ! -d $MakeDir ]
165 # FOAM_APPS=$(find . -maxdepth 1 \( -type d -a ! -name "." -a ! -name Optional -a ! -name Make \) -printf "%f ")
166 # avoid 'find' with '-printf' ... not entirely portable
167 FOAM_APPS
=$
(for d
in *; do [ -d "$d" -a "$d" != Optional
-a "$d" != Make
] && echo "$d"; done |
xargs)
168 $make -k -f $WM_DIR/MakefileApps FOAM_APPS
="$FOAM_APPS"
172 # This is the end of the recursion down the application directories tree
173 # so remove the "all" option so that the call to make builds the application
178 #------------------------------------------------------------------------------
179 # Check the existance of the Make directory and files file
180 # If both exist, make the wmake derived files
181 #------------------------------------------------------------------------------
184 echo "$Script error: '$MakeDir' directory does not exist" 1>&2
188 [ -r $MakeDir/files
] ||
{
189 echo "$Script error: file '$MakeDir/files' does not exist" 1>&2
193 # Spawn a sub-shell and unset MAKEFLAGS in that sub-shell to avoid
194 # files and options being built in parallel
198 make -s -f $WM_DIR/MakefileOptions
199 make -s -f $WM_DIR/MakefileFiles allFiles
203 #------------------------------------------------------------------------------
204 # Check the $OBJECTS_DIR = $MakeDir/$WM_OPTIONS/objectFiles file
205 # was created successfully
206 #------------------------------------------------------------------------------
208 OBJECTS_DIR
=$MakeDir/$WM_OPTIONS
210 [ -r $OBJECTS_DIR/objectFiles
] ||
{
211 echo "$Script error: file '$OBJECTS_DIR/objectFiles' could not be created" 1>&2
216 #------------------------------------------------------------------------------
217 # Make the dependency files
218 #------------------------------------------------------------------------------
220 touch $OBJECTS_DIR/dontIncludeDeps
222 case "$makeOption" in
224 $make -s -f $WM_DIR/Makefile MAKE_DIR
=$MakeDir INCLUDE_DEPS
=$OBJECTS_DIR/dontIncludeDeps lnInclude
/uptodate
228 $make -s -f $WM_DIR/Makefile MAKE_DIR
=$MakeDir INCLUDE_DEPS
=$OBJECTS_DIR/dontIncludeDeps
$OBJECTS_DIR/dependencies
237 #------------------------------------------------------------------------------
238 # make the object files and link
239 #------------------------------------------------------------------------------
241 cmd
="$make -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/includeDeps $makeOption"
245 #------------------------------------------------------------------------------