diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m index 8b0f03c51..845c4e574 100644 --- a/compiler/compile_target_code.m +++ b/compiler/compile_target_code.m @@ -639,16 +639,6 @@ assemble(ErrorStream, PIC, ModuleName, Succeeded) --> %-----------------------------------------------------------------------------% make_init_file(ErrorStream, MainModuleName, AllModules, Succeeded) --> - globals__io_lookup_maybe_string_option(make_init_file_command, - MaybeInitFileCommand), - ( - { MaybeInitFileCommand = yes(InitFileCommand0) }, - { InitFileCommand = substitute_user_command(InitFileCommand0, - MainModuleName, AllModules) }, - invoke_shell_command(ErrorStream, verbose_commands, - InitFileCommand, Succeeded) - ; - { MaybeInitFileCommand = no }, module_name_to_file_name(MainModuleName, ".init.tmp", yes, TmpInitFileName), io__open_output(TmpInitFileName, InitFileRes), @@ -674,10 +664,25 @@ make_init_file(ErrorStream, MainModuleName, AllModules, Succeeded) --> [] ) ), AllModules), + globals__io_lookup_maybe_string_option(extra_init_command, + MaybeInitFileCommand), + ( + { MaybeInitFileCommand = yes(InitFileCommand0) }, + { InitFileCommand = substitute_user_command( + InitFileCommand0, MainModuleName, + AllModules) }, + invoke_shell_command(InitFileStream, verbose_commands, + InitFileCommand, Succeeded0) + ; + { MaybeInitFileCommand = no }, + { Succeeded0 = yes } + ), + io__close_output(InitFileStream), module_name_to_file_name(MainModuleName, ".init", yes, InitFileName), - update_interface(InitFileName, Succeeded) + update_interface(InitFileName, Succeeded1), + { Succeeded = Succeeded0 `and` Succeeded1 } ; { InitFileRes = error(Error) }, io__progname_base("mercury_compile", ProgName), @@ -689,8 +694,7 @@ make_init_file(ErrorStream, MainModuleName, AllModules, Succeeded) --> io__write_string(ErrorStream, io__error_message(Error)), io__nl(ErrorStream), { Succeeded = no } - ) - ). + ). %-----------------------------------------------------------------------------% diff --git a/compiler/modules.m b/compiler/modules.m index 21be377f0..3fb36a468 100644 --- a/compiler/modules.m +++ b/compiler/modules.m @@ -4047,6 +4047,12 @@ generate_dep_file(SourceFileName, ModuleName, DepsMap, DepStream) --> "\techo > ", InitFileName, "\n" ]), list__foldl(append_to_init_list(DepStream, InitFileName), Modules), + + % $(EXTRA_INIT_COMMAND) should expand to a command to + % generate extra entries in the `.init' file for a library. + % It may expand to the empty string. + io__write_string(DepStream, "\t$(EXTRA_INIT_COMMAND) >> "), + io__write_string(DepStream, InitFileName), io__write_string(DepStream, "\n"), % The `force-module_init' dependency forces the commands for diff --git a/compiler/options.m b/compiler/options.m index 967a790b5..bf3535b93 100644 --- a/compiler/options.m +++ b/compiler/options.m @@ -544,7 +544,7 @@ ; keep_going ; rebuild ; invoked_by_mmc_make - ; make_init_file_command + ; extra_init_command ; pre_link_command ; install_prefix ; install_command @@ -1086,7 +1086,7 @@ option_defaults_2(build_system_option, [ rebuild - bool(no), invoked_by_mmc_make - bool(no), pre_link_command - maybe_string(no), - make_init_file_command - maybe_string(no), + extra_init_command - maybe_string(no), install_prefix - string("/usr/local/"), install_command - string("cp"), libgrades - accumulating([]), @@ -1665,7 +1665,7 @@ long_option("keep-going", keep_going). long_option("rebuild", rebuild). long_option("invoked-by-mmc-make", invoked_by_mmc_make). long_option("pre-link-command", pre_link_command). -long_option("make-init-file-command", make_init_file_command). +long_option("extra-init-command", extra_init_command). long_option("install-prefix", install_prefix). long_option("install-command", install_command). long_option("library-grade", libgrades). @@ -3433,11 +3433,10 @@ options_help_build_system --> "\treplaced with the list of modules making up the library.", "\tOccurrences of `@@' and `%%' will be replaced with `@'", "\tand `%' respectively.", - "--make-init-file-command ", - "\tSpecify an alternative command to produce the `.init' file", - "\tfor a library. Occurrences of `@' and `%' in the command", + "--extra-init-command ", + "\tSpecify a command to produce extra entries in the `.init'", + "\tfile for a library. Occurrences of `@' and `%' in the command", "\tare substituted as for the `--pre-link-command' option.", - "\tBy default, `mmc --make' creates the `.init' file itself.", "--install-prefix ", "\tThe directory under which to install Mercury libraries.", "--install-command ", diff --git a/doc/user_guide.texi b/doc/user_guide.texi index ae195ef7d..47fb5cea1 100644 --- a/doc/user_guide.texi +++ b/doc/user_guide.texi @@ -5634,12 +5634,11 @@ 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 -Specify an alternative command to produce the @file{.init} file +@item --extra-init-command @var{command} +@findex --extra-init-command +Specify a command to produce extra entries in 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. @item -k @itemx --keep-going diff --git a/library/Mmakefile b/library/Mmakefile index c50eeceb4..276c963a6 100644 --- a/library/Mmakefile +++ b/library/Mmakefile @@ -246,23 +246,19 @@ lib_std: lib$(STD_LIB_NAME) ifeq ($(MMAKE_USE_MMC_MAKE),no) -$(STD_LIB_NAME).init: $(deps_subdir)$(STD_LIB_NAME).dep +EXTRA_INIT_COMMAND = \ for file in $($(STD_LIB_NAME).ms); do \ grep '^INIT ' $$file; \ - echo "INIT mercury__`basename $$file .m`__init"; \ - done > $(STD_LIB_NAME).init - + true; \ + done else -# The command below is invoked as "command >& module.err". The braces -# stop the output meant for the `.init' file being redirected to the -# `.err' file. -MCFLAGS += --make-init-file-command \ - "{ for module in %; do \ +MCFLAGS += --extra-init-command \ + "for module in %; do \ grep '^INIT ' $$$${module}.m; \ - echo INIT mercury__$$$${module}__init; \ - done > @.init; }" + true; \ + done" endif endif # GRADE != il diff --git a/scripts/Mmake.vars.in b/scripts/Mmake.vars.in index 1ad9fae06..49973bd0e 100644 --- a/scripts/Mmake.vars.in +++ b/scripts/Mmake.vars.in @@ -282,6 +282,10 @@ C2INITARGS = EXTRA_C2INITARGS = LIB_C2INITARGS = $(patsubst %,%.init,$(ALL_EXTRA_LIBRARIES)) +# $(EXTRA_INIT_COMMAND) should expand to a command to generate extra entries +# in the `.init' file for a library. It may expand to the empty string. +EXTRA_INIT_COMMAND = + # c2init and ml take the same arguments. C2INIT_AND_MLFLAGS = $(MLFLAGS) $(C2INITFLAGS) \ $(EXTRA_MLFLAGS) $(EXTRA_C2INITFLAGS) \