[m-rev.] diff: handle `mmc --make lib<module>'
Simon Taylor
stayl at cs.mu.OZ.AU
Mon May 13 18:30:10 AEST 2002
On 13-May-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 13-May-2002, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> >
> > + at item --pre-link-command @var{command}
> > + at findex --pre-link-command
> > +Specify a command to run before linking with @samp{mmc --make}.
> > +This can be used to compile C source files which rely on
> > +header files generated by the Mercury compiler.
> > +Occurrences of @samp{@@} in the command will be replaced with
> > +the name of the main module with @samp{.} as the module
> > +qualifier. Occurrences of @samp{%} in the command will be
> > +replaced by the list of modules making up the library.
> > +
> > + at item --make-init-file-command @var{command}
> > + at findex --make-init-file-command
> > +Specify an alternative command to produce the @file{.init} file
> > +for a library. Occurrences of @samp{@@} and @samp{%} in the command
> > +are substituted as for the @samp{--pre-link-command} option.
> > +By default, @samp{mmc --make} creates the @samp{.init} file itself.
>
> What if pre-link command that you want to use contains an "@" or a "%"?
>
> For example, on Windows it is common to use option files, rather than
> passing options on the command line, especially when invoking complicated
> programs such as a C compiler. (This technique avoids overflowing
> the command line length limits.) The usual syntax for specifying the
> option file is to pass "@<filename>", e.g. "@myoptions", on the command
> line.
`@@' and `%%' are now replaced with `@' and `%' respectively.
Simon.
diff -u compiler/compile_target_code.m compiler/compile_target_code.m
--- compiler/compile_target_code.m
+++ compiler/compile_target_code.m
@@ -150,7 +150,7 @@
:- import_module ll_backend__llds_out. % for llds_out__make_init_name and
% llds_out__make_rl_data_name
-:- import_module dir, int, require, string.
+:- import_module char, dir, int, require, string.
il_assemble(ErrorStream, ModuleName,
HasMain, Succeeded) -->
@@ -1110,22 +1110,44 @@
%-----------------------------------------------------------------------------%
substitute_user_command(Command0, MainModule, AllModules) = Command :-
- ( string__contains_char(Command0, '@') ->
+ ( string__contains_char(Command0, Char), (Char = ('@') ; Char = '%') ->
prog_out__sym_name_to_string(MainModule, ".", MainModuleStr),
- Command1 = string__replace_all(Command0, "@", MainModuleStr)
- ;
- Command1 = Command0
- ),
- ( string__contains_char(Command0, '%') ->
AllModulesStrings = list__map(
(func(Module) = ModuleStr :-
prog_out__sym_name_to_string(Module, ".", ModuleStr)
), AllModules),
join_string_list(AllModulesStrings,
"", "", " ", AllModulesStr),
- Command = string__replace_all(Command1, "%", AllModulesStr)
+ Command = string__from_rev_char_list(substitute_user_command_2(
+ string__to_char_list(Command0),
+ reverse(string__to_char_list(MainModuleStr)),
+ reverse(string__to_char_list(AllModulesStr)),
+ []))
+ ;
+ Command = Command0
+ ).
+
+:- func substitute_user_command_2(list(char), list(char),
+ list(char), list(char)) = list(char).
+
+substitute_user_command_2([], _, _, RevChars) = RevChars.
+substitute_user_command_2([Char | Chars], RevMainModule,
+ RevAllModules, RevChars0) =
+ (
+ ( Char = ('@'), Subst = RevMainModule
+ ; Char = '%', Subst = RevAllModules
+ )
+ ->
+ ( Chars = [Char | Chars2] ->
+ substitute_user_command_2(Chars2, RevMainModule,
+ RevAllModules, [Char | RevChars0])
+ ;
+ substitute_user_command_2(Chars, RevMainModule,
+ RevAllModules, Subst ++ RevChars0)
+ )
;
- Command = Command1
+ substitute_user_command_2(Chars, RevMainModule,
+ RevAllModules, [Char | RevChars0])
).
%-----------------------------------------------------------------------------%
diff -u compiler/options.m compiler/options.m
--- compiler/options.m
+++ compiler/options.m
@@ -3392,7 +3392,9 @@
"\tOccurrences of `@' in the command will be replaced with",
"\tthe name of the main module with `.' as the module",
"\tqualifier. Occurrences of `%' in the command will be",
- "\treplaced by the list of modules making up the library.",
+ "\treplaced with the list of modules making up the library.",
+ "\tOccurrences of `@@' and `%%' will be replaced with `@'",
+ "\tand `%' respectively.",
"--make-init-file-command <command>",
"\tSpecify an alternative command to produce the `.init' file",
"\tfor a library. Occurrences of `@' and `%' in the command",
diff -u doc/user_guide.texi doc/user_guide.texi
--- doc/user_guide.texi
+++ doc/user_guide.texi
@@ -5627,7 +5627,9 @@
Occurrences of @samp{@@} in the command will be replaced with
the name of the main module with @samp{.} as the module
qualifier. Occurrences of @samp{%} in the command will be
-replaced by the list of modules making up the library.
+replaced with the list of modules making up the library.
+Occurrences of @samp{@@@@} and @samp{%%} will be replaced
+with @samp{@@} and @samp{%} respectively.
@item --make-init-file-command @var{command}
@findex --make-init-file-command
--------------------------------------------------------------------------
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