diff: centralize file-name handling

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 17 04:08:15 AEDT 1998


Estimated hours taken: 4.5

Change things so that almost all the places which create file names
do so via just a few predicates (such as module_name_to_file_name)
in modules.m.  Centralising the file handling in this way
will make future changes to the file naming convention simpler.

(The one place which still creates file names other than via the predicates
declared at the start of modules.m is mercury_compile__link_module_list.
It creates them based on the value of the `-o <filename>' option.
I didn't change that because I am not yet sure what the semantics of
the `-o <filename>' option ought to be.)

compiler/modules.m:
	Add three extra arguments to module_name_to_file_name/2:
	the file extension, and an io__state pair.
	Add new predicates module_name_to_lib_file_name/6,
	module_name_to_split_c_file_name/6, and
	module_name_to_make_var_name/2.
	
compiler/export.m:
compiler/intermod.m:
compiler/llds_out.m:
compiler/mercury_compile.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/termination.m:
compiler/trans_opt.m:
compiler/unused_args.m:
	Change all calls to module_name_to_file_name/2 to instead
	call one of the above-mentioned predicates in modules.m.

compiler/llds_out.m:
	Add new predicate llds_out__make_init_name/2 which returns
	the name of the initialization function for a module,
	for use by modules.m.

compiler/modules.m:
	A few minor changes to the generated .dep files:
		- add a new phony target `foo.trans_opt',
		  to match `foo.opt';
		- change the generated rule for `change_clean'
		  so that it removes `.pic_o' files;
		- add `.PHONY' declarations for phony targets;
		- change the generated rule for making `foo.init'
		  so that it used the names returned by
		  llds_out__make_init_name/2, rather than
		  using "mercury__`basename foo.m .m`__init";
		- fix a bug in the generated rule for making `libfoo.a':
		  it had `rm -f foo.a' instead of `rm -f libfoo.a'.

-----------------------------------------------------------------------------

First, here's the diff of the generated `.dep' files for
the library directory:

-----------------------------------------------------------------------------
--- t1/library.dep	Tue Mar 17 03:08:49 1998
+++ t2/library.dep	Tue Mar 17 04:04:51 1998
@@ -1,5 +1,5 @@
 # Automatically generated dependencies for module `library'.
-# Generated by the Mercury compiler, version rotd-1998-03-16, configured for alpha-dec-osf3.2.
+# Generated by the Mercury compiler, version DEV, configured for alpha-dec-osf3.2.
 
 library.ms = \
 	array.m \
@@ -88,6 +88,7 @@
 	done
 	$(RANLIB) $(RANLIBFLAGS) library.split.a
 
+.PHONY : liblibrary
 liblibrary : liblibrary.a liblibrary.$(EXT_FOR_SHARED_LIB) \
 		$(library.ints) $(library.int3s) $(library.opts) library.init
 
@@ -96,14 +97,58 @@
 		$(library.pic_os) $(MLPICOBJS) $(MLLIBS)
 
 liblibrary.a : $(library.os) MLOBJS-library
-	rm -f library.a
+	rm -f liblibrary.a
 	$(AR) $(ARFLAGS) liblibrary.a $(library.os) $(MLOBJS)
 	$(RANLIB) $(RANLIBFLAGS) liblibrary.a
 
 library.init : library.dep
-	for file in $(library.ms); do \
-		echo "INIT mercury__`basename $$file .m`__init"; \
-	done > library.init
+	echo > library.init
+	echo "INIT mercury__array__init" >> library.init
+	echo "INIT mercury__assoc_list__init" >> library.init
+	echo "INIT mercury__bag__init" >> library.init
+	echo "INIT mercury__benchmarking__init" >> library.init
+	echo "INIT mercury__bimap__init" >> library.init
+	echo "INIT mercury__bintree__init" >> library.init
+	echo "INIT mercury__bintree_set__init" >> library.init
+	echo "INIT mercury__bool__init" >> library.init
+	echo "INIT mercury__bt_array__init" >> library.init
+	echo "INIT mercury__char__init" >> library.init
+	echo "INIT mercury__dir__init" >> library.init
+	echo "INIT mercury__eqvclass__init" >> library.init
+	echo "INIT mercury__float__init" >> library.init
+	echo "INIT mercury__getopt__init" >> library.init
+	echo "INIT mercury__graph__init" >> library.init
+	echo "INIT mercury__group__init" >> library.init
+	echo "INIT mercury__int__init" >> library.init
+	echo "INIT mercury__io__init" >> library.init
+	echo "INIT mercury__lexer__init" >> library.init
+	echo "INIT mercury__library__init" >> library.init
+	echo "INIT mercury__list__init" >> library.init
+	echo "INIT mercury__map__init" >> library.init
+	echo "INIT mercury__math__init" >> library.init
+	echo "INIT mercury__mercury_builtin__init" >> library.init
+	echo "INIT mercury__multi_map__init" >> library.init
+	echo "INIT mercury__ops__init" >> library.init
+	echo "INIT mercury__parser__init" >> library.init
+	echo "INIT mercury__pqueue__init" >> library.init
+	echo "INIT mercury__prolog__init" >> library.init
+	echo "INIT mercury__queue__init" >> library.init
+	echo "INIT mercury__random__init" >> library.init
+	echo "INIT mercury__rbtree__init" >> library.init
+	echo "INIT mercury__relation__init" >> library.init
+	echo "INIT mercury__require__init" >> library.init
+	echo "INIT mercury__set__init" >> library.init
+	echo "INIT mercury__set_bbbtree__init" >> library.init
+	echo "INIT mercury__set_ordlist__init" >> library.init
+	echo "INIT mercury__set_unordlist__init" >> library.init
+	echo "INIT mercury__stack__init" >> library.init
+	echo "INIT mercury__std_util__init" >> library.init
+	echo "INIT mercury__store__init" >> library.init
+	echo "INIT mercury__string__init" >> library.init
+	echo "INIT mercury__term__init" >> library.init
+	echo "INIT mercury__term_io__init" >> library.init
+	echo "INIT mercury__tree234__init" >> library.init
+	echo "INIT mercury__varset__init" >> library.init
 
 library_init.c :
 	$(C2INIT) $(C2INITFLAGS) $(library.ms) > library_init.c
@@ -128,7 +173,10 @@
 
 library.opts : $(library.optdates)
 
+library.trans_opts : $(library.trans_opt_dates)
+
 clean : library.clean
+.PHONY : library.clean
 library.clean :
 	-rm -rf library.dir
 	-rm -f $(library.cs) library_init.c
@@ -142,15 +190,18 @@
 	-rm -f $(library.qls)
 	-rm -f $(library.errs)
 
+.PHONY : library.change_clean
 library.change_clean :
 	-rm -f $(library.cs) library_init.c
 	-rm -f $(library.ss) library_init.s
 	-rm -f $(library.os) library_init.o
+	-rm -f $(library.pic_os) library_init.pic_o
 	-rm -f $(library.hs)
 	-rm -f $(library.ds)
 	-rm -f library library.split library.split.a library.init liblibrary.a liblibrary.so library.dep
 
 realclean : library.realclean
+.PHONY : library.realclean
 library.realclean : library.clean
 	-rm -f $(library.dates)
 	-rm -f $(library.date0s)
@@ -162,13 +213,15 @@
 	-rm -f $(library.opts)
 	-rm -f $(library.ds)
 	-rm -f $(library.hs)
-	-rm -f library library.split library.split.a library.init liblibrary.a liblibrary.so library.nu library.nu.save library.nu.debug.save library.nu.debug library.sicstus library.sicstus.debug library.dep
+	-rm -f library library.split library.split.a library.init liblibrary.a liblibrary.so library.nu library.nu.save library.nu.debug library.nu.debug.save library.sicstus library.sicstus.debug library.dep
 
 clean_nu : library.clean_nu
+.PHONY : library.clean_nu
 library.clean_nu :
 	-rm -f $(library.nos)
 
 clean_sicstus : library.clean_sicstus
+.PHONY : library.clean_sicstus
 library.clean_sicstus :
 	-rm -f $(library.qls)
-----------------------------------------------------------------------------

Now, here's the diff for the source code changes.
 
-----------------------------------------------------------------------------
cvs diff: Diffing .
Index: export.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/export.m,v
retrieving revision 1.19
diff -u -u -r1.19 export.m
--- export.m	1998/03/03 17:34:11	1.19
+++ export.m	1998/03/16 14:50:27
@@ -449,16 +449,17 @@
 	->
 		{ module_info_get_predicate_table(Module, PredicateTable) },
 		{ predicate_table_get_preds(PredicateTable, Preds) },
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".h", FileName) },
+		module_name_to_file_name(ModuleName, ".h", FileName),
 		io__tell(FileName, Result),
 		(
 			{ Result = ok }
 		->
+			module_name_to_file_name(ModuleName, ".m",
+				SourceFileName),
 			{ library__version(Version) },
 			io__write_strings(
 				["/*\n** Automatically generated from `", 
-				BaseFileName,
+				SourceFileName,
 				".m' by the\n** Mercury compiler, version ", 
 				Version,
 				".  Do not edit.\n*/\n"]),
Index: intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.46
diff -u -u -r1.46 intermod.m
--- intermod.m	1998/03/03 17:34:44	1.46
+++ intermod.m	1998/03/16 14:51:19
@@ -79,8 +79,7 @@
 
 intermod__write_optfile(ModuleInfo0, ModuleInfo) -->
 	{ module_info_name(ModuleInfo0, ModuleName) },
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, ".opt.tmp", TmpName) },
+	module_name_to_file_name(ModuleName, ".opt.tmp", TmpName),
 	io__tell(TmpName, Result2),
 	(
 		{ Result2 = error(Err2) },
@@ -1321,8 +1320,7 @@
 	maybe_flush_output(VeryVerbose),
 	maybe_write_string(VeryVerbose, "% done.\n"),
 
-	{ module_name_to_file_name(Import, BaseFileName) },
-	{ string__append(BaseFileName, ".opt", FileName) },
+	module_name_to_file_name(Import, ".opt", FileName),
 	prog_io__read_module(FileName, Import, yes,
 			ModuleError, Messages, Items1),
 	update_error_status(FileName, ModuleError, Messages, Error0, Error1),
Index: llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.75
diff -u -u -r1.75 llds_out.m
--- llds_out.m	1998/03/11 05:09:59	1.75
+++ llds_out.m	1998/03/16 15:47:02
@@ -103,6 +103,12 @@
 :- pred llds_out__make_base_typeclass_info_name(class_id, string, string).
 :- mode llds_out__make_base_typeclass_info_name(in, in, out) is det.
 
+	% Returns the name of the initialization function
+	% for a given module.
+
+:- pred llds_out__make_init_name(module_name, string).
+:- mode llds_out__make_init_name(in, out) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- implementation.
@@ -133,8 +139,7 @@
 	globals__io_lookup_bool_option(split_c_files, SplitFiles),
 	( { SplitFiles = yes } ->
 		{ C_File = c_file(ModuleName, C_HeaderInfo, C_Modules) },
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".dir", ObjDirName) },
+		module_name_to_file_name(ModuleName, ".dir", ObjDirName),
 		make_directory(ObjDirName),
 		output_c_file_init(ModuleName, C_Modules),
 		output_c_file_list(C_Modules, 1, ModuleName, C_HeaderInfo)
@@ -165,18 +170,21 @@
 :- mode output_c_file_init(in, in, di, uo) is det.
 
 output_c_file_init(ModuleName, C_Modules) -->
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__format("%s.dir/%s_%03d.c",
-		[s(BaseFileName), s(BaseFileName), i(0)], FileName) },
+	module_name_to_file_name(ModuleName, ".m", SourceFileName),
+	module_name_to_split_c_file_name(ModuleName, 0, ".c", FileName),
+
 	io__tell(FileName, Result),
 	(
 		{ Result = ok }
 	->
 		{ library__version(Version) },
 		io__write_strings(
-			["/*\n** Automatically generated from `", BaseFileName,
-			".m' by the Mercury compiler,\n** version ", Version,
-			".\n** Do not edit.\n*/\n"]),
+			["/*\n",
+			"** Automatically generated from `", SourceFileName,
+				"' by the Mercury compiler,\n",
+			"** version ", Version, ".\n",
+			"** Do not edit.\n",
+			"*/\n"]),
 		io__write_string("/*\n"),
 		io__write_string("INIT "),
 		output_init_name(ModuleName),
@@ -202,23 +210,25 @@
 
 output_single_c_file(c_file(ModuleName, C_HeaderLines, Modules), SplitFiles) 
 		-->
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
 	( { SplitFiles = yes(Num) } ->
-		{ string__format("%s.dir/%s_%03d.c",
-			[s(BaseFileName), s(BaseFileName), i(Num)],
-			FileName) }
+		module_name_to_split_c_file_name(ModuleName, Num, ".c",
+			FileName)
 	;
-		{ string__append(BaseFileName, ".c", FileName) }
+		module_name_to_file_name(ModuleName, ".c", FileName)
 	),
 	io__tell(FileName, Result),
 	(
 		{ Result = ok }
 	->
 		{ library__version(Version) },
+		module_name_to_file_name(ModuleName, ".m", SourceFileName),
 		io__write_strings(
-			["/*\n** Automatically generated from `", BaseFileName,
-			".m' by the Mercury compiler,\n** version ", Version,
-			".\n** Do not edit.\n*/\n"]),
+			["/*\n",
+			"** Automatically generated from `", SourceFileName,
+				"' by the Mercury compiler,\n",
+			"** version ", Version, ".\n",
+			"** Do not edit.\n",
+			"*/\n"]),
 		( { SplitFiles = yes(_) } ->
 			[]
 		;
@@ -396,10 +406,13 @@
 :- mode output_init_name(in, di, uo) is det.
 
 output_init_name(ModuleName) -->
-	io__write_string("mercury__"),
-	{ llds_out__sym_name_mangle(ModuleName, MangledModuleName) },
-	io__write_string(MangledModuleName),
-	io__write_string("__init").
+	{ llds_out__make_init_name(ModuleName, InitName) },
+	io__write_string(InitName).
+
+llds_out__make_init_name(ModuleName, InitName) :-
+	llds_out__sym_name_mangle(ModuleName, MangledModuleName),
+	string__append_list(["mercury__", MangledModuleName, "__init"],
+		InitName).
 
 :- pred output_bunch_name(module_name, int, io__state, io__state).
 :- mode output_bunch_name(in, in, di, uo) is det.
Index: mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.76
diff -u -u -r1.76 mercury_compile.m
--- mercury_compile.m	1998/03/03 17:35:03	1.76
+++ mercury_compile.m	1998/03/16 15:50:50
@@ -162,9 +162,9 @@
 process_module_2(ModuleName) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
 	maybe_write_string(Verbose, "% Parsing `"),
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	maybe_write_string(Verbose, BaseFileName),
-	maybe_write_string(Verbose, ".m' and imported interfaces...\n"),
+	module_name_to_file_name(ModuleName, ".m", FileName),
+	maybe_write_string(Verbose, FileName),
+	maybe_write_string(Verbose, "' and imported interfaces...\n"),
 	read_mod(ModuleName, ".m", "Reading module", yes, Items0, Error), !,
 	globals__io_lookup_bool_option(statistics, Stats),
 	maybe_report_stats(Stats),
@@ -188,7 +188,7 @@
 	; { MakePrivateInterface = yes } ->
 		make_private_interface(ModuleName, Items0)
 	; { ConvertToMercury = yes } ->
-		{ string__append(BaseFileName, ".ugly", OutputFileName) },
+		module_name_to_file_name(ModuleName, ".ugly", OutputFileName),
 		convert_to_mercury(ModuleName, OutputFileName, Items0)
 	; { ConvertToGoedel = yes } ->
 		convert_to_goedel(ModuleName, Items0)
@@ -257,14 +257,14 @@
 		mercury_compile__middle_pass(ModuleName, HLDS25, HLDS50), !,
 		globals__io_lookup_bool_option(highlevel_c, HighLevelC),
 		( { HighLevelC = yes } ->
-			{ module_name_to_file_name(ModuleName, BaseFileName) },
-			{ string__append(BaseFileName, ".c", C_File) },
+			module_name_to_file_name(ModuleName, ".c", C_File),
+			module_name_to_file_name(ModuleName, ".o", O_File),
 			mercury_compile__gen_hlds(C_File, HLDS50),
 			globals__io_lookup_bool_option(compile_to_c,
 				CompileToC),
 			( { CompileToC = no } ->
-				mercury_compile__single_c_to_obj(BaseFileName,
-					_CompileOK)
+				mercury_compile__single_c_to_obj(
+					C_File, O_File, _CompileOK)
 			;
 				[]
 			)
@@ -395,14 +395,12 @@
 			( { WarnNoTransOptDeps = yes } ->
 				{ prog_out__sym_name_to_string(ModuleName,
 					ModuleString) },
-				{ module_name_to_file_name(ModuleName,
-					BaseFileName) },
 				io__write_strings([
 				    "Warning: cannot read trans-opt ",
 				    "dependencies for module `",
 				    ModuleString, "'.\n",
-				    "  Run `mmake ", BaseFileName, ".depend' ",
-				    "to remake the dependencies.\n"]),
+				    "  You need to remake ",
+				    "the dependencies.\n"]),
 				globals__io_lookup_bool_option(halt_at_warn,
 					Halt),
 				( { Halt = yes } ->
@@ -596,8 +594,7 @@
 			{ HLDS = HLDS1 }
 		),
 		{ module_info_name(HLDS, ModuleName) },
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".opt", OptName) },
+		module_name_to_file_name(ModuleName, ".opt", OptName),
 		update_interface(OptName),
 		touch_interface_datestamp(ModuleName, ".optdate")
 	;
@@ -1218,8 +1215,8 @@
 	( { ShowDepGraph = yes } ->
 		maybe_write_string(Verbose, "% Writing dependency graph..."),
 		{ module_info_name(ModuleInfo0, ModuleName) },
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".dependency_graph", FileName) },
+		module_name_to_file_name(ModuleName, ".dependency_graph",
+			FileName),
 		io__tell(FileName, Res),
 		( { Res = ok } ->
 			dependency_graph__write_dependency_graph(ModuleInfo0,
@@ -1253,9 +1250,8 @@
 		maybe_write_string(Verbose, "% Outputing profiling call graph..."),
 		maybe_flush_output(Verbose),
 		{ module_info_name(ModuleInfo0, ModuleName) },
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".prof", WholeFileName) },
-		io__tell(WholeFileName, Res),
+		module_name_to_file_name(ModuleName, ".prof", ProfFileName),
+		io__tell(ProfFileName, Res),
 		(
 			{ Res = ok }
 		->
@@ -1342,8 +1338,8 @@
 		bytecode_gen__module(HLDS1, Bytecode),
 		maybe_write_string(Verbose, "% done.\n"),
 		maybe_report_stats(Stats),
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".bytedebug", BytedebugFile) },
+		module_name_to_file_name(ModuleName, ".bytedebug",
+			BytedebugFile),
 		maybe_write_string(Verbose,
 			"% Writing bytecodes to `"),
 		maybe_write_string(Verbose, BytedebugFile),
@@ -1351,7 +1347,7 @@
 		maybe_flush_output(Verbose),
 		debug_bytecode_file(BytedebugFile, Bytecode),
 		maybe_write_string(Verbose, " done.\n"),
-		{ string__append(BaseFileName, ".mbc", BytecodeFile) },
+		module_name_to_file_name(ModuleName, ".mbc", BytecodeFile),
 		maybe_write_string(Verbose,
 			"% Writing bytecodes to `"),
 		maybe_write_string(Verbose, BytecodeFile),
@@ -1735,7 +1731,7 @@
 
 maybe_add_header_file_include(PragmaExports, ModuleName, 
 		C_HeaderCode0, C_HeaderCode) -->
-	{ module_name_to_file_name(ModuleName, BaseName) },
+	module_name_to_file_name(ModuleName, ".h", HeaderFileName),
 	(
 		{ PragmaExports = [] },
 		{ C_HeaderCode = C_HeaderCode0 }
@@ -1744,14 +1740,13 @@
                 globals__io_lookup_bool_option(split_c_files, SplitFiles),
                 { 
 			SplitFiles = yes,
-			
                         string__append_list(
-                                ["#include ""../", BaseName, ".h""\n"],
+                                ["#include ""../", HeaderFileName, """\n"],
 				Include0)
                 ;
 			SplitFiles = no,
                         string__append_list(
-				["#include """, BaseName, ".h""\n"],
+				["#include """, HeaderFileName, """\n"],
 				Include0)
                 },
 
@@ -1799,9 +1794,9 @@
 mercury_compile__output_llds(ModuleName, LLDS, Verbose, Stats) -->
 	maybe_write_string(Verbose,
 		"% Writing output to `"),
-	{ module_name_to_file_name(ModuleName, FileName) },
+	module_name_to_file_name(ModuleName, ".c", FileName),
 	maybe_write_string(Verbose, FileName),
-	maybe_write_string(Verbose, ".c'..."),
+	maybe_write_string(Verbose, "'..."),
 	maybe_flush_output(Verbose),
 	output_c_file(LLDS),
 	maybe_write_string(Verbose, " done.\n"),
@@ -1845,44 +1840,45 @@
 :- mode mercury_compile__c_to_obj(in, in, out, di, uo) is det.
 
 mercury_compile__c_to_obj(ModuleName, NumChunks, Succeeded) -->
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
 	globals__io_lookup_bool_option(split_c_files, SplitFiles),
 	( { SplitFiles = yes } ->
-		mercury_compile__c_to_obj_list(BaseFileName, 0, NumChunks,
+		mercury_compile__c_to_obj_list(ModuleName, 0, NumChunks,
 			Succeeded)
 	;
-		mercury_compile__single_c_to_obj(BaseFileName, Succeeded)
+		module_name_to_file_name(ModuleName, ".c", C_File),
+		module_name_to_file_name(ModuleName, ".o", O_File),
+		mercury_compile__single_c_to_obj(C_File, O_File, Succeeded)
 	).
 
-:- pred mercury_compile__c_to_obj_list(string, int, int, bool,
+:- pred mercury_compile__c_to_obj_list(module_name, int, int, bool,
 					io__state, io__state).
 :- mode mercury_compile__c_to_obj_list(in, in, in, out, di, uo) is det.
 
 	% compile each of the C files in `<module>.dir'
 
-mercury_compile__c_to_obj_list(BaseFileName, Chunk, NumChunks, Succeeded) -->
+mercury_compile__c_to_obj_list(ModuleName, Chunk, NumChunks, Succeeded) -->
 	( { Chunk > NumChunks } ->
 		{ Succeeded = yes }
 	;
-		{ dir__basename(BaseFileName, BaseName) },
-		{ string__format("%s.dir/%s_%03d",
-			[s(BaseName), s(BaseName), i(Chunk)], NewName) },
-		mercury_compile__single_c_to_obj(NewName, Succeeded0),
+		module_name_to_split_c_file_name(ModuleName, Chunk,
+			".c", C_File),
+		module_name_to_split_c_file_name(ModuleName, Chunk,
+			".o", O_File),
+		mercury_compile__single_c_to_obj(C_File, O_File, Succeeded0),
 		( { Succeeded0 = no } ->
 			{ Succeeded = no }
 		;
 			{ Chunk1 is Chunk + 1 },
-			mercury_compile__c_to_obj_list(BaseFileName,
+			mercury_compile__c_to_obj_list(ModuleName,
 				Chunk1, NumChunks, Succeeded)
 		)
 	).
 
-:- pred mercury_compile__single_c_to_obj(string, bool, io__state, io__state).
-:- mode mercury_compile__single_c_to_obj(in, out, di, uo) is det.
+:- pred mercury_compile__single_c_to_obj(string, string, bool,
+					io__state, io__state).
+:- mode mercury_compile__single_c_to_obj(in, in, out, di, uo) is det.
 
-mercury_compile__single_c_to_obj(BaseFileName, Succeeded) -->
-	{ string__append(BaseFileName, ".c", C_File) },
-	{ string__append(BaseFileName, ".o", O_File) },
+mercury_compile__single_c_to_obj(C_File, O_File, Succeeded) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
 	maybe_write_string(Verbose, "% Compiling `"),
 	maybe_write_string(Verbose, C_File),
@@ -2102,7 +2098,10 @@
 		% compile it
 		maybe_write_string(Verbose,
 			"% Compiling initialization file...\n"),
-		mercury_compile__single_c_to_obj(C_Init_Base, CompileOK),
+		{ string__append(C_Init_Base, ".c", C_InitSrc) },
+		{ string__append(C_Init_Base, ".o", C_InitObj) },
+		mercury_compile__single_c_to_obj(C_InitSrc, C_InitObj,
+			CompileOK),
 		maybe_report_stats(Stats),
 		( { CompileOK = no } ->
 		    report_error("compilation of init file failed.")
@@ -2201,9 +2200,11 @@
 		}
 	->
 		{ module_info_name(HLDS, ModuleName) },
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append_list( [BaseFileName, ".hlds_dump.",
-				StageNum, "-", StageName], DumpFile) },
+		module_name_to_file_name(ModuleName, ".hlds_dump",
+			BaseFileName),
+		{ string__append_list(
+			[BaseFileName, ".", StageNum, "-", StageName],
+			DumpFile) },
 		mercury_compile__dump_hlds(DumpFile, HLDS)
 	;
 		[]
Index: module_qual.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/module_qual.m,v
retrieving revision 1.33
diff -u -u -r1.33 module_qual.m
--- module_qual.m	1998/03/11 19:55:28	1.33
+++ module_qual.m	1998/03/16 14:53:16
@@ -1003,8 +1003,7 @@
 	->
 		[]
 	;
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".m", FileName) },
+		module_name_to_file_name(ModuleName, ".m", FileName),
 		{ term__context_init(FileName, 1, Context) },
 		prog_out__write_context(Context),
 		io__write_string("In module `"),
Index: modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.61
diff -u -u -r1.61 modules.m
--- modules.m	1998/03/06 09:05:12	1.61
+++ modules.m	1998/03/16 17:02:23
@@ -44,14 +44,46 @@
 
 %-----------------------------------------------------------------------------%
 
-	% Convert a module name to the corresponding file name
-	% (excluding the trailing `.m').
+	% module_name_to_file_name(Module, Extension, FileName):
+	%	Convert a module name and file extension to the
+	%	corresponding file name.
+	%
+	%	Currently we use the convention that the module
+	%	`foo:bar:baz' should be named `foo.bar.baz.m',
+	%	but eventually we will also allow other file
+	%	naming conventions.
+	%
+	%	Note that this predicate is also used to create
+	%	some "phony" Makefile targets that do not have
+	%	corresponding files, e.g. `<foo>.clean'.
 	%
-	% Currently we use the convention that the module
-	% `foo:bar:baz' should be named `foo.bar.baz.m'.
+:- pred module_name_to_file_name(module_name, string, file_name,
+				io__state, io__state).
+:- mode module_name_to_file_name(in, in, out, di, uo) is det.
+
+	% module_name_to_lib_file_name(Prefix, Module, Extension, FileName):
+	%	Like module_name_to_file_name, but also allows a prefix.
+	%
+	%	Used for creating library names, e.g. `lib<foo>.a'
+	%	and `lib<foo>.so'.
+	%
+:- pred module_name_to_lib_file_name(string, module_name, string, file_name,
+				io__state, io__state).
+:- mode module_name_to_lib_file_name(in, in, in, out, di, uo)
+	is det.
+
+	% module_name_to_split_c_file_name(Module, Num, Extension, FileName):
+	%	Like module_name_to_file_name, but also allows a sequence
+	%	number.  The files produced by this predicate will all be
+	%	in a subdirectory DirName, which be obtained by calling
+	%	`module_name_to_file_name(Module, ".dir", DirName)'.
+	%
+	%	This predicate is used for the names of .c and .o files
+	%	for --split-c-files.
 	%
-:- pred module_name_to_file_name(module_name, file_name).
-:- mode module_name_to_file_name(in, out) is det.
+:- pred module_name_to_split_c_file_name(module_name, int, string, file_name,
+				io__state, io__state).
+:- mode module_name_to_split_c_file_name(in, in, in, out, di, uo) is det.
 
 	% convert a file name (excluding the trailing `.m')
 	% to the corresponding module name
@@ -59,6 +91,11 @@
 :- pred file_name_to_module_name(file_name, module_name).
 :- mode file_name_to_module_name(in, out) is det.
 
+	% Convert a module name to something that is suitable
+	% for use as a variable name in makefiles.
+:- pred module_name_to_make_var_name(module_name, string).
+:- mode module_name_to_make_var_name(in, out) is det.
+
 %-----------------------------------------------------------------------------%
 
 	% read_mod(ModuleName, Extension, Descr, Search, Items, Error):
@@ -326,7 +363,7 @@
 %-----------------------------------------------------------------------------%
 
 :- implementation.
-:- import_module passes_aux, prog_out, prog_util, mercury_to_mercury.
+:- import_module llds_out, passes_aux, prog_out, prog_util, mercury_to_mercury.
 :- import_module prog_io_util, globals, options, intermod, module_qual.
 
 :- import_module string, set, map, term, varset, dir, library.
@@ -339,12 +376,28 @@
 	% `foo:bar:baz' will be in files `foo.bar.baz.{m,int,etc.}'.
 	% It would be nice to allow a more flexible mapping.
 
-module_name_to_file_name(ModuleName, BaseFileName) :-
-	prog_out__sym_name_to_string(ModuleName, ".", BaseFileName).
-
+module_name_to_file_name(ModuleName, Ext, FileName) -->
+	{ prog_out__sym_name_to_string(ModuleName, ".", BaseFileName) },
+	{ string__append(BaseFileName, Ext, FileName) }.
+
+module_name_to_lib_file_name(Prefix, ModuleName, Ext, FileName) -->
+	{ prog_out__sym_name_to_string(ModuleName, ".", BaseFileName) },
+	{ string__append_list([Prefix, BaseFileName, Ext], FileName) }.
+
+module_name_to_split_c_file_name(ModuleName, Num, Ext, FileName) -->
+	module_name_to_file_name(ModuleName, ".dir", DirName),
+	{ unqualify_name(ModuleName, BaseFileName) },
+	{ dir__directory_separator(Slash) },
+	{ string__format("%s%c%s_%03d%s",
+		[s(DirName), c(Slash), s(BaseFileName), i(Num), s(Ext)],
+		FileName) }.
+		
 file_name_to_module_name(FileName, ModuleName) :-
 	string_to_sym_name(FileName, ".", ModuleName).
 
+module_name_to_make_var_name(ModuleName, MakeVarName) :-
+	prog_out__sym_name_to_string(ModuleName, ".", MakeVarName).
+
 %-----------------------------------------------------------------------------%
 
 	% Read in the .int3 files that the current module depends on,
@@ -355,10 +408,10 @@
 		%
 		% Check whether we succeeded
 		%
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
+	module_name_to_file_name(ModuleName, ".int0", FileName),
 	( { Error = yes } ->
 		io__write_strings(["Error reading interface files.\n",
-				"`", BaseFileName, ".int0' not written.\n"])
+				"`", FileName, "' not written.\n"])
 	;
 			%
 			% Module-qualify all items.
@@ -368,8 +421,7 @@
 				Items2, ModuleName, yes, _, _, _, _),
 		io__get_exit_status(Status),
 		( { Status \= 0 } ->
-			io__write_strings(["`", BaseFileName, ".int0' ",
-				"not written.\n"])
+			io__write_strings(["`", FileName, "' not written.\n"])
 		;
 				%
 				% Write out the `.int0' file.
@@ -395,12 +447,13 @@
 		%
 		% Check whether we succeeded
 		%
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
 	{ module_imports_get_items(Module0, InterfaceItems1) },
 	( { Error = yes } ->
+		module_name_to_file_name(ModuleName, ".int", IntFileName),
+		module_name_to_file_name(ModuleName, ".int2", Int2FileName),
 		io__write_strings(["Error reading short interface files.\n",
-				"`", BaseFileName, ".int' and ",
-				"`", BaseFileName, ".int2' not written.\n"])
+				"`", IntFileName, "' and ",
+				"`", Int2FileName, "' not written.\n"])
 	;
 			%
 			% Module-qualify all items.
@@ -409,7 +462,9 @@
 				InterfaceItems2, ModuleName, yes, _, _, _, _),
 		io__get_exit_status(Status),
 		( { Status \= 0 } ->
-			io__write_strings(["`", BaseFileName, ".int' ",
+			module_name_to_file_name(ModuleName, ".int",
+				IntFileName),
+			io__write_strings(["`", IntFileName, "' ",
 				"not written.\n"])
 		;
 			%
@@ -583,8 +638,7 @@
 	( 	
 		{ ExportWarning = yes }
 	->
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".m", FileName) },
+		module_name_to_file_name(ModuleName, ".m", FileName),
 		{ sym_name_to_string(ModuleName, ModuleNameString) },
 		{ string__append_list(["interface for module `",
 			ModuleNameString, "' does not export anything."],
@@ -618,14 +672,14 @@
 
 		% create (e.g.) `foo.int.tmp'
 
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, Suffix, OutputFileName) },
-	{ string__append(OutputFileName, ".tmp", TmpOutputFileName) },
+	{ string__append(Suffix, ".tmp", TmpSuffix) },
+	module_name_to_file_name(ModuleName, Suffix, OutputFileName),
+	module_name_to_file_name(ModuleName, TmpSuffix, TmpOutputFileName),
 
 		% we need to add a `:- interface' declaration at the start
 		% of the item list
 	{ varset__init(VarSet) },
-	{ term__context_init(BaseFileName, 0, Context) },
+	{ term__context_init(Context) },
 	{ InterfaceDeclaration = module_defn(VarSet, interface) - Context },
 	{ InterfaceItems1 = [InterfaceDeclaration | InterfaceItems] },
 
@@ -655,8 +709,7 @@
 %-----------------------------------------------------------------------------%
 
 touch_interface_datestamp(ModuleName, Ext) -->
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, Ext, OutputFileName) },
+	module_name_to_file_name(ModuleName, Ext, OutputFileName),
 
 	globals__io_lookup_bool_option(verbose, Verbose),
 	maybe_write_string(Verbose, "% Touching `"),
@@ -868,10 +921,7 @@
 			; list__member(ModuleName, UsedModules)
 			}
 		->
-			{ module_name_to_file_name(ModuleName,
-				BaseFileName) },
-			{ string__append(BaseFileName, ".m",
-				FileName) },
+			module_name_to_file_name(ModuleName, ".m", FileName),
 			{ term__context_init(FileName, 1, Context) },
 			prog_out__write_context(Context),
 			report_warning("Warning: module `"),
@@ -895,8 +945,7 @@
 :- mode warn_imported_ancestor(in, in, di, uo) is det.
 
 warn_imported_ancestor(ModuleName, AncestorName) -->
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, ".m", FileName) },
+	module_name_to_file_name(ModuleName, ".m", FileName),
 	{ term__context_init(FileName, 1, Context) },
 	prog_out__write_context(Context),
 	report_warning("module `"),
@@ -938,8 +987,7 @@
 		{ set__to_sorted_list(BothSet, BothList) },
 		globals__io_lookup_bool_option(warn_simple_code, WarnSimple),
 		( { WarnSimple = yes } ->
-			{ module_name_to_file_name(ModuleName, BaseFileName) },
-			{ string__append(BaseFileName, ".m", FileName) },
+			module_name_to_file_name(ModuleName, ".m", FileName),
 			{ term__context_init(FileName, 1, Context) },
 			prog_out__write_context(Context),
 			io__write_string("Warning:"),
@@ -979,8 +1027,10 @@
 	{ Module = module_imports(ModuleName, ParentDeps, IntDeps, ImplDeps,
 			IndirectDeps, _InclDeps, FactDeps0, _Items, _Error) },
 	globals__io_lookup_bool_option(verbose, Verbose),
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, ".d", DependencyFileName) },
+	{ module_name_to_make_var_name(ModuleName, MakeVarName) },
+	module_name_to_file_name(ModuleName, ".d", DependencyFileName),
+	module_name_to_file_name(ModuleName, ".trans_opt_date",
+						TransOptDateFileName),
 	%
 	% To avoid problems with concurrent updates of `.d' files
 	% during parallel makes, we first create the file with a
@@ -1017,7 +1067,7 @@
 			% this exact pattern
 			%
 			io__write_strings(DepStream,
-				[BaseFileName, ".trans_opt_date :"]),
+				[TransOptDateFileName, " :"]),
 			write_dependencies_list(TransOptDateDeps, ".trans_opt", 
 				DepStream)
 		;
@@ -1026,29 +1076,29 @@
 
 		( { FactDeps \= [] } ->
 			io__write_strings(DepStream, 
-				["\n\n", BaseFileName, ".fact_tables ="]),
+				["\n\n", MakeVarName, ".fact_tables ="]),
 			write_file_dependencies_list(FactDeps, "", DepStream),
 			io__nl(DepStream),
 			globals__io_lookup_bool_option(assume_gmake,
 				AssumeGmake),
 			( { AssumeGmake = no } ->
 				io__write_strings(DepStream,
-					[BaseFileName, ".fact_tables.os ="]),
+					[MakeVarName, ".fact_tables.os ="]),
 				write_file_dependencies_list(FactDeps, ".o",
 					DepStream),
 				io__write_strings(DepStream, [
 					"\n\n", 
-					BaseFileName, ".fact_tables.cs ="]),
+					MakeVarName, ".fact_tables.cs ="]),
 				write_file_dependencies_list(FactDeps, ".c",
 					DepStream),
 				io__nl(DepStream)
 			;
 				io__write_strings(DepStream, [
-					"\n\n", BaseFileName,
-					".fact_tables.os = $(", BaseFileName,
+					"\n\n", MakeVarName,
+					".fact_tables.os = $(", MakeVarName,
 					".fact_tables:%=%.o)\n\n",
-					BaseFileName,
-					".fact_tables.cs = $(", BaseFileName,
+					MakeVarName,
+					".fact_tables.cs = $(", MakeVarName,
 					".fact_tables:%=%.c)\n\n"
 				])
 			)
@@ -1056,13 +1106,19 @@
 			[]
 		),
 
+		module_name_to_file_name(ModuleName, ".optdate",
+					OptDateFileName),
+		module_name_to_file_name(ModuleName, ".c", CFileName),
+		module_name_to_file_name(ModuleName, ".err", ErrFileName),
+		module_name_to_file_name(ModuleName, ".o", ObjFileName),
+		module_name_to_file_name(ModuleName, ".m", SourceFileName),
 		io__write_strings(DepStream, ["\n\n",
-			BaseFileName, ".optdate ",
-			BaseFileName, ".trans_opt_date ",
-			BaseFileName, ".c ",
-			BaseFileName, ".err ",
-			BaseFileName, ".o : ",
-			BaseFileName, ".m"
+			OptDateFileName, " ",
+			TransOptDateFileName, " ",
+			CFileName, " ",
+			ErrFileName, " ",
+			ObjFileName, " : ",
+			SourceFileName
 		] ),
 		write_dependencies_list(ParentDeps, ".int0", DepStream),
 		write_dependencies_list(LongDeps, ".int", DepStream),
@@ -1070,12 +1126,12 @@
 
 		( { FactDeps \= [] } ->
 			io__write_strings(DepStream, [
-				" \\\n\t$(", BaseFileName, ".fact_tables)\n\n",
-				"$(", BaseFileName, ".fact_tables.os) : $(",
-				BaseFileName, ".fact_tables) ",
-				BaseFileName, ".m\n\n",
-				"$(", BaseFileName, ".fact_tables.cs) : ",
-				BaseFileName, ".o\n"
+				" \\\n\t$(", MakeVarName, ".fact_tables)\n\n",
+				"$(", MakeVarName, ".fact_tables.os) : $(",
+				MakeVarName, ".fact_tables) ",
+				SourceFileName, "\n\n",
+				"$(", MakeVarName, ".fact_tables.cs) : ",
+				ObjFileName, ".o\n"
 			] )
 		;
 			[]
@@ -1086,10 +1142,10 @@
 		( { Intermod = yes } ->
 			io__write_strings(DepStream, [
 				"\n\n", 
-				BaseFileName, ".c ",
-				BaseFileName, ".trans_opt_date ",
-				BaseFileName, ".err ", 
-				BaseFileName, ".o :"
+				CFileName, " ",
+				TransOptDateFileName, " ",
+				ErrFileName, " ", 
+				ObjFileName, " :"
 			]),
 			% The .c file only depends on the .opt files from 
 			% the current directory, so that inter-module
@@ -1111,9 +1167,9 @@
 					".opt", DepStream),
 				io__write_strings(DepStream, [
 					"\n\n", 
-					BaseFileName, ".c ",
-					BaseFileName, ".err ", 
-					BaseFileName, ".o :"
+					CFileName, " ",
+					ErrFileName, " ", 
+					ObjFileName, " :"
 				]),
 				write_dependencies_list(TransOptDeps,
 					".trans_opt", DepStream)
@@ -1127,22 +1183,27 @@
 			[]
 		),
 
+		module_name_to_file_name(ModuleName, ".date", DateFileName),
+		module_name_to_file_name(ModuleName, ".date0", Date0FileName),
 		io__write_strings(DepStream, [
-				"\n\n", BaseFileName, ".date ",
-				BaseFileName, ".date0 : ",
-				BaseFileName, ".m"
+				"\n\n", DateFileName, " ",
+				Date0FileName, " : ",
+				SourceFileName
 		]),
 		write_dependencies_list(ParentDeps, ".int0", DepStream),
 		write_dependencies_list(LongDeps, ".int3", DepStream),
 		write_dependencies_list(ShortDeps, ".int3", DepStream),
 
+		module_name_to_file_name(ModuleName, ".dir", DirFileName),
+		module_name_to_split_c_file_name(ModuleName, 0, ".o",
+			SplitCObj0FileName),
 		io__write_strings(DepStream, [
 			"\n\n",
-			BaseFileName, ".dir/", BaseFileName, "_000.o : ",
-				BaseFileName, ".m\n",
-			"\trm -rf ", BaseFileName, ".dir\n",
+			SplitCObj0FileName, " : ",
+				SourceFileName, "\n",
+			"\trm -rf ", DirFileName, "\n",
 			"\t$(MCS) $(GRADEFLAGS) $(MCSFLAGS) ",
-				BaseFileName, ".m\n"
+				SourceFileName, "\n"
 		]),
 
 		io__close_output(DepStream),
@@ -1168,8 +1229,7 @@
 	globals__io_lookup_bool_option(transitive_optimization, TransOpt),
 	( { TransOpt = yes } ->
 		globals__io_lookup_bool_option(verbose, Verbose),
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".d", DependencyFileName) },
+		module_name_to_file_name(ModuleName, ".d", DependencyFileName),
 		maybe_write_string(Verbose, "% Reading auto-dependency file `"),
 		maybe_write_string(Verbose, DependencyFileName),
 		maybe_write_string(Verbose, "'..."),
@@ -1177,11 +1237,13 @@
 		io__open_input(DependencyFileName, OpenResult),
 		( { OpenResult = ok(Stream) } ->
 			io__set_input_stream(Stream, OldStream),
-			{ string__append(BaseFileName, ".trans_opt_date :", 
-				TransOptFileName0) },
-			{ string__to_char_list(TransOptFileName0, 
-				TransOptFileName) },
-			read_dependency_file_find_start(TransOptFileName, 
+			module_name_to_file_name(ModuleName, ".trans_opt_date", 
+				TransOptDateFileName0),
+			{ string__to_char_list(TransOptDateFileName0, 
+				TransOptDateFileName) },
+			{ list__append(TransOptDateFileName, [' ', ':'],
+				SearchPattern) },
+			read_dependency_file_find_start(SearchPattern,
 				FindResult),
 			( { FindResult = yes } ->
 				read_dependency_file_get_modules(TransOptDeps),
@@ -1205,18 +1267,17 @@
 	).
 			
 	% Read lines from the dependency file (module.d) until one is found
-	% which begins with TransOptFileName.
+	% which begins with SearchPattern.
 :- pred read_dependency_file_find_start(list(char)::in, bool::out, 
 	io__state::di, io__state::uo) is det.
-read_dependency_file_find_start(TransOptFileName, Success) -->
+read_dependency_file_find_start(SearchPattern, Success) -->
 	io__read_line(Result),
 	( { Result = ok(CharList) } ->
-		( { list__append(TransOptFileName, _, CharList) } ->
+		( { list__append(SearchPattern, _, CharList) } ->
 			% Have found the start
 			{ Success = yes }
 		;
-			read_dependency_file_find_start(TransOptFileName, 
-				Success)
+			read_dependency_file_find_start(SearchPattern, Success)
 		)
 	; 
 		{ Success = no }
@@ -1264,8 +1325,7 @@
 	io__state::di, io__state::uo) is det.
 get_both_opt_deps([], _, [], []) --> [].
 get_both_opt_deps([Dep | Deps], IntermodDirs, OptDeps, TransOptDeps) -->
-	{ module_name_to_file_name(Dep, BaseFileName) },
-	{ string__append(BaseFileName, ".m", DepName) },
+	module_name_to_file_name(Dep, ".m", DepName), 
 	search_for_file(IntermodDirs, DepName, Result1),
 	get_both_opt_deps(Deps, IntermodDirs, OptDeps0, TransOptDeps0),
 	( { Result1 = yes } ->
@@ -1273,7 +1333,7 @@
 		{ TransOptDeps = [Dep | TransOptDeps0] },
 		io__seen
 	;
-		{ string__append(BaseFileName, ".opt", OptName) },
+		module_name_to_file_name(Dep, ".opt", OptName), 
 		search_for_file(IntermodDirs, OptName, Result2),
 		( { Result2 = yes } ->
 			{ OptDeps = [Dep | OptDeps0] },
@@ -1281,7 +1341,7 @@
 		;
 			{ OptDeps = OptDeps0 }
 		),
-		{ string__append(BaseFileName, ".trans_opt", TransOptName) },
+		module_name_to_file_name(Dep, ".trans_opt", TransOptName), 
 		search_for_file(IntermodDirs, TransOptName, Result3),
 		( { Result3 = yes } ->
 			{ TransOptDeps = [Dep | TransOptDeps0] },
@@ -1297,15 +1357,14 @@
 	list(module_name)::out, io__state::di, io__state::uo) is det.
 get_opt_deps([], _, _, []) --> [].
 get_opt_deps([Dep | Deps], IntermodDirs, Suffix, OptDeps) -->
-	{ module_name_to_file_name(Dep, BaseFileName) },
-	{ string__append(BaseFileName, ".m", DepName) },
+	module_name_to_file_name(Dep, ".m", DepName),
 	search_for_file(IntermodDirs, DepName, Result1),
 	get_opt_deps(Deps, IntermodDirs, Suffix, OptDeps0),
 	( { Result1 = yes } ->
 		{ OptDeps = [Dep | OptDeps0] },
 		io__seen
 	;
-		{ string__append(BaseFileName, Suffix, OptName) },
+		module_name_to_file_name(Dep, Suffix, OptName),
 		search_for_file(IntermodDirs, OptName, Result2),
 		( { Result2 = yes } ->
 			{ OptDeps = [Dep | OptDeps0] },
@@ -1360,8 +1419,7 @@
 	globals__io_lookup_bool_option(generate_module_order, Order),
 	globals__io_lookup_bool_option(verbose, Verbose),
 	( { Order = yes } ->
-		{ module_name_to_file_name(Module, BaseFileName) },
-		{ string__append(BaseFileName, ".order", OrdFileName) },
+		module_name_to_file_name(Module, ".order", OrdFileName),
 		maybe_write_string(Verbose, "% Creating module order file `"),
 		maybe_write_string(Verbose, OrdFileName),
 		maybe_write_string(Verbose, "'...\n"),
@@ -1541,8 +1599,7 @@
 	io__state::di, io__state::uo) is det.
 generate_dependencies_write_dep_file(ModuleName, DepsMap) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, ".dep", DepFileName) },
+	module_name_to_file_name(ModuleName, ".dep", DepFileName),
 	maybe_write_string(Verbose, "% Creating auto-dependency file `"),
 	maybe_write_string(Verbose, DepFileName),
 	maybe_write_string(Verbose, "'...\n"),
@@ -1563,7 +1620,6 @@
 :- mode generate_dep_file(in, in, in, di, uo) is det.
 
 generate_dep_file(ModuleName, DepsMap, DepStream) -->
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
 	io__write_string(DepStream,
 		"# Automatically generated dependencies for module `"),
 	{ prog_out__sym_name_to_string(ModuleName, ModuleNameString) },
@@ -1578,7 +1634,8 @@
 	{ map__keys(DepsMap, Modules0) },
 	{ select_ok_modules(Modules0, DepsMap, Modules) },
 
-	io__write_string(DepStream, BaseFileName),
+	{ module_name_to_make_var_name(ModuleName, MakeVarName) },
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".ms ="),
 	write_dependencies_list(Modules, ".m", DepStream),
 	io__write_string(DepStream, "\n\n"),
@@ -1586,7 +1643,7 @@
 	globals__io_lookup_bool_option(assume_gmake, Gmake),
 	(
 		{ Gmake = yes },
-		{ string__append(BaseFileName, ".ms", VarName) },
+		{ string__append(MakeVarName, ".ms", VarName) },
 		{ Basis = yes(VarName - ".m") }
 	;
 		{ Gmake = no },
@@ -1595,298 +1652,355 @@
 
 	{ get_extra_link_objects(Modules, DepsMap, ExtraLinkObjs) },
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".nos = "),
 	write_compact_dependencies_list(Modules, ".no", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".qls = "),
 	write_compact_dependencies_list(Modules, ".ql", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".cs = "),
 	write_compact_dependencies_list(Modules, ".c", Basis, DepStream),
 	write_file_dependencies_list(ExtraLinkObjs, ".c", DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".os = "),
 	write_compact_dependencies_list(Modules, ".o", Basis, DepStream),
 	write_file_dependencies_list(ExtraLinkObjs, ".o", DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".pic_os = "),
 	write_compact_dependencies_list(Modules, ".$(EXT_FOR_PIC_OBJECTS)",
 		Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".dirs = "),
 	write_compact_dependencies_list(Modules, ".dir", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".dir_os = "),
 	write_compact_dependencies_list(Modules, ".dir/*.o", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".ss = "),
 	write_compact_dependencies_list(Modules, ".s", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".errs = "),
 	write_compact_dependencies_list(Modules, ".err", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".dates = "),
 	write_compact_dependencies_list(Modules, ".date", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".date0s = "),
 	write_compact_dependencies_list(Modules, ".date0", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".date3s = "),
 	write_compact_dependencies_list(Modules, ".date3", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".optdates = "),
 	write_compact_dependencies_list(Modules, ".optdate", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".trans_opt_dates = "),
 	write_compact_dependencies_list(Modules, ".trans_opt_date", Basis,
 								DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".ds = "),
 	write_compact_dependencies_list(Modules, ".d", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".hs = "),
 	write_compact_dependencies_list(Modules, ".h", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".ints = "),
 	write_compact_dependencies_list(Modules, ".int", Basis, DepStream),
 	write_compact_dependencies_separator(Basis, DepStream),
 	write_compact_dependencies_list(Modules, ".int2", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".int0s = "),
 	write_compact_dependencies_list(Modules, ".int0", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".int3s = "),
 	write_compact_dependencies_list(Modules, ".int3", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".opts = "),
 	write_compact_dependencies_list(Modules, ".opt", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".trans_opts = "),
 	write_compact_dependencies_list(Modules, ".trans_opt", Basis,
 								DepStream),
 	io__write_string(DepStream, "\n"),
 
-	io__write_string(DepStream, BaseFileName),
+	io__write_string(DepStream, MakeVarName),
 	io__write_string(DepStream, ".profs = "),
 	write_compact_dependencies_list(Modules, ".prof", Basis, DepStream),
 	io__write_string(DepStream, "\n\n"),
 
+	module_name_to_file_name(ModuleName, ".init", InitFileName),
+	module_name_to_file_name(ModuleName, "_init.c", InitCFileName),
+	module_name_to_file_name(ModuleName, "_init.s", InitAsmFileName),
+	module_name_to_file_name(ModuleName, "_init.o", InitObjFileName),
+	module_name_to_file_name(ModuleName, "_init.pic_o",
+							InitPicObjFileName),
+
+	module_name_to_file_name(ModuleName, "", ExeFileName),
 	io__write_strings(DepStream, [
-		BaseFileName, " : $(", BaseFileName, ".os) ",
-		BaseFileName, "_init.o MLOBJS-", BaseFileName, "\n",
-		"\t$(ML) $(GRADEFLAGS) $(MLFLAGS) -o ", BaseFileName, " ",
-		BaseFileName, "_init.o \\\n",
-		"\t	$(", BaseFileName, ".os) $(MLOBJS) $(MLLIBS)\n\n"
+		ExeFileName, " : $(", MakeVarName, ".os) ",
+		InitObjFileName, " MLOBJS-", MakeVarName, "\n",
+		"\t$(ML) $(GRADEFLAGS) $(MLFLAGS) -o ", ExeFileName, " ",
+		InitObjFileName, " \\\n",
+		"\t	$(", MakeVarName, ".os) $(MLOBJS) $(MLLIBS)\n\n"
 	]),
 
+	module_name_to_file_name(ModuleName, ".split", SplitExeFileName),
+	module_name_to_file_name(ModuleName, ".split.a", SplitLibFileName),
 	io__write_strings(DepStream, [
-		BaseFileName, ".split : ", BaseFileName, ".split.a ",
-				BaseFileName, "_init.o\n",
-		"\t$(ML) $(GRADEFLAGS) $(MLFLAGS) -o ", BaseFileName, ".split ",
-			BaseFileName, "_init.o \\\n",
-		"\t	", BaseFileName, ".split.a $(MLLIBS)\n\n"
+		SplitExeFileName, " : ", SplitLibFileName, " ",
+				InitObjFileName, "\n",
+		"\t$(ML) $(GRADEFLAGS) $(MLFLAGS) -o ", SplitExeFileName,
+			" ", InitObjFileName, " \\\n",
+		"\t	", SplitLibFileName, " $(MLLIBS)\n\n"
 	]),
 
 	io__write_strings(DepStream, [
-		BaseFileName, ".split.a : $(", BaseFileName, ".dir_os) ",
-				"MLOBJS-", BaseFileName, "\n",
-		"\trm -f ", BaseFileName, ".split.a\n",
-		"\t$(AR) $(ARFLAGS) ", BaseFileName, ".split.a $(MLOBJS)\n",
-		"\tfor dir in $(", BaseFileName, ".dirs); do \\\n",
-		"\t	$(AR) q ", BaseFileName, ".split.a $$dir/*.o; \\\n",
+		SplitLibFileName, " : $(", MakeVarName, ".dir_os) ",
+				"MLOBJS-", MakeVarName, "\n",
+		"\trm -f ", SplitLibFileName, "\n",
+		"\t$(AR) $(ARFLAGS) ", SplitLibFileName, " $(MLOBJS)\n",
+		"\tfor dir in $(", MakeVarName, ".dirs); do \\\n",
+		"\t	$(AR) q ", SplitLibFileName, " $$dir/*.o; \\\n",
 		"\tdone\n",
-		"\t$(RANLIB) $(RANLIBFLAGS) ", BaseFileName, ".split.a\n\n"
+		"\t$(RANLIB) $(RANLIBFLAGS) ", SplitLibFileName, "\n\n"
 	]),
 
+	module_name_to_lib_file_name("lib", ModuleName, "", LibTargetName),
+	module_name_to_lib_file_name("lib", ModuleName, ".a", LibFileName),
+	module_name_to_lib_file_name("lib", ModuleName,
+		".so", SharedLibFileName),
+	module_name_to_lib_file_name("lib", ModuleName,
+		".$(EXT_FOR_SHARED_LIB)", MaybeSharedLibFileName),
 	io__write_strings(DepStream, [
-		"lib", BaseFileName, " : ",
-		"lib", BaseFileName, ".a ",
-		"lib", BaseFileName, ".$(EXT_FOR_SHARED_LIB) \\\n",
-		"\t\t$(", BaseFileName, ".ints) ",
-		"$(", BaseFileName, ".int3s) ",
-		"$(", BaseFileName, ".opts) ",
-		BaseFileName, ".init\n\n"
+		".PHONY : ", LibTargetName, "\n",
+		LibTargetName, " : ",
+		LibFileName, " ",
+		MaybeSharedLibFileName, " \\\n",
+		"\t\t$(", MakeVarName, ".ints) ",
+		"$(", MakeVarName, ".int3s) ",
+		"$(", MakeVarName, ".opts) ",
+		InitFileName, "\n\n"
 	]),
 
 	io__write_strings(DepStream, [
-		"lib", BaseFileName, ".so : $(", BaseFileName, ".pic_os) ",
-				"MLPICOBJS-", BaseFileName, "\n",
+		SharedLibFileName, " : $(", MakeVarName, ".pic_os) ",
+				"MLPICOBJS-", MakeVarName, "\n",
 		"\t$(ML) --make-shared-lib $(GRADEFLAGS) $(MLFLAGS) -o ",
-			"lib", BaseFileName, ".so \\\n",
-		"\t\t$(", BaseFileName, ".pic_os) $(MLPICOBJS) $(MLLIBS)\n\n"
+			SharedLibFileName, " \\\n",
+		"\t\t$(", MakeVarName, ".pic_os) $(MLPICOBJS) $(MLLIBS)\n\n"
 	]),
 
 	io__write_strings(DepStream, [
-		"lib", BaseFileName, ".a : $(", BaseFileName,
-				".os) MLOBJS-", BaseFileName, "\n",
-		"\trm -f ", BaseFileName, ".a\n",
-		"\t$(AR) $(ARFLAGS) lib", BaseFileName, ".a ",
-			"$(", BaseFileName, ".os) $(MLOBJS)\n",
-		"\t$(RANLIB) $(RANLIBFLAGS) lib", BaseFileName, ".a\n\n"
+		LibFileName, " : $(", MakeVarName, ".os) ",
+				"MLOBJS-", MakeVarName, "\n",
+		"\trm -f ", LibFileName, "\n",
+		"\t$(AR) $(ARFLAGS) ", LibFileName, " ",
+			"$(", MakeVarName, ".os) $(MLOBJS)\n",
+		"\t$(RANLIB) $(RANLIBFLAGS) ", LibFileName, "\n\n"
 	]),
 
+	module_name_to_file_name(ModuleName, ".dep", DepFileName),
 	io__write_strings(DepStream, [
-		BaseFileName, ".init : ", BaseFileName, ".dep\n",
-		"\tfor file in $(", BaseFileName, ".ms); do \\\n",
-		"\t\techo ""INIT mercury__`basename $$file .m`__init""; \\\n",
-		"\tdone > ", BaseFileName, ".init\n\n"
+		InitFileName, " : ", DepFileName, "\n",
+		"\techo > ", InitFileName, "\n"
 	]),
+	list__foldl(append_to_init_list(DepStream, InitFileName), Modules),
+	io__write_string(DepStream, "\n"),
 
 	io__write_strings(DepStream, [
-		BaseFileName, "_init.c :\n",
-		"\t$(C2INIT) $(C2INITFLAGS) $(", BaseFileName, ".ms) > ",
-			BaseFileName, "_init.c\n\n"
+		InitCFileName, " :\n",
+		"\t$(C2INIT) $(C2INITFLAGS) $(", MakeVarName, ".ms) > ",
+			InitCFileName, "\n\n"
 	]),
 
+	module_name_to_file_name(ModuleName, ".nu", NU_ExeFileName),
+	module_name_to_file_name(ModuleName, ".nu.debug", NU_DebugExeFileName),
 	io__write_strings(DepStream, [
-		BaseFileName, ".nu : $(", BaseFileName, ".nos)\n",
-		"\t$(MNL) $(MNLFLAGS) -o ", BaseFileName, ".nu ",
-			"$(", BaseFileName, ".nos)\n\n",
-
-		BaseFileName, ".nu.debug : $(", BaseFileName, ".nos)\n",
-		"\t$(MNL) --debug $(MNLFLAGS) -o ", BaseFileName, ".nu.debug ",
-			"$(", BaseFileName, ".nos)\n\n"
+		NU_ExeFileName, " : $(", MakeVarName, ".nos)\n",
+		"\t$(MNL) $(MNLFLAGS) -o ", NU_ExeFileName, " ",
+			"$(", MakeVarName, ".nos)\n\n",
+
+		NU_DebugExeFileName, " : $(", MakeVarName, ".nos)\n",
+		"\t$(MNL) --debug $(MNLFLAGS) -o ", NU_DebugExeFileName, " ",
+			"$(", MakeVarName, ".nos)\n\n"
 	]),
 
+	module_name_to_file_name(ModuleName, ".sicstus", SicstusExeFileName),
+	module_name_to_file_name(ModuleName, ".sicstus.debug",
+						SicstusDebugExeFileName),
 	io__write_strings(DepStream, [
-		BaseFileName, ".sicstus : $(", BaseFileName, ".qls)\n",
-		"\t$(MSL) $(MSLFLAGS) -o ", BaseFileName, ".sicstus ",
-			"$(", BaseFileName, ".qls)\n\n",
-
-		BaseFileName, ".sicstus.debug : $(", BaseFileName, ".qls)\n",
-			"\t$(MSL) --debug $(MSLFLAGS) -o ", BaseFileName,
-			".sicstus.debug $(", BaseFileName, ".qls)\n\n"
+		SicstusExeFileName, " : $(", MakeVarName, ".qls)\n",
+		"\t$(MSL) $(MSLFLAGS) -o ", SicstusExeFileName, " ",
+			"$(", MakeVarName, ".qls)\n\n",
+
+		SicstusDebugExeFileName, " : $(", MakeVarName, ".qls)\n",
+		"\t$(MSL) --debug $(MSLFLAGS) -o ", SicstusDebugExeFileName,
+			" $(", MakeVarName, ".qls)\n\n"
 	]),
 
+	module_name_to_file_name(ModuleName, ".check", CheckTargetName),
+	module_name_to_file_name(ModuleName, ".ints", IntsTargetName),
+	module_name_to_file_name(ModuleName, ".int3s", Int3sTargetName),
+	module_name_to_file_name(ModuleName, ".opts", OptsTargetName),
+	module_name_to_file_name(ModuleName, ".trans_opts",
+						TransOptsTargetName),
 	io__write_strings(DepStream, [
-		BaseFileName, ".check : $(", BaseFileName, ".errs)\n\n",
-
-		BaseFileName, ".ints : $(", BaseFileName, ".dates)\n\n",
-		BaseFileName, ".int3s : $(", BaseFileName, ".date3s)\n\n",
-		BaseFileName, ".opts : $(", BaseFileName, ".optdates)\n\n"
+		CheckTargetName, " : $(", MakeVarName, ".errs)\n\n",
+		IntsTargetName, " : $(", MakeVarName, ".dates)\n\n",
+		Int3sTargetName, " : $(", MakeVarName, ".date3s)\n\n",
+		OptsTargetName, " : $(", MakeVarName, ".optdates)\n\n",
+		TransOptsTargetName, " : $(", MakeVarName,
+						".trans_opt_dates)\n\n"
 	]),
 
+	module_name_to_file_name(ModuleName, ".clean", CleanTargetName),
 	io__write_strings(DepStream, [
-		"clean : ", BaseFileName, ".clean\n"
+		"clean : ", CleanTargetName, "\n"
 	]),
-
 	io__write_strings(DepStream, [
-		BaseFileName, ".clean :\n",
-		"\t-rm -rf ", BaseFileName, ".dir\n",
-		"\t-rm -f $(", BaseFileName, ".cs) ", BaseFileName, "_init.c\n",
-		"\t-rm -f $(", BaseFileName, ".ss) ", BaseFileName, "_init.s\n",
-		"\t-rm -f $(", BaseFileName, ".os) ", BaseFileName, "_init.o\n",
-		"\t-rm -f $(", BaseFileName, ".pic_os) ",
-						BaseFileName, "_init.pic_o\n",
-		"\t-rm -f $(", BaseFileName, ".trans_opt_dates)\n",
-		"\t-rm -f $(", BaseFileName, ".trans_opts)\n",
-		"\t-rm -f $(", BaseFileName, ".profs)\n",
-		"\t-rm -f $(", BaseFileName, ".nos)\n",
-		"\t-rm -f $(", BaseFileName, ".qls)\n",
-		"\t-rm -f $(", BaseFileName, ".errs)\n"
+		".PHONY : ", CleanTargetName, "\n",
+		CleanTargetName, " :\n",
+		"\t-rm -rf ", MakeVarName, ".dir\n",
+		"\t-rm -f $(", MakeVarName, ".cs) ", InitCFileName, "\n",
+		"\t-rm -f $(", MakeVarName, ".ss) ", InitAsmFileName, "\n",
+		"\t-rm -f $(", MakeVarName, ".os) ", InitObjFileName, "\n",
+		"\t-rm -f $(", MakeVarName, ".pic_os) ", InitPicObjFileName,
+									"\n",
+		"\t-rm -f $(", MakeVarName, ".trans_opt_dates)\n",
+		"\t-rm -f $(", MakeVarName, ".trans_opts)\n",
+		"\t-rm -f $(", MakeVarName, ".profs)\n",
+		"\t-rm -f $(", MakeVarName, ".nos)\n",
+		"\t-rm -f $(", MakeVarName, ".qls)\n",
+		"\t-rm -f $(", MakeVarName, ".errs)\n"
 	]),
 
 	io__write_string(DepStream, "\n"),
 
+	module_name_to_file_name(ModuleName, ".change_clean",
+			ChangeCleanTargetName),
 	io__write_strings(DepStream, [
-		BaseFileName, ".change_clean :\n",
-		"\t-rm -f $(", BaseFileName, ".cs) ", BaseFileName, "_init.c\n",
-		"\t-rm -f $(", BaseFileName, ".ss) ", BaseFileName, "_init.s\n",
-		"\t-rm -f $(", BaseFileName, ".os) ", BaseFileName, "_init.o\n",
-		"\t-rm -f $(", BaseFileName, ".hs)\n",
-		"\t-rm -f $(", BaseFileName, ".ds)\n",
+		".PHONY : ", ChangeCleanTargetName, "\n",
+		ChangeCleanTargetName, " :\n",
+		"\t-rm -f $(", MakeVarName, ".cs) ", InitCFileName, "\n",
+		"\t-rm -f $(", MakeVarName, ".ss) ", InitAsmFileName, "\n",
+		"\t-rm -f $(", MakeVarName, ".os) ", InitObjFileName, "\n",
+		"\t-rm -f $(", MakeVarName, ".pic_os) ", InitPicObjFileName,
+									"\n",
+		"\t-rm -f $(", MakeVarName, ".hs)\n",
+		"\t-rm -f $(", MakeVarName, ".ds)\n",
 		"\t-rm -f ",
-			BaseFileName, " ",
-			BaseFileName, ".split ",
-			BaseFileName, ".split.a ",
-			BaseFileName, ".init ",
-			"lib", BaseFileName, ".a ",
-			"lib", BaseFileName, ".so ",
-			BaseFileName, ".dep\n\n"
+			ExeFileName, " ",
+			SplitExeFileName, " ",
+			SplitLibFileName, " ",
+			InitFileName, " ",
+			LibFileName, " ",
+			SharedLibFileName, " ",
+			DepFileName, "\n\n"
 	]),
 
+	module_name_to_file_name(ModuleName, ".realclean",
+			RealCleanTargetName),
 	io__write_strings(DepStream, [
-		"realclean : ", BaseFileName, ".realclean\n"
+		"realclean : ", RealCleanTargetName, "\n"
 	]),
-
 	io__write_strings(DepStream, [
-		BaseFileName, ".realclean : ", BaseFileName, ".clean\n",
-		"\t-rm -f $(", BaseFileName, ".dates)\n",
-		"\t-rm -f $(", BaseFileName, ".date0s)\n",
-		"\t-rm -f $(", BaseFileName, ".date3s)\n",
-		"\t-rm -f $(", BaseFileName, ".optdates)\n",
-		"\t-rm -f $(", BaseFileName, ".ints)\n",
-		"\t-rm -f $(", BaseFileName, ".int0s)\n",
-		"\t-rm -f $(", BaseFileName, ".int3s)\n",
-		"\t-rm -f $(", BaseFileName, ".opts)\n",
-		"\t-rm -f $(", BaseFileName, ".ds)\n",
-		"\t-rm -f $(", BaseFileName, ".hs)\n"
+		".PHONY : ", RealCleanTargetName, "\n",
+		RealCleanTargetName, " : ", CleanTargetName, "\n",
+		"\t-rm -f $(", MakeVarName, ".dates)\n",
+		"\t-rm -f $(", MakeVarName, ".date0s)\n",
+		"\t-rm -f $(", MakeVarName, ".date3s)\n",
+		"\t-rm -f $(", MakeVarName, ".optdates)\n",
+		"\t-rm -f $(", MakeVarName, ".ints)\n",
+		"\t-rm -f $(", MakeVarName, ".int0s)\n",
+		"\t-rm -f $(", MakeVarName, ".int3s)\n",
+		"\t-rm -f $(", MakeVarName, ".opts)\n",
+		"\t-rm -f $(", MakeVarName, ".ds)\n",
+		"\t-rm -f $(", MakeVarName, ".hs)\n"
 	]),
+	module_name_to_file_name(ModuleName, ".nu.save", NU_SaveExeFileName),
+	module_name_to_file_name(ModuleName, ".nu.debug.save",
+						NU_DebugSaveExeFileName),
 	io__write_strings(DepStream, [
 		"\t-rm -f ",
-			BaseFileName, " ",
-			BaseFileName, ".split ",
-			BaseFileName, ".split.a ",
-			BaseFileName, ".init ",
-			"lib", BaseFileName, ".a ",
-			"lib", BaseFileName, ".so ",
-			BaseFileName, ".nu ",
-			BaseFileName, ".nu.save ",
-			BaseFileName, ".nu.debug.save ",
-			BaseFileName, ".nu.debug ",
-			BaseFileName, ".sicstus ",
-			BaseFileName, ".sicstus.debug ",
-			BaseFileName, ".dep\n\n"
+			ExeFileName, " ",
+			SplitExeFileName, " ",
+			SplitLibFileName, " ",
+			InitFileName, " ",
+			LibFileName, " ",
+			SharedLibFileName, " ",
+			NU_ExeFileName, " ",
+			NU_SaveExeFileName, " ",
+			NU_DebugExeFileName, " ",
+			NU_DebugSaveExeFileName, " ",
+			SicstusExeFileName, " ",
+			SicstusDebugExeFileName, " ",
+			DepFileName, "\n\n"
 	]),
+
+	module_name_to_file_name(ModuleName, ".clean_nu", CleanNU_TargetName),
+	module_name_to_file_name(ModuleName, ".clean_sicstus",
+						CleanSicstusTargetName),
+	io__write_strings(DepStream, [
+		"clean_nu : ", CleanNU_TargetName, "\n",
+		".PHONY : ", CleanNU_TargetName, "\n",
+		CleanNU_TargetName, " :\n",
+		"\t-rm -f $(", MakeVarName, ".nos)\n\n",
+
+		"clean_sicstus : ", CleanSicstusTargetName, "\n",
+		".PHONY : ", CleanSicstusTargetName, "\n",
+		CleanSicstusTargetName, " :\n",
+		"\t-rm -f $(", MakeVarName, ".qls)\n\n"
+	]).
+
+:- pred append_to_init_list(io__output_stream, file_name, module_name,
+				io__state, io__state).
+:- mode append_to_init_list(in, in, in, di, uo) is det.
+
+append_to_init_list(DepStream, InitFileName, Module) -->
+	{ llds_out__make_init_name(Module, InitFuncName) },
 	io__write_strings(DepStream, [
-		"clean_nu : ", BaseFileName, ".clean_nu\n",
-		BaseFileName, ".clean_nu :\n",
-		"\t-rm -f $(", BaseFileName, ".nos)\n\n",
-
-		"clean_sicstus : ", BaseFileName, ".clean_sicstus\n",
-		BaseFileName, ".clean_sicstus :\n",
-		"\t-rm -f $(", BaseFileName, ".qls)\n\n"
+		"\techo ""INIT ", InitFuncName, """ >> ", InitFileName, "\n"
 	]).
 
 %-----------------------------------------------------------------------------%
@@ -1934,9 +2048,12 @@
 				io__state, io__state).
 :- mode write_dependencies_list(in, in, in, di, uo) is det.
 
-write_dependencies_list(Modules, Suffix, DepStream) -->
-	{ list__map(module_name_to_file_name, Modules, FileNames) },
-	write_file_dependencies_list(FileNames, Suffix, DepStream).
+write_dependencies_list([], _, _) --> [].
+write_dependencies_list([Module | Modules], Suffix, DepStream) -->
+	module_name_to_file_name(Module, Suffix, FileName),
+	io__write_string(DepStream, " \\\n\t"),
+	io__write_string(DepStream, FileName),
+	write_dependencies_list(Modules, Suffix, DepStream).
 
 :- pred write_file_dependencies_list(list(string), string, io__output_stream,
 				io__state, io__state).
@@ -2046,8 +2163,7 @@
 %-----------------------------------------------------------------------------%
 
 read_mod(ModuleName, Extension, Descr, Search, Items, Error) -->
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, Extension, FileName) },
+	module_name_to_file_name(ModuleName, Extension, FileName),
 	globals__io_lookup_bool_option(very_verbose, VeryVerbose),
 	maybe_write_string(VeryVerbose, "% "),
 	maybe_write_string(VeryVerbose, Descr),
@@ -2080,8 +2196,7 @@
 */
 
 read_mod_ignore_errors(ModuleName, Extension, Descr, Search, Items, Error) -->
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, Extension, FileName) },
+	module_name_to_file_name(ModuleName, Extension, FileName),
 	globals__io_lookup_bool_option(very_verbose, VeryVerbose),
 	maybe_write_string(VeryVerbose, "% "),
 	maybe_write_string(VeryVerbose, Descr),
Index: termination.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/termination.m,v
retrieving revision 1.9
diff -u -u -r1.9 termination.m
--- termination.m	1998/03/03 17:36:18	1.9
+++ termination.m	1998/03/16 14:57:49
@@ -668,8 +668,7 @@
 
 termination__make_opt_int(PredIds, Module) -->
 	{ module_info_name(Module, ModuleName) },
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, ".opt.tmp", OptFileName) },
+	module_name_to_file_name(ModuleName, ".opt.tmp", OptFileName),
 	io__open_append(OptFileName, OptFileRes),
 	( { OptFileRes = ok(OptFile) } ->
 		io__set_output_stream(OptFile, OldStream),
Index: trans_opt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trans_opt.m,v
retrieving revision 1.7
diff -u -u -r1.7 trans_opt.m
--- trans_opt.m	1998/03/03 17:36:20	1.7
+++ trans_opt.m	1998/03/16 15:35:59
@@ -78,13 +78,12 @@
 
 %-----------------------------------------------------------------------------%
 
-% Open the file "<module-name>.trans_opt", and write out the
+% Open the file "<module-name>.trans_opt.tmp", and write out the
 % declarations.
 
 trans_opt__write_optfile(Module) -->
 	{ module_info_name(Module, ModuleName) },
-	{ module_name_to_file_name(ModuleName, BaseFileName) },
-	{ string__append(BaseFileName, ".trans_opt.tmp", TmpOptName) },
+	module_name_to_file_name(ModuleName, ".trans_opt.tmp", TmpOptName),
 	io__open_output(TmpOptName, Result),
 	(
 		{ Result = error(Error) },
@@ -117,7 +116,7 @@
 		io__set_output_stream(OldStream, _),
 		io__close_output(Stream),
 
-		{ string__append(BaseFileName, ".trans_opt", OptName) },
+		module_name_to_file_name(ModuleName, ".trans_opt", OptName),
 		update_interface(OptName),
 		touch_interface_datestamp(ModuleName, ".trans_opt_date")
 	).
@@ -205,8 +204,7 @@
 	maybe_flush_output(VeryVerbose),
 	maybe_write_string(VeryVerbose, "% done.\n"),
 
-	{ module_name_to_file_name(Import, BaseFileName) },
-	{ string__append(BaseFileName, ".trans_opt", FileName) },
+	module_name_to_file_name(Import, ".trans_opt", FileName),
 	prog_io__read_module(FileName, Import, yes,
 			ModuleError, Messages, Items1),
 	update_error_status(ModuleError, Messages, Error0, Error1),
Index: unused_args.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.46
diff -u -u -r1.46 unused_args.m
--- unused_args.m	1998/03/03 17:36:32	1.46
+++ unused_args.m	1998/03/16 14:54:25
@@ -98,8 +98,7 @@
 	globals__io_lookup_bool_option(make_optimization_interface, MakeOpt),
 	( { MakeOpt = yes } ->
 		{ module_info_name(ModuleInfo0, ModuleName) },
-		{ module_name_to_file_name(ModuleName, BaseFileName) },
-		{ string__append(BaseFileName, ".opt.tmp", OptFileName) },
+		module_name_to_file_name(ModuleName, ".opt.tmp", OptFileName),
 		io__open_append(OptFileName, OptFileRes),
 		( { OptFileRes = ok(OptFile) } ->
 			{ MaybeOptFile = yes(OptFile) }
cvs diff: Diffing notes

-- 
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.



More information about the developers mailing list