]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | # Copyright Vladimir Prus 2004. |
92f5a8d4 TL |
2 | # Copyright Peter Dimov 2018 |
3 | # | |
7c673cae FG |
4 | # Distributed under the Boost Software License, Version 1.0. |
5 | # (See accompanying file LICENSE_1_0.txt | |
6 | # or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | ||
7c673cae FG |
8 | import common ; |
9 | import errors ; | |
10 | import feature ; | |
11 | import clang ; | |
12 | import msvc ; | |
13 | import os ; | |
14 | import toolset ; | |
15 | import generators ; | |
7c673cae | 16 | import path ; |
92f5a8d4 | 17 | import regex ; |
7c673cae FG |
18 | |
19 | feature.extend-subfeature toolset clang : platform : win ; | |
20 | ||
92f5a8d4 TL |
21 | toolset.inherit-generators clang-win <toolset>clang <toolset-clang:platform>win : msvc : msvc.compile.c.pch msvc.compile.c++.pch ; |
22 | toolset.inherit-flags clang-win : msvc ; | |
7c673cae FG |
23 | toolset.inherit-rules clang-win : msvc ; |
24 | ||
25 | # Override default do-nothing generators. | |
7c673cae FG |
26 | generators.override clang-win.compile.rc : rc.compile.resource ; |
27 | generators.override clang-win.compile.mc : mc.compile ; | |
28 | ||
92f5a8d4 | 29 | if [ MATCH (--debug-(clang-(win-)?)?configuration) : [ modules.peek : ARGV ] ] |
7c673cae | 30 | { |
92f5a8d4 | 31 | local rule .notice ( messages * ) |
7c673cae | 32 | { |
92f5a8d4 | 33 | ECHO "notice: [clang-win]" $(messages) ; |
7c673cae | 34 | } |
92f5a8d4 TL |
35 | } |
36 | else | |
37 | { | |
38 | local rule .notice ( messages * ) | |
7c673cae | 39 | { |
7c673cae | 40 | } |
92f5a8d4 TL |
41 | } |
42 | ||
43 | # [ get-option archiver : 32 : $(options) ] | |
44 | # | |
45 | # returns <archiver-32>, or <archiver> | |
46 | ||
47 | local rule get-option ( option : addr : options * ) | |
48 | { | |
49 | local r = [ feature.get-values "<$(option)-$(addr)>" : $(options) ] ; | |
50 | r ?= [ feature.get-values "<$(option)>" : $(options) ] ; | |
51 | return $(r) ; | |
52 | } | |
53 | ||
54 | # init | |
55 | # | |
56 | # options: | |
57 | # | |
58 | # <assembler>ml.exe (or <assembler-32>, or <assembler-64>) | |
59 | # <archiver>lib.exe | |
60 | # <manifest-tool>mt.exe | |
61 | # <resource-compiler>rc.exe | |
62 | # <mc-compiler>mc.exe | |
63 | # <idl-compiler>midl.exe | |
64 | ||
65 | rule init ( version ? : command * : options * ) | |
66 | { | |
67 | command = [ common.get-invocation-command-nodefault clang-win : clang-cl.exe : $(command) ] ; | |
68 | ||
69 | if ! $(command) | |
7c673cae | 70 | { |
92f5a8d4 | 71 | errors.error "Cannot configure toolset clang-win: no 'clang-cl.exe' command found or given" ; |
7c673cae | 72 | } |
92f5a8d4 TL |
73 | |
74 | local compiler = "\"$(command)\"" ; | |
75 | compiler = "$(compiler:J= )" ; | |
76 | ||
77 | version ?= [ MATCH "version ([0-9.]+)" : [ SHELL "$(compiler) -v 2>&1" ] ] ; | |
78 | ||
79 | .notice "using compiler '$(compiler)', version '$(version)'" ; | |
80 | ||
81 | local condition = [ common.check-init-parameters clang-win : version $(version) ] ; | |
82 | ||
83 | common.handle-options clang-win : $(condition) : $(command) : $(options) ; | |
7c673cae | 84 | |
92f5a8d4 | 85 | for local addr in 32 64 |
7c673cae | 86 | { |
92f5a8d4 TL |
87 | local config = [ SPLIT_BY_CHARACTERS [ SHELL "$(compiler) -m$(addr) -### foo.obj /link 2>&1" ] : "\n" ] ; |
88 | ||
89 | local match = 1 ; | |
90 | local items ; | |
91 | ||
92 | while $(match) | |
7c673cae | 93 | { |
92f5a8d4 TL |
94 | match = [ MATCH "^ *(\"[^\"]*\")(.*)" : $(config) ] ; |
95 | ||
96 | if $(match) | |
7c673cae | 97 | { |
92f5a8d4 TL |
98 | items += $(match[1]) ; |
99 | config = $(match[2]) ; | |
7c673cae FG |
100 | } |
101 | } | |
7c673cae | 102 | |
92f5a8d4 TL |
103 | local ml = [ regex.replace $(items[1]) "x64\\\\+link\\.exe" "x64\\ml64.exe" ] ; |
104 | ml = [ regex.replace $(ml) "x86\\\\+link\\.exe" "x86\\ml.exe" ] ; | |
7c673cae | 105 | |
92f5a8d4 TL |
106 | if ! [ MATCH "(ml\\.exe)" "(ml64\\.exe)" : $(ml) ] |
107 | { | |
108 | ml = ; | |
109 | } | |
7c673cae | 110 | |
92f5a8d4 TL |
111 | local assembler = [ get-option "assembler" : $(addr) : $(options) ] ; |
112 | assembler ?= $(ml) ; | |
113 | if $(addr) = 32 { assembler ?= ml.exe ; } else { assembler ?= ml64.exe ; } | |
7c673cae | 114 | |
92f5a8d4 | 115 | local link = [ regex.replace $(items[1]) "\\\\+HostX64\\\\+x86\\\\+" "\\HostX86\\x86\\" ] ; |
7c673cae | 116 | |
92f5a8d4 TL |
117 | local archiver = [ get-option "archiver" : $(addr) : $(options) ] ; |
118 | archiver ?= "$(link) /lib" ; | |
119 | archiver ?= lib.exe ; | |
7c673cae | 120 | |
92f5a8d4 TL |
121 | .notice "$(addr):" "using assembler '$(assembler)'" ; |
122 | .notice "$(addr):" "using archiver '$(archiver)'" ; | |
7c673cae | 123 | |
92f5a8d4 TL |
124 | local manifest-tool = [ get-option "manifest-tool" : $(addr) : $(options) ] ; |
125 | local resource-compiler = [ get-option "resource-compiler" : $(addr) : $(options) ] ; | |
126 | local mc-compiler = [ get-option "mc-compiler" : $(addr) : $(options) ] ; | |
127 | local idl-compiler = [ get-option "idl-compiler" : $(addr) : $(options) ] ; | |
7c673cae | 128 | |
92f5a8d4 TL |
129 | for local item in $(items) |
130 | { | |
131 | match = [ MATCH "\"-libpath:(.*)\\\\+Lib\\\\.*\\\\um\\\\+x(.*)\"" : $(item) ] ; | |
7c673cae | 132 | |
92f5a8d4 TL |
133 | if $(match) |
134 | { | |
135 | local sdk-path = "$(match[1])\\bin\\x$(match[2])" ; | |
136 | .notice "$(addr):" "using SDK path '$(sdk-path)'" ; | |
7c673cae | 137 | |
92f5a8d4 TL |
138 | manifest-tool ?= "\"$(sdk-path)\\mt.exe\"" ; |
139 | resource-compiler ?= "\"$(sdk-path)\\rc.exe\"" ; | |
140 | mc-compiler ?= "\"$(sdk-path)\\mc.exe\"" ; | |
141 | idl-compiler ?= "\"$(sdk-path)\\midl.exe\"" ; | |
142 | } | |
143 | } | |
7c673cae | 144 | |
92f5a8d4 TL |
145 | manifest-tool ?= mt.exe ; |
146 | resource-compiler ?= rc.exe ; | |
147 | mc-compiler ?= mc.exe ; | |
148 | idl-compiler ?= midl.exe ; | |
149 | ||
150 | .notice "$(addr):" "using manifest-tool '$(manifest-tool)'" ; | |
151 | .notice "$(addr):" "using resource-compiler '$(resource-compiler)'" ; | |
152 | .notice "$(addr):" "using mc-compiler '$(mc-compiler)'" ; | |
153 | .notice "$(addr):" "using idl-compiler '$(idl-compiler)'" ; | |
154 | ||
155 | local cond = "$(condition)/<architecture>/<address-model>$(addr)" "$(condition)/<architecture>x86/<address-model>$(addr)" ; | |
156 | if $(addr) = 32 { cond += "$(condition)/<architecture>/<address-model>" ; } | |
157 | ||
158 | toolset.flags clang-win.compile .CC $(cond) : $(compiler) -m$(addr) ; | |
159 | toolset.flags clang-win.link .LD $(cond) : $(compiler) -m$(addr) /link "/incremental:no" "/manifest" ; | |
160 | toolset.flags clang-win.compile .ASM $(cond) : $(assembler) -nologo ; | |
161 | toolset.flags clang-win.archive .LD $(cond) : $(archiver) /nologo ; | |
162 | toolset.flags clang-win.link .MT $(cond) : $(manifest-tool) -nologo ; | |
163 | toolset.flags clang-win.compile .MC $(cond) : $(mc-compiler) ; | |
164 | toolset.flags clang-win.compile .RC $(cond) : $(resource-compiler) /nologo ; | |
165 | toolset.flags clang-win.compile .IDL $(cond) : $(idl-compiler) ; | |
166 | } | |
167 | } |