9393
9494-- load compiler tool
9595function compiler ._load_tool (sourcekind , target )
96-
97- -- get program from target
9896 local program , toolname , toolchain_info
9997 if target and target .tool then
10098 program , toolname , toolchain_info = target :tool (sourcekind )
@@ -136,16 +134,15 @@ function compiler.load(sourcekind, target)
136134 local plat = compiler_tool :plat () or config .plat () or os .host ()
137135 local arch = compiler_tool :arch () or config .arch () or os .arch ()
138136 local cachekey = sourcekind .. (program_or_errors or " " ) .. plat .. arch
137+ if target then
138+ cachekey = cachekey .. tostring (target )
139+ end
139140
140141 -- get it directly from cache dirst
141142 compiler ._INSTANCES = compiler ._INSTANCES or {}
142143 local instance = compiler ._INSTANCES [cachekey ]
143144 if not instance then
144-
145- -- new instance
146145 instance = table .inherit (compiler , builder )
147-
148- -- save the compiler tool
149146 instance ._TOOL = compiler_tool
150147
151148 -- load the compiler language from the source kind
200197
201198-- build the source files (compile and link)
202199function compiler :build (sourcefiles , targetfile , opt )
203-
204- -- init options
205200 opt = opt or {}
206201
207202 -- get compile flags
@@ -225,15 +220,11 @@ function compiler:build(sourcefiles, targetfile, opt)
225220 if not targetkind and opt .target and opt .target .targetkind then
226221 targetkind = opt .target :kind ()
227222 end
228-
229- -- get it
230223 return sandbox .load (self :_tool ().build , self :_tool (), sourcefiles , targetkind or " binary" , targetfile , flags )
231224end
232225
233226-- get the build arguments list (compile and link)
234227function compiler :buildargv (sourcefiles , targetfile , opt )
235-
236- -- init options
237228 opt = opt or {}
238229
239230 -- get compile flags
@@ -257,8 +248,6 @@ function compiler:buildargv(sourcefiles, targetfile, opt)
257248 if not targetkind and opt .target and opt .target .targetkind then
258249 targetkind = opt .target :kind ()
259250 end
260-
261- -- get it
262251 return self :_tool ():buildargv (sourcefiles , targetkind or " binary" , targetfile , flags )
263252end
264253
@@ -322,14 +311,10 @@ end
322311-- @return flags list
323312--
324313function compiler :compflags (opt )
325-
326- -- init options
327314 opt = opt or {}
328315
329316 -- get target
330- local target = opt .target
331-
332- -- get target kind
317+ local target = opt .target or self :target ()
333318 local targetkind = opt .targetkind
334319 if not targetkind and target and target :type () == " target" then
335320 targetkind = target :kind ()
0 commit comments