[m-rev.] for review: MinGW portability fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Apr 7 19:05:44 AEST 2001


Estimated hours taken: 2

Some changes needed to port Mercury to work on MinGW <http://www.mingw.org>.
(There are still more changes required, this is just a start...)

util/Mmakefile:
	Compile mkinit.c with `mgnuc --no-ansi'.
	This is needed to get the declaration of `struct stat' on MinGW.

compiler/modules.m:
	If renaming the `tmp_d' file doesn't work,
	try again after removing the `.d' file.
	This is needed since on MinGW, io__rename_file
	(i.e. rename()) won't remove the target if it already exists.
	Note that the behaviour of io__rename_file is explicitly
	documented as being implementation-dependent in this situation,
	so we need to handle this case here.

cvs -n diff -u compiler/modules.m util/Mmakefile
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.151.4.2
diff -u -r1.151.4.2 modules.m
--- compiler/modules.m	2001/02/26 01:40:49	1.151.4.2
+++ compiler/modules.m	2001/04/07 09:03:30
@@ -1984,15 +1984,40 @@
 		io__close_output(DepStream),
 		io__rename_file(TmpDependencyFileName, DependencyFileName,
 			Result3),
-		( { Result3 = error(Error) } ->
-			maybe_write_string(Verbose, " failed.\n"),
-			maybe_flush_output(Verbose),
-			{ io__error_message(Error, ErrorMsg) },
-			{ string__append_list(["can't rename file `",
-				TmpDependencyFileName, "' as `",
-				DependencyFileName, "': ", ErrorMsg],
-				Message) },
-			report_error(Message)
+		( { Result3 = error(_) } ->
+			% On some systems, we need to remove the existing file
+			% first, if any.  So try again that way.
+			io__remove_file(DependencyFileName, Result4),
+			( { Result4 = error(Error4) } ->
+				maybe_write_string(Verbose, " failed.\n"),
+				maybe_flush_output(Verbose),
+				{ io__error_message(Error4, ErrorMsg) },
+				{ string__append_list(["can't remove file `",
+					DependencyFileName, "': ", ErrorMsg],
+					Message) },
+				report_error(Message)
+			;
+				io__rename_file(TmpDependencyFileName,
+					DependencyFileName, Result5),
+				( { Result5 = error(Error5) } ->
+					maybe_write_string(Verbose,
+						" failed.\n"),
+					maybe_flush_output(Verbose),
+					{ io__error_message(Error5,
+						ErrorMsg) },
+					{ string__append_list(
+						["can't rename file `",
+						TmpDependencyFileName,
+						"' as `",
+						DependencyFileName,
+						"': ",
+						ErrorMsg],
+						Message) },
+					report_error(Message)
+				;
+					maybe_write_string(Verbose, " done.\n")
+				)
+			)
 		;
 			maybe_write_string(Verbose, " done.\n")
 		)
Index: util/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/util/Mmakefile,v
retrieving revision 1.10
diff -u -r1.10 Mmakefile
--- util/Mmakefile	2000/10/10 03:49:49	1.10
+++ util/Mmakefile	2001/04/07 09:03:30
@@ -26,6 +26,9 @@
 
 GETOPT_SRC=$(RUNTIME_DIR)/GETOPT/getopt.c $(RUNTIME_DIR)/GETOPT/getopt1.c
 
+# mkinit.c needs `struct stat'
+MGNUCFLAGS-mkinit = --no-ansi
+
 #-----------------------------------------------------------------------------#
 
 all:	$(PROGS)

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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