########################################################################
# HOW TO INSTALL A CROSS-COMPILING (LINUX -> MS) G++ COMPILER 
########################################################################
This file is supposed to live in 

    sanity@lamarc.gs.washington.edu:cross-tools/cross-notes.txt

#########################################
# Where to put it

I installed stuff in the "sanity" user account on lamarc. You should be
able to read and use stuff there just by following the path

    /net/gs/vol1/home/sanity

If you want to make changes, you'll need the IT folks to give you sudo
access. Once that is done, you can log in this way:

    sudo -H -s -u sanity


#########################################
# Getting the packages

I used the link below as my starting point, though I've also built 
cross-compilers before, and can tell you that the correct thing to do
will likely change by the time you next wish to update the compilers

    http://www.blogcompiler.com/2010/07/11/compile-for-windows-on-linux/

I went to the mingw-64 sourceforge page here:

    http://sourceforge.net/projects/mingw-w64/files/

    and from there followed each of

    * Toolchains targeting Win64 > Personal Builds
    * Toolchains targeting Win32 > Personal Builds


Ending up with the following two tar files:

    mingw-w32-bin_x86_64-linux_20110510_sezero.tar.gz
    mingw-w64-bin_x86_64-linux_20110510_sezero.tar.gz

Note that the part that says 'x86_64-linux' refers to the machine
you will run the cross-compiler on. I chose lamarc.gs.washington.edu

I untar'd the packages and installed them under

    /net/gs/vol1/home/sanity/cross-tools

#########################################
# Using the compilers -- 64 bit lamarc.exe

I recommend that before you try to build lam_conv.exe (the windows
version of the converter gui), you first build the plain lamarc.exe
executable. This is because lam_conv.exe requires compiling wxWidgets,
which is typically more complicated than building lamarc.exe

Here are the steps I used to cross-compile a lamarc-only (no converter)
64-bit version of lamarc.exe on lamarc.gs.washington.edu

    # Step 1:
    # create a directory and check a new lamarc distribution out in it
    mkdir myBuildDir
    cd myBuildDIr
    export CVS_RSH=ssh
    export CVSROOT=/local/cvs
    cvs co -P lamarc

    # Step 2:
    # invoke modules to get a more modern default g++ compiler and
    # library. this is interesting -- we're not going to use the
    # resulting compiler for our code, but our compiler needs 
    # access to some of its libraries
    . /etc/profile.d/modules.sh
    module load modules modules-init modules-gs
    module load gmp mpfr/2.4.1 gcc

    # Step 3:
    # get the desired cross-compiler on our $PATH
    export CROSS_HOME=/net/gs/vol1/home/sanity/cross-tools/cross_win64
    export HOST_TYPE=x86_64-w64-mingw32
    export PATH=$CROSS_HOME/bin:$CROSS_HOME/$HOST_TYPE/bin/:$PATH

    # Step 4:
    # unfortunately, in order to make the modules command make everything
    # 'just work' for the typical user, several environment variables
    # are set which hose the cross-compiling process. these steps
    # undo that
    unset CC
    unset CPP
    unset CXX
    unset CPPFLAGS
    unset LDFLAGS

    # Step 5:
    # make sure the autotools-produced Makefiles are up-to-date
    # I used automake and autoconf
    # If you update to new versions, you may need to change these
    # directions as well as the Makefile.am and configure.ac files
    cd lamarc
    aclocal
    autoconf
    automake

    # Step 6:
    # configure and make the executable
    mkdir rel64
    cd rel64
    ../configure --disable-converter --host=$HOST_TYPE 
    make lamarc.exe

#########################################
# Using the compilers -- 32 bit lamarc.exe

To build a 32-bit windows executable, do as above, but replace steps 3
and 6 with these:

    # Step 3 for win-32
    export CROSS_HOME=/net/gs/vol1/home/sanity/cross-tools/cross_win32
    export HOST_TYPE=i686-w64-mingw32
    export PATH=$CROSS_HOME/bin:$CROSS_HOME/$HOST_TYPE/bin/:$PATH

    # Step 6 for win-32
    mkdir rel32
    cd rel32
    ../configure --disable-converter --host=$HOST_TYPE 
    make lamarc.exe


#########################################
# building wxWidgets-enabled lam_conv.exe

Once you have the the above working, you can try to cross-compile
lam_conv.exe . First make sure you have cross-compiled versions
of the wxWidgets library. See here:

    sanity@lamarc.gs.washington.edu:wx-libs/wx-notes.txt

Assuming things are cool there, here's the instructions for
a 64-bit lam_conv.exe on lamarc.gs.washington.edu

    # modules as above
    . /etc/profile.d/modules.sh
    module load modules modules-init modules-gs
    module load gmp mpfr/2.4.1 gcc

    # get the desired cross-compiler on our $PATH
    export CROSS_HOME=/net/gs/vol1/home/sanity/cross-tools/cross_win64
    export HOST_TYPE=x86_64-w64-mingw32
    export PATH=$CROSS_HOME/bin:$CROSS_HOME/$HOST_TYPE/bin/:$PATH

    # remove unfortunate modules side-effects
    unset CC
    unset CPP
    unset CXX
    unset CPPFLAGS
    unset LDFLAGS

    # configure for compilation with wxWidgets cross-compiled library
    cd <path to lamarc checkout>

    export WX_LIB=/net/gs/vol1/home/sanity/wx-libs/
    mkdir wxRel64
    cd wxRel64
    ../configure --host=$HOST_TYPE \
        --with-wx-config=/net/gs/vol1/home/sanity/wx-libs/wxMSW/bin/wx-config
    make lam_conv.exe


# and now the same for 32 bits

    # modules as above
    . /etc/profile.d/modules.sh
    module load modules modules-init modules-gs
    module load gmp mpfr/2.4.1 gcc

    # get the desired cross-compiler on our $PATH
    export CROSS_HOME=/net/gs/vol1/home/sanity/cross-tools/cross_win32
    export HOST_TYPE=i686-w64-mingw32
    export PATH=$CROSS_HOME/bin:$CROSS_HOME/$HOST_TYPE/bin/:$PATH

    # Step 4:
    # remove unfortunate modules side-effects
    unset CC
    unset CPP
    unset CXX
    unset CPPFLAGS
    unset LDFLAGS

    # configure for compilation with wxWidgets cross-compiled library
    cd <path to lamarc checkout>

    export WX_LIB=/net/gs/vol1/home/sanity/wx-libs/
    mkdir wxRel32
    cd wxRel32
    ../configure --host=$HOST_TYPE \
        --with-wx-config=/net/gs/vol1/home/sanity/wx-libs/wxMSW/bin/wx-config
    make lam_conv.exe


