-----------------------------------------------------------------------------

BUILDING WITH MICROSOFT VISUAL C++

Mercury has been ported to use the Microsoft Visual C++ compiler.
It has been tested with both version 9.0 (2008) and version 10.0 (2010).
Version 8.0 (2005) should also work but we have not tested that with 
Mercury recently.

-----------------------------------------------------------------------------

SETTING UP THE BUILD ENVIRONMENT

A Unix-like environment is required for building and installing Mercury.
Either Cygwin <http://www.cygwin.com/> or MSYS <http://www.mingw.org/> will
suffice for this purpose.

A Unix-like environment is *not* required in order to use Mercury once it
has been installed.

To make MSVC and its supporting tools available under the Cygwin or MSYS shells
do the following:

(1) Open the Windows Command Prompt.
    (Start -> All Programs -> Accessories -> Command Prompt on Windows XP)
    (Start -> Accessories -> Command Prompt on Windows 7)

(2) Enter the following command:

       C:\> "%VS90COMNTOOLS%"\vsvars32.bat
    
    This command sets up the environment for MSVC version 9.0 (2008).
    For MSVC version 10.0 (2010) the corresponding environment variable
    is VS100COMNTOOLS.

(3) Enter the following command to start the MSYS shell:

        C:\> C:\MinGW\MSYS\1.0\msys.bat 

    or this one to start the Cygwin shell:
    
        C:\> C:\CYGWIN\cygwin.bat

(We assume the default installation locations for MinGW/MSYS and Cygwin above.)

In order to install the C#, Erlang or Java grades you will require a C#,
Erlang or Java compiler to be included in the Windows PATH.
(See the relevant README files for further details, e.g. README.Java etc)

-----------------------------------------------------------------------------

CONFIGURATION AND INSTALLATION

The MSVC port of Mercury is compatible with the prebuilt C files contained in
the Mercury source distribution.  The 'asm_fast' and 'reg' grades will not work
with MSVC (see below).  When using the prebuilt C files the compiler will be
built in the 'none.gc' grade.

Alternatively, if you have an existing Mercury installation that uses the MinGW
or Cygwin GCC ports, or clang then you can checkout the Mercury source from the
CVS repository and use your existing installation to cross-compile the MSVC
port.  In this case the compiler will be built using the more efficient
'hlc.gc' grade.

In either case, to use MSVC as the C compiler with Mercury, invoke configure
as follows:

    $ ./configure --with-cc=cl [--with-msvcrt] [<any other options>]

The `--with-msvcrt' flag causes executables built with this install of Mercury
to be linked with the MS Visual C runtime, instead of the standard libC
runtime.

On Cygwin, configure and mmake will do translation of Unix style paths, so you
may specify the installation directory using either a Unix- or Window-style
path.  On MSYS, you must use a full Windows-style path with a drive letter,
except that you must use '/' instead of `\' as a directory separator.
For example, this is acceptable:

    $ ./configure --prefix="c:/where/to/install/mercury"

whereas the following is not:

    $ ./configure --prefix="c:\where\to\install\mercury"

Once configure has successfully finished, then you should do

    $ make 
    $ make install

as normal.

-----------------------------------------------------------------------------

LIMITATIONS

The MSVC port currently has a number of limitation:

* The 'asm_fast' and 'reg' grades do not work with MSVC.
  Both use GNU extensions to C that MSVC does not provide.

* Time profiling does not (currently) work with MSVC.
  Time profiling grades (those whose name contains the 'prof' grade component)
  will not be installed.

  Note that memory profiling _does_ work with MSVC.  (Memory profiling grades
  are those whose name contains the 'memprof' grade component.)

* Parallel grades (those whose name contains the `par' component) do not
  currently work with MSVC.

  In parallel grades the Mercury runtime currently requires the use of POSIX
  threads; it has not currently been ported to use Windows threads.
  (It might be possible to use the pthreads-win32 library with MSVC to
  provide POSIX threads but we have not tested that yet.) 

* Deep profiling, e.g. the *.profdeep grades, does not (currently) work
  with MSVC.  (In principle, it should work if the clock tick metric is
  disabled.)

* The deep profiling tool (mdprof_cgi) does not currently work with MSVC.
  This is due to it containing a number of Unix dependencies.  (Other
  tools that work with deep profiles should be fine.)

* Mercury has not yet been ported to 64-bit Windows.

* When used directly from the Windows command prompt, mmake will not work.
  You should use `mmc --make' instead.  (mmake requires a POSIX-like shell
  and GNU make; it will however work with the Cygwin or MSYS shells.)

  Note that we have no intention of ever supporting mmake directly on
  Windows.

* Creation of shared libraries (DLLs) is not currently supported.

-----------------------------------------------------------------------------

POST-INSTALLATION CONFIGURATION

The above instructions create a Mercury installation that targets MSVC that
works from within the Cygwin or MSYS shells.  If you want to be able to run the
Mercury compiler directly from the Windows command prompt (e.g. cmd.exe)
then you need to manually edit some configuration files in the installation.
(In future releases, this will all hopefully be automated.)

All references to files in the following are within the Mercury installation
directory

* By default, the Mercury compiler will attempt to use the "cp" command to
  install files.  Since Windows does not provide this, you will need to provide
  an alternative (see the next section for details of how to do this).

  We recommend installing the UnxUtils port of "cp" and using that with
  Mercury.  See: <http://sourceforge.net/projects/unxutils/>.

* In the file lib/mercury/conf/Mercury.config:
   
  + Replace any Unix-style paths with their Windows-style equivalent. 

  + Add the following option in the value of the variable DEFAULT_MCFLAGS
 
    --env-type windows

  + To specify the commands used to install files and directories include
    the following options in the value of the variable DEFAULT_MCFLAGS
    
    --install-command <cp>
    --install-command-dir-option <opt>

    (NOTE: if you are using the UnxUtils port of "cp" then you don't need to
    do anything here; the default settings will suffice.)

* In the file lib/mercury/mdb/mdbrc

  + The backslash character, `\`, is used as an escape character in mdbrc
    files.  You need to escape it if it occurs in any paths used in argument
    of source commands, e.g.

        source c:\mercury-11.07\lib\mercury\mdb\mdb_doc

    needs to be replaced with:

        source c:\\mercury-11.07\\lib\\mercury\\mdb\\mdb_doc

  + Delete the aliases for the "open" and "grep" commands.
    The scripts that implement these commands assume a Unix-style environment.

* The bin directory contains batch files equivalent to the mmc, mdb and prof
  scripts.  Note that the batch file equivalent to the mmc script is named
  mercury.bat in order to avoid clashing with the executable for the
  Microsoft Management Console.

* The following scripts do not currently have a Windows equivalent.

    + mprof_merge_runs
    + mtc

* The other shell scripts in the bin directory do not have (or need) Windows
  equivalents.  (Most of them are part of the implementation of mmake which
  is not supported on Windows systems.)

-----------------------------------------------------------------------------

INSTALLING ON NETWORK DRIVES (Cygwin only)

If you want to install on the machine, foo, in the directory \usr\local
you need to add `--prefix //foo/usr/local' as an option to configure.

Then ensure that the directory that you wish to install into is mounted
somewhere, i.e.

	mount //foo/usr/local /temp_mount_point

and then use that mount point as the location to install into

	make install INSTALL_PREFIX=/temp_mount_point

This avoids the problem that

        mkdir -p //foo/usr/local/xxx

fails.

-----------------------------------------------------------------------------
