From 7d7ded94c428dd97eaf2ee80964ca78b7726904b Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Wed, 23 Jun 2004 09:07:02 +0000 Subject: [PATCH] New msvc.init. [SVN r23166] --- src/tools/common.jam | 5 +- src/tools/msvc.jam | 223 +++++++++++++------------------------------ 2 files changed, 68 insertions(+), 160 deletions(-) diff --git a/src/tools/common.jam b/src/tools/common.jam index 440360c1c..6e2ca5f6e 100644 --- a/src/tools/common.jam +++ b/src/tools/common.jam @@ -94,9 +94,12 @@ rule check-init-parameters ( toolset : * ) message += "$(p[1]) = $(p[2]:E=)" ; } } - errors.user-error $(message[1]) : $(message[2]) : $(message[3]) : $(message[4]) ; + message += "previous initialization at $(.init-loc.$(sig))" ; + errors.user-error $(message[1]) : $(message[2]) : $(message[3]) : $(message[4]) + : $(message[5]) : $(message[6]) : $(message[7]) : $(message[8]) ; } .all-signatures += $(sig) ; + .init-loc.$(sig) = [ errors.nearest-user-location ] ; return $(condition) ; } diff --git a/src/tools/msvc.jam b/src/tools/msvc.jam index 944ced32c..3c4610a09 100644 --- a/src/tools/msvc.jam +++ b/src/tools/msvc.jam @@ -29,14 +29,6 @@ feature.subfeature toolset msvc : vendor # to be seen, though ;-) ; - feature.subfeature toolset msvc : version - : # 6 7 7.1 # known subvalues - : propagated implicit - - # versions of msvc are link-compatible - # link-incompatible - ; - # Remember whether any versions have been initialized, allowing us to # set the first initialized version as the default. .initialized = ; @@ -65,51 +57,36 @@ feature.subfeature toolset msvc : vendor rule init ( version ? # the msvc version which is being configured. When omitted # the tools invoked when no explicit version is given will be configured. - : path ? - # the path to root directory of msvc installation. If not specified: + : command ? + # the command to invoke the compiler. If not specified: # - if version is given, default location for that version will be searched # # - if version is not given, default locations for 7.1, 7.0 and 6.* will # be searched # # - if compiler is not found in default locations, PATH will be searched. - : vendor ? : setup ? compiler ? linker ? resource-compiler ? ) + : setup ? compiler ? linker ? resource-compiler ? ) { + # setup will be used iff a path has been specified. If setup is + # not specified, vcvars32.bat will be used instead. + setup ?= vcvars32.bat ; compiler ?= cl ; linker ?= link ; resource-compiler ?= rc ; - - if $(version) - { - feature.extend msvc version : $(version) ; + + local condition = [ common.check-init-parameters msvc : + version $(version) ] ; + + command = [ common.get-invocation-command msvc : cl.exe : $(command) + : [ default-paths $(version) ] ] ; - if ! $(.initialized) # The first version initialized becomes the default. - { - feature.set-default toolset-msvc:version : $(version) ; - } - } - - if $(vendor) && ( $(vendor) != intel ) - { - feature.extend msvc vendor : $(vendor) ; - } - - # setup will be used iff a path has been specified. If setup is - # not specified, vcvars32.bat will be used instead. - setup ?= vcvars32.bat ; - - if ! $(path) - { - setup = [ locate $(setup) : $(version) : $(vendor) ] ; - } - else - { - # Don't bother with any searches. User has provided a path, - # and we assume it's correct. - # TODO: actually, it's better to check the path even in this - # case. - setup = $(path)\\bin\\$(setup) ; + if $(command) + { + command = [ common.get-absolute-tool-path $(command) ] ; } + local root = $(command:D) ; + + setup = $(root)\\bin\\$(setup) ; # CONSIDER: What's the point of 'call'. Can we invoke the script directly? setup = "call \""$(setup)"\" > nul " ; @@ -126,34 +103,11 @@ rule init ( # prefix with setup, or quoted path if any local prefix = $(setup) ; - - local condition ; - if $(version) - { - vendor = $(vendor)- ; - vendor ?= "" ; - - condition = -$(vendor)$(version) ; - condition ?= "" ; - condition = msvc$(condition) ; - - flags msvc.compile .CC $(condition) : $(prefix)$(compiler) ; - flags msvc.compile .RC $(condition) : $(prefix)$(resource-compiler) ; - flags msvc.link .LD $(condition) : $(prefix)$(linker) ; - flags msvc.archive .LD $(condition) : $(prefix)$(linker) ; - } - else - { - # When version is not specified, we cannot form any useful - # condition. Since subfeatures don't have defaults, we can't - # use 'unspecified' as version. Therefore, just set global - # variables in this module. - .CC = $(prefix)$(compiler) ; - .RC = $(prefix)$(resource-compiler) ; - .LD = $(prefix)$(linker) ; - } - .initialized = true ; # remember that we've initialized at least one version of msvc + flags msvc.compile .CC $(condition) : $(prefix)$(compiler) ; + flags msvc.compile .RC $(condition) : $(prefix)$(resource-compiler) ; + flags msvc.link .LD $(condition) : $(prefix)$(linker) ; + flags msvc.archive .LD $(condition) : $(prefix)$(linker) ; # The following options work only for 7* versions. It means # that if the user has not specified a version he gets 6.0 compatible @@ -165,107 +119,58 @@ rule init ( } -.CC = cl ; -.LD = LINK ; -.RC = rc ; - - -# Attempts to find the vcvars32.bat script for the relevant version, and returns the path -# to it. If path is not found, issues an error. -# If there are several possibilities, returns arbitrary one, after issuing a -# warning message. -local rule locate ( setup : version ? : vendor ? ) +rule default-paths ( version ? ) { local possible-paths ; - - # Append the list of relevant default locations. - # We know default locations only for msvc, not for alternative vendors - if ! $(vendor) - { - local ProgramFiles = [ modules.peek : ProgramFiles ] ; - if $(ProgramFiles) - { - ProgramFiles = "$(ProgramFiles:J= )" ; - } - else - { - ProgramFiles = "c:\\Program Files" ; - } - - local version-6-path = $(ProgramFiles)"\\Microsoft Visual Studio\\VC98" ; - local version-7-path = $(ProgramFiles)"\\Microsoft Visual Studio .NET\\VC7" ; - local version-7.0-path = $(version-7-path) ; - local version-7.1-path = $(ProgramFiles)"\\Microsoft Visual Studio .NET 2003\\VC7" ; - - local VS71COMNTOOLS = [ modules.peek : VS71COMNTOOLS ] ; - if $(VS71COMNTOOLS) - { - # VS71COMNTOOLS is set by VS .NET 2003 to \Common7\Tools - version-7.1-path = [ path.make "$(VS71COMNTOOLS:J= )" ] ; - version-7.1-path = [ path.parent $(version-7.1-path) ] ; - version-7.1-path = [ path.parent $(version-7.1-path) ] ; - version-7.1-path = [ path.join $(version-7.1-path) "VC7" ] ; - version-7.1-path = [ path.native $(version-7.1-path) ] ; - } - - local VCToolkitInstallDir = [ modules.peek : VCToolkitInstallDir ] ; - if $(VCToolkitInstallDir) - { - version-7.1-path = [ path.make "$(VCToolkitInstallDir:J= )" ] ; - } - - if $(version) - { - local v = [ MATCH ^(6|[^6].*) : $(version) ] ; - possible-paths += $(version-$(v)-path) ; - } - else - { - possible-paths += $(version-7.1-path) $(version-7.0-path) $(version-6-path) ; - } - # The vccars32.bat is actually in "bin" directory. - # (except for free VC7.1 tools) - possible-paths = $(possible-paths)\\bin $(possible-paths) ; - } - - # Append PATH - possible-paths += [ modules.peek : PATH Path path ] ; - # Search now - local setup = [ GLOB $(possible-paths) : $(setup) ] ; - # Try to avoid reporting ambiguity when there's several occurences - # of the same path, probably differing by case. - setup = [ unique $(setup:L) ] ; - - if $(setup[2]) && ! ( --quiet in [ modules.peek : ARGV ] ) + local ProgramFiles = [ modules.peek : ProgramFiles ] ; + if $(ProgramFiles) { - ECHO warning: toolset msvc $(vendor) $(version) initialization: ; - ECHO "warning: several msvc installations found." ; - ECHO "$(setup:D)" ; - ECHO "warning: using the one in $(setup[1]:D)." ; - setup = $(setup[1]) ; + ProgramFiles = "$(ProgramFiles:J= )" ; + } + else + { + ProgramFiles = "c:\\Program Files" ; } - if ! $(setup) - { - ECHO warning: toolset msvc $(vendor) $(version) initialization: ; - ECHO warning: couldn't find compiler ; - if $(.debug-configuration) - { - ECHO warning: looked in $(possible-paths) ; - } - - } + local version-6-path = $(ProgramFiles)"\\Microsoft Visual Studio\\VC98" ; + local version-7-path = $(ProgramFiles)"\\Microsoft Visual Studio .NET\\VC7" ; + local version-7.0-path = $(version-7-path) ; + local version-7.1-path = $(ProgramFiles)"\\Microsoft Visual Studio .NET 2003\\VC7" ; - if $(.debug-configuration) && $(setup) + local VS71COMNTOOLS = [ modules.peek : VS71COMNTOOLS ] ; + if $(VS71COMNTOOLS) { - ECHO "notice: msvc $(version:E=) $(vendor:E="")" ; - ECHO "notice: found at \"$(setup:D)\"" ; - } - return $(setup) ; + # VS71COMNTOOLS is set by VS .NET 2003 to \Common7\Tools + version-7.1-path = [ path.make "$(VS71COMNTOOLS:J= )" ] ; + version-7.1-path = [ path.parent $(version-7.1-path) ] ; + version-7.1-path = [ path.parent $(version-7.1-path) ] ; + version-7.1-path = [ path.join $(version-7.1-path) "VC7" ] ; + version-7.1-path = [ path.native $(version-7.1-path) ] ; + } + + local VCToolkitInstallDir = [ modules.peek : VCToolkitInstallDir ] ; + if $(VCToolkitInstallDir) + { + version-7.1-path = [ path.make "$(VCToolkitInstallDir:J= )" ] ; + } + + if $(version) + { + local v = [ MATCH ^(6|[^6].*) : $(version) ] ; + possible-paths += $(version-$(v)-path) ; + } + else + { + possible-paths += $(version-7.1-path) $(version-7.0-path) $(version-6-path) ; + } + # The vccars32.bat is actually in "bin" directory. + # (except for free VC7.1 tools) + possible-paths = $(possible-paths)\\bin $(possible-paths) ; + + return $(possible-paths) ; } - # Register scanner for resources type.register RC : rc ;