public
Created

Build Script for cross-compiling OpenFOAM 2.1.x for Windows

  • Download Gist
build.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.