Instructions for getting Mercury 0.10.1 to run under MacOSX. Written by Roy Ward Additions by Richard Hagen 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) (richard) Compilation with the default flags is infeasibly slow. Selecting -no-cpp-precomp when using gcc removes much of the slowness. Summary of issues: ================== - configuration information - gcc vs. cc - patches for MR_Word and other symbol problems - library issues - -no-cpp-precomp 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 richard% diff -u -d gcconfig.h.orig gcconfig.h --- gcconfig.h.orig Mon Sep 10 13:34:46 2001 +++ gcconfig.h Mon Sep 10 13:35:02 2001 @@ -17,6 +17,8 @@ # define GCCONFIG_H +#define macosx + /* Machine dependent parameters. Some tuning parameters can be found */ /* near the top of gc_private.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 runtime/mercury_bootstrap.h, about line 31, add #define MR_NO_BACKWARDS_COMPAT above the #ifdef MR_NO_BACKWARDS_COMPAT richard% diff -u -d mercury_bootstrap.h.orig mercury_bootstrap.h --- mercury_bootstrap.h.orig Mon Sep 10 13:36:54 2001 +++ mercury_bootstrap.h Mon Sep 10 13:37:17 2001 @@ -28,6 +28,7 @@ ** but you can disable it by defining MR_NO_BACKWARDS_COMPAT. */ +#define MR_NO_BACKWARDS_COMPAT #ifndef MR_NO_BACKWARDS_COMPAT #define r1 MR_r1 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). richard% diff -u -d ml.in.orig ml.in --- ml.in.orig Mon Sep 10 13:42:04 2001 +++ ml.in Mon Sep 10 13:42:55 2001 @@ -91,6 +91,10 @@ # `gcc -s' is broken in gnu-win32 strip=false ;; + *-apple-darwin*) + # -s not implemented on Darwin? + strip=false + ;; *) strip=true ;; 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: (richard: Some of these problems might be an artefact of the cpp-precomp phase. The preprocessor used isn't compatible with some gcc extensions.) 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) Patch the scripts/mgnuc file. The -no-cpp-precomp turns off a lot of the slowness. richard% diff -u -d mgnuc.in.orig mgnuc.in --- mgnuc.in.orig Mon Sep 10 13:55:43 2001 +++ mgnuc.in Mon Sep 10 13:56:59 2001 @@ -389,6 +389,9 @@ ;; esac ;; + *-apple-darwin*) + GCC_OPTS="$GCC_OPTS -no-cpp-precomp" + ;; esac # 9) (richard) Build the system % CFLAGS=-no-cpp-precomp ./configure --disable-most-grades You should be using the Bourne shell (/bin/sh) or something compatible to get the above incantation to work. I've chosen to "install only the most essential versions of the library" (--disable-most-grades). % make (Wait a while...) In order to install in the default directories, you need to have set a root password. Most users will have done this during Mac OS 9 setup (under the guise of setting a machine password). It can also be set after booting from the Mac OS X installation CD. % su Password: # make install (Wait a while longer...) 9) After I compiled and installed Mercury, I found that I had to ranlib a few libraries. I was prompted for this. (richard: this hasn't happened to me yet.) 10) (richard) Compilation times on a 333 MHz iMac with 160 MB RAM running Mac OS X 10.0.4 (4Q12): make start: Mon Sep 10 16:45:02 EST 2001 make end/ make install start: make install end: Slow, yes, but a tad less than 2 days that it used to take. The machine doing the build was being used normally at the same time. The grades installed were (from configure.log): using `GRADE=none.gc' to compile the compiler using `DEFAULT_GRADE=none.gc' as the default grade for applications using `LIBGRADES= none.gc.tr.debug hlc.gc ' as the set of library grades to install These could be slimmed down further with the --enable-libgrades option at the configure stage. We're stuck with these grades (none*, hlc*) due to issues with gcc labels and global registers. 11) A copy of the mercury-compiler-0.10.1 source, with the correct config.* files and the above patches applied can be found at: http://www.richardhagen.org/~richard/downloads/mercurycompiler-0.10.1-macosx.tar.gz