[m-dev.] diff: build .c files first

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Dec 21 20:49:59 AEDT 1999


This change is in response to something that one of the summer
students -- I think it was either Peter Malkin or
Robert Jeschofnik -- pointed out a couple of weeks ago.

----------

Estimated hours taken: 0.5

compiler/modules.m:
	Change the generated `.dep' file so that in the rules for
	creating executables and `.so' files, we include $(foo.cs)
	first in the dependency list (unless RM_C != ":").
	This ensures that Make will build all the .c files first,
	which avoids unnecessary effort compiling the .c files to .o
	in the case where the program gets compilation errors.

Workspace: /d-drive/home/hg/fjh/mercury
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.113
diff -u -d -r1.113 modules.m
--- compiler/modules.m	1999/12/03 12:51:59	1.113
+++ compiler/modules.m	1999/12/10 15:56:46
@@ -2624,9 +2624,33 @@
 		All_C2InitArgsDepString = "$(ALL_C2INITARGS)"
 	},
 
+	%
+	% We include $(foo.cs) first in the dependency list, before $(foo.os).
+	% This is not strictly necessary, since the .o files themselves depend
+	% on the .c files, but we do it to ensure that Make will try to
+	% create all the C files first, thus detecting errors early,
+	% rather than first spending time compiling C files to .o,
+	% which could be a waste of time if the program contains errors.
+	%
+	% But we can only do this if we don't remove the .c files,
+	% i.e. if RM_C=:
+	% So we define $(foo.maybe_cs) here and use it in the rules below.
+	% This needs to be defined here in the .dep file rather than
+	% in the .dv file since it depends on the setting of the $(RM_C) file
+	% which can be overridden by the user's Mmakefile.
+	%
 	module_name_to_file_name(SourceModuleName, "", no, ExeFileName),
 	io__write_strings(DepStream, [
-		ExeFileName, " : $(", MakeVarName, ".os) ",
+		"ifeq ($(RM_C),:)\n",
+		MakeVarName, ".maybe_cs=$(", MakeVarName, ".cs)\n",
+		"else\n",
+		MakeVarName, ".maybe_cs=\n",
+		"endif\n\n"
+	]),
+
+	io__write_strings(DepStream, [
+		ExeFileName, " : $(", MakeVarName, ".maybe_cs) ",
+			"$(", MakeVarName, ".os) ",
 			InitObjFileName, " $(MLOBJS) ", All_MLLibsDepString,
 			"\n",
 		"\t$(ML) $(ALL_GRADEFLAGS) $(ALL_MLFLAGS) -o ",
@@ -2686,8 +2710,9 @@
 	]),
 
 	io__write_strings(DepStream, [
-		SharedLibFileName, " : $(", MakeVarName,
-			".pic_os) $(MLPICOBJS) ", All_MLLibsDepString, "\n",
+		SharedLibFileName, " : $(", MakeVarName, ".maybe_cs) ",
+			"$(", MakeVarName, ".pic_os) ",
+			"$(MLPICOBJS) ", All_MLLibsDepString, "\n",
 		"\t$(ML) --make-shared-lib $(ALL_GRADEFLAGS) $(ALL_MLFLAGS) ",
 			"-o ", SharedLibFileName, " \\\n",
 		"\t\t$(", MakeVarName, ".pic_os) $(MLPICOBJS) ",
@@ -2695,7 +2720,8 @@
 	]),
 
 	io__write_strings(DepStream, [
-		LibFileName, " : $(", MakeVarName, ".os) $(MLOBJS)\n",
+		LibFileName, " : $(", MakeVarName, ".maybe_cs) ",
+			"$(", MakeVarName, ".os) $(MLOBJS)\n",
 		"\trm -f ", LibFileName, "\n",
 		"\t$(AR) $(ALL_ARFLAGS) ", LibFileName, " ",
 			"$(", MakeVarName, ".os) $(MLOBJS)\n",

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