[m-rev.] for review: installing extra C headers with Mercury libraries

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Sep 1 08:55:12 AEST 2008


For review by anyone.

Estimated hours taken: 1
Branches: main

Add a mechanism that allows extra C header files to be installed as part
of a Mercury library, in the same location as the header files generated
by the Mercury compiler.  This is useful when writing Mercury bindings
to C++ libraries since these often require an interface from C++ to C to
be written (at least where one does not already exist) and this usually
involves one or more header files that are then referenced from foreign_decl
pragmas on the Mercury side of things.

compiler/options.m:
  	Add a new option, --install-extra-header, that specifies extra
  	header files to install.

compiler/make.program_target.m:
  	When installing a library installing any extra header files.

doc/user_guide.texi:
  	Document the new option.

Julien.

Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.90
diff -u -r1.90 make.program_target.m
--- compiler/make.program_target.m	25 Jul 2008 00:47:56 -0000	1.90
+++ compiler/make.program_target.m	31 Aug 2008 22:41:35 -0000
@@ -1099,13 +1099,14 @@
       ->
           list.map_foldl2(install_ints_and_headers(LinkSucceeded), AllModules,
               IntsSucceeded, !Info, !IO),
-
+        install_extra_headers(ExtraHdrsSucceeded, !IO),
+
           globals.io_get_globals(Globals, !IO),
           grade_directory_component(Globals, Grade),
           install_library_grade_files(LinkSucceeded, Grade, MainModuleName,
               AllModules, GradeSucceeded, !Info, !IO),
           (
-            bool.and_list(IntsSucceeded) = yes,
+            bool.and_list([ExtraHdrsSucceeded | IntsSucceeded]) = yes,
               GradeSucceeded = yes
           ->
               % XXX With Mmake, LIBGRADES is target-specific.
@@ -1123,6 +1124,7 @@
           Succeeded = no
       ).

+
   :- pred install_ints_and_headers(bool::in, module_name::in, bool::out,
       make_info::in, make_info::out, io::di, io::uo) is det.

@@ -1195,6 +1197,23 @@
           Succeeded = no
       ).

+:- pred install_extra_headers(bool::out, io::di, io::uo) is det.
+
+install_extra_headers(ExtraHdrsSucceeded, !IO) :-
+    globals.io_lookup_accumulating_option(install_extra_header, ExtraHdrs,
+        !IO),
+    globals.io_lookup_string_option(install_prefix, Prefix, !IO),
+    IncDir = Prefix / "lib" / "mercury" / "inc",
+    list.foldl2(install_extra_header(IncDir), ExtraHdrs,
+        yes, ExtraHdrsSucceeded, !IO).
+
+:- pred install_extra_header(dir_name::in, string::in, bool::in, bool::out,
+    io::di, io::uo) is det.
+
+install_extra_header(IncDir, FileName, !Succeeded, !IO) :-
+    install_file(FileName, IncDir, InstallSucceeded, !IO),
+    !:Succeeded = bool.and(InstallSucceeded, !.Succeeded). 
+
   :- pred install_library_grade(bool::in, module_name::in, list(module_name)::in,
       string::in, bool::out, make_info::in, make_info::out,
       io::di, io::uo) is det.
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.624
diff -u -r1.624 options.m
--- compiler/options.m	29 Jul 2008 23:57:59 -0000	1.624
+++ compiler/options.m	31 Aug 2008 22:41:36 -0000
@@ -876,6 +876,7 @@
       ;       use_search_directories_for_intermod
       ;       libgrade_install_check
       ;       show_make_times
+    ;       install_extra_header

       % Miscellaneous Options
       ;       filenames_from_stdin
@@ -1704,7 +1705,8 @@
       intermod_directories                -   accumulating([]),
       use_search_directories_for_intermod -   bool(yes),
       libgrade_install_check              -   bool(yes),
-    show_make_times                     -   bool(no)
+    show_make_times                     -   bool(no),
+    install_extra_header                -   accumulating([])
   ]).
   option_defaults_2(miscellaneous_option, [
       % Miscellaneous Options
@@ -2579,6 +2581,7 @@
                       use_search_directories_for_intermod).
   long_option("libgrade-install-check", libgrade_install_check).
   long_option("show-make-times",      show_make_times).
+long_option("install-extra-header", install_extra_header).

   % misc options
   long_option("typecheck-ambiguity-warn-limit",
@@ -5252,7 +5255,10 @@
           "\tattempting to use them.  (This option is only meaningful with",
           "\t`mmc --make'.)",
           "--show-make-times",
-        "\tReport run times for commands executed by `mmc --make'."
+        "\tReport run times for commands executed by `mmc --make'.",
+        "--install-extra-header <file>",
+        "\tInstall the specified C header file with a Mercury library.",
+        "\t(This option is only supported by `mmc --make'.)"
       ]).

   :- pred options_help_misc(io::di, io::uo) is det.
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.572
diff -u -r1.572 user_guide.texi
--- doc/user_guide.texi	29 Jul 2008 23:58:00 -0000	1.572
+++ doc/user_guide.texi	31 Aug 2008 22:41:37 -0000
@@ -8966,6 +8966,12 @@
   @findex --show-make-times
   Report run times for commands executed by @samp{mmc --make}.

+ at sp 1
+ at item --install-extra-header @var{file}
+ at findex --install-extra-header
+Install the specified C header file with a Mercury library.
+(This option is only supported by @samp{mmc --make})
+
   @end table

   @node Miscellaneous options

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list