Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Build Script for cross-compiling OpenFOAM 2.1.x for Windows
#!/bin/bash
#
# Refer to http://www.symscape.com/openfoam-2-1-x-on-windows-64-mpi for original instructions
# Following script is for Ubuntu Linux
#
# Check if apropriate file/packages exists - if not install the package
#
set -x
function maketar()
{
cd $FOAM_INST_DIR
cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/zlib1.dll OpenFOAM-2.1.x/lib/$WM_OPTIONS/
tar cvf OpenFOAM-2.1.0-winbuild.`date +%F`.tar OpenFOAM-2.1.x/applications/bin/$WM_OPTIONS/*.exe OpenFOAM-2.1.x/lib/$WM_OPTIONS/*.dll OpenFOAM-2.1.x/lib/$WM_OPTIONS/*/*.dll OpenFOAM-2.1.x/etc
}
echo "Starting the build at :"
date
x=`which flex`
if [ -z $x ]; then
echo "installing flex ..."
sudo apt-get install flex
else
echo "flex already installed ..."
fi
x=`which bison`
if [ -z $x ]; then
echo "installing bison ..."
sudo apt-get install bison
else
echo "bison already installed ..."
fi
x=`which gcc`
if [ -z $x ]; then
echo "installing gcc ..."
sudo apt-get install gcc
else
echo "gcc already installed ..."
fi
x=`find /usr/lib -name libz.a`
if [ -z $x ]; then
echo "installing zlib1g-dev ..."
sudo apt-get install zlib1g-dev
else
echo "zlib1g-dev already installed ..."
fi
x=`which g++`
if [ -z $x ]; then
echo "installing g++ ..."
sudo apt-get install g++
else
echo "g++ already installed ..."
fi
x=`which gendef`
if [ -z $x ]; then
echo "installing gendef ..."
if [ ! -e mingw-w64-gendef.tar.gz ]; then
wget http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/trunk/mingw-w64-tools/gendef/?view=tar
mv "index.html?view=tar" mingw-w64-gendef.tar.gz
fi
tar xvzf mingw-w64-gendef.tar.gz
cd gendef
./configure;make;sudo make install
else
echo "gendef already installed ..."
fi
# Set the variables
export FOAM_INST_DIR=`pwd`
# patch the OpenFOAM installation
#cd $FOAM_INST_DIR/OpenFOAM-2.1.x
#patch -p0 --verbose < $FOAM_INST_DIR/downloads/v1-mingw-openfoam-2-1-x.patch > patch.log 2>&1
# Make dummysizes binary on linux platform
cd $FOAM_INST_DIR/ThirdParty-2.1.0/scotch_5.1.11/src
if [ ! -f libscotch/dummysizes.linux ]; then
make libscotch
cp libscotch/dummysizes libscotch/dummysizes.linux
fi
# We also need to build wmkdep on linux - Needed for creating dependencies in
# rest of the projects
source $FOAM_INST_DIR/OpenFOAM-2.1.x/etc/bashrc
cd $FOAM_INST_DIR/OpenFOAM-2.1.x/wmake/src;make
ln -s $WM_PROJECT_DIR/wmake/platforms/linux64Gcc $WM_PROJECT_DIR/wmake/platforms/linux64mingw-w64
source $FOAM_INST_DIR/OpenFOAM-2.1.x/etc/bashrc.modified
#export WM_OSTYPE=MSwindows
#export WM_COMPILER=mingw-w64
#export WM_ARCH_OPTION=64
#export WM_PRECISION_OPTION=DP
export WM_CC=x86_64-w64-mingw32-gcc
export WM_CXX=x86_64-w64-mingw32-g++
#export WM_OPTIONS=$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_COMPILE_OPTION
#export WM_MPLIB=MSMPI
export MPI_ARCH_PATH=$WM_THIRD_PARTY_DIR/msmpi-1-home
export | grep FOAM
# Build libscotch
cd $FOAM_INST_DIR
ln -s ThirdParty-2.1.0 $WM_THIRD_PARTY_DIR
ln -s $WM_THIRD_PARTY_DIR/scotch_5.1.11 $WM_THIRD_PARTY_DIR/scotch
mv $WM_THIRD_PARTY_DIR/scotch/src/Makefile.inc $WM_THIRD_PARTY_DIR/scotch/src/Makefile.inc.orig
# ALERT : Once we execute following four lines, building dummysizes breaks
# To start over - get rid of ThirdPary-2.1.0 and extract from TAR
#
# Need to modify $WM_THIRD_PARTY_DIR/scotch/src/Makefile.inc as follows :
# -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -lz (Instead of just -lz)
ln -s $WM_PROJECT_DIR/extra/scotch/src/Make.inc/Makefile.inc.mingw-w64 $WM_THIRD_PARTY_DIR/scotch/src/Makefile.inc
# TODO : Need to put this block under if
# Why rebuild libscotch if libscotch.dll exists ??
if [ ! -e $WM_THIRD_PARTY_DIR/scotch/src/libscotch/libscotch.dll ]; then
cd $WM_THIRD_PARTY_DIR/scotch/src
cp $WM_PROJECT_DIR/extra/scotch/src/Makefile .
make clean
cp $WM_PROJECT_DIR/extra/scotch/src/libscotch/* $WM_THIRD_PARTY_DIR/scotch/src/libscotch
cp libscotch/dummysizes.linux libscotch/dummysizes
# Some time this fails, run it again, it works second time
# It fails because SCOTCH_VERSION in $WM_THIRD_PARTY_DIR/scotch/src/libscotch/scotch.h is NOT defined
# But we just copied correct scotch.h from $WM_PROJECT_DIR/extra/scotch/src/libscotch/
# Then why ???
# what changes second time ? Rather why doesn't it work for the first time ???
# TODO : investigate
echo "Building libscotch"
make libscotch
else
echo "libscotch.dll already built ... not rebuilding.."
fi
export FOAM_LIB=$WM_PROJECT_DIR/lib
export FOAM_LIBBIN=$FOAM_LIB/$WM_OPTIONS
set FOAM_APP=$WM_PROJECT_DIR/applications
export FOAM_APPBIN=$WM_PROJECT_DIR/applications/bin/$WM_OPTIONS
export FOAM_EXT_LIBBIN=$WM_THIRD_PARTY_DIR/scotch/src/libscotch
if [ ! -e $WM_PROJECT_DIR/lib/linux64mingw-w64DPOpt/libscotch.dll ]; then
mkdir -p $FOAM_LIBBIN
cd $WM_THIRD_PARTY_DIR/scotch/src/libscotch
cp libscotch.* $FOAM_LIBBIN
else
echo "libscotch already copied to $WM_PROJECT_DIR/lib/linux64mingw-w64DPOpt"
fi
# Check if ThirdParty-2.1.0/msmpi-1-home exists, if not Error and come out
if [ ! -d $WM_THIRD_PARTY_DIR/msmpi-1-home ]; then
echo "$WM_THIRD_PARTY_DIR/msmpi-1-home Does not Exists. Unable to proceed";
exit 1
else
mkdir -p $HOME/projects/msmpi
cd $HOME/projects/msmpi
ln -s $WM_THIRD_PARTY_DIR/msmpi-1-home install
cd $WM_THIRD_PARTY_DIR/msmpi-1-home/Lib/amd64;gendef msmpi.dll
x86_64-w64-mingw32-dlltool -d msmpi.def -l libmsmpi.a -D msmpi.dll
x=`grep stdint $WM_THIRD_PARTY_DIR/msmpi-1-home/Inc/mpi.h`
if [ -z "$x" ]; then
echo "ERROR : Please manually add #include <stdint.h> to $WM_THIRD_PARTY_DIR/msmpi-1-home/Inc/mpi.h"
echo "Unable to proceed.. exiting"
exit 1
else
echo "Found stdint in $WM_THIRD_PARTY_DIR/msmpi-1-home/Inc/mpi.h"
fi
fi
# build OpenFOAM
cd $WM_PROJECT_DIR
find . -name Allwmake | xargs chmod a+x
echo "Cleaning old build files"
$WM_PROJECT_DIR/wmake/wcleanAll
cd $WM_PROJECT_DIR/wmake/src; make
#ln -s $WM_PROJECT_DIR/wmake/platforms/linux64Gcc $WM_PROJECT_DIR/wmake/platforms/linux64mingw-w64
if [ ! -L $WM_PROJECT_DIR/lib/linux64GccDPOpt ]; then
ln -s $WM_PROJECT_DIR/lib/linux64mingw-w64DPOpt $WM_PROJECT_DIR/lib/linux64GccDPOpt
else
echo "symlink $WM_PROJECT_DIR/lib/linux64GccDPOpt already exists"
fi
if [ ! -d $WM_PROJECT_DIR/platforms/linux64mingw-w64DPOpt ]; then
mkdir -p $WM_PROJECT_DIR/platforms/linux64mingw-w64DPOpt
else
echo "$WM_PROJECT_DIR/platforms/linux64mingw-w64DPOpt exists"
fi
if [ ! -L $WM_PROJECT_DIR/platforms/linux64GccDPOpt ]; then
ln -s $WM_PROJECT_DIR/platforms/linux64mingw-w64DPOpt $WM_PROJECT_DIR/platforms/linux64GccDPOpt
else
echo "symlink $WM_PROJECT_DIR/platforms/linux64mingw-w64DPOpt already exists"
fi
cd $WM_PROJECT_DIR/src;
./testMake
./Allwmake
# Pass 1 - setSet fails in Pass 1
cd $WM_PROJECT_DIR;./Allwmake
# Build setSet Manually
cd $WM_PROJECT_DIR/applications/utilities/mesh/manipulation/setSet;./Allwmake NO_READLINE
# Pass 2 - everything builds correctly.
cd $WM_PROJECT_DIR;./Allwmake
echo "Making tar ..."
maketar
echo "Build ended at :"
date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.