[m-rev.] for review: Java: class file destination and cleanup fixes

Michael Wybrow mjwybrow at cs.mu.OZ.AU
Tue Feb 11 18:01:10 AEDT 2003


Estimated hours taken: 3
Branches: main

Make sure the Java back-end puts class files in the right place with 
`--use-subdirs' and properly cleans up all generated .class files.

mercury/compiler/compile_target_code.m:
mercury/scripts/Mmake.rules:
	Tell to Java compiler to put generated .class files in the
	`Mercury/classs' directory.

mercury/compiler/modules.m:
	Clean up all generated .class files.


Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.37
diff -u -r1.37 compile_target_code.m
--- compiler/compile_target_code.m	11 Feb 2003 02:14:25 -0000	1.37
+++ compiler/compile_target_code.m	11 Feb 2003 06:31:28 -0000
@@ -653,9 +653,30 @@
 	;
 		Target_DebugOpt = ""
 	},
+
+	globals__io_lookup_bool_option(use_subdirs, UseSubdirs),
+	globals__io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs),
+	globals__io_lookup_string_option(fullarch, FullArch),
+ 	globals__io_get_globals(Globals),
+	( { UseSubdirs = yes } ->
+		{ UseGradeSubdirs = yes ->
+			grade_directory_component(Globals, Grade),
+			DirName = "Mercury"/Grade/FullArch/"Mercury/classs"
+		;
+			DirName = "Mercury/classs"
+		},
+		% javac won't create the destination directory for
+		% class files, so we need to do it.
+		make_directory(DirName),
+		% Set destination directory for class files.
+		{ DestDir = "-d " ++ DirName ++ " " }
+	;
+		{ DestDir = "" }
+	),
+
 	% Be careful with the order here!  Some options may override others.
 	% Also be careful that each option is separated by spaces.
-	{ string__append_list([JavaCompiler, " ", InclOpt,
+	{ string__append_list([JavaCompiler, " ", InclOpt, DestDir,
 		Target_DebugOpt, JAVAFLAGS, JavaFile], Command) },
 	invoke_system_command(ErrorStream, verbose_commands,
 		Command, Succeeded).
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.263
diff -u -r1.263 modules.m
--- compiler/modules.m	6 Feb 2003 13:09:22 -0000	1.263
+++ compiler/modules.m	11 Feb 2003 05:00:04 -0000
@@ -3947,6 +3947,13 @@
 	io__write_string(DepStream, ".classes = "),
 	write_compact_dependencies_list(Modules, "$(classes_subdir)", ".class",
 					Basis, DepStream),
+	io__write_string(DepStream, " "),
+	% The Java compiler creates a .class file for each class
+	% within the original .java file.  The filenames of all
+	% these can be matched with `module\$*.class', hence the
+	% "\\$$*.class" below.
+	write_compact_dependencies_list(Modules, "$(classes_subdir)",
+					"\\$$*.class", Basis, DepStream),
 	io__write_string(DepStream, "\n"),
 
 	io__write_string(DepStream, MakeVarName),
Index: scripts/Mmake.rules
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mmake.rules,v
retrieving revision 1.141
diff -u -r1.141 Mmake.rules
--- scripts/Mmake.rules	20 Nov 2002 12:33:02 -0000	1.141
+++ scripts/Mmake.rules	11 Feb 2003 05:04:03 -0000
@@ -89,6 +89,9 @@
 $(deps_subdir)%.dep $(deps_subdir)%.dv:
 	$(MCD) $(ALL_GRADEFLAGS) $(ALL_MCDFLAGS) $*
 ifeq ($(MMAKE_USE_SUBDIRS),yes)
+	# javac doesn't create the destination directory for class files
+	# so we must create it manually
+	-[ -d $(classes_subdir) ] || mkdir $(classes_subdir)
 	# the following mkdirs work around a bug in GNU Make
 	-[ -d Mercury/dates ] || mkdir Mercury/dates
 	-[ -d Mercury/date0s ] || mkdir Mercury/date0s
@@ -106,6 +109,9 @@
 %.depend :
 	$(MCD) $(ALL_GRADEFLAGS) $(ALL_MCDFLAGS) $*
 ifeq ($(MMAKE_USE_SUBDIRS),yes)
+	# javac doesn't create the destination directory for class files
+	# so we must create it manually
+	-[ -d $(classes_subdir) ] || mkdir $(classes_subdir)
 	# the following mkdirs work around a bug in GNU Make
 	-[ -d Mercury/dates ] || mkdir Mercury/dates
 	-[ -d Mercury/date0s ] || mkdir Mercury/date0s
@@ -236,12 +242,17 @@
 
 # Java back-end
 
-# XXX Need to fix this rule to work properly with --use-subdirs,
-#    i.e. put the .class file in the $(classes_subdir) directory
-#    (since javac doesn't have a `-o' option to name the object file,
-#    we may need to use `mv' to move it?)
+ifeq ($(MMAKE_USE_SUBDIRS),yes)
+
+$(classes_subdir)%.class: $(javas_subdir)%.java
+	$(JAVAC) -d $(classes_subdir) $<
+
+else
+
 $(classes_subdir)%.class: $(javas_subdir)%.java
 	$(JAVAC) $<
+
+endif
 
 # When smart recompilation finds that a module does not need to be
 # recompiled, it only touches the `.java_date' file.


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