[m-rev.] for review: remove compiler Unix dependencies

Simon Taylor stayl at cs.mu.OZ.AU
Wed Aug 6 19:08:53 AEST 2003


Estimated hours taken: 50
Branches: main

Remove Unix dependencies in the compiler.

Avoid calling passes_aux.invoke_shell_command, which
requires the presence of a Unix shell.

The implementation of fact tables still has dependencies
on Unix utilities (e.g. sort).

aclocal.m4:
	Don't pass Unix style paths to MSVC.

configure.in:
	Use `cygpath -m' rather than `cygpath -w'.
	`cygpath -m' uses '/' as the directory separator,
	so it doesn't cause quoting problems in shell
	scripts.

	Apply $CYGPATH to $PREFIX, $LIBDIR, $CONFIG_PREFIX
	and $CONFIG_LIBDIR.

	Don't pass `-lm' when linking with MSVC.

configure.in:
compiler/options.m:
scripts/Mercury.config.in:
	Add extra configuration options to deal with differences
	between linking with gcc and MSVC:
		--linker-opt-separator
		--linker-link-lib-flag
		--linker-link-lib-suffix
		--shlib-linker-link-lib-flag
		--shlib-linker-link-lib-suffix
		--linker-path-flag

NEWS:
doc/user_guide.texi:
compiler/options.m:
compiler/compile_target_code.m:
compiler/make.program_target.m:
	Instead of substituting in an arbitrary shell script when
	processing `--pre-link-command' and `--extra-init-command',
	require that these options specify a command which will
	be passed the name of the source file containing the main
	module as the first argument, with the source files containing
	the remaining modules following. This is simpler and avoids
	dependencies on a shell.

	Fix quote_arg to handle Windows paths better.

compiler/handle_options.m:
	Don't attempt to use symlinks if they're not available.

compiler/compile_target_code.m:
	Be more careful about quoting.

	Don't call invoke_shell_command where invoke_system_command
	would do.

	Allow linking using MSVC.

compiler/modules.m:
	Remove make_directory, which is now implemented by dir.m.

	Use io.make_symlink rather than shell scripts.

	Implement mercury_update_interface in Mercury.

compiler/llds_out.m:
compiler/make.program_target.m:
	Use dir.make_directory, not modules.make_directory,
	which has been removed.

compiler/make.module_target.m:
	Invoke mercury_compiler directly, not through the
	mmc script to avoid shell dependencies.

	If we can't fork() child `mmc --make' processes,
	pass the arguments to the child process using a
	file to avoid overflowing system limits on Windows.

compiler/mercury_compile.m:
compiler/options_file.m:
	Read argument files.

	Handle backslash-newline in options files correctly.

compiler/passes_aux.m:
	invoke_system_command shouldn't set the exit status --
	the caller may be able to try something else.

compiler/process_util.m:
	Export can_fork for use by make.module_target.m.
	
	Remove hacks to work around bugs in the implementation
	of zero-arity foreign procs.

compiler/prog_io.m:
	Handle bizarre file names without aborting.

library/Mmakefile:
library/print_extra_inits:
	Move code to find extra initialization functions into
	print_extra_inits, due to the change to the handling
	of the --extra-init-command option described above.

scripts/mmc.in:
	Set the MERCURY_COMPILER environment variable if it is
	not already set, so that the mercury_compile executable
	knows where to find itself.

scripts/mercury.bat.in:
	Make this actually work.

tools/bootcheck:
	Set ANALYSIS_LIB_NAME.

	Apply cygpath (-m not -w) to $root.

	Link print_extra_inits into the stage2 and stage3
	library directories.

util/mkinit.c:
	Handle '\\' in path names.

diff -u NEWS NEWS
--- NEWS
+++ NEWS
@@ -223,10 +223,5 @@
   option.  This is done by default when debugging, as without this option the
   execution of builtins is not traced.
 
-* By default `mmc --make' implies `--use-subdirs'.
-  There is new option, `--no-make-implies-use-subdirs', to disable
-  that behaviour.  Library installation does not work with
-  `--no-make-implies-use-subdirs'.
-
 * The Mercury compiler now uses `.' and not `:' as the module separator
   in all output.
diff -u compiler/handle_options.m compiler/handle_options.m
--- compiler/handle_options.m
+++ compiler/handle_options.m
@@ -513,14 +513,8 @@
 	% This is needed for library installation (the library grades
 	% are built using `--use-grade-subdirs', and assume that
 	% the interface files were built using `--use-subdirs').
-	globals__io_lookup_bool_option(make_implies_use_subdirs,
-		MakeImpliesUseSubdirs),
-	( { MakeImpliesUseSubdirs = yes } ->
-		option_implies(make, use_subdirs, bool(yes)),
-		option_implies(invoked_by_mmc_make, use_subdirs, bool(yes))
-	;
-		[]
-	),
+	option_implies(make, use_subdirs, bool(yes)),
+	option_implies(invoked_by_mmc_make, use_subdirs, bool(yes)),
 	option_implies(invoked_by_mmc_make, make, bool(no)),
 
 	% --make handles creation of the module dependencies itself,
diff -u compiler/make.program_target.m compiler/make.program_target.m
--- compiler/make.program_target.m
+++ compiler/make.program_target.m
@@ -520,22 +520,13 @@
 		)
 	;
 		{ TargetType = install_library },
-		globals__io_lookup_bool_option(make_implies_use_subdirs,
-			MakeImpliesUseSubdirs),
-		( { MakeImpliesUseSubdirs = no } ->
-			io__write_string("Error: library installation does not work with `--no-make-implies-use-subdirs'.\n"),
-			{ Info = Info3 },
-			{ Succeeded = no }
+		make_misc_target(MainModuleName - build_library,
+			LibSucceeded, Info3, Info4),
+		( { LibSucceeded = yes } ->
+			install_library(MainModuleName, Succeeded, Info4, Info)
 		;
-			make_misc_target(MainModuleName - build_library,
-				LibSucceeded, Info3, Info4),
-			( { LibSucceeded = yes } ->
-				install_library(MainModuleName, Succeeded,
-					Info4, Info)
-			;
-			    { Info = Info4 },
-			    { Succeeded = no }
-			)
+		    { Info = Info4 },
+		    { Succeeded = no }
 		)
 	).
 
reverted:
--- compiler/make.util.m	31 Jul 2003 15:02:50 -0000
+++ compiler/make.util.m	15 Mar 2003 03:08:56 -0000	1.15
@@ -330,24 +330,16 @@
 		{ Succeeded = no }
 	;
 		{ OptionsResult = yes(ModuleOptionArgs) }, 
-		globals__io_lookup_bool_option(make_implies_use_subdirs,
-			MakeImpliesUseSubdirs),
 		globals__io_get_globals(Globals),
 
+		% --invoked-by-mmc-make disables reading DEFAULT_MCFLAGS
+		% from the environment (DEFAULT_MCFLAGS is included in
+		% OptionArgs) and generation of `.d' files.
-		% --invoked-by-mmc-make disables reading the options file.
-		% (DEFAULT_MCFLAGS is included in OptionArgs) and generation
-		% of `.d' files.
 		% --use-subdirs is needed because the code to install
 		% libraries uses `--use-grade-subdirs' and assumes the
 		% interface files were built with `--use-subdirs'.
 		{ InvokedByMmcMake = yes ->
+			UseSubdirs = ["--use-subdirs"],
-			(
-				MakeImpliesUseSubdirs = yes,
-				UseSubdirs = ["--use-subdirs"]
-			;
-				MakeImpliesUseSubdirs = no,
-				UseSubdirs = []
-			),
 			InvokedByMake = ["--invoked-by-mmc-make"]
 		;
 			UseSubdirs = [],
diff -u compiler/options.m compiler/options.m
--- compiler/options.m
+++ compiler/options.m
@@ -633,7 +633,6 @@
 
 	% Build system options
 		;	make
-		;	make_implies_use_subdirs
 		;	keep_going
 		;	rebuild
 		;	invoked_by_mmc_make
@@ -1250,7 +1249,6 @@
 option_defaults_2(build_system_option, [
 		% Build System Options
 	make			-	bool(no),
-	make_implies_use_subdirs -	bool(yes),
 	keep_going		-	bool(no),
 	rebuild			-	bool(no),
 	invoked_by_mmc_make	-	bool(no),
@@ -1913,7 +1911,6 @@
 
 % build system options
 long_option("make",			make).
-long_option("make-implies-use-subdirs",	make_implies_use_subdirs).
 long_option("keep-going",		keep_going).
 long_option("rebuild",			rebuild).
 long_option("invoked-by-mmc-make",	invoked_by_mmc_make).
@@ -2379,25 +2376,42 @@
 	append_to_accumulating_option(Option - quote_arg(Flag), Table)).
 
 quote_arg(Arg0) = Arg :-
-	ArgList = quote_arg_2(string__to_char_list(Arg0)),
-	(
-		ArgList = []
-	->
-		Arg = """"""
+	( dir__use_windows_paths ->
+		ArgList = quote_arg_windows(string__to_char_list(Arg0)),
+		(
+			ArgList = []
+		->
+			Arg = """"""
+		;
+			Arg = string__from_char_list(ArgList)
+		)
 	;
-		Arg = string__from_char_list(ArgList)
+		ArgList = quote_arg_unix(string__to_char_list(Arg0)),
+		(
+			list__member(Char, ArgList),
+			\+ ( char__is_alnum_or_underscore(Char)
+			; Char = ('-')
+			; Char = ('/')
+			; Char = ('.')
+			; Char = (',')
+			; Char = (':')
+			)
+		->
+			Arg = """" ++ string__from_char_list(ArgList) ++ """"
+		;
+			Arg = string__from_char_list(ArgList)
+		)
 	).
 
-:- func quote_arg_2(list(char)) = list(char).
+:- func quote_arg_windows(list(char)) = list(char).
 
-quote_arg_2([]) = [].
-quote_arg_2([Char | Chars0]) = Chars :-
-	Chars1 = quote_arg_2(Chars0),
-	( quote_char(Char) ->
+quote_arg_windows([]) = [].
+quote_arg_windows([Char | Chars0]) = Chars :-
+	Chars1 = quote_arg_windows(Chars0),
+	( quote_char_windows(Char) ->
 		% We want whitespace characters within an argument to not be
 		% treated as whitespace when splitting the command line
-		% into words. \newline is still treated as whitespace,
-		% and not all shells will understand "\n".
+		% into words.
 		% Newlines and tabs within a word don't really make
 		% sense, so just convert them to spaces.
 		QuoteChar = ( char__is_whitespace(Char) -> ' ' ; Char ),
@@ -2406,15 +2420,31 @@
 		Chars = [Char | Chars1]
 	).
 
-:- pred quote_char(char::in) is semidet.
+:- pred quote_char_windows(char::in) is semidet.
 
-quote_char(' ').
-quote_char('\n').
-quote_char('\t').
-quote_char('\\') :- \+ dir__use_windows_paths.
-quote_char('"').
-quote_char('`').
-quote_char('$').
+quote_char_windows(' ').
+quote_char_windows('\n').
+quote_char_windows('\t').
+quote_char_windows('"').
+quote_char_windows('%').
+
+:- func quote_arg_unix(list(char)) = list(char).
+
+quote_arg_unix([]) = [].
+quote_arg_unix([Char | Chars0]) = Chars :-
+	Chars1 = quote_arg_unix(Chars0),
+	( quote_char_unix(Char) ->
+		Chars = [('\\'), Char | Chars1]
+	;
+		Chars = [Char | Chars1]
+	).
+
+:- pred quote_char_unix(char::in) is semidet.
+
+quote_char_unix('\\').
+quote_char_unix('"').
+quote_char_unix('`').
+quote_char_unix('$').
 
 %-----------------------------------------------------------------------------%
 
@@ -3909,13 +3939,20 @@
 		% --link-executable-command, --link-shared-lib-command,
 		% --mkinit-command, --demangle-command, --trace-libs,
 		% --thread-libs, --shared-libs, --math-lib, --readline-libs,
-		% linker-thread-flags, --shlib-linker-thread-flags,
+		% --linker-opt-separator,
+		% --linker-debug-flags, --shlib-linker-debug-flags,
+		% --linker-trace-flags, --shlib-linker-trace-flags,
+		% --linker-thread-flags, --shlib-linker-thread-flags,
 		% --linker-static-flags, --linker-strip-flag,
+		% --linker-link-lib-flag, --linker-link-lib-suffix,
+		% --shlib-linker-link-lib-flag, --shlib-linker-link-lib-suffix,
+		% --linker-path-flag, --linker-link-with-lib-flag,
 		% --linker-rpath-flag, --linker-rpath-separator,
+		% --shlib-linker-link-with-lib-flag,
 		% --shlib-linker-rpath-flag, --shlib-linker-rpath-separator,
 		% --linker-allow-undefined-flag and
 		% --linker-error-undefined-flag,
-		% options are reserved for use by the `mmc' script;
+		% options are reserved for use by the `Mercury.config' file;
 		% they are deliberately not documented.
 	]).
 
@@ -4003,13 +4040,7 @@
 		"\tExecutables and libraries will be symlinked or copied into",
 		"\tthe current directory.",
 		"\t`--use-grade-subdirs' does not work with Mmake (it does",
-		"\twork with `mmc --make').",
-
-		"--no-make-implies-use-subdirs",
-		"\tNormally, `--make' implies `--use-subdirs'.",
-		"\tThis option disables that behaviour.",
-		"\tLibrary installation does not work with",
-		"\t--no-make-implies-use-subdirs."
+		"\twork with `mmc --make')."
 	]).
 
 :- pred options_help_misc(io__state::di, io__state::uo) is det.
diff -u doc/user_guide.texi doc/user_guide.texi
--- doc/user_guide.texi
+++ doc/user_guide.texi
@@ -6458,20 +6458,6 @@
 current directory.
 @samp{--use-grade-subdirs} does not work with Mmake (it does
 work with @samp{mmc --make}).
-
- at sp 1
- at item --no-make-implies-use-subdirs
- at findex --no-make-implies-use-subdirs
- at findex --make-implies-use-subdirs
- at cindex File names
- at cindex Directories
- at cindex Subdirectories
- at cindex @file{Mercury} subdirectory
- at cindex Grades
-Normally, @samp{--make} implies @samp{--use-subdirs}.
-This option disables that behaviour.
-Library installation does not work with
- at samp{--no-make-implies-use-subdirs}.
 @end table
 
 @node Miscellaneous options
diff -u library/Mmakefile library/Mmakefile
--- library/Mmakefile
+++ library/Mmakefile
@@ -322,11 +322,11 @@
 
 ifeq ($(MMAKE_USE_MMC_MAKE),no)
 
-EXTRA_INIT_COMMAND = print_extra_inits $($(STD_LIB_NAME).ms)
+EXTRA_INIT_COMMAND = ./print_extra_inits $($(STD_LIB_NAME).ms)
 
 else
 
-MCFLAGS += --extra-init-command print_extra_inits
+MCFLAGS += --extra-init-command ./print_extra_inits
 
 endif	# 
 
diff -u library/print_extra_inits library/print_extra_inits
--- library/print_extra_inits
+++ library/print_extra_inits
@@ -17,7 +17,7 @@
 	if [ -f $file ]; then
 		grep '^INIT ' $file
 	else
-		echo "source file $file not found" 1>&2
+		echo "$0: source file $file not found" 1>&2
 		exit 1
 	fi
 done
diff -u scripts/mercury.bat.in scripts/mercury.bat.in
--- scripts/mercury.bat.in
+++ scripts/mercury.bat.in
@@ -91,4 +91,12 @@
 shift
 shift
 
-%MERCURY_COMPILER% %v1% %v2% %v3% %v4% %v5% %v6% %v7% %v8% %v9% %v10% %v11% %v12% %v13% %v14% %v15% %v16% %v17% %v18% %v19% %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
+if "%9"=="" goto :exec
+
+echo mercury.bat: too many arguments (maximum 28)
+goto :end
+
+:exec
+%MERCURY_COMPILER% %v1% %v2% %v3% %v4% %v5% %v6% %v7% %v8% %v9% %v10% %v11% %v12% %v13% %v14% %v15% %v16% %v17% %v18% %v19% %0 %1 %2 %3 %4 %5 %6 %7 %8
+
+:end
diff -u util/mkinit.c util/mkinit.c
--- util/mkinit.c
+++ util/mkinit.c
@@ -876,6 +876,10 @@
 	if ((position = strrchr(filename, '/')) != NULL) {
 		filename = position + 1;
 	}
+	/*
+	** There's not meant to be an `else' here -- we need to handle
+	** file names that contain both `/' and '\\'.
+	*/
 	if ((position = strrchr(filename, '\\')) != NULL) {
 		filename = position + 1;
 	}
--------------------------------------------------------------------------
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