Removed dependency on objectRegistry in constructor
[foam-extend-3.0.git] / wmake / wmake
blob0dc477510087406ee46a02f117a2743c62b65ca4
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration |
6 # \\ / A nd | For copyright notice see file Copyright
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
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/>.
25 # Script
26 # wmake
28 # Description
29 # General, easy to use make system for multi-platform development.
31 #------------------------------------------------------------------------------
32 Script=${0##*/}
34 usage() {
35 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
36 cat<<USAGE
37 usage: $Script [dir]
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
45 or a special target:
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)
51 jar build Java jar
53 USAGE
54 exit 1
57 # provide immediate help, even if none of the environment is set
58 if [ "$1" = "-h" -o "$1" = "-help" ]
59 then
60 usage
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
71 exit 1
73 done
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
81 exit 1
85 #------------------------------------------------------------------------------
86 # Select the version of make to be used
87 #------------------------------------------------------------------------------
89 make="make"
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" ]
93 then
94 WM_NCOMPPROCS=$(wmakeScheduler -count)
95 [ $? -eq 0 ] || unset WM_NCOMPPROCS
98 if [ "$WM_NCOMPPROCS" ]
99 then
100 if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ]
101 then
102 lockDir=$HOME/.wmakeScheduler
104 if [ -d $lockDir ]
105 then
106 rm -f $lockDir/*
107 else
108 mkdir -p $lockDir
111 make="make --no-print-directory -j "$WM_NCOMPPROCS
116 #------------------------------------------------------------------------------
117 # check arguments and change to the directory in which to run wmake
118 #------------------------------------------------------------------------------
120 unset dir makeOption
121 MakeDir=Make
123 if [ $# -ge 1 ]
124 then
125 if [ -d "$1" ]
126 then
127 dir=$1
128 else
129 makeOption=$1
132 if [ $# -ge 2 ]
133 then
134 dir=$2
137 # alternative name for the Make sub-directory
138 if [ $# -ge 3 ]
139 then
140 MakeDir=$3
143 if [ "$dir" ]
144 then
145 cd $dir 2>/dev/null || {
146 echo "$Script error: could not change to directory '$dir'" 1>&2
147 exit 1
153 #------------------------------------------------------------------------------
154 # Recurse the application directories tree
155 #------------------------------------------------------------------------------
157 if [ "$makeOption" = all ]
158 then
159 if [ -e Allwmake ]
160 then
161 ./Allwmake
162 exit $?
163 elif [ ! -d $MakeDir ]
164 then
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"
169 exit $?
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
174 makeOption=
178 #------------------------------------------------------------------------------
179 # Check the existance of the Make directory and files file
180 # If both exist, make the wmake derived files
181 #------------------------------------------------------------------------------
183 [ -d $MakeDir ] || {
184 echo "$Script error: '$MakeDir' directory does not exist" 1>&2
185 exit 1
188 [ -r $MakeDir/files ] || {
189 echo "$Script error: file '$MakeDir/files' does not exist" 1>&2
190 exit 1
193 # Spawn a sub-shell and unset MAKEFLAGS in that sub-shell to avoid
194 # files and options being built in parallel
196 cd $MakeDir
197 unset MAKEFLAGS
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
212 exit 1
216 #------------------------------------------------------------------------------
217 # Make the dependency files
218 #------------------------------------------------------------------------------
220 touch $OBJECTS_DIR/dontIncludeDeps
222 case "$makeOption" in
223 lib | libso | libo )
224 $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps lnInclude/uptodate
226 esac
228 $make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps $OBJECTS_DIR/dependencies
230 retVal=$?
231 if [ $retVal -ne 0 ]
232 then
233 exit $retVal
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"
242 # echo "cmd=$cmd"
243 exec $cmd
245 #------------------------------------------------------------------------------