[m-rev.] for review: add --lib-linkage option

Peter Wang wangp at students.cs.mu.OZ.AU
Fri Jan 6 10:49:15 AEDT 2006


Estimated hours taken: 3
Branches: main

Add a `--lib-linkage' accumulating option for `mmc --make'.  This option
allows you to specify whether libraries should be installed for shared
linking (`shared') or static linking (`static').  The option corresponds
to a options file or environment variable called `LIB_LINKAGES'.

compiler/options.m:
compiler/options_file.m:
doc/user_guide.texi:
	Add and document `--lib-linkage' option and `LIB_LINKAGES'
	variable.

	Unrelated change: document `--no-libgrade' option.

compiler/handle_options.m:
	If no --lib-linkage option has been specified, default to the
	set of all possible linkages.

compiler/make.program_target.m:
	Skip building/installing static or shared libraries according to
	the `--lib-linkage' options.

Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.247
diff -u -r1.247 handle_options.m
--- compiler/handle_options.m	3 Jan 2006 04:03:06 -0000	1.247
+++ compiler/handle_options.m	5 Jan 2006 06:18:24 -0000
@@ -645,6 +645,17 @@
         % without checking timestamps.
         option_implies(rebuild, make, bool(yes), !Globals),
 
+        % If no --lib-linkage option has been specified, default to the
+        % set of all possible linkages.
+        globals__lookup_accumulating_option(!.Globals, lib_linkages,
+            LibLinkages0),
+        ( LibLinkages0 = [] ->
+            globals__set_option(lib_linkages,
+                accumulating(["static", "shared"]), !Globals)
+        ;
+            true
+        ),
+
         % make.m controls generating object code and linking itself,
         % so mercury_compile.m should only generate target code when
         % given a module to process.
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.35
diff -u -r1.35 make.program_target.m
--- compiler/make.program_target.m	5 Dec 2005 02:17:20 -0000	1.35
+++ compiler/make.program_target.m	5 Jan 2006 05:48:57 -0000
@@ -51,9 +51,22 @@
     ;
         ExtraOptions = []
     ),
-    build_with_module_options(MainModuleName, ExtraOptions,
-        make_linked_target_2(MainModuleName - FileType),
-        Succeeded, !Info, !IO).
+    globals.io_lookup_accumulating_option(lib_linkages, LibLinkages, !IO),
+    (
+        (
+            FileType = static_library,
+            not list.member("static", LibLinkages)
+        ;
+            FileType = shared_library,
+            not list.member("shared", LibLinkages)
+        )
+    ->
+        Succeeded = yes
+    ;
+        build_with_module_options(MainModuleName, ExtraOptions,
+            make_linked_target_2(MainModuleName - FileType),
+            Succeeded, !Info, !IO)
+    ).
 
 :- pred make_linked_target_2(linked_target_file::in, list(string)::in,
     bool::out, make_info::in, make_info::out, io::di, io::uo) is det.
@@ -778,12 +791,13 @@
             install_file(JarFileName, GradeLibDir, LibsSucceeded, !IO)
         ;
             GradeLibDir = Prefix/"lib"/"mercury"/"lib"/Grade,
-            install_file(LibFileName, GradeLibDir, LibSuccess, !IO),
+            maybe_install_library_file("static", LibFileName, GradeLibDir,
+                LibSuccess, !IO),
             ( LibFileName = SharedLibFileName ->
                 LibsSucceeded = LibSuccess
             ;
-                install_file(SharedLibFileName, GradeLibDir, SharedLibSuccess,
-                    !IO),
+                maybe_install_library_file("shared", SharedLibFileName,
+                    GradeLibDir, SharedLibSuccess, !IO),
                 LibsSucceeded = LibSuccess `and` SharedLibSuccess
             )
         ),
@@ -873,6 +887,17 @@
         Succeeded = Succeeded1
     ).
 
+:- pred maybe_install_library_file(string::in, file_name::in, dir_name::in,
+    bool::out, io::di, io::uo) is det.
+
+maybe_install_library_file(Linkage, FileName, InstallDir, Succeeded, !IO) :-
+    globals.io_lookup_accumulating_option(lib_linkages, LibLinkages, !IO),
+    ( list.member(Linkage, LibLinkages) ->
+        install_file(FileName, InstallDir, Succeeded, !IO)
+    ;
+        Succeeded = yes
+    ).
+
 :- pred install_file(file_name::in, dir_name::in, bool::out,
     io::di, io::uo) is det.
 
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.487
diff -u -r1.487 options.m
--- compiler/options.m	3 Jan 2006 04:07:50 -0000	1.487
+++ compiler/options.m	5 Jan 2006 23:21:17 -0000
@@ -735,6 +735,7 @@
     ;       mercury_configuration_directory_special
     ;       install_command
     ;       libgrades
+    ;       lib_linkages
     ;       flags_file
     ;       options_files
     ;       config_file
@@ -1458,6 +1459,7 @@
     mercury_configuration_directory     -   maybe_string(no),
     install_command                     -   string("cp"),
     libgrades                           -   accumulating([]),
+    lib_linkages                        -   accumulating([]),
     flags_file                          -   file_special,
     options_files                       -   accumulating(["Mercury.options"]),
 
@@ -2198,6 +2200,7 @@
 long_option("use-symlinks",         use_symlinks).
 long_option("library-grade",        libgrades).
 long_option("libgrade",             libgrades).
+long_option("lib-linkage",          lib_linkages).
 long_option("flags",                flags_file).
 long_option("flags-file",           flags_file).
 long_option("options-file",         options_files).
@@ -4457,6 +4460,14 @@
         "--libgrade <grade>",
         "\tAdd <grade> to the list of compilation grades in",
         "\twhich a library to be installed should be built.",
+        "--no-libgrade",
+        "\tClear the list of compilation grades in which a library",
+        "\tto be installed should be built.",
+        "--lib-linkage {shared|static}",
+        "\tSpecify whether libraries should be installed for shared",
+        "\tor static linking.  This option can be specified multiple",
+        "\ttimes.  By default libraries will be installed for",
+        "\tboth shared and static linking.",
         "--flags <file>",
         "--flags-file <file>",
         "\tTake options from the specified file, and handle them",
Index: compiler/options_file.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options_file.m,v
retrieving revision 1.32
diff -u -r1.32 options_file.m
--- compiler/options_file.m	28 Nov 2005 04:11:50 -0000	1.32
+++ compiler/options_file.m	5 Jan 2006 06:27:52 -0000
@@ -877,6 +877,7 @@
     ;       libraries
     ;       lib_dirs
     ;       lib_grades
+    ;       lib_linkages
     ;       install_prefix
     ;       stdlib_dir
     ;       config_dir
@@ -892,8 +893,8 @@
     % `MCFLAGS'. Settings in `MCFLAGS' (e.g. `--no-mercury-stdlib-dir')
     % should override settings of these MERCURY_STDLIB_DIR in the environment.
 options_variable_types =
-    [grade_flags, linkage, mercury_linkage, lib_grades, stdlib_dir,
-    config_dir, mmc_flags, c_flags, java_flags, ilasm_flags,
+    [grade_flags, linkage, mercury_linkage, lib_grades, lib_linkages,
+    stdlib_dir, config_dir, mmc_flags, c_flags, java_flags, ilasm_flags,
     csharp_flags, mcpp_flags, ml_objs, lib_dirs, ld_flags,
     libraries, ml_libs, c2init_args, install_prefix].
 
@@ -914,6 +915,7 @@
 options_variable_name(libraries) = "LIBRARIES".
 options_variable_name(lib_dirs) = "LIB_DIRS".
 options_variable_name(lib_grades) = "LIBGRADES".
+options_variable_name(lib_linkages) = "LIB_LINKAGES".
 options_variable_name(install_prefix) = "INSTALL_PREFIX".
 options_variable_name(stdlib_dir) = "MERCURY_STDLIB_DIR".
 options_variable_name(config_dir) = "MERCURY_CONFIG_DIR".
@@ -940,6 +942,7 @@
 options_variable_type_is_target_specific(stdlib_dir) = no.
 options_variable_type_is_target_specific(config_dir) = no.
 options_variable_type_is_target_specific(lib_grades) = yes.
+options_variable_type_is_target_specific(lib_linkages) = yes.
 options_variable_type_is_target_specific(linkage) = yes.
 options_variable_type_is_target_specific(mercury_linkage) = yes.
 
@@ -994,6 +997,7 @@
 mmc_option_type(libraries) = option([], "--mercury-library").
 mmc_option_type(lib_dirs) = option([], "--mercury-library-directory").
 mmc_option_type(lib_grades) = option(["--no-libgrade"], "--libgrade").
+mmc_option_type(lib_linkages) = option(["--no-lib-linkage"], "--lib-linkage").
 mmc_option_type(install_prefix) = option([], "--install-prefix").
 mmc_option_type(stdlib_dir) = option([], "--mercury-stdlib-dir").
 mmc_option_type(config_dir) = option([], "--mercury-config-dir").
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.463
diff -u -r1.463 user_guide.texi
--- doc/user_guide.texi	3 Jan 2006 04:03:06 -0000	1.463
+++ doc/user_guide.texi	5 Jan 2006 23:27:37 -0000
@@ -562,8 +562,11 @@
 the name of the command to use to install each file, by default
 @samp{cp}. The variable @code{INSTALL_MKDIR} specifies the command to use
 to create directories, by default @samp{mkdir -p}.
+For @samp{mmc --make} whether to install libraries for static or shared
+linking can be specified with the @code{LIB_LINKAGES} variable.
 For more information, see @ref{Installing libraries}.
 @vindex LIBGRADES
+ at vindex LIB_LINKAGES
 @vindex INSTALL
 @vindex INSTALL_MKDIR
 
@@ -803,6 +806,13 @@
 Note also that any @code{GRADEFLAGS} settings will also be applied when
 the library is built in each of the listed grades, so you may not get what
 you expect if those options are not subsumed by each of the grades listed.
+
+ at item LIB_LINKAGES
+ at vindex LIB_LINKAGES
+A list of linkage styles (@samp{shared} or @samp{static}) for which libraries
+should be built and installed.  The default is to install libraries for both
+static and shared linking.  This variable only has an effect with
+ at samp{mmc --make}.
 @end table
 
 Other variables also exist --- see
@@ -7567,6 +7577,21 @@
 which a library to be installed should be built.
 
 @sp 1
+ at item --no-libgrade
+ at findex --no-libgrade
+Clear the list of compilation grades in which a library
+to be installed should be built.  The main use of this is to avoid
+building and installing the default set of grades.
+
+ at sp 1
+ at item --lib-linkage @{shared,static@}
+ at findex --lib-linkage
+Specify whether libraries should be installed for shared
+or static linking.  This option can be specified multiple
+times.  By default libraries will be installed for
+both shared and static linking.
+
+ at sp 1
 @item --flags @var{file}
 @itemx --flags-file @var{file}
 @findex --flags
--------------------------------------------------------------------------
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