### OpenFlow Build Process

To build OpenFOAM® for Windows with a cross-compiler requires expert knowledge of Windows and Linux utilities and compilers.

Instructions based on "OpenFOAM 2.1.x on Windows 64-bit with MS MPI"

The following steps are required to produce a native Windows version of OpenFOAM 2.1.x 64-bit with [optional] native Windows MS MPI:

1. Install MinGW-w64 cross-compiler and zlib on Linux
2. Install zlib files into following locations:
   - `<mingw-w64>/x86_64-w64-mingw32/include/zconf.h`
   - `<mingw-w64>/x86_64-w64-mingw32/include/zlib.h`
   - `<mingw-w64>/bin/zlib1.dll`
   - `<mingw-w64>/x86_64-w64-mingw32/lib/libz.a`
   - `<mingw-w64>/x86_64-w64-mingw32/lib/libzdll.a`
3. If you see an error while compiling like:
   `signals/sigFpe.C:45:15: error: '_clearfp' was not declared in this scope`
   You need to add `#include_next <float.h>` to the end of
   `<mingw-w64>/lib/gcc/x86_64-w64-mingw32/<gcc-version>/include/float.h` and remove it from
   `<mingw-w64>/x86_64-w64-mingw32/include/float.h` to include the right float.h
4. [optional] Create libmsmpi.a from Microsoft MPI Redistributable
5. At various stages during this process you will need to set OpenFOAM MinGW-w64 environment variables and source etc/bashrc. As an example:
   `export FOAM_INST_DIR="$(HOME)/projects/of/2.1"; source $(FOAM_INST_DIR)/OpenFOAM-2.1.x/etc/bashrc WM_OSTYPE=MSwindows WM_COMPILER=mingw-w64 WM_ARCH_OPTION=64 WM_PRECISION_OPTION=SP WM_CC=x86_64-w64-mingw32-gcc WM_CXX=x86_64-w64-mingw32-g++ compilerInstall=system [optional] WM_MPLIB=MSMPI [optional] MPI_ARCH_PATH="$(HOME)/projects/msmpi/install"`
6. [optional] Build scotch (in WM_THIRD_PARTY_DIR = ThirdParty-2.1.x) according to:
   1. `ln -s $(WM_THIRD_PARTY_DIR)/scotch<version> $(WM_THIRD_PARTY_DIR)/scotch`
   2. `ln -s $(WM_PROJECT_DIR)/extra/scotch/src/Make.inc/Makefile.inc.mingw-w64 $(WM_THIRD_PARTY_DIR)/scotch/src/Makefile.inc`
   3. `cp $(WM_PROJECT_DIR)/extra/scotch/src/libscotch/* $(WM_THIRD_PARTY_DIR)/scotch/src/libscotch/.`
   4. `cd $(WM_THIRD_PARTY_DIR)/scotch/src`
   5. `cp $(WM_PROJECT_DIR)/extra/scotch/src/Makefile .`
   6. `make libscotch`
   7. `mkdir -p $(FOAM_LIBBIN)`
   8. `cd $(WM_THIRD_PARTY_DIR)/scotch/src/libscotch`
   9. `cp libscotch.* $(FOAM_LIBBIN)`
7. To build OpenFOAM:
   1. source the OpenFOAM native linux environment variables
   2. `cd $(WM_PROJECT_DIR)/wmake/src; make`
   3. `ln -s $(WM_PROJECT_DIR)/wmake/platforms/linux64Gcc $(WM_PROJECT_DIR)/wmake/platforms/linux64mingw-w64`
   4. source the OpenFOAM MinGW-w64 environment variables
   5. `cd $(WM_PROJECT_DIR);./Allwmake`
8. Transfer the OpenFOAM etc directory ($(WM_PROJECT_DIR)/etc), executables ($(WM_PROJECT_DIR)/platforms/linux64mingw-w64*/bin/*.exe), and libraries ($(WM_PROJECT_DIR)/platforms/linux64mingw-w64*/lib/*.dll and $(WM_PROJECT_DIR)/platforms/linux64mingw-w64*/lib/*/*.dll) to the Windows computer
9. Transfer the MinGW-w64 libraries:
   - `<mingw-w64>/bin/zlib1.dll`
   - `<mingw-w64>/bin/libgcc_s_sjlj-1.dll`
   - `<mingw-w64>/bin/libstdc++-6.dll`

   to the Windows computer

10. On the Windows computer ensure the following environment variables are set:
    - The WM_PROJECT_DIR and USERNAME variables are set.
    - The PATH variable is set to include the OpenFOAM executable and library locations (including $(WM_PROJECT_DIR)/lib/linux64mingw-w64*/dummy or [optional] $(WM_PROJECT_DIR)/lib/linux64mingw-w64*/msmpi).

OpenFOAM is a registered trademark of OpenCFD and is unaffiliated with Symscape