openfoam/wmake/wmake
2008-04-15 18:56:58 +01:00

243 lines
6.5 KiB
Bash
Executable File

#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Script
# wmake
#
# Description
# General, easy to use make system for multi-platform development.
#
#------------------------------------------------------------------------------
Script=${0##*/}
usage() {
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
usage: $Script [dir]
$Script target [dir [MakeDir]]
A general, easy-to-use make system for multi-platform development
The 'target' is a Makefile target:
e.g., Make/linux64GccDPOpt/fvMesh.o
or a special target:
all all subdirectories
exe build statically linked executable
lib build statically linked archive lib (.a)
libso build dynamically linked lib (.so)
libo build statically linked lib (.o)
jar build Java jar
USAGE
exit 1
}
# provide immediate help
if [ "$1" = "-h" -o "$1" = "-help" ]; then
usage
fi
#
# check environment variables
#
for check in WM_OPTIONS WM_LINK_LANGUAGE WM_DIR
do
eval test "\$$check" || {
echo "$Script error"
echo " environment variable \$$check not set"
exit 1
}
done
# when compiling anything but a standalone exe,
# WM_PROJECT and WM_PROJECT_DIR must be set
[ "$1" = exe -o \( "$WM_PROJECT" -a "$WM_PROJECT_DIR" \) ] || {
echo "$Script error"
echo " environment variable \$WM_PROJECT or \$WM_PROJECT_DIR not set"
echo " while building project library or executable"
exit 1
}
#------------------------------------------------------------------------------
# Select the version of make to be used
#------------------------------------------------------------------------------
make="make"
if [ "$WM_NCOMPPROCS" ]
then
if [ "$WM_NCOMPPROCS" -ne 1 -a ! "$MAKEFLAGS" ]
then
lockDir=$HOME/.wmakeScheduler
if [ -d $lockDir ]
then
rm -f $lockDir/*
else
mkdir -p $lockDir
fi
make="make --no-print-directory -j "$WM_NCOMPPROCS
fi
fi
#------------------------------------------------------------------------------
# check arguments and change to the directory in which to run wmake
#------------------------------------------------------------------------------
unset dir makeOption
MakeDir=Make
if [ $# -ge 1 ]
then
if [ -d "$1" ]
then
dir=$1
else
makeOption=$1
fi
if [ $# -ge 2 ]
then
dir=$2
fi
# alternative name for the Make sub-directory
if [ $# -ge 3 ]
then
MakeDir=$3
fi
if [ "$dir" ]
then
cd $dir 2>/dev/null || {
echo "$Script error"
echo " could not change to directory '$dir'"
exit 1
}
fi
fi
#------------------------------------------------------------------------------
# Recurse the application directories tree
#------------------------------------------------------------------------------
if [ "$makeOption" = all ]
then
if [ -e Allwmake ]
then
./Allwmake
exit $?
elif [ ! -d $MakeDir ]
then
$make -k -f $WM_DIR/MakefileApps FOAM_APPS="`find . -maxdepth 1 \( -type d -a ! -name "." -a ! -name ".svn" -a ! -name "Make" \) -printf "%f "`"
exit $?
fi
# This is the end of the recursion down the application directories tree
# so remove the "all" option so that the call to make builds the application
makeOption=
fi
#------------------------------------------------------------------------------
# Check the existance of the Make directory and files file
# If both exist make the wmake derived files
#------------------------------------------------------------------------------
if [ ! -d $MakeDir ]
then
echo "$Script error"
echo " '$MakeDir' directory does not exist"
exit 1
fi
if [ ! -r $MakeDir/files ]
then
echo "$Script error"
echo " file '$MakeDir/files' does not exist"
exit 1
fi
# Spawn a sub-shell and unset MAKEFLAGS in that sub-shell to avoid
# files and options being built in parallel
(
cd $MakeDir
unset MAKEFLAGS
make -s -f $WM_DIR/MakefileOptions
make -s -f $WM_DIR/MakefileFiles allFiles
)
#------------------------------------------------------------------------------
# Check the $OBJECTS_DIR = $MakeDir/$WM_OPTIONS/objectFiles file
# was created successfully
#------------------------------------------------------------------------------
OBJECTS_DIR=$MakeDir/$WM_OPTIONS
if [ ! -r $OBJECTS_DIR/objectFiles ]
then
echo "$Script error"
echo " file '$OBJECTS_DIR/objectFiles' was not created successfully"
exit 1
fi
#------------------------------------------------------------------------------
# Make the dependency files
#------------------------------------------------------------------------------
touch $OBJECTS_DIR/dontIncludeDeps
case "$makeOption" in
lib | libso | libo )
$make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps lnInclude/uptodate
;;
esac
$make -s -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/dontIncludeDeps $OBJECTS_DIR/dependencies
retVal=$?
if [ $retVal -ne 0 ]; then
exit $retVal
fi
#------------------------------------------------------------------------------
# make the object files and link
#------------------------------------------------------------------------------
cmd="$make -f $WM_DIR/Makefile MAKE_DIR=$MakeDir INCLUDE_DEPS=$OBJECTS_DIR/includeDeps $makeOption"
#echo "cmd=$cmd"
exec $cmd
#------------------------------------------------------------------------------