<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, 31 Aug 2025 at 23:24, Zoltan Somogyi <<a href="mailto:zoltan.somogyi@runbox.com">zoltan.somogyi@runbox.com</a>> wrote:<br></div><div>> Update the description of module compilation.<br><br>...<br><br><br>> diff --git a/doc/mercury_user_guide.texi b/doc/mercury_user_guide.texi<br>> index 81dd36224..231dbeced 100644<br>> --- a/doc/mercury_user_guide.texi<br>> +++ b/doc/mercury_user_guide.texi<br>> @@ -2370,6 +2370,8 @@ specifically, the subset that come after @var{module_3} in the module order.<br>>  @node Creating target and object code files<br>>  @section Creating target and object code files<br>>  <br>> +@heading Compiling Mercury programs in C grades<br>> +<br>>  To compile a Mercury source file to C code,<br>>  use a command such as<br>>  <br>> @@ -2380,16 +2382,30 @@ mmc --grade asm_fast.gc -C @var{module_name}.m<br>>  @findex --target-code-only<br>>  <br>>  On that command line,<br>> -the @code{--grade asm_fast.gc} part obviously specifies the grade,<br>> -while the @code{-C} option,<br>> -whose long name is @code{--target-code-only},<br>> +the @command{--grade asm_fast.gc} part obviously specifies the grade,<br><br>Delete "obviously".<br><br>Use @option rather than @command where appropriate here and elsewhere below.<br><br>> +while the @command{-C} option,<br>> +whose long name is @command{--target-code-only},<br>>  tells the compiler to stop after generating the target language file<br>>  (in this case, @file{@var{module_name}.c}).<br>>  <br>> -You can then compile @file{@var{module_name}.c} to @file{@var{module_name}.o},<br>> +You can then<br>> +compile @file{@var{module_name}.c} to @file{@var{module_name}.o} yourself,<br>>  or you can tell the Mercury compiler to do this for you.<br>> -To compile a source file not just to C code but to object code,<br>> -use the command<br>> +<br>> +The command for doing it yourself is a command such as<br>> +@example<br>> +mgnuc --grade asm_fast.gc -- -c @var{module_name}.c -o @var{module_name}.o<br>> +@end example<br>> +<br>> +The part of the command line<br>> +between the command name (@command{mgnuc})<br>> +and to the double dash (@command{--})<br>> +contains the options interpreted by @command{mgnuc},<br>> +while the part after the double dash contains options<br>> +for the configured C compiler (usually gcc, clang, or MSVC).<br><br>I don't think you need to list the C compilers there.<br><br>> +The command that tells the Mercury compiler<br>> +to generate both the @file{.c} and @file{.o} file of a module is<br>>  <br>>  @example<br>>  mmc --grade asm_fast.gc -c @var{module_name}.m<br>> @@ -2397,14 +2413,63 @@ mmc --grade asm_fast.gc -c @var{module_name}.m<br>>  @findex -c<br>>  @findex --compile-only<br>>  <br>> -The @code{-c} option, whose long name is @code{--compile-only},<br>> +The @command{-c} option, whose long name is @command{--compile-only},<br>>  tells the compiler to stop after compiling the Mercury code into object code.<br>> -(In grades that target Java,<br>> -it tells the compiler to stop after generating @file{@var{module_name}.class},<br>> -and In grades that target C#,<br>> -it tells the compiler to stop after generating @file{@var{module_name}.dll},<br>> -since these file types are the equivalents of object files<br>> -for these target languages.)<br>> +<br>> +If the source file contains nested modules,<br>> +then both the main module in the file,<br>> +and all the submodules nested inside it, directly or indirectly, <br>> +will all get compiled<br>> +first to separate @file{.c} files,<br>> +and then to separate @file{.o} files.<br>> +<br>> +@heading Compiling Mercury programs in Java grades<br>> +<br>> +In grades that target Java,<br>> +@command{-C} (@command{--target-code-only}) tells the compiler to stop<br>> +after generating @file{@var{module_name}.java}:<br>> +<br>> +@example<br>> +mmc --grade java -C @var{module_name}.m<br>> +@end example<br>> +<br>> +while @command{-c} (@command{--compile-only})<br>> +tells the compiler to stop<br>> +after generating @file{@var{module_name}.class}:<br>> +<br>> +@example<br>> +mmc --grade java -c @var{module_name}.m<br>> +@end example<br>> +<br>> +since @file{.class} files are the Java equivalents of object files for C.<br>> +<br>> +If the source file contains nested modules,<br>> +then both the main module in the file,<br>> +and all the submodules nested inside it, directly or indirectly, <br>> +will all get compiled<br>> +first to separate @file{.java} files,<br>> +and then to separate @file{.class} files.<br><br>You should mention that both the .java and .class files created by the<br>above examples will be placed in a directory named jmercury.<br><br>...<br><br>> diff --git a/scripts/<a href="http://mgnuc.in">mgnuc.in</a> b/scripts/<a href="http://mgnuc.in">mgnuc.in</a><br>> index fcb9a2d3c..4b83a6527 100644<br>> --- a/scripts/<a href="http://mgnuc.in">mgnuc.in</a><br>> +++ b/scripts/<a href="http://mgnuc.in">mgnuc.in</a><br>> @@ -9,10 +9,6 @@<br>>  # This file may only be copied under the terms of the GNU General<br>>  # Public License - see the file COPYING in the Mercury distribution.<br>>  #---------------------------------------------------------------------------#<br>> -#<br>> -# IMPORTANT: the manpage is produced automatically from this help<br>> -# message, so if you change the help message, don't forget to check<br>> -# that the manpage still looks OK.<br>>  <br>>  # *************************************************************************<br>>  # *** IMPORTANT NOTE: any changes to this file may also require similar ***<br>> @@ -121,9 +117,12 @@ halt_at_warn_if_possible=false<br>>  # include the file `init_grade_options.sh-subr'<br>>  @INIT_GRADE_OPTIONS@<br>>  <br>> +# IMPORTANT: The manpage is produced automatically from this help message,<br>> +# so if you change it, do not forget to check that the manpage still looks OK.<br>> +<br>>  Help="\<br>>  Name:   mgnuc - Mercury front-end to GNU C<br>> -Usage:  mgnuc [<options>] [-- <gcc options>] files...<br>> +Usage:  mgnuc [<options>] [-- <gcc/clang/msvc options>] files...<br><br>One minor point; if msvc is an option, then this script cannot really be<br>a "front-end to GNU C".  Perhaps, we should just s/GNU C/C/.<br><br>Also, I would just say "C compiler options" rather than listing specific<br>C compilers.<br><br>>  Options:<br>>      -v, --verbose<br>>          Echo gcc command before executing it.<br>> @@ -152,8 +151,9 @@ Options:<br>>  ${grade_usage}<br>>  <br>>  Description:<br>> -    This runs gcc with the appropriate options for compiling Mercury programs.<br>> -    Normally it invokes gcc with almost all warnings enabled,<br>> +    This command runs the configured C compiler (usually gcc, clang, or msvc)<br><br>Again, I would not list the C compilers there.<br><br>> +    with the appropriate options for compiling Mercury programs.<br>> +    Normally it invokes the C compiler with almost all warnings enabled,<br>>      but this can be changed using \`--no-check' option.<br>>  Environment variables:<br>>      MERCURY_DEFAULT_GRADE.<br><br>The rest looks fine.<br><br>Julien.<br></div><div> </div></div></div>