[m-rev.] for review: implement ml and c2init in the compiler

Simon Taylor stayl at cs.mu.OZ.AU
Thu Jan 30 17:50:15 AEDT 2003


Estimated hours taken: 25
Branches: main

Implement the ml and c2init scripts in the compiler to
reduce dependencies on Cygwin.

compiler/compile_target_code.m:
	Implement the functionality of ml and c2init, rather than
	calling those scripts.

	Handle all compiler dependencies using options, rather than
	testing for particular compilers here.

compiler/options.m:
NEWS:
doc/user_guide.texi:
	Add options which implement functionality which is part
	of ml, c2init or mgnuc when using Mmake:
	--warn-target-code, --output-link-command,
	--output-shared-lib-link-command, --ansi-c, 
	--no-strip, --no-demangle, --no-main,
	--allow-undefined, --use-readline, --runtime-flags,
	--extra-inits.

	Add options to describe the C compiler and linker, for
	use by configure/mmc.

	The `--ml-flags' (`--link-flags') option has been removed.

compiler/options_file.m:
	Remove the MLFLAGS variable.

compiler/handle_options.m:
	`--target-debug' implies `--no-strip'.

	Add the path to the GC libraries to the library search paths.

compiler/mercury_compile.m:
	Handle --output-link-command and --output-shared-lib-link-command.

compiler/passes_aux.m:
	Add a variant of invoke_shell_command which takes a second
	command to process the first command's output. This is used
	by compile_target_code.m to invoke the demangler.

configure.in:
scripts/mmc.in:
	Handle extra default options.

scripts/c2init.in:
scripts/ml.in:
	Document that the code here is duplicated in
	compiler/compile_target_code.m.	

Mmake.workspace:
browser/Mmakefile:
compiler/Mercury.options:
compiler/Mmakefile:
library/Mmakefile:
	Pass `-R' options pointing to the installation directories
	to mmc, as we already do for ml.

Index: Mmake.workspace
===================================================================
RCS file: /home/mercury1/repository/mercury/Mmake.workspace,v
retrieving revision 1.10
diff -u -u -r1.10 Mmake.workspace
--- Mmake.workspace	2 Jan 2003 06:53:51 -0000	1.10
+++ Mmake.workspace	23 Jan 2003 07:15:51 -0000
@@ -73,9 +73,9 @@
 # have just a ".init" suffix. (The trace library does not have a .init file,
 # since it contains no Mercury code.)
 #
-# If you change these, you will also need to change scripts/ml.in,
-# scripts/c2init.in, tools/bootcheck, tools/binary, tools/binary_step
-# and tools/linear.
+# If you change these, you will also need to change
+# compiler/compile_target_code.m, scripts/ml.in, scripts/c2init.in,
+# tools/bootcheck, tools/binary, tools/binary_step and tools/linear.
 RT_LIB_NAME = mer_rt
 STD_LIB_NAME = mer_std
 TRACE_LIB_NAME = mer_trace
@@ -196,10 +196,12 @@
 		-L$(LIBRARY_DIR) -L$(TRACE_DIR) -L$(BROWSER_DIR)
 
 MLFLAGS +=	$(LIB_DIR_OPTS)
+MCFLAGS +=	$(LIB_DIR_OPTS)
 MLLIBS +=	$(LINK_LIB_OPTS)
 
 ifeq ($(SET_RPATH),yes)
 MLFLAGS += $(LIB_DIR_OPTS:-L%=-R%)
+MCFLAGS += $(LIB_DIR_OPTS:-L%=-R%)
 endif
 
 endif # LINK_STATIC != yes
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.349
diff -u -u -r1.349 configure.in
--- configure.in	28 Jan 2003 01:53:56 -0000	1.349
+++ configure.in	28 Jan 2003 13:50:53 -0000
@@ -512,6 +512,8 @@
 
 AC_CHECK_PROG(CYGPATH, cygpath, cygpath -w, echo)
 
+LDFLAGS_FOR_TRACE=
+LD_LIBFLAGS_FOR_TRACE=
 if test "$ac_microsoft" = "yes" ; then
 	# Use MS-style file names and command-line options
 	OBJ_SUFFIX="obj"
@@ -526,6 +528,9 @@
 	ARFLAGS=""
 	AR_LIBFILE_OPT="/OUT:"
 
+	LDFLAGS_FOR_DEBUG="/DEBUG"
+	LD_LIBFLAGS_FOR_DEBUG="/DEBUG"
+
 	USING_MICROSOFT_CL_COMPILER="yes"
 
 	case "$CYGPATH" in "echo")
@@ -550,6 +555,21 @@
 	ARFLAGS="cr"
 	AR_LIBFILE_OPT=""
 
+	LDFLAGS_FOR_DEBUG="-g"
+	LD_LIBFLAGS_FOR_DEBUG="-g"
+
+	#
+	# On Linux ELF, `-rdynamic' is needed to make symbols
+	# exported for use in code linked in with dlopen(),
+	# which is used for interactive queries in the
+	# Mercury debugger.
+	#
+	case $FULLARCH in
+		*-linux*aout) ;; # no special options needed
+		*-linux*)
+			LDFLAGS_FOR_TRACE="-rdynamic" ;;
+	esac
+
 	USING_MICROSOFT_CL_COMPILER="no"
 
 	FIX_PATH_FOR_CC=echo
@@ -574,6 +594,10 @@
 AC_SUBST(AR)
 AC_SUBST(ARFLAGS)
 AC_SUBST(AR_LIBFILE_OPT)
+AC_SUBST(LDFLAGS_FOR_DEBUG)
+AC_SUBST(LD_LIBFLAGS_FOR_DEBUG)
+AC_SUBST(LDFLAGS_FOR_TRACE)
+AC_SUBST(LD_LIBFLAGS_FOR_TRACE)
 AC_SUBST(USING_MICROSOFT_CL_COMPILER)
 AC_SUBST(OBJ_SUFFIX)
 AC_SUBST(LIB_SUFFIX)
@@ -2048,24 +2072,43 @@
 # options to tell (a) the Mercury runtime & library
 # (b) the boehm collector and (c) the C library
 # that they need to be thread-safe.
+#
+# For Linux, Irix, Solaris, and HPUX,
+# the thread-enabled version of the Boehm
+# collector contains a reference to dlopen(), so
+# if threads are enabled, we need to link with the
+# appropriate extra library for that (-ldl on Linux
+# and Solaris, -lrt on HPUX, and nothing on Irix).
+# XXX That should only be done if conservative GC
+#     is enabled.
+#
+# Note that changes here may require changes in scripts/ml.in.
+LDFLAGS_FOR_THREADS=
+LD_LIBFLAGS_FOR_THREADS=
 case "$host" in
 	*solaris*)
 		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DSOLARIS_THREADS \
 			-D_SOLARIS_PTHREADS -DGC_SOLARIS_PTHREADS -D_REENTRANT"
+		THREAD_LIBS="-lpthread -ldl"
 		;;
 
 	*linux*)
-		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DLINUX_THREADS \
-			-D_THREAD_SAFE -D_REENTRANT"
 		# Note that for old versions of Linux / glibc,
 		# you may also need to make sure that you don't
 		# pass -ansi to gcc.
+		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DLINUX_THREADS \
+			-D_THREAD_SAFE -D_REENTRANT"
+		THREAD_LIBS="-lpthread -ldl"
 		;;
 
 	*cygwin*)
+		THREAD_LIBS=""
 		case "$CC" in
 			*cl* | *CL*)	# cl is the Microsoft C compiler
-				CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DWIN32_THREADS /MD" ;;
+				CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DWIN32_THREADS /MD"
+				LDFLAGS_FOR_THREADS="/MD"
+				LD_LIBFLAGS_FOR_THREADS="/MD"
+				;;
 			*)
 				CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE" ;;
 		esac
@@ -2078,13 +2121,21 @@
 ###	# XXX is this fixed in the Boehm collector now?
 ###	*-osf*)
 ###		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE"
+###		THREAD_LIBS="-lpthreads -lmach -lc_r"
 ###		;;
 
+###	# The threads stuff on HPUX is not yet enabled because
+###	# we don't have an HPUX box to test it on.
+###	*hpux*)    
+###		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE" # XXX incomplete
+###		THREAD_LIBS="-lpthread -lrt" ;;
+
 ###	# The threads stuff on IRIX is not yet enabled because
 ###	# we don't have an IRIX box to test it on.
 ###	# (XXX perhaps we should enable it anyway, so it is easier to test?)
 ###	*irix*)
 ###		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DIRIX_THREADS"
+###		THREAD_LIBS="-lpthread"
 ###		;;
 
 	*)	
@@ -2096,6 +2147,9 @@
 		;;
 esac
 AC_SUBST(CFLAGS_FOR_THREADS)
+AC_SUBST(THREAD_LIBS)
+AC_SUBST(LDFLAGS_FOR_THREADS)
+AC_SUBST(LD_LIBFLAGS_FOR_THREADS)
 
 #-----------------------------------------------------------------------------#
 
@@ -2646,8 +2700,12 @@
 
 # set up some default values that should work on most systems
 # see Mmake.common.in for documentation on the meaning of these variables
+LINK_EXE=$CC
+LD_STRIP_FLAG="-s"
 LINK_SHARED_OBJ="$CC -shared"
 LINK_SHARED_OBJ_SH="$CC -shared"
+LD_DEBUG_FLAGS="-g"
+LD_LIB_DEBUG_FLAGS="-g"
 if test "$GCC" = "yes"; then
 	SHARED_LIBS="\`$CC -print-libgcc-file-name\` \$(MATH_LIB) -lc"
 	SHARED_LIBS_SH="\`$CC -print-libgcc-file-name\` \$MATH_LIB -lc"
@@ -2712,6 +2770,8 @@
 			AC_MSG_RESULT(no)
 			;;
 		esac
+		# Shared libraries are not the default on x86 systems that
+		# use ELF -- see README.Linux
 		DEFAULT_LINKAGE=static
 		;;
 	m68*-linux|m68*-linux-gnu)
@@ -2886,6 +2946,116 @@
 esac
 
 #-----------------------------------------------------------------------------#
+# Note that changes here may require changes in scripts/mgnuc.in.
+
+case "$CC" in
+    *gcc*)
+	COMPILER=gcc
+	CFLAGS_FOR_ANSI="-ansi"
+
+	# For a full list of the other gcc warnings that we don't
+	# enable, and why, see scripts/mgnuc.in.
+	CFLAGS_FOR_WARNINGS="-Wall -Wwrite-strings -Wshadow -Wmissing-prototypes -Wno-unused -Wno-uninitialized -Wstrict-prototypes"
+
+	CFLAGS_FOR_OPT="-O2 -fomit-frame-pointer"
+	CFLAGS_FOR_DEBUG="-g"
+	MCFLAGS_FOR_CC=
+	;;
+    *lcc*)
+	COMPILER=lcc
+	CFLAGS_FOR_ANSI=
+
+	# turn off all warnings due to spurious warnings.
+	CFLAGS_FOR_WARNINGS="-w"
+
+	CFLAGS_FOR_OPT=
+	CFLAGS_FOR_DEBUG="-g"
+	MCFLAGS_FOR_CC=
+	;;
+    *cl* | *CL*)
+	COMPILER=cl
+	CFLAGS_FOR_ANSI=
+	CFLAGS_FOR_WARNINGS=
+	CFLAGS_FOR_OPT=
+	CFLAGS_FOR_DEBUG="/Zi"
+
+	# Using the MSVC compiler implies that we must use a maximum jump
+	# table size of 512 to avoid a fixed limit in the compiler.
+	MCFLAGS_FOR_CC="--max-jump-table-size 512"
+	;;
+    cc* | */cc*)
+	COMPILER=cc
+	CFLAGS_FOR_ANSI=
+	CFLAGS_FOR_OPT="-O"
+	CFLAGS_FOR_WARNINGS=
+	CFLAGS_FOR_DEBUG="-g"
+	MCFLAGS_FOR_CC=
+	;;
+    *)
+	COMPILER=unknown
+	CFLAGS_FOR_ANSI=
+	CFLAGS_FOR_OPT="-O"
+	CFLAGS_FOR_WARNINGS=
+	CFLAGS_FOR_DEBUG="-g"
+	MCFLAGS_FOR_CC=
+	;;
+esac
+
+AC_SUBST(CFLAGS_FOR_ANSI)
+AC_SUBST(CFLAGS_FOR_WARNINGS)
+AC_SUBST(CFLAGS_FOR_OPT)
+AC_SUBST(CFLAGS_FOR_DEBUG)
+AC_SUBST(MCFLAGS_FOR_CC)
+
+#-----------------------------------------------------------------------------#
+# Work out how to link statically.
+# Note that changes here may require changes in scripts/ml.in.
+
+LD_STATIC_FLAGS=
+case $COMPILER in gcc|lcc)
+	LD_STATIC_FLAGS=-static
+	;;
+esac
+case $FULLARCH in
+	*-linux*)
+		# On Linux, if we're linking statically, we need to
+		# pass `-defsym _DYNAMIC=0' to the linker, to avoid
+		# undefined references to _DYNAMIC in
+		# boehm_gc/dyn_load.c.
+		# (We might eventually need similar treatment
+		# for other OSs too)
+		case $COMPILER in
+		gcc)
+			LD_STATIC_FLAGS="-static \
+				-Wl-defsym -Wl_DYNAMIC=0"
+			;;
+		lcc)
+			LD_STATIC_FLAGS="-static \
+				-Wl,-defsym -Wl,_DYNAMIC=0"
+			;;
+		esac
+		;;
+	alpha*-dec-osf*)
+		case $COMPILER in cc)
+			LD_STATIC_FLAGS=-non_shared
+			;;
+		esac
+		;;
+	*-sun-solaris*)
+		case $COMPILER in cc)
+			LD_STATIC_FLAGS="-B static"
+			;;
+		esac
+		;;
+esac
+case "$LD_STATIC_FLAGS" in "")
+	AC_MSG_WARN(
+[\`mmc --linkage static' and \`ml --static' not implemented with
+****	this C compiler (\`$CC').])
+esac
+
+
+#-----------------------------------------------------------------------------#
 
 case "$host" in
 	*-cygwin*)
@@ -2898,6 +3068,10 @@
 
 #-----------------------------------------------------------------------------#
 
+AC_SUBST(LINK_EXE)
+AC_SUBST(LD_STRIP_FLAG)
+AC_SUBST(LD_STATIC_FLAGS)
+AC_SUBST(DEFAULT_LINKAGE)
 AC_SUBST(LINK_SHARED_OBJ)
 AC_SUBST(LINK_SHARED_OBJ_SH)
 AC_SUBST(ERROR_UNDEFINED)
@@ -3256,6 +3430,9 @@
 	# restore old value of LIBS
 	LIBS="$save_LIBS"
 fi
+
+TRACE_LIBS_SYSTEM="$SOCKET_LIBRARY $NSL_LIBRARY $DL_LIBRARY"
+AC_SUBST(TRACE_LIBS_SYSTEM)
 #-----------------------------------------------------------------------------#
 
 AC_MSG_CHECKING(whether to enable the new MercuryFile struct)
Index: browser/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/Mmakefile,v
retrieving revision 1.26
diff -u -u -r1.26 Mmakefile
--- browser/Mmakefile	20 Oct 2002 11:59:41 -0000	1.26
+++ browser/Mmakefile	23 Jan 2003 13:22:00 -0000
@@ -44,6 +44,8 @@
 CFLAGS	+=	$(DLL_CFLAGS) -I$(TRACE_DIR)
 MLFLAGS +=	-R$(FINAL_INSTALL_MERC_LIB_DIR)	\
 		-R$(FINAL_INSTALL_MERC_GC_LIB_DIR)
+MCFLAGS +=	-R$(FINAL_INSTALL_MERC_LIB_DIR)	\
+		-R$(FINAL_INSTALL_MERC_GC_LIB_DIR)
 MLLIBS +=	$(SOCKET_LIBRARY) $(NSL_LIBRARY) $(DL_LIBRARY)	\
 		$(READLINE_LIBRARIES)
 
Index: compiler/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mercury.options,v
retrieving revision 1.2
diff -u -u -r1.2 Mercury.options
--- compiler/Mercury.options	24 Nov 2002 06:03:32 -0000	1.2
+++ compiler/Mercury.options	23 Jan 2003 13:21:07 -0000
@@ -17,11 +17,17 @@
 # process_util.m uses `kill' and `struct sigaction' from <signal.h>,
 # which are not available with `--ansi'.
 MGNUCFLAGS-libs.process_util = --no-ansi
+
 # If intermodule optimization is enabled, we also need to use `--no-ansi'
 # for the following modules, because they import process_util.
 MGNUCFLAGS-make.module_dep_file = --no-ansi
 MGNUCFLAGS-make.module_target = --no-ansi
 MGNUCFLAGS-make.program_target = --no-ansi
+
+MCFLAGS-libs.process_util = --no-ansi-c
+MGFLAGS-make.module_dep_file = --no-ansi-c
+MCFLAGS-make.module_target = --no-ansi-c
+MCFLAGS-make.program_target = --no-ansi-c
 
 # The c_code in the module gcc.m needs the header files from the GNU C
 # distribution.
Index: compiler/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mmakefile,v
retrieving revision 1.64
diff -u -u -r1.64 Mmakefile
--- compiler/Mmakefile	23 Jan 2003 00:24:05 -0000	1.64
+++ compiler/Mmakefile	23 Jan 2003 00:40:11 -0000
@@ -48,7 +48,8 @@
 	cd $(GCC_SRC_DIR)/gcc && $(MAKE) mercury_gcc_backend_libs
 
 MCFLAGS +=	-I $(BROWSER_DIR) -I $(ANALYSIS_DIR) \
-			--c-include-directory $(ANALYSIS_DIR)
+			--c-include-directory $(ANALYSIS_DIR) \
+			--no-main --linkage shared
 CFLAGS +=	-I $(ANALYSIS_DIR)
 MLOBJS :=	../main.$O ../analysis/lib$(ANALYSIS_LIB_NAME).$A $(MLOBJS)
 ALL_MLLIBS =	$(MLLIBS) $(EXTRA_MLLIBS) $(GCC_BACKEND_LIBS)
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.35
diff -u -u -r1.35 compile_target_code.m
--- compiler/compile_target_code.m	24 Jan 2003 07:17:07 -0000	1.35
+++ compiler/compile_target_code.m	28 Jan 2003 08:08:29 -0000
@@ -377,16 +377,6 @@
 	globals__io_lookup_string_option(cc, CC),
 	globals__io_lookup_accumulating_option(cflags, C_Flags_List),
 	{ join_string_list(C_Flags_List, "", "", " ", CFLAGS) },
-	
-	{ string__sub_string_search(CC, "gcc", _) ->
-		CompilerType = gcc
-	; string__sub_string_search(CC, "lcc", _) ->
-		CompilerType = lcc
-	; string__sub_string_search(string__to_lower(CC), "cl", _) ->
-		CompilerType = cl
-	;
-		CompilerType = unknown
-	},
 
 	globals__io_lookup_bool_option(use_subdirs, UseSubdirs),
 	globals__io_lookup_bool_option(split_c_files, SplitCFiles),
@@ -551,19 +541,12 @@
 		StackTraceOpt = ""
 	},
 	globals__io_lookup_bool_option(target_debug, Target_Debug),
-	{ Target_Debug = yes ->
-		( CompilerType = gcc,
-			Target_DebugOpt = "-g "
-		; CompilerType = lcc,
-			Target_DebugOpt = "-g "
-		; CompilerType = cl,
-			Target_DebugOpt = "/Zi "
-		; CompilerType = unknown,
-			Target_DebugOpt = "-g "
-		)
+	( { Target_Debug = yes } ->
+		globals__io_lookup_string_option(cflags_for_debug,
+			Target_DebugOpt)
 	;
-		Target_DebugOpt = ""
-	},
+		{ Target_DebugOpt = "" }
+	),
 	globals__io_lookup_bool_option(low_level_debug, LL_Debug),
 	{ LL_Debug = yes ->
 		LL_DebugOpt = "-DMR_LOW_LEVEL_DEBUG "
@@ -595,50 +578,38 @@
 		TypeLayoutOpt = ""
 	},
 	globals__io_lookup_bool_option(c_optimize, C_optimize),
-	{ C_optimize = yes ->
-		( CompilerType = gcc ->
-			OptimizeOpt = "-O2 -fomit-frame-pointer "
-		; CompilerType = lcc ->
-			OptimizeOpt = ""
-		;
-			OptimizeOpt = "-O "
-		)
+	( { C_optimize = yes } ->
+		globals__io_lookup_string_option(cflags_for_optimization,
+			OptimizeOpt)
 	;
-		OptimizeOpt = ""
-	},
+		{ OptimizeOpt = "" }
+	),
+	globals__io_lookup_bool_option(ansi_c, Ansi),
+	( { Ansi = yes } ->
+		globals__io_lookup_string_option(cflags_for_ansi, AnsiOpt)
+	;
+		{ AnsiOpt = "" }
+	),
 	globals__io_lookup_bool_option(inline_alloc, InlineAlloc),
 	{ InlineAlloc = yes ->
 		InlineAllocOpt = "-DMR_INLINE_ALLOC -DSILENT "
 	;
 		InlineAllocOpt = ""
 	},
-	{ CompilerType = gcc ->
-		% We don't enable `-Wpointer-arith', because it causes
-		% too many complaints in system header files.
-		% This is fixed in gcc 3.0, though, so at some
-		% point we should re-enable this.
-		%
-		% If --inline-alloc is enabled, don't enable missing-prototype
-		% warnings, since gc_inline.h is missing lots of prototypes.
-		%
-		% For a full list of the other gcc warnings that we don't
-		% enable, and why, see scripts/mgnuc.in.
-		( InlineAlloc = yes ->
-			WarningOpt = "-Wall -Wwrite-strings -Wshadow -Wmissing-prototypes -Wno-unused -Wno-uninitialized "
-		;
-			WarningOpt = "-Wall -Wwrite-strings -Wshadow -Wmissing-prototypes -Wno-unused -Wno-uninitialized -Wstrict-prototypes "
-		)
-	; CompilerType = lcc ->
-		WarningOpt = "-w "
+	globals__io_lookup_bool_option(warn_target_code, Warn),
+	( { Warn = yes } ->
+		globals__io_lookup_string_option(cflags_for_warnings,
+			WarningOpt)
 	;
-		WarningOpt = ""
-	},
+		{ WarningOpt = "" }
+	),
+
 	% Be careful with the order here!  Some options override others,
 	% e.g. CFLAGS_FOR_REGS must come after OptimizeOpt so that
 	% it can override -fomit-frame-pointer with -fno-omit-frame-pointer.
 	% Also be careful that each option is separated by spaces.
 	{ string__append_list([CC, " ", SubDirInclOpt, InclOpt,
-		SplitOpt, OptimizeOpt,
+		SplitOpt, " ", OptimizeOpt, " ",
 		HighLevelCodeOpt, NestedFunctionsOpt, HighLevelDataOpt,
 		RegOpt, GotoOpt, AsmOpt,
 		CFLAGS_FOR_REGS, " ", CFLAGS_FOR_GOTOS, " ",
@@ -648,7 +619,7 @@
 		Target_DebugOpt, LL_DebugOpt,
 		DeclDebugOpt, RequireTracingOpt, StackTraceOpt,
 		UseTrailOpt, ReserveTagOpt, MinimalModelOpt, TypeLayoutOpt,
-		InlineAllocOpt, WarningOpt, CFLAGS,
+		InlineAllocOpt, " ", AnsiOpt, " ", WarningOpt, " ", CFLAGS,
 		" -c ", C_File, " ", NameObjectFile, O_File], Command) },
 	invoke_system_command(ErrorStream, verbose_commands,
 		Command, Succeeded).
@@ -880,6 +851,9 @@
 	make_init_obj_file(ErrorStream,
 		MustCompile, ModuleName, ModuleNames, Result).
 
+% WARNING: The code here duplicates the functionality of scripts/c2init.in.
+% Any changes there may also require changes here, and vice versa.
+
 :- pred make_init_obj_file(io__output_stream, bool,
 	module_name, list(module_name), maybe(file_name),
 	io__state, io__state).
@@ -892,17 +866,9 @@
 	globals__io_lookup_bool_option(statistics, Stats),
 	maybe_write_string(Verbose, "% Creating initialization file...\n"),
 
-	globals__io_get_trace_level(TraceLevel),
-	{ given_trace_level_is_none(TraceLevel) = no ->
-		TraceOpt = "--trace "
-	;
-		TraceOpt = ""
-	},
 	globals__io_get_globals(Globals),
 	{ compute_grade(Globals, Grade) },
 
-	standard_library_directory_option(StdLibOpt),
-
 	get_object_code_type(executable, PIC),
 	maybe_pic_object_file_extension(PIC, ObjExt),
 	{ InitObj = "_init" ++ ObjExt },
@@ -917,28 +883,65 @@
 	    ), ModuleNames, CFileNameList),
 	{ join_string_list(CFileNameList, "", "", " ", CFileNames) },
 
-	globals__io_lookup_accumulating_option(link_flags, LinkFlagsList),
-	{ join_string_list(LinkFlagsList, "", "", " ", LinkFlags) },
-
 	globals__io_lookup_accumulating_option(init_file_directories,
 		InitFileDirsList),
 	{ join_quoted_string_list(InitFileDirsList,
 		"-I ", "", " ", InitFileDirs) },
 
-	globals__io_lookup_accumulating_option(init_files, InitFileNamesList),
+
+	globals__io_lookup_accumulating_option(init_files, InitFileNamesList0),
+	globals__io_lookup_accumulating_option(trace_init_files,
+			TraceInitFileNamesList0),
+	globals__io_lookup_maybe_string_option(
+		mercury_standard_library_directory, MaybeStdLibDir),
+	(
+		{ MaybeStdLibDir = yes(StdLibDir) },
+		{ InitFileNamesList1 = [StdLibDir/"modules"/"mer_rt.init",
+				StdLibDir/"modules"/"mer_std.init" |
+				InitFileNamesList0] },
+		{ TraceInitFileNamesList =
+				[StdLibDir/"modules"/"mer_browser.init" |
+				TraceInitFileNamesList0] }
+	;
+		{ MaybeStdLibDir = no },
+		{ InitFileNamesList1 = InitFileNamesList0 },
+		{ TraceInitFileNamesList = TraceInitFileNamesList0 }
+	),
+
+	globals__io_get_trace_level(TraceLevel),
+	( { given_trace_level_is_none(TraceLevel) = no } ->
+		{ TraceOpt = "-t" },
+		{ InitFileNamesList =
+			InitFileNamesList1 ++ TraceInitFileNamesList }
+	;
+		{ TraceOpt = "" },
+		{ InitFileNamesList = InitFileNamesList1 }
+	),
 	{ join_quoted_string_list(InitFileNamesList,
 		"", "", " ", InitFileNames) },
 
-	globals__io_lookup_accumulating_option(trace_init_files,
-		TraceInitFileNamesList),
-	{ join_quoted_string_list(TraceInitFileNamesList, "--trace-init-file ",
-		"", " ", TraceInitFileNames) },
+	globals__io_lookup_accumulating_option(runtime_flags,
+		RuntimeFlagsList),
+	{ join_quoted_string_list(RuntimeFlagsList, "-r ",
+		"", " ", RuntimeFlags) },
+
+	globals__io_lookup_bool_option(extra_initialization_functions,
+		ExtraInits),
+	{ ExtraInitsOpt = ( ExtraInits = yes -> "-x" ; "" ) },
 
+	globals__io_lookup_bool_option(main, Main),
+	{ NoMainOpt = ( Main = no -> "-l" ; "" ) },
+
+	globals__io_lookup_bool_option(aditi, Aditi),
+	{ AditiOpt = ( Aditi = yes -> "-a" ; "" ) },
+
+	globals__io_lookup_string_option(mkinit_command, Mkinit),
 	{ TmpInitCFileName = InitCFileName ++ ".tmp" },
 	{ MkInitCmd = string__append_list(
-		["c2init --grade ", Grade, " ", TraceOpt, StdLibOpt, LinkFlags,
-		" --init-c-file ", TmpInitCFileName, " ", InitFileDirs, " ",
-		TraceInitFileNames, " ", InitFileNames, " ", CFileNames]) },
+		[Mkinit,  " -g ", Grade, " ", TraceOpt, " ", ExtraInitsOpt,
+		" ", NoMainOpt, " ", AditiOpt, " ", RuntimeFlags,
+		" -o ", TmpInitCFileName, " ", InitFileDirs,
+		" ", InitFileNames, " ", CFileNames]) },
 	invoke_shell_command(ErrorStream, verbose, MkInitCmd, MkInitOK0),
 	maybe_report_stats(Stats),
 	( { MkInitOK0 = yes } ->
@@ -994,53 +997,123 @@
 	    { Result = no }
 	).
 
+% WARNING: The code here duplicates the functionality of scripts/ml.in.
+% Any changes there may also require changes here, and vice versa.
 link(ErrorStream, LinkTargetType, ModuleName, ObjectsList, Succeeded) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
 	globals__io_lookup_bool_option(statistics, Stats),
 
-	globals__io_get_trace_level(TraceLevel),
-	{ given_trace_level_is_none(TraceLevel) = no ->
-		TraceOpt = "--trace "
-	;
-		TraceOpt = ""
-	},
-	globals__io_get_globals(Globals),
-	{ compute_grade(Globals, Grade) },
-
 	maybe_write_string(Verbose, "% Linking...\n"),
+	globals__io_lookup_string_option(library_extension, LibExt),
+	globals__io_lookup_string_option(shared_library_extension,
+		SharedLibExt),
+	globals__io_lookup_string_option(executable_file_extension, ExeExt),
 	( { LinkTargetType = static_library } ->
-	    	globals__io_lookup_string_option(library_extension, Ext),
-		module_name_to_lib_file_name("lib", ModuleName, Ext,
+		{ Ext = LibExt },
+		module_name_to_lib_file_name("lib", ModuleName, LibExt,
 			yes, OutputFileName),
 		create_archive(ErrorStream, OutputFileName, ObjectsList,
 			LinkSucceeded)
 	;
-		( { LinkTargetType = shared_library } ->
-			{ SharedLibOpt = "--make-shared-lib " },
+		(
+			{ LinkTargetType = shared_library },
+			{ CommandOpt = link_shared_lib_command },
+			{ RpathFlagOpt = shlib_linker_rpath_flag },
+			{ RpathSepOpt = shlib_linker_rpath_separator },
 			{ LDFlagsOpt = ld_libflags },
-			globals__io_lookup_string_option(
-				shared_library_extension, Ext),
+			{ ThreadFlagsOpt = shlib_linker_thread_flags },
+			{ DebugFlagsOpt = shlib_linker_debug_flags },
+			{ TraceFlagsOpt = shlib_linker_trace_flags },
+			globals__io_lookup_bool_option(allow_undefined,
+				AllowUndef),
+			( { AllowUndef = yes } ->
+				globals__io_lookup_string_option(
+					linker_allow_undefined_flag, UndefOpt)
+			;
+				globals__io_lookup_string_option(
+					linker_error_undefined_flag, UndefOpt)
+			),
+			{ Ext = SharedLibExt },
 			module_name_to_lib_file_name("lib", ModuleName,
 				Ext, yes, OutputFileName)
 		;
-			{ SharedLibOpt = "" },
+			{ LinkTargetType = static_library },
+			{ error("compile_target_code__link") }
+		;
+			{ LinkTargetType = executable },
+			{ CommandOpt = link_executable_command },
+			{ RpathFlagOpt = linker_rpath_flag },
+			{ RpathSepOpt = linker_rpath_separator },
 			{ LDFlagsOpt = ld_flags },
-			globals__io_lookup_string_option(
-				executable_file_extension, Ext),
+			{ ThreadFlagsOpt = linker_thread_flags },
+			{ DebugFlagsOpt = linker_debug_flags },
+			{ TraceFlagsOpt = linker_trace_flags },
+			{ UndefOpt = "" },
+			{ Ext = ExeExt },
 			module_name_to_file_name(ModuleName, Ext,
 				yes, OutputFileName)
 		),
-		globals__io_lookup_bool_option(target_debug, Target_Debug),
-		{ Target_Debug = yes ->
-			Target_Debug_Opt = "--no-strip "
+
+		%
+		% Should the executable be stripped?
+		%
+		globals__io_lookup_bool_option(strip, Strip),
+		( { LinkTargetType = executable, Strip = yes } ->
+			globals__io_lookup_string_option(linker_strip_flag,
+				StripOpt)
 		;
-			Target_Debug_Opt = ""
-		},
-		standard_library_directory_option(StdLibOpt),
+			{ StripOpt = "" }
+		),
+
+		globals__io_lookup_bool_option(target_debug, TargetDebug),
+		( { TargetDebug = yes } ->
+			globals__io_lookup_string_option(DebugFlagsOpt,
+				DebugOpts)
+		;
+			{ DebugOpts = "" }
+		),
+
+		%
+		% Should the executable be statically linked?
+		%
+		globals__io_lookup_string_option(linkage, Linkage),
+		( { LinkTargetType = executable, Linkage = "static" } ->
+			globals__io_lookup_string_option(linker_static_flags,
+				StaticOpts)
+		;
+			{ StaticOpts = "" }
+		),
+
+		%
+		% Are the thread libraries needed?
+		%
+		use_thread_libs(UseThreadLibs),
+		( { UseThreadLibs = yes } ->
+			globals__io_lookup_string_option(ThreadFlagsOpt,
+				ThreadOpts)
+		;
+			{ ThreadOpts = "" }
+		),
+
+		%
+		% Find the Mercury standard libraries.
+		%
+		globals__io_lookup_maybe_string_option(
+			mercury_standard_library_directory, MaybeStdLibDir),
+		(
+			{ MaybeStdLibDir = yes(StdLibDir) },
+			get_mercury_std_libs(StdLibDir, MercuryStdLibs)
+		;
+			{ MaybeStdLibDir = no },
+			{ MercuryStdLibs = "" }
+		),
+
+		%
+		% Find which system libraries are needed.
+		%
+		get_system_libs(LinkTargetType, SystemLibs),
+
 		{ join_string_list(ObjectsList, "", "", " ", Objects) },
-		globals__io_lookup_accumulating_option(link_flags,
-				LinkFlagsList),
-		{ join_string_list(LinkFlagsList, "", "", " ", LinkFlags) },
 		globals__io_lookup_accumulating_option(LDFlagsOpt,
 				LDFlagsList),
 		{ join_string_list(LDFlagsList, "", "", " ", LDFlags) },
@@ -1049,12 +1122,39 @@
 				LinkLibraryDirectoriesList),
 		{ join_quoted_string_list(LinkLibraryDirectoriesList, "-L", "",
 				" ", LinkLibraryDirectories) },
-		globals__io_lookup_accumulating_option(
+
+		%
+		% Set up the runtime library path.
+		%
+		(
+			{ SharedLibExt \= LibExt },
+			{ Linkage = "shared" ; LinkTargetType = shared_library }
+		->
+			globals__io_lookup_accumulating_option(
 				runtime_link_library_directories,
-				RuntimeLinkLibraryDirectoriesList),
-		{ join_quoted_string_list(RuntimeLinkLibraryDirectoriesList,
-				"-R", "", " ",
-				RuntimeLinkLibraryDirectories) },
+				RpathDirs),
+			( { RpathDirs = [] } ->
+				{ RpathOpts = "" }
+			;
+				globals__io_lookup_string_option(RpathSepOpt,
+					RpathSep),
+				globals__io_lookup_string_option(RpathFlagOpt,
+					RpathFlag),
+				{ RpathOpts0 = string__join_list(RpathSep,
+					RpathDirs) },
+				{ RpathOpts = RpathFlag ++ RpathOpts0 }
+			)
+		;
+			{ RpathOpts = "" }
+		),
+
+		globals__io_get_trace_level(TraceLevel),
+		( { given_trace_level_is_none(TraceLevel) = yes } ->
+			{ TraceOpts = "" }
+		;
+			globals__io_lookup_string_option(TraceFlagsOpt,
+				TraceOpts )
+		),
 
 		%
 		% Pass either `-llib' or `PREFIX/lib/GRADE/FULLARCH/liblib.a',
@@ -1065,6 +1165,8 @@
 				mercury_library_directories,
 				MercuryLibDirs0),
 		globals__io_lookup_string_option(fullarch, FullArch),
+		globals__io_get_globals(Globals),
+		{ compute_grade(Globals, Grade) },
 		{ MercuryLibDirs = list__map(
 				(func(LibDir) = LibDir/"lib"/Grade/FullArch),
 				MercuryLibDirs0) },
@@ -1078,33 +1180,30 @@
 			{ join_quoted_string_list(LinkLibrariesList,
 				"", "", " ", LinkLibraries) },
 
-			globals__io_lookup_string_option(linkage, Linkage),
-			{ LinkageOpt = "--" ++ Linkage },
-			globals__io_lookup_maybe_string_option(
-				mercury_standard_library_directory,
-				MaybeStdLibDir),
-			globals__io_lookup_string_option(mercury_linkage,
-				MercuryLinkage),
-			{ MaybeStdLibDir = yes(_),
-				MercuryLinkageOpt =
-					"--mercury-libs " ++ MercuryLinkage
-			; MaybeStdLibDir = no,
-				MercuryLinkageOpt = ""
-			},
-
 			% Note that LDFlags may contain `-l' options
 			% so it should come after Objects.
+			globals__io_lookup_string_option(CommandOpt, Command),
 			{ string__append_list(
-				["ml --grade ", Grade, " ", SharedLibOpt,
-				Target_Debug_Opt, TraceOpt, StdLibOpt,
-				LinkageOpt, " ", MercuryLinkageOpt, " ",
-				LinkFlags, " ", LinkLibraryDirectories, " ",
-				RuntimeLinkLibraryDirectories,
-				" -- -o ", OutputFileName, " ", Objects, " ",
-				LDFlags, " ", LinkLibraries],
+				[Command, " ", UndefOpt, " ", StripOpt,
+				" ", DebugOpts, " ", StaticOpts, " ",
+				ThreadOpts, " ", TraceOpts, " ",
+				LinkLibraryDirectories, " ", RpathOpts,
+				" -o ", OutputFileName, " ", Objects, " ",
+				LDFlags, " ", LinkLibraries, " ",
+				MercuryStdLibs, " ", SystemLibs],
 				LinkCmd) },
+
+			globals__io_lookup_bool_option(demangle, Demangle),
+			( { Demangle = yes } ->
+				globals__io_lookup_string_option(
+					demangle_command, DemamngleCmd),
+				{ MaybeDemangleCmd = yes(DemamngleCmd) }
+			;
+				{ MaybeDemangleCmd = no }
+			),
+
 			invoke_shell_command(ErrorStream, verbose_commands,
-				LinkCmd, LinkSucceeded)
+				LinkCmd, MaybeDemangleCmd, LinkSucceeded)
 		;
 			{ LibrariesSucceeded = no },
 			{ LinkSucceeded = no }
@@ -1137,6 +1236,145 @@
 	;
 		{ Succeeded = LinkSucceeded }
 	).
+
+	% Find the standard Mercury libraries, and the system
+	% libraries needed by them.
+:- pred get_mercury_std_libs(dir_name::in, string::out,
+		io__state::di, io__state::uo) is det.
+
+get_mercury_std_libs(StdLibDir, StdLibs) -->
+	globals__io_lookup_string_option(fullarch, FullArch),
+	globals__io_get_gc_method(GCMethod),
+	globals__io_lookup_string_option(library_extension, LibExt),
+	globals__io_get_globals(Globals),
+	{ compute_grade(Globals, Grade) },
+
+	%
+	% GC libraries.
+	%
+	(
+		{ GCMethod = none },
+		{ StaticGCLibs = "" },
+		{ SharedGCLibs = "" }
+	;
+		{ GCMethod = boehm },
+		globals__io_lookup_bool_option(profile_time, ProfTime),
+		globals__io_lookup_bool_option(profile_deep, ProfDeep),
+		{ ( ProfTime = yes ; ProfDeep = yes ) ->
+			GCGrade0 = "gc_prof"
+		;
+			GCGrade0 = "gc"
+		},
+		globals__io_lookup_bool_option(parallel, Parallel),
+		{ Parallel = yes ->
+			GCGrade = "par_" ++ GCGrade0
+		;
+			GCGrade = GCGrade0
+		},
+		{ SharedGCLibs = "-l" ++ GCGrade },
+		{ StaticGCLibs =
+			StdLibDir/"lib"/FullArch/("lib" ++ GCGrade ++ LibExt) }
+	;
+		{ GCMethod = mps },
+		{ SharedGCLibs = "-lmps" },
+		{ StaticGCLibs =
+			StdLibDir/"lib"/FullArch/("libmps" ++ LibExt) }
+	;
+		{ GCMethod = accurate },
+		{ StaticGCLibs = "" },
+		{ SharedGCLibs = "" }
+	),
+
+	%
+	% Trace libraries.
+	%
+	globals__io_get_trace_level(TraceLevel),
+	( { given_trace_level_is_none(TraceLevel) = yes } ->
+		{ StaticTraceLibs = "" },
+		{ SharedTraceLibs = "" }
+	;
+		{ StaticTraceLibs =
+			StdLibDir/"lib"/Grade/FullArch/
+				("libmer_trace" ++ LibExt) ++
+			" " ++
+			StdLibDir/"lib"/Grade/FullArch/
+				("libmer_browser" ++ LibExt) },
+		{ SharedTraceLibs = "-lmer_trace -lmer_browser" }
+	),
+
+	globals__io_lookup_string_option(mercury_linkage, MercuryLinkage),
+	{ MercuryLinkage = "static" ->
+	    StdLibs = string__join_list(" ",
+		[StaticTraceLibs,
+		StdLibDir/"lib"/Grade/FullArch/("libmer_std" ++ LibExt),
+		StdLibDir/"lib"/Grade/FullArch/("libmer_rt" ++ LibExt),
+		StaticGCLibs])
+	; MercuryLinkage = "shared" ->
+	    StdLibs = string__join_list(" ",
+		[SharedTraceLibs, "-lmer_std -lmer_rt", SharedGCLibs])
+	;
+		error("unknown linkage " ++ MercuryLinkage)
+	}.
+
+:- pred get_system_libs(linked_target_type::in, string::out,
+		io__state::di, io__state::uo) is det.
+
+get_system_libs(TargetType, SystemLibs) -->
+	%
+	% System libraries used when tracing.
+	%
+	globals__io_get_trace_level(TraceLevel),
+	( { given_trace_level_is_none(TraceLevel) = yes } ->
+		{ SystemTraceLibs = "" }
+	;
+		globals__io_lookup_string_option(trace_libs, SystemTraceLibs0),
+		globals__io_lookup_bool_option(use_readline, UseReadline),
+		( { UseReadline = yes } ->
+			globals__io_lookup_string_option(readline_libs,
+				ReadlineLibs),
+			{ SystemTraceLibs =
+				SystemTraceLibs0 ++ " " ++ ReadlineLibs }
+		;
+			{ SystemTraceLibs = SystemTraceLibs0 }
+		)
+	),
+
+	%
+	% Thread libraries
+	%
+	use_thread_libs(UseThreadLibs),
+	( { UseThreadLibs = yes } ->
+		globals__io_lookup_string_option(thread_libs, ThreadLibs)
+	;
+		{ ThreadLibs = "" }
+	),
+
+	%
+	% Other system libraries.
+	%
+	(
+		{ TargetType = shared_library },
+		globals__io_lookup_string_option(shared_libs, OtherSystemLibs)
+	;
+		{ TargetType = static_library },
+		{ error("compile_target_code__get_std_libs: static library") }
+	;
+		{ TargetType = executable },
+		globals__io_lookup_string_option(math_lib, OtherSystemLibs)
+	),	
+
+	{ SystemLibs = string__join_list(" ",
+			[SystemTraceLibs, OtherSystemLibs, ThreadLibs]) }.
+
+:- pred use_thread_libs(bool::out, io__state::di, io__state::uo) is det.
+
+use_thread_libs(UseThreadLibs) -->
+	globals__io_lookup_bool_option(parallel, Parallel),
+	globals__io_get_gc_method(GCMethod),
+	{ UseThreadLibs =
+		( ( Parallel = yes ; GCMethod = mps ) -> yes ; no ) }.
+
+%-----------------------------------------------------------------------------%
 
 :- pred process_link_library(list(dir_name), string, string, bool, bool,
 		io__state, io__state).
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.166
diff -u -u -r1.166 handle_options.m
--- compiler/handle_options.m	30 Jan 2003 05:59:18 -0000	1.166
+++ compiler/handle_options.m	30 Jan 2003 05:59:44 -0000
@@ -266,15 +266,6 @@
 	globals__io_init(OptionTable1, Target, GC_Method, TagsMethod,
 		TermNorm, TraceLevel, TraceSuppress),
 
-	% Using the MSVC compiler implies that we must use a maximum jump
-	% table size of 512 to avoid a fixed limit in the compiler.
-	globals__io_lookup_string_option(cc, CC),
-	( { string__sub_string_search(string__to_lower(CC), "cl", _) } ->
-		globals__io_set_option(max_jump_table_size, int(512))
-	;
-		[]
-	),
-
 	% Conservative GC implies --no-reclaim-heap-*
 	( { gc_is_conservative(GC_Method) = yes } ->
 		globals__io_set_option(
@@ -634,6 +625,8 @@
 		Error = no
 	},
 
+	option_implies(target_debug, strip, bool(no)),
+
 	% --decl-debug is an extension of --debug
 	option_implies(decl_debug, require_tracing, bool(yes)),
 	option_implies(decl_debug, stack_trace, bool(yes)),
@@ -945,6 +938,8 @@
 		[]
 	),
 
+	globals__io_lookup_string_option(fullarch, FullArch),
+
 	%
 	% Add the standard library directory.
 	%
@@ -958,7 +953,23 @@
 				OptionTable2, StdLibDir),
 			Globals3) },
 		{ unsafe_promise_unique(Globals3, Globals4) },
-		globals__io_set_globals(Globals4)
+		globals__io_set_globals(Globals4),
+
+		%
+		% Add `-L' and `-R' options for the location
+		% of the GC libraries. 
+		%
+		globals__io_lookup_accumulating_option(
+			link_library_directories, LinkLibDirs0),
+		globals__io_set_option(link_library_directories,
+			accumulating(
+				[StdLibDir/"lib"/FullArch | LinkLibDirs0])),
+
+		globals__io_lookup_accumulating_option(
+			runtime_link_library_directories, Rpath0),
+		globals__io_set_option(runtime_link_library_directories,
+			accumulating([StdLibDir/"lib"/FullArch | Rpath0]))
+
 	;
 		[]
 	),
@@ -984,7 +995,6 @@
 	%
 	globals__io_lookup_accumulating_option(mercury_library_directories,
 		MercuryLibDirs),
-	globals__io_lookup_string_option(fullarch, FullArch),
 	globals__io_get_globals(Globals),
 	{ grade_directory_component(Globals, GradeString) },
 	(
@@ -993,6 +1003,7 @@
 			(func(MercuryLibDir) =
 				MercuryLibDir/"lib"/GradeString/FullArch
 			), MercuryLibDirs) },
+
 		globals__io_lookup_accumulating_option(
 			link_library_directories, LinkLibDirs),
 		globals__io_set_option(link_library_directories,
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.270
diff -u -u -r1.270 mercury_compile.m
--- compiler/mercury_compile.m	23 Jan 2003 00:24:05 -0000	1.270
+++ compiler/mercury_compile.m	23 Jan 2003 00:37:55 -0000
@@ -204,6 +204,9 @@
 	globals__io_lookup_bool_option(generate_source_file_mapping,
 		GenerateMapping),
 	globals__io_lookup_bool_option(output_grade_string, OutputGrade),
+	globals__io_lookup_bool_option(output_link_command, OutputLinkCommand),
+	globals__io_lookup_bool_option(output_shared_lib_link_command,
+		OutputShLibLinkCommand),
 	globals__io_lookup_bool_option(filenames_from_stdin,
 		FileNamesFromStdin),
 	globals__io_lookup_bool_option(make, Make),
@@ -217,6 +220,18 @@
 		{ compute_grade(Globals, Grade) },
 		io__stdout_stream(Stdout),
 		io__write_string(Stdout, Grade),
+		io__write_string(Stdout, "\n")
+	; { OutputLinkCommand = yes } ->
+		globals__io_lookup_string_option(link_executable_command,
+			LinkCommand),
+		io__stdout_stream(Stdout),
+		io__write_string(Stdout, LinkCommand),
+		io__write_string(Stdout, "\n")
+	; { OutputShLibLinkCommand = yes } ->
+		globals__io_lookup_string_option(link_shared_lib_command,
+			LinkCommand),
+		io__stdout_stream(Stdout),
+		io__write_string(Stdout, LinkCommand),
 		io__write_string(Stdout, "\n")
 	; { GenerateMapping = yes } ->
 		source_file_map__write_source_file_map(Args)
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.402
diff -u -u -r1.402 options.m
--- compiler/options.m	30 Jan 2003 05:59:21 -0000	1.402
+++ compiler/options.m	30 Jan 2003 05:59:45 -0000
@@ -559,8 +559,6 @@
 
 	% Link options
 		;	output_file_name
-		;	link_flags
-		;	quoted_link_flag
 		;	ld_flags
 		;	quoted_ld_flag
 		;	ld_libflags
@@ -613,6 +611,8 @@
 		;	linker_strip_flag
 		;	linker_debug_flags
 		;	shlib_linker_debug_flags
+		;	linker_trace_flags
+		;	shlib_linker_trace_flags
 		;	linker_rpath_flag
 		;	linker_rpath_separator
 		;	shlib_linker_rpath_flag
@@ -1156,8 +1156,6 @@
 					% if the output_file_name is an empty
 					% string, we use the name of the first
 					% module on the command line
-	link_flags		-	accumulating([]),
-	quoted_link_flag	-	string_special,
 	ld_flags		-	accumulating([]),
 	quoted_ld_flag		-	string_special,
 	ld_libflags		-	accumulating([]),
@@ -1212,6 +1210,8 @@
 	readline_libs -			string(""),
 	linker_debug_flags -		string("-g"),
 	shlib_linker_debug_flags -	string("-g"),
+	linker_trace_flags -		string("-g"),
+	shlib_linker_trace_flags -	string("-g"),
 	linker_thread_flags -		string(""),
 	shlib_linker_thread_flags -	string(""),
 	linker_static_flags -		string("-static"),
@@ -1813,10 +1813,6 @@
 
 % link options
 long_option("output-file",		output_file_name).
-long_option("link-flags",		link_flags).
-long_option("link-flag",		quoted_link_flag).
-long_option("ml-flags",			link_flags).
-long_option("ml-flag",			quoted_link_flag).
 long_option("ld-flags",			ld_flags).
 long_option("ld-flag",			quoted_ld_flag).
 long_option("ld-libflags",		ld_libflags).
@@ -1866,6 +1862,8 @@
 long_option("readline-libs",		readline_libs).
 long_option("linker-debug-flags",  	linker_debug_flags).
 long_option("shlib-linker-debug-flags",	shlib_linker_debug_flags).
+long_option("linker-trace-flags",  	linker_trace_flags).
+long_option("shlib-linker-trace-flags",	shlib_linker_trace_flags).
 long_option("linker-thread-flags",	linker_thread_flags).
 long_option("shlib-linker-thread-flags", shlib_linker_thread_flags).
 long_option("linker-static-flags",	linker_static_flags).
@@ -2069,9 +2067,6 @@
 special_handler(quoted_csharp_flag, string(Flag),
 			OptionTable0, ok(OptionTable)) :-
 	handle_quoted_flag(csharp_flags, Flag, OptionTable0, OptionTable).
-special_handler(quoted_link_flag, string(Flag),
-			OptionTable0, ok(OptionTable)) :-
-	handle_quoted_flag(link_flags, Flag, OptionTable0, OptionTable).
 special_handler(quoted_ld_flag, string(Flag),
 			OptionTable0, ok(OptionTable)) :-
 	handle_quoted_flag(ld_flags, Flag, OptionTable0, OptionTable).
@@ -2476,12 +2471,10 @@
 		"\tThis requires --high-level-code.",
 		"--no-warn-up-to-date",
 		"\tDon't warn if targets specified on the command line",
-		"\twith `--make' are already up to date."
-		/* NYI
+		"\twith `--make' are already up to date.",
 		"--no-warn-target-code",
 		"\tDisable warnings from the compiler used to process the",
 		"\ttarget code (e.g. gcc)."
-		*/
 	]).
 
 :- pred options_help_verbosity(io__state::di, io__state::uo) is det.
@@ -2607,15 +2600,13 @@
 		"--output-grade-string",
 		"\tCompute the grade of the library to link with based on",
 		"\tthe command line options, and print it to the standard",
-		"\toutput."
-		/* NYI	
+		"\toutput.",
 		"--output-link-command",
 		"\tPrint the command used to link executables to the",
 		"\tstandard output.",
 		"--output-shared-lib-link-command",
 		"\tPrint the command used to link shared libraries to the",
 		"\tstandard output."
-		*/
 	]).
 
 :- pred options_help_aux_output(io__state::di, io__state::uo) is det.
@@ -3680,12 +3671,10 @@
 		"--no-c-optimize",
 		"\tDon't enable the C compiler's optimizations.",
 
-		/* NYI
 		"--no-ansi-c",
 		"\tDon't specify to the C compiler that the ANSI dialect",
 		"\tof C should be used.  Use the full contents of system",
 		"\theaders, rather than the ANSI subset.",
-		*/
 
 		"--c-debug",
 		"\tEnable debugging of the generated C code.",
@@ -3832,9 +3821,8 @@
 		"\tbe passed to c2init.",
 		"--trace-init-file <init-file>",
 		"\tAppend <init-file> to the list of `.init' files to",
-		"\tbe passed to c2init when tracing is enabled."
+		"\tbe passed to c2init when tracing is enabled.",
 
-		/* NYI 
 		"--no-strip",
 		"\tDon't strip executables.",
 		"--no-demangle",
@@ -3854,7 +3842,6 @@
 		"\thand-coded C code with `INIT' comments, rather than",
 		"\tcontaining only C code that was automatically generated",
 		"\tby the Mercury compiler.)"
-		*/
 
 		% The --shared-library-extension,
 		% --library-extension, --executable-file-extension
Index: compiler/options_file.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options_file.m,v
retrieving revision 1.14
diff -u -u -r1.14 options_file.m
--- compiler/options_file.m	23 Jan 2003 00:24:06 -0000	1.14
+++ compiler/options_file.m	23 Jan 2003 00:37:55 -0000
@@ -766,7 +766,6 @@
 	;	ilasm_flags
 	;	csharp_flags
 	;	mcpp_flags
-	;	ml_flags
 	;	ml_objs
 	;	ml_libs
 	;	ld_flags
@@ -788,7 +787,7 @@
 options_variable_types =
 	[grade_flags, linkage, mercury_linkage, mmc_flags, c_flags, java_flags,
 	ilasm_flags, csharp_flags, mcpp_flags,
-	ml_objs, lib_dirs, ml_flags, ld_flags,
+	ml_objs, lib_dirs, ld_flags,
 	libraries, ml_libs, c2init_args,
 	lib_grades, install_prefix].
 
@@ -801,7 +800,6 @@
 options_variable_name(ilasm_flags) = "MS_ILASM_FLAGS".
 options_variable_name(mcpp_flags) = "MS_CL_FLAGS".
 options_variable_name(csharp_flags) = "MS_CSC_FLAGS".
-options_variable_name(ml_flags) = "MLFLAGS".
 options_variable_name(ml_objs) = "MLOBJS".
 options_variable_name(ml_libs) = "MLLIBS".
 options_variable_name(ld_flags) = "LDFLAGS".
@@ -823,7 +821,6 @@
 options_variable_type_is_target_specific(ilasm_flags) = yes.
 options_variable_type_is_target_specific(mcpp_flags) = yes.
 options_variable_type_is_target_specific(csharp_flags) = yes.
-options_variable_type_is_target_specific(ml_flags) = yes.
 options_variable_type_is_target_specific(ml_objs) = yes.
 options_variable_type_is_target_specific(ml_libs) = yes.
 options_variable_type_is_target_specific(ld_flags) = yes.
@@ -879,7 +876,6 @@
 mmc_option_type(ilasm_flags) = option([], "--ilasm-flag").
 mmc_option_type(mcpp_flags) = option([], "--mcpp-flag").
 mmc_option_type(csharp_flags) = option([], "--csharp-flag").
-mmc_option_type(ml_flags) = option([], "--link-flag").
 mmc_option_type(ml_objs) = option([], "--link-object").
 mmc_option_type(ml_libs) = mmc_flags.
 mmc_option_type(ld_flags) = option([], "--ld-flag").
Index: compiler/passes_aux.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/passes_aux.m,v
retrieving revision 1.50
diff -u -u -r1.50 passes_aux.m
--- compiler/passes_aux.m	31 Oct 2002 05:47:57 -0000	1.50
+++ compiler/passes_aux.m	31 Oct 2002 14:27:43 -0000
@@ -191,6 +191,8 @@
 					% interest to the user.
 	.
 
+	% invoke_shell_command(ErrorStream, Verbosity, Command, Succeeded)
+	%
 	% Invoke a shell script.
 	% Both standard and error output will go to the
 	% specified output stream.
@@ -198,6 +200,19 @@
 	command_verbosity::in, string::in, bool::out,
 	io__state::di, io__state::uo) is det.
 
+	% invoke_shell_command(ErrorStream, Verbosity, Command,
+	%		ProcessOutput, Succeeded)
+	%
+	% Invoke a shell script.
+	% Both standard and error output will go to the
+	% specified output stream after being piped through
+	% `ProcessOutput'.
+:- pred invoke_shell_command(io__output_stream::in,
+	command_verbosity::in, string::in, maybe(string)::in, bool::out,
+	io__state::di, io__state::uo) is det.
+
+	% invoke_system_command(ErrorStream, Verbosity, Command, Succeeded)
+	%
 	% Invoke an executable.
 	% Both standard and error output will go to the
 	% specified output stream.
@@ -205,6 +220,17 @@
 	command_verbosity::in, string::in, bool::out,
 	io__state::di, io__state::uo) is det.
 
+	% invoke_system_command(ErrorStream, Verbosity, Command,
+	%		ProcessOutput, Succeeded)
+	%
+	% Invoke an executable.
+	% Both standard and error output will go to the
+	% specified output stream after being piped through
+	% `ProcessOutput'.
+:- pred invoke_system_command(io__output_stream::in,
+	command_verbosity::in, string::in, maybe(string)::in, bool::out,
+	io__state::di, io__state::uo) is det.
+
 	% Make a command string, which needs to be invoked in a shell
 	% environment.
 :- pred make_command_string(string::in, quote_char::in, string::out) is det.
@@ -460,10 +486,19 @@
 maybe_set_exit_status(no) --> io__set_exit_status(1).
 
 invoke_shell_command(ErrorStream, Verbosity, Command0, Succeeded) -->
+	invoke_shell_command(ErrorStream, Verbosity, Command0, no, Succeeded).
+
+invoke_shell_command(ErrorStream, Verbosity, Command0,
+		ProcessOutput, Succeeded) -->
 	{ make_command_string(Command0, forward, Command) },
-	invoke_system_command(ErrorStream, Verbosity, Command, Succeeded).
+	invoke_system_command(ErrorStream, Verbosity, Command,
+		ProcessOutput, Succeeded).
 
 invoke_system_command(ErrorStream, Verbosity, Command, Succeeded) -->
+	invoke_system_command(ErrorStream, Verbosity, Command, no, Succeeded).
+
+invoke_system_command(ErrorStream, Verbosity, Command,
+		MaybeProcessOutput, Succeeded) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
 	(
 		{ Verbosity = verbose },
@@ -495,11 +530,11 @@
 		{ Result = ok(exited(Status)) },
 		maybe_write_string(PrintCommand, "% done.\n"),
 		( { Status = 0 } ->
-			{ Succeeded = yes }
+			{ CommandSucceeded = yes }
 		;
 			% The command should have produced output
 			% describing the error.
-			{ Succeeded = no }
+			{ CommandSucceeded = no }
 		)
 	;
 		{ Result = ok(signalled(Signal)) },
@@ -509,17 +544,60 @@
 		raise_signal(Signal),
 		report_error(ErrorStream, "system command received signal "
 					++ int_to_string(Signal) ++ "."),
-		{ Succeeded = no }
+		{ CommandSucceeded = no }
 	;
 		{ Result = error(Error) },
 		report_error(ErrorStream, io__error_message(Error)),
-		{ Succeeded = no }
+		{ CommandSucceeded = no }
+	),
+
+	(
+		{ MaybeProcessOutput = yes(ProcessOutput) },
+		io__make_temp(ProcessedTmpFile),
+		io__call_system_return_signal(
+			string__append_list([ProcessOutput, " < ",
+				TmpFile, " > ", ProcessedTmpFile, " 2>&1"]),
+				ProcessOutputResult),
+		io__remove_file(TmpFile, _),
+		(
+			{ ProcessOutputResult =
+				ok(exited(ProcessOutputStatus)) },
+			maybe_write_string(PrintCommand, "% done.\n"),
+			( { ProcessOutputStatus = 0 } ->
+				{ ProcessOutputSucceeded = yes }
+			;
+				% The command should have produced output
+				% describing the error.
+				{ ProcessOutputSucceeded = no }
+			)
+		;
+			{ ProcessOutputResult =
+				ok(signalled(ProcessOutputSignal)) },
+			% Make sure the current process gets the signal. Some
+			% systems (e.g. Linux) ignore SIGINT during a call to
+			% system().
+			raise_signal(ProcessOutputSignal),
+			report_error(ErrorStream,
+				"system command received signal "
+				++ int_to_string(ProcessOutputSignal) ++ "."),
+			{ ProcessOutputSucceeded = no }
+		;
+			{ ProcessOutputResult = error(ProcessOutputError) },
+			report_error(ErrorStream,
+				io__error_message(ProcessOutputError)),
+			{ ProcessOutputSucceeded = no }
+		)
+	;
+		{ MaybeProcessOutput = no },
+		{ ProcessOutputSucceeded = yes },
+		{ ProcessedTmpFile = TmpFile }
 	),
+	{ Succeeded = CommandSucceeded `and` ProcessOutputSucceeded },
 
 	%
 	% Write the output to the error stream.
 	%
-	io__open_input(TmpFile, TmpFileRes),
+	io__open_input(ProcessedTmpFile, TmpFileRes),
 	(
 		{ TmpFileRes = ok(TmpFileStream) },
 		io__input_stream_foldl_io(TmpFileStream,
@@ -538,7 +616,7 @@
 		report_error(ErrorStream, "error opening command output: "
 				++ io__error_message(TmpFileError))
 	),
-	io__remove_file(TmpFile, _).
+	io__remove_file(ProcessedTmpFile, _).
 
 make_command_string(String0, QuoteType, String) :-
 	( use_win32 ->
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.351
diff -u -u -r1.351 user_guide.texi
--- doc/user_guide.texi	30 Jan 2003 05:59:24 -0000	1.351
+++ doc/user_guide.texi	30 Jan 2003 05:59:46 -0000
@@ -4187,6 +4187,12 @@
 This option also requires @samp{--high-level-code}.
 
 @sp 1
+ at item --no-warn-target-code
+ at findex --no-warn-target-code
+Disable warnings from the compiler used to process the
+target code (e.g. gcc).
+
+ at sp 1
 @item --no-warn-up-to-date
 @findex --no-warn-up-to-date
 @findex --warn-up-to-date
@@ -4480,6 +4486,18 @@
 @findex --output-grade-string
 Compute from the rest of the option settings the canonical grade
 string and print it on the standard output.
+
+ at sp 1
+ at item --output-link-command
+ at findex --output-link-command
+Print the command used to link executables to the
+standard output.
+
+ at sp 1
+ at item --output-shared-lib-link-command
+ at findex --output-shared-lib-link-command
+Print the command used to link shared libraries to the
+standard output.
 @end table
 
 @node Auxiliary output options
@@ -6409,17 +6427,25 @@
 @cindex C debugging
 @cindex Debugging the generated C code
 Pass the @samp{-g} flag to the C compiler, to enable debugging
-of the generated C code, and also pass @samp{--no-strip} to the Mercury
-linker, to tell it not to strip the C debugging information.
+of the generated C code, and also disable stripping of C debugging
+information from the executable.
 Since the generated C code is very low-level, this option is not likely
 to be useful to anyone except the Mercury implementors, except perhaps
 for debugging code that uses Mercury's C interface extensively.
 
+ at sp 1
 @item --no-c-optimize
 @findex --no-c-optimize
 Don't enable the C compiler's optimizations.
 
 @sp 1
+ at item --no-ansi-c
+ at findex --no-ansi-c
+Don't specify to the C compiler that the ANSI dialect
+of C should be used.  Use the full contents of system
+headers, rather than the ANSI subset.
+
+ at sp 1
 @item --inline-alloc
 @findex --inline-alloc
 Inline calls to @samp{GC_malloc()}.
@@ -6488,26 +6514,13 @@
 This option is ignored by @samp{mmc --make}.
 
 @sp 1
- at item --ml-flags @var{options}
- at itemx --link-flags @var{options}
- at itemx --ml-flag @var{option}
- at findex --link-flags
- at findex --ml-flags
- at findex --ml-flag
- at cindex Link options
- at cindex Linker options
-Specify options to be passed to @samp{ml}, the Mercury linker.
- at samp{--ml-flag} should be used for single words which need
-to be quoted when passed to the shell.
-
- at sp 1
 @item --ld-flags @var{options}
 @item --ld-flags @var{option}
 @findex --ld-flags
 @findex --ld-flag
 Specify options to be passed to the command
-invoked by ml to link an executable.
-Use @code{ml --print-link-command} to find out
+invoked by mmc to link an executable.
+Use @code{mmc --output-link-command} to find out
 which command is used.
 @samp{--ld-flag} should be used for single words which need
 to be quoted when passed to the shell.
@@ -6518,8 +6531,8 @@
 @findex --ld-libflags
 @findex --ld-libflag
 Specify options to be passed to the command
-invoked by ml to link a shared library.
-Use @code{ml --print-shared-lib-link-command}
+invoked by mmc to link a shared library.
+Use @code{mmc --output-shared-lib-link-command}
 to find out which command is used.
 @samp{--ld-libflag} should be used for single words which need
 to be quoted when passed to the shell.
@@ -6549,11 +6562,13 @@
 @cindex Libraries, linking with
 Link with the specified library.
 
+ at sp 1
 @item --link-object @var{object}
 @findex --link-object
 @cindex Object files, linking with
 Link with the specified object file.
 
+ at sp 1
 @item --mld @var{directory}
 @itemx --mercury-library-directory @var{directory}
 @findex --mld
@@ -6566,6 +6581,7 @@
 @samp{--init-file-directory} and @samp{--c-include-directory}
 options as needed.  @xref{Using libraries}.
 
+ at sp 1
 @item --ml @var{library}
 @itemx --mercury-library @var{library}
 @findex --ml
@@ -6573,6 +6589,7 @@
 @cindex Libraries, linking with
 Link with the specified Mercury library.  @xref{Using libraries}.
 
+ at sp 1
 @item --mercury-standard-library-directory @var{directory}
 @itemx --mercury-stdlib-dir @var{directory}
 @findex --mercury-standard-library-directory
@@ -6581,6 +6598,7 @@
 Implies @samp{--mercury-library-directory @var{directory}}
 and @samp{--mercury-configuration-directory @var{directory}}.
 
+ at sp 1
 @item --no-mercury-standard-library-directory
 @itemx --no-mercury-stdlib-dir
 @findex --no-mercury-standard-library-directory
@@ -6588,16 +6606,19 @@
 Don't use the Mercury standard library.
 Implies @samp{--no-mercury-configuration-directory}.
 
+ at sp 1
 @item --init-file-directory @var{directory}
 @findex --init-file-directory
 Append @var{directory} to the list of directories to
 be searched for @samp{.init} files by @samp{c2init}.
 
+ at sp 1
 @item --init-file @var{file}
 @findex --init-file
 Append @var{file} to the list of @samp{.init} files
 to be passed to @samp{c2init}.
 
+ at sp 1
 @item --trace-init-file @var{file}
 @findex --trace-init-file
 Append @var{file} to the list of @samp{.init} files
@@ -6615,6 +6636,48 @@
 Specify whether to use shared or static linking when
 linking an executable with Mercury libraries.
 Shared libraries are always linked with @samp{--mercury-linkage shared}.
+
+ at sp 1
+ at item --no-strip
+ at findex --no-strip
+Don't strip executables.
+
+ at sp 1
+ at item --no-demangle
+ at findex --no-demangle
+Don't pipe link errors through the Mercury demangler.
+
+ at sp 1
+ at item --no-main
+ at findex --no-main
+Don't generate a C main() function.  The user's code must
+provide a main() function.
+
+ at sp 1
+ at item --allow-undefined
+ at findex --allow-undefined
+Allow undefined symbols in shared libraries.
+
+ at sp 1
+ at item --no-use-readline
+ at findex --no-use-readline
+Disable use of the readline library in the debugger.
+
+ at sp 1
+ at item --runtime-flags @var{flags}
+ at findex --runtime-flags
+Specify flags to pass to the Mercury runtime.
+
+ at sp 1
+ at item --extra-initialization-functions
+ at itemx --extra-inits
+ at findex --extra-initialization-functions
+ at findex --extra-inits
+Search @samp{.c} files for extra initialization functions.
+(This may be necessary if the C files contain
+hand-coded C code with @samp{INIT} comments, rather than
+containing only C code that was automatically generated
+by the Mercury compiler.)
 
 @end table
 
Index: library/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/library/Mmakefile,v
retrieving revision 1.104
diff -u -u -r1.104 Mmakefile
--- library/Mmakefile	13 Dec 2002 11:51:10 -0000	1.104
+++ library/Mmakefile	23 Jan 2003 13:22:21 -0000
@@ -88,6 +88,8 @@
 CFLAGS	+=	$(DLL_CFLAGS) -I$(TRACE_DIR)
 MLFLAGS	+=	-R$(FINAL_INSTALL_MERC_LIB_DIR) \
 		-R$(FINAL_INSTALL_MERC_GC_LIB_DIR)
+MCFLAGS +=	-R$(FINAL_INSTALL_MERC_LIB_DIR) \
+		-R$(FINAL_INSTALL_MERC_GC_LIB_DIR)
 
 MTAGS	=	$(SCRIPTS_DIR)/mtags
 
Index: scripts/c2init.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/c2init.in,v
retrieving revision 1.37
diff -u -u -r1.37 c2init.in
--- scripts/c2init.in	29 Apr 2002 08:22:04 -0000	1.37
+++ scripts/c2init.in	24 Oct 2002 03:40:33 -0000
@@ -11,6 +11,10 @@
 # This script outputs an appropriate init.c, given the .c files.
 # Type `c2init --help' for usage message.
 #
+# *************************************************************************
+# *** IMPORTANT NOTE: any changes to this file may also require similar ***
+# *** changes to compiler/compile_target_code.m                         ***
+# *************************************************************************
 
 Usage="\
 Name:	c2init - Create Mercury initialization file.
@@ -25,9 +29,9 @@
 # include the file `canonical_grade.sh-subr'
 @CANONICAL_GRADE@
 
-# If you change these, you will also need to change Mmake.workspace
-# scripts/ml.in, tools/bootcheck, tools/binary, tools/binary_step and
-# tools/linear.
+# If you change these, you will also need to change Mmake.workspace,
+# compiler/compile_target_code.m, scripts/ml.in, tools/bootcheck,
+# tools/binary, tools/binary_step and tools/linear.
 RT_LIB_NAME=mer_rt
 STD_LIB_NAME=mer_std
 TRACE_LIB_NAME=mer_trace
Index: scripts/ml.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/ml.in,v
retrieving revision 1.103
diff -u -u -r1.103 ml.in
--- scripts/ml.in	22 Jan 2003 03:04:51 -0000	1.103
+++ scripts/ml.in	28 Jan 2003 07:57:59 -0000
@@ -13,6 +13,11 @@
 # Usage: see below.
 #
 # Environment variables: MERCURY_C_LIB_DIR, MERCURY_DEFAULT_GRADE, ...
+#
+# *************************************************************************
+# *** IMPORTANT NOTE: any changes to this file may also require similar ***
+# *** changes to compiler/compile_target_code.m and configure.in        ***
+# *************************************************************************
 
 Usage="\
 Name: ml - Mercury Linker
@@ -39,6 +44,13 @@
 SHLIB_RPATH_OPT=${MERCURY_SHLIB_RPATH_OPT="@SHLIB_RPATH_OPT@"}
 SHLIB_RPATH_SEP=${MERCURY_SHLIB_RPATH_SEP="@SHLIB_RPATH_SEP@"}
 FIX_PATH_FOR_LINKER=${MERCURY_PATH_FOR_LINKER="@FIX_PATH_FOR_CC@"}
+LD_STATIC_FLAGS="@LD_STATIC_FLAGS@"
+LDFLAGS_FOR_THREADS="@LDFLAGS_FOR_THREADS@"
+LDFLAGS_FOR_TRACE="@LDFLAGS_FOR_TRACE@"
+LD_LIBFLAGS_FOR_THREADS="@LD_LIBFLAGS_FOR_THREADS@"
+THREAD_LIBS="@THREAD_LIBS@"
+TRACE_LIBS_SYSTEM="@TRACE_LIBS_SYSTEM@"
+
 TMPDIR=${TMPDIR=/tmp}
 MATH_LIB=${MERCURY_MATH_LIB="@MATH_LIB@"}
 # Note: the setting of SHARED_LIBS needs to come after the setting of MATH_LIB,
@@ -70,12 +82,6 @@
 	;;
 esac
 
-# On some systems (Solaris for exemple), we need libraries to be able to 
-# use sockets. The name of the needed libraries is determined by autoconf
-# and passed through this variable.
-SOCKET_LIBRARY="@SOCKET_LIBRARY@"
-NSL_LIBRARY="@NSL_LIBRARY@"
-
 # Likewise for -ldl (libdl.so), which is often needed for dlopen() etc.
 DL_LIBRARY="@DL_LIBRARY@"
 
@@ -83,8 +89,8 @@
 READLINE_LIBRARIES="@READLINE_LIBRARIES@"
 
 # If you change these, you will also need to change Mmake.workspace,
-# scripts/c2init.in, tools/bootcheck, tools/binary, tools/binary_step
-# and tools/linear.
+# compiler/compile_target_code.m, scripts/c2init.in, tools/bootcheck,
+# tools/binary, tools/binary_step and tools/linear.
 RT_LIB_NAME=mer_rt
 STD_LIB_NAME=mer_std
 TRACE_LIB_NAME=mer_trace
@@ -146,49 +152,7 @@
 # Defaults have been set, now set options.
 
 case $all_libs in static)
-	case $COMPILER in gcc|lcc)
-		MAYBE_STATIC_OPT=-static
-		;;
-	esac
-	case $FULLARCH in
-		*-linux*)
-			# On Linux, if we're linking statically, we need to
-			# pass `-defsym _DYNAMIC=0' to the linker, to avoid
-			# undefined references to _DYNAMIC in
-			# boehm_gc/dyn_load.c.
-			# (We might eventually need similar treatment
-			# for other OSs too)
-			case $COMPILER in
-	 		gcc)
-				MAYBE_STATIC_OPT="-static \
-					-Wl-defsym -Wl_DYNAMIC=0"
-				;;
-			lcc)
-				MAYBE_STATIC_OPT="-static \
-					-Wl,-defsym -Wl,_DYNAMIC=0"
-				;;
-			esac
-			;;
-		alpha*-dec-osf*)
-			case $COMPILER in cc)
-				MAYBE_STATIC_OPT=-non_shared
-				;;
-			esac
-			;;
-		*-sun-solaris*)
-			case $COMPILER in cc)
-				MAYBE_STATIC_OPT="-B static"
-				;;
-			esac
-			;;
-	esac
-	case "$MAYBE_STATIC_OPT" in "")
-		echo "ml: warning: \`--static' ignored, since I don't" 1>&2
-		echo "	know how to enable static linking with this" 1>&2
-		echo "	C compiler (\`$CC')." 1>&2
-		echo "	Using \`--mercury-libs static' instead." 1>&2
-		;;
-	esac
+	MAYBE_STATIC_OPT=$LD_STATIC_FLAGS
 esac
 
 #
@@ -249,8 +213,7 @@
 
 case $trace in
 	true)	TRACE_LIBS="-l$TRACE_LIB_NAME -l$BROWSER_LIB_NAME"
-		TRACE_LIBS_SYSTEM="$SOCKET_LIBRARY $NSL_LIBRARY $DL_LIBRARY \
-			$READLINE_LIBRARIES"
+		TRACE_LIBS_SYSTEM="$TRACE_LIBS_SYSTEM $READLINE_LIBRARIES"
 		TRACE_STATIC_LIBS="\
 		  `$FIX_PATH_FOR_LINKER \
 		    $LIBDIR/$GRADE/$FULLARCH/lib$TRACE_LIB_NAME. at LIB_SUFFIX@` \
@@ -284,37 +247,10 @@
 	use_thread_libs=true ;;
 esac
 
-case $use_thread_libs in
-	true)
-		# For Linux, Irix, Solaris, and HPUX,
-		# the thread-enabled version of the Boehm
-		# collector contains a reference to dlopen(), so 
-		# if threads are enabled, we need to link with the
-		# appropriate extra library for that (-ldl on Linux
-		# and Solaris, -lrt on HPUX, and nothing on Irix).
-		# XXX That should only be done if conservative GC
-		#     is enabled.
-
-		case "$FULLARCH" in
- 		*-osf*)		THREAD_LIBS="-lpthreads -lmach -lc_r" ;;
-		*-linux*)	THREAD_LIBS="-lpthread -ldl" ;;
-		*-solaris*)	THREAD_LIBS="-lpthread -ldl" ;;
-		### We don't yet support threads on HPUX and IRIX
-		### *-hpux*)	THREAD_LIBS="-lpthread -lrt" ;;
-		### *-irix*)	THREAD_LIBS="-lpthread" ;;
-		*cygwin*)
-			case $COMPILER in
-				cl)	ARCH_OPTS="/MD"
-					;;
-
-			esac
-			;;
-		*)		echo "$0: warning: don't know which" \
-					"library to use for pthreads" 1>&2
-				THREAD_LIBS=""
-				;;
-		esac ;;
-	false)	THREAD_LIBS="" ;;
+case $use_thread_libs.$make_shared_lib in
+	true.false)	ARCH_OPTS=$LDFLAGS_FOR_THREADS ;;
+	true.true)	ARCH_OPTS=$LD_LIBFLAGS_FOR_THREADS ;;
+	false.*)	THREAD_LIBS="" ;;
 esac
 
 case $make_shared_lib in
@@ -327,6 +263,9 @@
 	RPATH_OPT="$SHLIB_RPATH_OPT"
 	RPATH_SEP="$SHLIB_RPATH_SEP"
 	STDLIBS="$SHARED_LIBS $THREAD_LIBS"
+	case $trace in true)
+		ARCH_OPTS="$ARCH_OPTS $LD_LIBFLAGS_FOR_TRACE"
+	esac
 	;;
     false)
 	LINKER="$CC"
@@ -334,6 +273,9 @@
 	RPATH_OPT="$EXE_RPATH_OPT"
 	RPATH_SEP="$EXE_RPATH_SEP"
 	STDLIBS="$MATH_LIB $THREAD_LIBS"
+	case $trace in true)
+		ARCH_OPTS="$ARCH_OPTS $LDFLAGS_FOR_TRACE"
+	esac
 	;;
 esac
 
@@ -415,36 +357,6 @@
 	;;
 esac
 
-case $FULLARCH in
-    #
-    # On Irix 5, grades `fast' and `jump' only work in non_shared mode.
-    #
-    *-sgi-irix5*)
-	case $non_local_gotos in
-	    true)
-		ARCH_OPTS=-non_shared
-		NONSHARED_PATH="$NONSHARED_LIB_DIR:/usr/lib/nonshared"
-		LIBRARY_PATH="$NONSHARED_PATH:$LIBRARY_PATH"
-		export LIBRARY_PATH
-		;;
-	esac
-	;;
-    #
-    # On Linux ELF, `-rdynamic' is needed to make symbols
-    # exported for use in code linked in with dlopen(),
-    # which is used for interactive queries in the
-    # Mercury debugger.
-    #
-    *-linux*aout*)
-	# Linux a.out -- no special options needed
-	;;
-    *-linux*)
-	# Linux ELF -- need to add `-rdynamic' if using the debugger
-	case $trace in true)
-		ARCH_OPTS=-rdynamic
-	esac
-	;;
-esac
 
 case "$MKFIFO" in
     none) demangle=false ;;
Index: scripts/mmc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mmc.in,v
retrieving revision 1.30
diff -u -u -r1.30 mmc.in
--- scripts/mmc.in	24 Jan 2003 07:17:12 -0000	1.30
+++ scripts/mmc.in	28 Jan 2003 08:53:10 -0000
@@ -35,6 +35,9 @@
 	;;
 esac
 
+MATH_LIB=${MERCURY_MATH_LIB="@MATH_LIB@"}
+SHARED_LIBS="@SHARED_LIBS_SH@"
+
 DEFAULT_MERCURY_LINKAGE=${MERCURY_LINKAGE=@DEFAULT_LINKAGE@}
 export DEFAULT_MERCURY_LINKAGE
 
@@ -44,11 +47,19 @@
 #
 # The default optimization level should be after
 # all the options that describe the machine configuration.
+#
+# XXX Add --linker-trace-flags "@LDFLAGS_FOR_TRACE@" and
+#	--shlib-linker-trace-flags "@LD_LIBFLAGS_FOR_TRACE@"
+#	once those options are accepted everywhere.
 DEFAULT_MCFLAGS=${DEFAULT_MCFLAGS-"\
 		$MERCURY_ALL_MC_C_INCL_DIRS \
 		--cc \"${MERCURY_C_COMPILER=@CC@}\" \
 		--grade \"${MERCURY_DEFAULT_GRADE=@DEFAULT_GRADE@}\" \
+		--cflags-for-ansi \"@CFLAGS_FOR_ANSI@\" \
+		--cflags-for-optimization \"@CFLAGS_FOR_OPT@\" \
+		--cflags-for-warnings \"@CFLAGS_FOR_WARNINGS@\" \
 		--cflags-for-threads \"@CFLAGS_FOR_THREADS@\" \
+		--cflags-for-debug \"@CFLAGS_FOR_DEBUG@\" \
 		--cflags-for-regs \"@CFLAGS_FOR_REGS@\" \
 		--cflags-for-gotos \"@CFLAGS_FOR_GOTOS@\" \
 		--cflags-for-pic \"@CFLAGS_FOR_PIC@\" \
@@ -63,6 +74,25 @@
 		--create-archive-command-output-flag \"@AR_LIBFILE_OPT@\" \
 		--create-archive-command-flags \"@ARFLAGS@\" \
 		--ranlib-command \"@RANLIB@\" \
+		--link-executable-command \"@LINK_EXE@\" \
+		--link-shared-lib-command \"@LINK_SHARED_OBJ@\" \
+		--trace-libs \"@TRACE_LIBS_SYSTEM@\" \
+		--thread-libs \"@THREAD_LIBS@\" \
+		--shared-libs \"$SHARED_LIBS\" \
+		--math-lib \"$MATH_LIB\" \
+		--readline-libs \"@READLINE_LIBRARIES@\" \
+		--linker-thread-flags \"@LDFLAGS_FOR_THREADS@\" \
+		--shlib-linker-thread-flags \"@LD_LIBFLAGS_FOR_THREADS@\" \
+		--linker-static-flags \"@LD_STATIC_FLAGS@\" \
+		--linker-strip-flag \"@LD_STRIP_FLAG@\" \
+		--linker-debug-flags \"@LDFLAGS_FOR_DEBUG@\" \
+		--shlib-linker-debug-flags \"@LD_LIBFLAGS_FOR_DEBUG@\" \
+		--linker-rpath-flag \"@EXE_RPATH_OPT@\" \
+		--linker-rpath-separator \"@EXE_RPATH_SEP@\" \
+		--shlib-linker-rpath-flag \"@SHLIB_RPATH_OPT@\" \
+		--shlib-linker-rpath-separator \"@SHLIB_RPATH_SEP@\" \
+		--linker-allow-undefined-flag \"@ALLOW_UNDEFINED@\" \
+		--linker-error-undefined-flag \"@ERROR_UNDEFINED@\" \
 		--fullarch \"@FULLARCH@\" \
 		--install-prefix \"@prefix@\" \
 		@LIBGRADE_OPTS@ \
@@ -74,6 +104,7 @@
 		--dotnet-library-version \"@MS_DOTNET_LIBRARY_VERSION@\" \
 		@HAVE_DELAY_SLOT@ \
 		@HAVE_BOXED_FLOATS@ \
+		@MCFLAGS_FOR_CC@ \
 		${MERCURY_DEFAULT_OPT_LEVEL=-O2} \
 		$STDLIB_DIR_OPT \
 		$CONFIG_DIR_OPT \
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list