[m-rev.] for review: handle LDFLAGS and LD_LIBFLAGS with `mmc --make'

Simon Taylor stayl at cs.mu.OZ.AU
Tue May 21 16:56:38 AEST 2002


Estimated hours taken: 1
Branches: main

Handle LDFLAGS and LD_LIBFLAGS with `mmc --make'.

compiler/options.m:
doc/user_guide.texi:
	Add `--ml-flags' as a synonym for `--link-flags'.

	Add `--ld-flags' and `--ld-libflags', which are the
	options corresponding to the LDFLAGS and LD_LIBFLAGS
	Mmake variables.

	Add a comment that the `--output-file' option is
	ignored with `mmc --make'.

compiler/options_file.m:
	Handle LDFLAGS and LD_LIBFLAGS.

	Handle MLLIBS correctly (it contains flags for the linker,
	not for ml).

compiler/compile_target_code.m:
	Pass the value `--ldflags' or `--ld-libflags' to ml.

scripts/Mmake.vars.in:
	Add LDFLAGS and LD_LIBFLAGS to the options file
	passed to the options file passed to `mmc --make'
	on standard input.

Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.9
diff -u -u -r1.9 compile_target_code.m
--- compiler/compile_target_code.m	13 May 2002 18:22:24 -0000	1.9
+++ compiler/compile_target_code.m	21 May 2002 06:16:28 -0000
@@ -903,12 +903,14 @@
 	;
 		( { LinkTargetType = shared_library } ->
 			{ SharedLibOpt = "--make-shared-lib " },
+			{ LDFlagsOpt = ld_libflags },
 			globals__io_lookup_string_option(
 				shared_library_extension, SharedLibExt),
 			module_name_to_lib_file_name("lib", ModuleName,
 				SharedLibExt, yes, OutputFileName)
 		;
 			{ SharedLibOpt = "" },
+			{ LDFlagsOpt = ld_flags },
 			globals__io_lookup_string_option(
 				executable_file_extension, ExeExt),
 			module_name_to_file_name(ModuleName, ExeExt,
@@ -925,6 +927,9 @@
 		globals__io_lookup_accumulating_option(link_flags,
 				LinkFlagsList),
 		{ join_string_list(LinkFlagsList, "", "", " ", LinkFlags) },
+		globals__io_lookup_accumulating_option(LDFlagsOpt,
+				LDFlagsList),
+		{ join_string_list(LDFlagsList, "", "", " ", LDFlags) },
 		globals__io_lookup_accumulating_option(
 				link_library_directories,
 				LinkLibraryDirectoriesList),
@@ -934,11 +939,15 @@
 				LinkLibrariesList),
 		{ join_string_list(LinkLibrariesList, "-l", "", " ",
 				LinkLibraries) },
+
+		% Note that LDFlags may contain `-l' options (from MLLIBS),
+		% so it should come after Objects.
 		{ string__append_list(
 			["ml --grade ", Grade, " ", SharedLibOpt,
 			Target_Debug_Opt, TraceOpt, StdLibOpt, LinkFlags,
-			" -o ", OutputFileName, " ", Objects, " ", 
-			LinkLibraryDirectories, " ", LinkLibraries],
+			LinkLibraryDirectories,
+			" -- -o ", OutputFileName, " ", Objects, " ",
+			LDFlags, " ", LinkLibraries],
 			LinkCmd) },
 		invoke_shell_command(ErrorStream, verbose_commands,
 			LinkCmd, Succeeded),
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.372
diff -u -u -r1.372 options.m
--- compiler/options.m	13 May 2002 18:22:25 -0000	1.372
+++ compiler/options.m	20 May 2002 17:27:08 -0000
@@ -514,6 +514,8 @@
 	% Link options
 		;	output_file_name
 		;	link_flags
+		;	ld_flags
+		;	ld_libflags
 		;	link_library_directories
 		;	link_libraries
 		;	link_objects
@@ -1039,6 +1041,8 @@
 					% string, we use the name of the first
 					% module on the command line
 	link_flags		-	accumulating([]),
+	ld_flags		-	accumulating([]),
+	ld_libflags		-	accumulating([]),
 	link_library_directories -	accumulating([]),
 	link_libraries		-	accumulating([]),
 	link_objects		-	accumulating([]),
@@ -1618,6 +1622,9 @@
 % link options
 long_option("output-file",		output_file_name).
 long_option("link-flags",		link_flags).
+long_option("ml-flags",			link_flags).
+long_option("ld-flags",			ld_flags).
+long_option("ld-libflags",		ld_libflags).
 long_option("library-directory",	link_library_directories).
 long_option("library",			link_libraries).
 long_option("link-object",		link_objects).
@@ -3325,8 +3332,19 @@
 		"\tSpecify the name of the final executable.",
 		"\t(The default executable name is the same as the name",
 		"\tof the first module on the command line.)",
-		"--link-flags <options>",
-		"\tSpecify options to be passed to the linker.",
+		"\tThis option is ignored by `mmc --make'.",
+		"--link-flags <options>, --ml-flags <options>",
+		"\tSpecify options to be passed to ml, the Mercury linker.",
+		"--ld-flags <options>",
+		"\tSpecify options to be passed to the linker command",
+		"\tinvoked by ml to link an executable.",
+		"\tUse `ml --print-link-command' to find out which",
+		"\tcommand is used.",
+		"--ld-libflags <options>",
+		"\tSpecify options to be passed to the linker command",
+		"\tinvoked by ml to link a shared library.",
+		"\tUse `ml --print-shared-lib-link-command' to find out",
+		"\twhich command is used.",
 		"-L <directory>, --library-directory <directory>",
 		"\tAppend <directory> to the list of directories in which",
 		"\tto search for libraries.",
Index: compiler/options_file.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options_file.m,v
retrieving revision 1.6
diff -u -u -r1.6 options_file.m
--- compiler/options_file.m	6 May 2002 14:37:02 -0000	1.6
+++ compiler/options_file.m	20 May 2002 17:40:59 -0000
@@ -757,6 +757,8 @@
 	;	ml_flags
 	;	ml_objs
 	;	ml_libs
+	;	ld_flags
+	;	ld_libflags
 	;	c2init_args
 	;	libraries
 	;	lib_dirs
@@ -767,7 +769,7 @@
 options_variable_types =
 	[grade_flags, mmc_flags, c_flags, java_flags,
 	ilasm_flags, csharp_flags, mcpp_flags, ml_flags, ml_objs,
-	ml_libs, c2init_args, libraries, lib_dirs].
+	ml_libs, ld_flags, c2init_args, libraries, lib_dirs].
 
 :- func options_variable_name(options_variable_type) = string.
 
@@ -781,6 +783,8 @@
 options_variable_name(ml_flags) = "MLFLAGS".
 options_variable_name(ml_objs) = "MLOBJS".
 options_variable_name(ml_libs) = "MLLIBS".
+options_variable_name(ld_flags) = "LDFLAGS".
+options_variable_name(ld_libflags) = "LD_LIBFLAGS".
 options_variable_name(c2init_args) = "C2INITARGS".
 options_variable_name(libraries) = "LIBRARIES".
 options_variable_name(lib_dirs) = "LIB_DIRS".
@@ -797,6 +801,8 @@
 options_variable_type_is_target_specific(ml_flags) = yes.
 options_variable_type_is_target_specific(ml_objs) = yes.
 options_variable_type_is_target_specific(ml_libs) = yes.
+options_variable_type_is_target_specific(ld_flags) = yes.
+options_variable_type_is_target_specific(ld_libflags) = yes.
 options_variable_type_is_target_specific(c2init_args) = yes.
 options_variable_type_is_target_specific(libraries) = yes.
 options_variable_type_is_target_specific(lib_dirs) = no.
@@ -804,8 +810,14 @@
 :- func convert_to_mmc_options(pair(options_variable_type, list(string)))
 			= list(string).
 
-convert_to_mmc_options(VariableType - VariableValue) = OptionsStrings :-
-	MMCOptionType = mmc_option_type(VariableType),
+convert_to_mmc_options(VariableType - VariableValue) =
+		list__condense(list__map(
+				convert_to_mmc_options_2(VariableValue),
+				mmc_option_type(VariableType))).
+
+:- func convert_to_mmc_options_2(list(string), mmc_option_type) = list(string).
+
+convert_to_mmc_options_2(VariableValue, MMCOptionType) = OptionsStrings :-
 	(
 		MMCOptionType = mmc_flags,
 		OptionsStrings = VariableValue
@@ -832,28 +844,31 @@
 	% one mmc option per word in a variable's value, or just a single
 	% mmc option.
 	% The value of CFLAGS is converted into a single `--cflags' option.
-	% The value of MLOBJS is converted into as multiple
-	% `--link-object' options.
+	% The value of MLOBJS is converted into multiple `--link-object'
+	% options.
 :- type split_into_words
 	--->	split
 	;	not_split
 	.
 
-:- func mmc_option_type(options_variable_type) = mmc_option_type.
+:- func mmc_option_type(options_variable_type) = list(mmc_option_type).
 
-mmc_option_type(grade_flags) = mmc_flags.
-mmc_option_type(mmc_flags) = mmc_flags.
-mmc_option_type(c_flags) = option(not_split, "--cflags").
-mmc_option_type(java_flags) = option(not_split, "--java-flags").
-mmc_option_type(ilasm_flags) = option(not_split, "--ilasm-flags").
-mmc_option_type(mcpp_flags) = option(not_split, "--mcpp-flags").
-mmc_option_type(csharp_flags) = option(not_split, "--csharp-flags").
-mmc_option_type(ml_flags) = option(not_split, "--link-flags").
-mmc_option_type(ml_objs) = option(split, "--link-object").
-mmc_option_type(ml_libs) = option(not_split, "--link-flags").
-mmc_option_type(c2init_args) = option(split, "--init-file").
-mmc_option_type(libraries) = option(split, "--mercury-library").
-mmc_option_type(lib_dirs) = option(split, "--mercury-library-directory").
+mmc_option_type(grade_flags) = [mmc_flags].
+mmc_option_type(mmc_flags) = [mmc_flags].
+mmc_option_type(c_flags) = [option(not_split, "--cflags")].
+mmc_option_type(java_flags) = [option(not_split, "--java-flags")].
+mmc_option_type(ilasm_flags) = [option(not_split, "--ilasm-flags")].
+mmc_option_type(mcpp_flags) = [option(not_split, "--mcpp-flags")].
+mmc_option_type(csharp_flags) = [option(not_split, "--csharp-flags")].
+mmc_option_type(ml_flags) = [option(not_split, "--link-flags")].
+mmc_option_type(ml_objs) = [option(split, "--link-object")].
+mmc_option_type(ml_libs) = [option(not_split, "--ld-flags"),
+				option(not_split, "--ld-libflags")].
+mmc_option_type(ld_flags) = [option(not_split, "--ld-flags")].
+mmc_option_type(ld_libflags) = [option(not_split, "--ld-libflags")].
+mmc_option_type(c2init_args) = [option(split, "--init-file")].
+mmc_option_type(libraries) = [option(split, "--mercury-library")].
+mmc_option_type(lib_dirs) = [option(split, "--mercury-library-directory")].
 
 %-----------------------------------------------------------------------------%
 
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.311
diff -u -u -r1.311 user_guide.texi
--- doc/user_guide.texi	13 May 2002 18:22:33 -0000	1.311
+++ doc/user_guide.texi	20 May 2002 17:27:00 -0000
@@ -5860,13 +5860,32 @@
 Specify the name of the final executable.
 (The default executable name is the same as the name of the
 first module on the command line, but without the @samp{.m} extension.)
+This option is ignored by @samp{mmc --make}.
 
 @sp 1
 @item --link-flags @var{options}
+ at itemx --ml-flags @var{options}
 @findex --link-flags
+ at findex --ml-flags
 @cindex Link options
 @cindex Linker options
 Specify options to be passed to @samp{ml}, the Mercury linker.
+
+ at sp 1
+ at item --ld-flags @var{options}
+ at findex --ld-flags
+Specify options to be passed to the command
+invoked by ml to link an executable.
+Use @code{ml --print-link-command} to find out
+which command is used.
+
+ at sp 1
+ at item --ld-libflags @var{options}
+ at findex --ld-libflags
+Specify options to be passed to the command
+invoked by ml to link a shared library.
+Use @code{ml --print-shared-lib-link-command}
+to find out which command is used.
 
 @sp 1
 @item -L @var{directory}
Index: scripts/Mmake.vars.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mmake.vars.in,v
retrieving revision 1.71
diff -u -u -r1.71 Mmake.vars.in
--- scripts/Mmake.vars.in	16 May 2002 06:48:43 -0000	1.71
+++ scripts/Mmake.vars.in	21 May 2002 06:17:26 -0000
@@ -121,6 +121,8 @@
 	echo MLFLAGS += '$(ALL_MLFLAGS)'; \
 	echo MLLIBS += '$(ALL_MLLIBS)'; \
 	echo MLOBJS += '$(ALL_MLOBJS)'; \
+	echo LDFLAGS += '$(ALL_LDFLAGS)'; \
+	echo LD_LIBFLAGS += '$(ALL_LD_LIBFLAGS)'; \
 	echo EXTRA_LIBRARIES += '$(EXTRA_LIBRARIES)'; \
 	echo EXTRA_LIB_DIRS += '$(EXTRA_LIB_DIRS)'; \
 	}
--------------------------------------------------------------------------
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