[mercury-users] Mac OS X Compilation HOWTO

Roy Ward roy at videoscript.com
Mon Apr 16 08:24:41 AEST 2001


Instructions for getting Mercury 0.10.1 to run under MacOSX.
Written by Roy Ward <roy at videoscript.com>

Revised from an earlier document about porting Mercury 0.9.1 to
Darwin.

Much thanks to Fergus Henderson, Tyson Dowd and Terrence Brannon
for help and some of this information.

This is a little verbose, but better too much information that too
little.

Some Caveats: 
============= 

1) This has only been tested with Mercury release 0.10.1.
2) This has only been tested with the first release of MacOSX (10.0?)
3) These changes are all hacks - there are certainly better ways of doing
things. These changes will also break the code for any other platform.
4) At least one of these changes need to be done _before_ the ./configure.
Have a look right through these before doing them.
5) Grade asm_fast.gc is not supported on PowerPC - I've found hlc.gc to
be best to use. 
6) I think things such as shared libraries and library stripping are
disabled - code is pretty bloated.
7) Compiling Mercury on OSX is _SLOW_. The install took about 2 _days_
on my G3/233. You might wanto to remove some grades - I found that
none.gc.tr.debug was the real time killer.

Summary of issues: 
================== 
- configuration information
- gcc vs. cc
- patches for MR_Word and other symbol problems
- library issues. 

On with the hacks: 
================== 

1) get recent versions of config.sub and config.guess

cp /usr/libexec/config.* .

This is so that the configure command knows what platform we are on

2) The garbage collector needs to be told separately which platform we are
on. Recent versions of the boehm gc know about this, but the version that
Mercury uses doesn't, so a hack for this is to add the line

#define macosx 

somewhere near the top of boehm_gc/gcconfig.h

[ 3) There was an issue with libm.a and Darwin 1.0 with mercury 0.9.1,
this has been resolved with either MacOSX or Mercury 0.10.1]

4) There is no gcc in OSX - it's called cc (but is still actually gcc,
just with a different name). Mercury mostly autodetects, but one place
got missed.

EITHER:

create a symbolic link from gcc to cc in /usr/bin,

OR:

Change gcc to cc in the definition SHARED_LIBS (about line 38) of
scripts/ml _after the ./configure. (I don't know how to do this
before the ./configure).

5) There is a symbol conflict with r0..r31 between Mercury and some of
the MacOSX libraries, the fix is to not define the symbols in Mercury.

In mercury_bootstrap.h, about line 31, add

#define MR_NO_BACKWARDS_COMPAT

above the 

#ifdef MR_NO_BACKWARDS_COMPAT

6) I'm not sure how Darwin handles library stripping, but it didn't like
the -s on about line 950 of scripts/ml. The fix for this is to change
ml.in, about line 95 _before_ the ./configure (or scripts/ml afterwards).
Change:

strip=true

to

strip=false

7a) There's a patch which has I think now been committed to the
Mercury source for later versions:

Index: runtime/mercury_heap.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_heap.h,v
retrieving revision 1.20
diff -u -d -r1.20 mercury_heap.h
--- runtime/mercury_heap.h    2001/02/21 05:53:43    1.20
+++ runtime/mercury_heap.h    2001/04/08 07:03:20
@@ -179,14 +179,14 @@
             proclabel, (type))
 #define    MR_incr_hp_type(dest, typename)                    \
         do {                            \
-            Word    tmp;                    \
+            MR_Word    tmp;                    \
             MR_tag_incr_hp(tmp, MR_mktag(0),        \
                 (MR_bytes_to_words(sizeof(typename))));    \
             (dest) = (typename *) tmp;            \
         } while (0)
 #define    MR_incr_hp_type_msg(dest, typename, proclabel, type)        \
         do {                            \
-            Word    tmp;                    \
+            MR_Word    tmp;                    \
             MR_tag_incr_hp_msg(tmp, MR_mktag(0),        \
                 (MR_bytes_to_words(sizeof(typename))),    \
                 proclabel, (type));            \

7b) Some more patches, at least some of these to workaround
bugs in gcc on OSX:

Index: mercury_trace.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.c,v
retrieving revision 1.40
diff -u -d -u -r1.40 mercury_trace.c
--- mercury_trace.c    2001/03/07 08:00:00    1.40
+++ mercury_trace.c    2001/04/08 09:10:27
@@ -170,7 +170,7 @@
         case MR_CMD_COLLECT:
           {
                 MR_Event_Info    event_info;
-            Word        *saved_regs = event_info.MR_saved_regs;
+            MR_Word        *saved_regs = event_info.MR_saved_regs;
             int        max_r_num;
             const char    *path;
             bool        stop_collecting = FALSE;

Index: mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.55
diff -u -d -u -r1.55 mercury_trace_external.c
--- mercury_trace_external.c    2001/03/18 23:10:16    1.55
+++ mercury_trace_external.c    2001/04/09 03:41:28
@@ -156,7 +156,7 @@
 */
 #ifdef __GNUC__
   #define MR_LIKE_PRINTF(format_argnum, vars_argnum) \
-    __attribute__ ((format (printf, (format_argnum), (vars_argnum))))
+    __attribute__ ((format (printf, format_argnum, vars_argnum)))
 #else
   #define MR_LIKE_PRINTF(n, m) /* nothing */
 #endif

Index: mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.87
diff -u -d -u -u -5 -r1.87 mercury_wrapper.c
--- mercury_wrapper.c    2001/03/28 08:18:11    1.87
+++ mercury_wrapper.c    2001/04/12 05:32:35
@@ -274,19 +274,21 @@
     ** and we need to preserve them, because they're callee-save,
     ** and our caller may need them ;-)
     */
     MR_save_regs_to_mem(c_regs);
 
+#if 0
     /*
     ** XXX Ensure that we link in atexit().
     ** XXX This works around a bug in gcc 2.95.3 (prerelease) and/or
     ** libc 2.2.2 on Debian Linux, where we'd get a link error when
     ** building libmer_rt.so with --no-undefined, due to a reference
     ** to atexit() from crtendS.o, which gets linked last, after any
     ** libraries such as `-lc'.
     */
     MR_global_pointer = (void *) atexit;
+#endif
 
 #if defined(MR_LOWLEVEL_DEBUG) || defined(MR_TABLE_DEBUG)
     /*
     ** Ensure stdio & stderr are unbuffered even if redirected.
     ** Using setvbuf() is more complicated than using setlinebuf(),

8) Now do the ./configure.

MacOSX doesn't support su 'out of the box' so you might have trouble
getting privileges do the install. I used

./configure --prefix <somewhere in user space>

to do an install I didn't need root permission to get at.

9) After I compiled and installed Mercury, I found that I had to ranlib a
few libraries. I was prompted for this.

Email me roy at videoscript.com about any feedback about this. Usually in
the past, I would have taken a fresh copy of the Mercury source, followed
the instructions and done a reinstall - but I don't have another 2 days
to do it this time. Have I left anything out?

Good luck, 
Roy Ward. 

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list