Mercury on macOS
================

This file documents the port of Mercury to Mac OS X / OS X / macOS,
i.e. the `*-apple-darwin*` configuration. 

Versions of Mac OS X prior to 10.9 are not supported.

Contents
--------

* Mercury on Intel Macs
* Note for users of Xcode 11
* Deployment Target Settings
* Deep profiling on Mac OS X

Mercury on Intel Macs
----------------------

Mercury should build and install "out-of-the-box" on Intel and Apple Silicon
Macs using Mac OS X 10.9 onwards.

The `asm_fast*` and `reg*` grades are only available on 64-bit Intel systems
and only when using GCC version 4.3 or later as the C compiler.

If `clang` is being used as the C compiler, then the only low-level C grades
available are the `none*` grades.  The high-level C, Java, and C# grades
all work. The C# grades require the Mono .NET implementation.
(See README.CSharp for further details.)

If the `asm_fast.gc` grade is not available, and unless otherwise directed,
then the `hlc.gc` grade will be used as the default grade for compiling
applications.

On x86-64 machines, the default is to install 64-bit versions of the
executables and libraries in the Mercury system.  On machines running versions
of MacOS up to and including 10.14, users can choose to install 32-bit versions
instead by invoking Mercury's `configure` script either with the option

    --with-cc="clang -m32"

or

    --with-cc="gcc -m32"

depending on their preferred compiler. In either case, every invocation
of the selected C compiler on Mercury-generated C files will specify
the `-m32` option. The reason for the limitation to 10.14 is that
32-bit executables are not supported at all from MacOS 10.15 onwards.

If, after installing Mercury, you encounter errors about missing `.mih` files,
and you have fink installed, then try removing the fink components from your
`PATH` (these usually start with `/sw`) and reinstalling.

Note for users of Xcode 11
--------------------------

Versions of Xcode 11 prior to 11.4 ship with a broken version of `clang`
that *cannot* be used to compile Mercury.  The `configure` script will print
a warning if it detects that you are using the broken version.

A discussion of this issue can be found at
<https://forums.developer.apple.com/thread/121887>.    
The github post
<https://github.com/Mercury-Language/mercury/issues/88#issuecomment-624329679>
describes a way that has been found to fix the problem.

Deployment Target Settings
--------------------------

By default, the Mercury compiler is configured so that the Mac OS X deployment
target (i.e. the value of the `MACOSX_DEPLOYMENT_TARGET` environment variable)
for code generated by the Mercury compiler is set to the same version as that
of the host system.

You can specify a different deployment target at configuration time using
the `configure` script's `--with-macosx-deployment-target` option.

(See the "SDK Compatibility Guide" in the Apple developer documentation
for further information about the deployment target setting.)

Deep profiling on Mac OS X
--------------------------

The Mercury deep profiler requires a local web server.  To use the deep
profiler:

- select and install a web server, and
- install and enable the `mdprof_cgi` script according to the rules of that
  web server.
