[m-rev.] For review: Implement mmake library installation for the Java grade
James Goddard
goddardjames at yahoo.com
Wed Feb 18 17:49:07 AEDT 2004
Estimated hours taken: 10
Branches: main
Implement mmake library installation for the Java grade.
modules.m:
Move code for extracting .class file lists into a form suited for jar
out into make_util.m
compile_target_code.m:
Added symbol `java_archive' as a `linked_target_type' type.
Added java_archive case for every switch on linked_target_type.
Added create_java_archive/7 which performs a similar function to
create_archive/6 but for Java.
make.util.m:
linked_target_file_name/5 implemented for `java_archive'
Added predicate list_class_files_for_jar/5.
make.program_target.m:
Implemented lib<module>.install target for the Java grade.
Added .jar file to realclean list.
Index: modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.295
diff -u -d -r1.295 modules.m
--- modules.m 17 Feb 2004 03:16:17 -0000 1.295
+++ modules.m 18 Feb 2004 02:24:40 -0000
@@ -808,6 +808,7 @@
:- import_module libs__handle_options.
:- import_module libs__options.
:- import_module make. % XXX undesirable dependency
+:- import_module make__util.
:- import_module parse_tree__mercury_to_mercury.
:- import_module parse_tree__module_qual.
:- import_module parse_tree__prog_io_util.
@@ -4856,27 +4857,7 @@
]),
{ ClassFiles = "$(" ++ MakeVarName ++ ".classes)" },
- globals__io_lookup_bool_option(use_subdirs, UseSubdirs),
- globals__io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs),
- { AnySubdirs = UseSubdirs `or` UseGradeSubdirs },
- (
- { AnySubdirs = yes },
- module_name_to_file_name(ModuleName, ".class", no, ClassFile),
- { ClassSubdir = dir.dirname(ClassFile) },
- % Here we use the `-C' option of jar to change directory during
- % execution, then use sed to strip away the Mercury/classs/
- % prefix to the class files.
- % Otherwise, the class files would be stored as
- % Mercury/classs/*.class
- % within the jar file, which is not what we want.
- % XXX It would be nice to avoid this dependency on sed.
- { ListClassFiles = "-C " ++ ClassSubdir ++ " \\\n" ++
- "\t\t`echo "" " ++ ClassFiles ++ """" ++
- " | sed 's| '" ++ ClassSubdir ++ "/| |'`" }
- ;
- { AnySubdirs = no },
- { ListClassFiles = ClassFiles }
- ),
+ list_class_files_for_jar(ModuleName, ClassFiles, ListClassFiles),
io__write_strings(DepStream, [
JarFileName, " : ", "$(", MakeVarName, ".classes)\n",
"\t$(JAR) $(JAR_CREATE_FLAGS) ", JarFileName, " ",
Index: compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.52
diff -u -d -r1.52 compile_target_code.m
--- compile_target_code.m 10 Feb 2004 12:43:30 -0000 1.52
+++ compile_target_code.m 17 Feb 2004 06:30:10 -0000
@@ -89,6 +89,7 @@
---> executable
; static_library
; shared_library
+ ; java_archive
.
% link(TargetType, MainModuleName, ObjectFileNames, Succeeded).
@@ -179,6 +180,8 @@
:- import_module libs__handle_options.
:- import_module libs__options.
:- import_module libs__trace_params.
+:- import_module make.
+:- import_module make__util.
:- import_module parse_tree__prog_out.
:- import_module char, dir, getopt, int, require, string.
@@ -1065,6 +1068,11 @@
yes, OutputFileName),
create_archive(ErrorStream, OutputFileName, ObjectsList,
LinkSucceeded)
+ ; { LinkTargetType = java_archive } ->
+ { Ext = ".jar" },
+ module_name_to_file_name(ModuleName, Ext, yes, OutputFileName),
+ create_java_archive(ErrorStream, ModuleName, OutputFileName,
+ ObjectsList, LinkSucceeded)
;
(
{ LinkTargetType = shared_library },
@@ -1091,6 +1099,9 @@
{ LinkTargetType = static_library },
{ error("compile_target_code__link") }
;
+ { LinkTargetType = java_archive },
+ { error("compile_target_code__link") }
+ ;
{ LinkTargetType = executable },
{ CommandOpt = link_executable_command },
{ RpathFlagOpt = linker_rpath_flag },
@@ -1404,6 +1415,9 @@
LinkLibFlag = shlib_linker_link_lib_flag,
LinkLibSuffix = shlib_linker_link_lib_suffix
;
+ TargetType = java_archive,
+ error("make_link_lib: java_archive")
+ ;
TargetType = static_library,
error("make_link_lib: static_library")
},
@@ -1454,6 +1468,9 @@
{ TargetType = static_library },
{ error("compile_target_code__get_std_libs: static library") }
;
+ { TargetType = java_archive },
+ { error("compile_target_code__get_std_libs: java archive") }
+ ;
{ TargetType = executable },
globals__io_lookup_string_option(math_lib, OtherSystemLibs)
),
@@ -1540,6 +1557,24 @@
RanLibCmd, Succeeded)
).
+:- pred create_java_archive(io__output_stream, module_name, file_name,
+ list(file_name), bool, io__state, io__state).
+:- mode create_java_archive(in, in, in, in, out, di, uo) is det.
+
+create_java_archive(ErrorStream, ModuleName, JarFileName, ObjectList,
+ Succeeded) -->
+ % XXX Maybe these should be set up as options:
+ { Jar = "jar" },
+ { JarCreateFlags = "cf" },
+
+ { join_quoted_string_list(ObjectList, "", "", " ", Objects) },
+ list_class_files_for_jar(ModuleName, Objects, ListClassFiles),
+ { Cmd = string__append_list([
+ Jar, " ", JarCreateFlags, " ", JarFileName, " ", ListClassFiles
+ ]) },
+
+ invoke_system_command(ErrorStream, verbose_commands, Cmd, Succeeded).
+
get_object_code_type(FileType, ObjectCodeType) -->
globals__io_lookup_string_option(pic_object_file_extension, PicObjExt),
globals__io_lookup_string_option(link_with_pic_object_file_extension,
@@ -1563,6 +1598,9 @@
FileType = shared_library,
ObjectCodeType =
( if PicObjExt = ObjExt then non_pic else pic )
+ ;
+ FileType = java_archive,
+ ObjectCodeType = non_pic
;
FileType = executable,
( MercuryLinkage = "shared" ->
Index: make.util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.17
diff -u -d -r1.17 make.util.m
--- make.util.m 24 Sep 2003 06:35:26 -0000 1.17
+++ make.util.m 17 Feb 2004 06:22:11 -0000
@@ -184,6 +184,13 @@
:- pred target_is_grade_or_arch_dependent(module_target_type::in) is semidet.
%-----------------------------------------------------------------------------%
+ % Java command-line tools utilities.
+
+ % Strip away the path prefix for a list of .class files.
+:- pred list_class_files_for_jar(module_name::in, string::in, string::out,
+ io__state::di, io__state::uo) is det.
+
+%-----------------------------------------------------------------------------%
% Debugging, verbose and error messages.
% Apply the given predicate if `--debug-make' is set.
@@ -696,6 +703,8 @@
linked_target_file_name(ModuleName, shared_library, FileName) -->
globals__io_lookup_string_option(shared_library_extension, Ext),
module_name_to_lib_file_name("lib", ModuleName, Ext, no, FileName).
+linked_target_file_name(ModuleName, java_archive, FileName) -->
+ module_name_to_file_name(ModuleName, ".jar", no, FileName).
:- pred module_target_to_file_name(module_name::in, module_target_type::in,
bool::in, file_name::out, io__state::di, io__state::uo) is det.
@@ -825,6 +834,34 @@
target_is_grade_or_arch_dependent(foreign_object(_, _), yes).
target_is_grade_or_arch_dependent(foreign_il_asm(_), yes).
target_is_grade_or_arch_dependent(fact_table_object(_, _), yes).
+
+%-----------------------------------------------------------------------------%
+%
+% Java command-line utilities.
+
+ % Strip away the path prefix for a list of .class files.
+list_class_files_for_jar(ModuleName, ClassFiles, ListClassFiles) -->
+ globals__io_lookup_bool_option(use_subdirs, UseSubdirs),
+ globals__io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs),
+ { AnySubdirs = UseSubdirs `or` UseGradeSubdirs },
+ (
+ { AnySubdirs = yes },
+ module_name_to_file_name(ModuleName, ".class", no, ClassFile),
+ { ClassSubdir = dir.dirname(ClassFile) },
+ % Here we use the `-C' option of jar to change directory during
+ % execution, then use sed to strip away the Mercury/classs/
+ % prefix to the class files.
+ % Otherwise, the class files would be stored as
+ % Mercury/classs/*.class
+ % within the jar file, which is not what we want.
+ % XXX It would be nice to avoid this dependency on sed.
+ { ListClassFiles = "-C " ++ ClassSubdir ++ " \\\n" ++
+ "\t\t`echo "" " ++ ClassFiles ++ """" ++
+ " | sed 's| '" ++ ClassSubdir ++ "/| |'`" }
+ ;
+ { AnySubdirs = no },
+ { ListClassFiles = ClassFiles }
+ ).
%-----------------------------------------------------------------------------%
Index: make.program_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.24
diff -u -d -r1.24 make.program_target.m
--- make.program_target.m 9 Feb 2004 12:13:28 -0000 1.24
+++ make.program_target.m 18 Feb 2004 02:14:12 -0000
@@ -735,7 +735,7 @@
),
globals__io_set_globals(unsafe_promise_unique(Globals)).
- % Install the `.a', `.so, `.opt' and `.mih' files
+ % Install the `.a', `.so, `.jar', `.opt' and `.mih' files
% for the current grade.
:- pred install_library_grade_files(bool::in, string::in, module_name::in,
list(module_name)::in, bool::out, make_info::in, make_info::out,
@@ -748,18 +748,25 @@
( { DirResult = yes } ->
linked_target_file_name(ModuleName, static_library, LibFileName),
linked_target_file_name(ModuleName, shared_library, SharedLibFileName),
+ linked_target_file_name(ModuleName, java_archive, JarFileName),
globals__io_lookup_string_option(install_prefix, Prefix),
globals__io_lookup_string_option(fullarch, FullArch),
- { GradeLibDir = Prefix/"lib"/"mercury"/"lib"/Grade/FullArch },
- install_file(LibFileName, GradeLibDir, LibSucceded),
- install_file(SharedLibFileName, GradeLibDir, SharedLibSucceded),
+ ( { Grade = "java" } ->
+ { GradeLibDir = Prefix/"lib"/"mercury"/"lib"/"java" },
+ install_file(JarFileName, GradeLibDir, LibsSucceeded)
+ ;
+ { GradeLibDir = Prefix/"lib"/"mercury"/"lib"/Grade/FullArch },
+ install_file(LibFileName, GradeLibDir, LibSuccess),
+ install_file(SharedLibFileName, GradeLibDir, SharedLibSuccess),
+ { LibsSucceeded = LibSuccess `and` SharedLibSuccess }
+ ),
list__map_foldl2(install_grade_ints_and_headers(LinkSucceeded, Grade),
- AllModules, IntsHeadersSucceded, Info0, Info),
+ AllModules, IntsHeadersSucceeded, Info0, Info),
{ Succeeded = bool__and_list(
- [LibSucceded, SharedLibSucceded | IntsHeadersSucceded]) }
+ [LibsSucceeded | IntsHeadersSucceeded]) }
;
{ Succeeded = no },
{ Info = Info0 }
@@ -950,6 +957,7 @@
linked_target_file_name(ModuleName, executable, ExeFileName),
linked_target_file_name(ModuleName, static_library, LibFileName),
linked_target_file_name(ModuleName, shared_library, SharedLibFileName),
+ linked_target_file_name(ModuleName, java_archive, JarFileName),
% Remove the symlinks created for `--use-grade-subdirs'.
globals__io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs),
@@ -959,12 +967,13 @@
ThisDirLibFileName),
linked_target_file_name(ModuleName, shared_library,
ThisDirSharedLibFileName),
+ linked_target_file_name(ModuleName, java_archive, ThisDirJarFileName),
globals__io_set_option(use_grade_subdirs, bool(UseGradeSubdirs)),
list__foldl2(remove_file,
- [ExeFileName, LibFileName, SharedLibFileName,
+ [ExeFileName, LibFileName, SharedLibFileName, JarFileName,
ThisDirExeFileName, ThisDirLibFileName,
- ThisDirSharedLibFileName],
+ ThisDirSharedLibFileName, ThisDirJarFileName],
Info0, Info1),
remove_file(ModuleName, ".init", Info1, Info2),
remove_init_files(ModuleName, Info2, Info).
--------------------------------------------------------------------------
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