[m-dev.] for review: mmc produce an executable using MSVC

Peter Ross petdr at cs.mu.OZ.AU
Thu Jun 15 01:55:55 AEST 2000


Hi,

For Fergus to review.

===================================================================


Estimated hours taken: 16

Changes needed to get
    mmc --grade hlc.gc file.m
producing an executable, using MSVC as the compiler.

compiler/options.m:
    Add the flags --c-flag-to-name-object-file and
    --object-file-extension.  --c-flag-to-name-object-file is the flag
    the C compiler uses to name object files (ie -o for gcc, /Fo for
    MSVC).  --object-file-extension is the extension used by object
    files on the current system.

compiler/mercury_compile.m:
    Use the values of --c-flag-to-name-object-file and
    --object-file-extension to generate the command line to compile
    C files.

scripts/mmc.in:
    Set the default values of the two new flags from the autoconfed
    settings.

configure.in:
    Set the value for CYGPATH, a utility which transforms between unix
    and window paths.  This is just echo under unix.
    
scripts/ml.in:
    Use the autoconfed extension for the library files.
    Use the autoconfed flag to add a path to list of directories to be
    searched for libraries.
    Make static libraries the default on cygwin systems.
    Factor out the code which determines all the flags to be passed to
    the linker.
    Add an autoconfed variable LINK_OPT_SET which is the flag used to
    indicate that all the options following this flag are to be passed
    on to the linker.
    Use the autoconfed setting for CYGPATH to transform the path to
    static libraries into the correct format.

Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.208
diff -u -r1.208 configure.in
--- configure.in	2000/06/13 10:12:48	1.208
+++ configure.in	2000/06/14 15:32:17
@@ -259,6 +259,8 @@
 	AR_LIBFILE_OPT="/OUT:"
 	BOEHMGC_MAKEFILE="-f NT_MAKEFILE"
 
+	CYGPATH="cygpath -w"
+
 	AC_DEFINE(MR_WIN32)
 
 		# MS doesn't use a ranlib.
@@ -279,6 +281,8 @@
 	AR_LIBFILE_OPT=""
 	BOEHMGC_MAKEFILE=""
 
+	CYGPATH=echo
+
 	AC_PROG_RANLIB
 fi
 
@@ -294,6 +298,7 @@
 AC_SUBST(LIB_LIBPATH)
 AC_SUBST(LINK_LIB)
 AC_SUBST(LINK_OPT_SEP)
+AC_SUBST(CYGPATH)
 
 #-----------------------------------------------------------------------------#
 # Don't try to use mprotect() on gnu-win32, since it is broken
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.166
diff -u -r1.166 mercury_compile.m
--- compiler/mercury_compile.m	2000/06/08 07:58:52	1.166
+++ compiler/mercury_compile.m	2000/06/14 15:32:31
@@ -454,7 +454,8 @@
 			( { CompileToC = no } ->
 				module_name_to_file_name(ModuleName, ".c", no,
 					C_File),
-				module_name_to_file_name(ModuleName, ".o", yes,
+				object_extension(Obj),
+				module_name_to_file_name(ModuleName, Obj, yes,
 					O_File),
 				mercury_compile__single_c_to_obj(
 					C_File, O_File, _CompileOK)
@@ -2397,8 +2398,9 @@
 		mercury_compile__c_to_obj_list(ModuleName, 0, NumChunks,
 			Succeeded)
 	;
+		object_extension(Obj),
 		module_name_to_file_name(ModuleName, ".c", no, C_File),
-		module_name_to_file_name(ModuleName, ".o", yes, O_File),
+		module_name_to_file_name(ModuleName, Obj, yes, O_File),
 		mercury_compile__single_c_to_obj(C_File, O_File, Succeeded)
 	).
 
@@ -2412,10 +2414,11 @@
 	( { Chunk > NumChunks } ->
 		{ Succeeded = yes }
 	;
+		object_extension(Obj),
 		module_name_to_split_c_file_name(ModuleName, Chunk,
 			".c", C_File),
 		module_name_to_split_c_file_name(ModuleName, Chunk,
-			".o", O_File),
+			Obj, O_File),
 		mercury_compile__single_c_to_obj(C_File, O_File, Succeeded0),
 		( { Succeeded0 = no } ->
 			{ Succeeded = no }
@@ -2432,6 +2435,8 @@
 
 mercury_compile__single_c_to_obj(C_File, O_File, Succeeded) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
+	globals__io_lookup_string_option(c_flag_to_name_object_file,
+			NameObjectFile),
 	maybe_write_string(Verbose, "% Compiling `"),
 	maybe_write_string(Verbose, C_File),
 	maybe_write_string(Verbose, "':\n"),
@@ -2638,7 +2643,7 @@
 		StackTraceOpt, RequireTracingOpt,
 		UseTrailOpt, MinimalModelOpt, TypeLayoutOpt,
 		InlineAllocOpt, WarningOpt, CFLAGS,
-		" -c ", C_File, " -o ", O_File], Command) },
+		" -c ", C_File, " ", NameObjectFile, O_File], Command) },
 	invoke_system_command(Command, Succeeded),
 	( { Succeeded = no } ->
 		report_error("problem compiling C file.")
@@ -2666,13 +2671,16 @@
 	),
 
 	{ file_name_to_module_name(OutputFileName, ModuleName) },
+	object_extension(Obj),
+	{ string__append("_init", Obj, InitObj) },
 	module_name_to_file_name(ModuleName, "_init.c", yes, InitCFileName),
-	module_name_to_file_name(ModuleName, "_init.o", yes, InitObjFileName),
+	module_name_to_file_name(ModuleName, InitObj, yes, InitObjFileName),
 
 	globals__io_lookup_bool_option(split_c_files, SplitFiles),
 	( { SplitFiles = yes } ->
 	    module_name_to_file_name(ModuleName, ".a", yes, SplitLibFileName),
-	    join_module_list(Modules, ".dir/*.o", [], ObjectList),
+	    { string__append(".dir/*", Obj, DirObj) },
+	    join_module_list(Modules, DirObj, [], ObjectList),
 	    { list__append(
 		["ar cr ", SplitLibFileName, " " | ObjectList],
 		[" && ranlib ", SplitLibFileName],
@@ -2682,7 +2690,7 @@
 	    { Objects = SplitLibFileName }
 	;
 	    { MakeLibCmdOK = yes },
-	    join_module_list(Modules, ".o", [], ObjectsList),
+	    join_module_list(Modules, Obj, [], ObjectsList),
 	    { string__append_list(ObjectsList, Objects) }
 	),
 	( { MakeLibCmdOK = no } ->
@@ -2940,5 +2948,14 @@
 		[]
 	).
 
+%-----------------------------------------------------------------------------%
+
+	% Extension for object files.
+:- pred object_extension(string::out, io__state::di, io__state::uo) is det.
+
+object_extension(Extension) -->
+	globals__io_lookup_string_option(object_file_extension, Extension0),
+	{ string__append(".", Extension0, Extension) }. 
+	
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.281
diff -u -r1.281 options.m
--- compiler/options.m	2000/05/24 05:18:08	1.281
+++ compiler/options.m	2000/06/14 15:32:43
@@ -258,6 +258,8 @@
 		;	cflags_for_gotos
 		;	c_debug
 		;	c_include_directory
+		;	c_flag_to_name_object_file
+		;	object_file_extension
 		;	max_jump_table_size
 		;	fact_table_max_array_size
 				% maximum number of elements in a single 
@@ -594,6 +596,14 @@
 					% the `mmc' script will override the
 					% above default with a value determined
 					% at configuration time
+	c_flag_to_name_object_file -	string("-o "),
+					% the `mmc' script will override the
+					% above default with a value determined
+					% at configuration time
+	object_file_extension	-	string("o"),
+					% the `mmc' script will override the
+					% above default with a value determined
+					% at configuration time
 	max_jump_table_size	-	int(0),
 					% 0 indicates any size.
 	fact_table_max_array_size -	int(1024),
@@ -945,6 +955,8 @@
 long_option("cflags-for-gotos",		cflags_for_gotos).
 long_option("c-debug",			c_debug).
 long_option("c-include-directory",	c_include_directory).
+long_option("c-flag-to-name-object-file", c_flag_to_name_object_file).
+long_option("object-file-extension",	object_file_extension).
 long_option("max-jump-table-size",	max_jump_table_size).
 long_option("fact-table-max-array-size",fact_table_max_array_size).
 long_option("fact-table-hash-percent-full",
@@ -1962,6 +1974,14 @@
 		"\tEnable debugging of the generated C code.",
 		"\t(This has the same effect as",
 		"\t`--cflags ""-g"" --link-flags ""--no-strip""'.)",
+
+		"--c-flag-to-name-object-file <flag>",
+		"\tThe flag the C compiler uses to name object files.",
+		"\t('-o ' for gcc and '/Fo' for Visual C.)",
+
+		"--object-file-extension <extension>",
+		"\tThe extension used to signify object files."
+		"\t('o' under unix and 'obj' under windows.)",
 
 		"--max-jump-table-size",
 		"\tThe maximum number of entries a jump table can have.",
Index: scripts/ml.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/ml.in,v
retrieving revision 1.77
diff -u -r1.77 ml.in
--- scripts/ml.in	2000/04/07 01:21:27	1.77
+++ scripts/ml.in	2000/06/14 15:32:50
@@ -109,7 +109,7 @@
 				Link with the shared libraries (*.so),
 				if possible, otherwise with the static ones.
 			--mercury-libs static
-				Link with the static libraries (*.a).
+				Link with the static libraries (*. at LIB_SUFFIX@).
 			--mercury-libs none
 				Don't link in the Mercury standard libraries.
 	-shared, --shared
@@ -241,7 +241,7 @@
 		;;
 	-L|--lib-dir)
 		dir="$2"
-		user_libdir_opts="$user_libdir_opts -L$dir"
+		user_libdir_opts="$user_libdir_opts @LIB_LIBPATH@$dir"
 		shift
 		;;
 	-L*)
@@ -310,7 +310,7 @@
 # it will also have set mercury_libs.
 case $mercury_libs in default)
 	mercury_libs=shared
-	case $FULLARCH in i?86-*-linux*|i?86-*-freebsd*)
+	case $FULLARCH in i?86-*-linux*|i?86-*-freebsd*|i?86-*-cygwin32)
 		# shared libraries are not the default on Linux
 		# -- see README.Linux
 		# Likewise for FreeBSD
@@ -327,7 +327,7 @@
 # (shared on most systems).
 case $all_libs in default)
 	all_libs=shared
-	case $FULLARCH in i?86-*-linux*|i?86-*-freebsd*)
+	case $FULLARCH in i?86-*-linux*|i?86-*-freebsd*|i?86-*-cygwin32)
 		# shared libraries are not the default on Linux
 		# -- see README.Linux
 		# Likewise for FreeBSD
@@ -441,11 +441,11 @@
 case "$GRADE" in
 	*.gc.prof*)
 		LIBGC="-lgc_prof"
-		LIBGC_STATIC="$LIBDIR/$FULLARCH/libgc_prof.a"
+		LIBGC_STATIC=`@CYGPATH@ $LIBDIR/$FULLARCH/libgc_prof. at LIB_SUFFIX@`
 		;;
 	*.gc*)
 		LIBGC="-lgc"
-		LIBGC_STATIC="$LIBDIR/$FULLARCH/libgc.a"
+		LIBGC_STATIC=`@CYGPATH@ $LIBDIR/$FULLARCH/libgc. at LIB_SUFFIX@`
 		;;
 	*)
 		LIBGC=
@@ -464,8 +464,8 @@
 		TRACE_LIBS_SYSTEM="$SOCKET_LIBRARY $NSL_LIBRARY $DL_LIBRARY \
 			$READLINE_LIBRARIES"
 		TRACE_STATIC_LIBS="\
-			$LIBDIR/$GRADE/$FULLARCH/lib$TRACE_LIB_NAME.a \
-			$LIBDIR/$GRADE/$FULLARCH/lib$BROWSER_LIB_NAME.a"
+		  `@CYGPATH@ $LIBDIR/$GRADE/$FULLARCH/lib$TRACE_LIB_NAME. at LIB_SUFFIX@` \
+		  `@CYGPATH@ $LIBDIR/$GRADE/$FULLARCH/lib$BROWSER_LIB_NAME. at LIB_SUFFIX@`"
 		;;
 	false)	TRACE_LIBS=
 		TRACE_LIBS_SYSTEM=
@@ -517,9 +517,9 @@
 esac
 
 merc_libdir_opts="\
-	-L$LIBDIR/$GRADE/$FULLARCH
-	-L$LIBDIR/$FULLARCH
-	-L/usr/local/lib
+	@LIB_LIBPATH@$LIBDIR/$GRADE/$FULLARCH
+	@LIB_LIBPATH@$LIBDIR/$FULLARCH
+	@LIB_LIBPATH@/usr/local/lib
 "
 LIBDIR_OPTS="$user_libdir_opts $merc_libdir_opts"
 
@@ -532,8 +532,8 @@
 		;;
 	static)
 		MERCURY_LIBS=${MERCURY_LIBS="$TRACE_STATIC_LIBS
-			$LIBDIR/$GRADE/$FULLARCH/lib$STD_LIB_NAME.a \
-			$LIBDIR/$GRADE/$FULLARCH/lib$RT_LIB_NAME.a \
+			`@CYGPATH@ $LIBDIR/$GRADE/$FULLARCH/lib$STD_LIB_NAME. at LIB_SUFFIX@` \
+			`@CYGPATH@ $LIBDIR/$GRADE/$FULLARCH/lib$RT_LIB_NAME. at LIB_SUFFIX@` \
 			$LIBGC_STATIC"}
 		LIBS=${LIBS="$MERCURY_LIBS $TRACE_LIBS_SYSTEM $STDLIBS"}
 		merc_shlib_dirs=""
@@ -610,17 +610,23 @@
     true) demangle=false ;;
 esac
 
+case $# in
+	0) LINKER_FLAGS="$UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT \
+		$ARCH_OPTS @LINK_OPT_SEP@ $LIBDIR_OPTS $RPATH_OPT_LIST $LIBS" ;;
+
+	*) LINKER_FLAGS="$UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT \
+		$ARCH_OPTS $@ @LINK_OPT_SEP@ $LIBDIR_OPTS $RPATH_OPT_LIST $LIBS" ;;
+esac
+
 case $verbose in
     true)
 	echo "ml: using grade \`$GRADE'"
 	case $demangle in
 	    false)
-		echo $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT \
-			$ARCH_OPTS $LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS
+		echo $LINKER $LINKER_FLAGS
 		;;
 	    true)
-		echo $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT \
-			$ARCH_OPTS $LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS "|"
+		echo $LINKER $LINKER_FLAGS "|"
 		echo "$DEMANGLER"
 		;;
 	esac
@@ -660,13 +666,7 @@
 	exec $DEMANGLER --explain-link-errors 1>&2 < $PIPE &
 		# execute $CC with stdout & stderr redirected to
 		# go via the pipe to $DEMANGLER and then to stderr
-	case $# in
-		0) $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
-			$LIBDIR_OPTS $RPATH_OPT_LIST $LIBS >$PIPE 2>&1 ;;
-
-		*) $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
-			$LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS >$PIPE 2>&1 ;;
-	esac
+	$LINKER $LINKER_FLAGS >$PIPE 2>&1
 	linker_status=$?
 		# now we can remove the pipe; since is an open file, it will
 		# stay around until $DEMANGLER exits
@@ -676,11 +676,6 @@
 	exit $linker_status
 	;;
 false)
-	case $# in
-		0) exec $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
-			$LIBDIR_OPTS $RPATH_OPT_LIST $LIBS ;;
-		*) exec $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
-			$LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS ;;
-	esac
+	exec $LINKER $LINKER_FLAGS
 	;;
 esac
Index: scripts/mmc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mmc.in,v
retrieving revision 1.8
diff -u -r1.8 mmc.in
--- scripts/mmc.in	2000/03/24 20:16:52	1.8
+++ scripts/mmc.in	2000/06/14 15:32:51
@@ -23,6 +23,8 @@
 CC=${MERCURY_C_COMPILER="@CC@"}
 CFLAGS_FOR_REGS="@CFLAGS_FOR_REGS@"
 CFLAGS_FOR_GOTOS="@CFLAGS_FOR_GOTOS@"
+CFLAG_TO_NAME_OBJECT_FILE="@OBJFILE_OPT@"
+OBJECT_FILE_EXTENSION="@OBJ_SUFFIX@"
 LOW_TAG_BITS=@LOW_TAG_BITS@
 BITS_PER_WORD=@BITS_PER_WORD@
 BYTES_PER_WORD=@BYTES_PER_WORD@
@@ -41,6 +43,8 @@
 		--cc "$CC" --grade "$DEFAULT_GRADE" \
 		--cflags-for-regs "$CFLAGS_FOR_REGS" \
 		--cflags-for-gotos "$CFLAGS_FOR_GOTOS" \
+		--c-flag-to-name-object-file "$CFLAG_TO_NAME_OBJECT_FILE" \
+		--object-file-extension "$OBJECT_FILE_EXTENSION" \
 		--num-real-r-regs "$NUM_REAL_R_REGS" \
 		--num-real-r-temps "$NUM_REAL_R_TEMPS" \
 		--conf-low-tag-bits "$LOW_TAG_BITS" \
@@ -56,6 +60,8 @@
 		--cc "$CC" --grade "$DEFAULT_GRADE" \
 		--cflags-for-regs "$CFLAGS_FOR_REGS" \
 		--cflags-for-gotos "$CFLAGS_FOR_GOTOS" \
+		--c-flag-to-name-object-file "$CFLAG_TO_NAME_OBJECT_FILE" \
+		--object-file-extension "$OBJECT_FILE_EXTENSION" \
 		--num-real-r-regs "$NUM_REAL_R_REGS" \
 		--num-real-r-temps "$NUM_REAL_R_TEMPS" \
 		--conf-low-tag-bits "$LOW_TAG_BITS" \

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list