Built win.arm64 against r3658
[kbuild-mirror.git] / kBuild / footer-pass2-compiling-targets.kmk
blob06af5160e1518e3c9c3cd470512acbc623c76c1e
1 # $Id$
2 ## @file
3 # kBuild - Footer - Target lists - Pass 2 - Compiling Targets.
7 # Copyright (c) 2004-2019 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
9 # This file is part of kBuild.
11 # kBuild is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version source of the License, or
14 # (at your option) any later version.
16 # kBuild is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with kBuild; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 # As a special exception you are granted permission to include this file, via
27 # the kmk include directive, as you wish without this in itself causing the
28 # resulting makefile, program or whatever to be covered by the GPL license.
29 # This exception does not however invalidate any other reasons why the makefile,
30 # program, whatever should not be covered the GPL.
36 # Object processing.
39 ifndef NO_COMPILE_CMDS_DEPS
40 ## Generates the rules for building a specific object and the aliases.
41 # for building a source file.
42 # @param $(obj) The object file.
43 define def_target_source_rule_v3plus
44 $$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
45 $$(obj) + $$(kbsrc_output) +| $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
46 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
47 ifndef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
48 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $(kbsrc_output) $(kbsrc_output_maybe)
49 endif
51 $(kbsrc_cmds)
53 %$$(QUIET2)$$(APPEND) -in '$(dep)' '' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_' '--insert-command=$(obj)' 'endef'
54 $$(basename $$(notdir $$(obj))).o: $$(obj)
55 endef # def_target_source_rule_v3plus
57 ## Generates the rules for building a specific object and the aliases, kObjCache variant.
58 # for building a source file.
59 # @param $(obj) The object file.
60 define def_target_source_rule_v3plus_objcache
61 $$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
62 _OUT_FILES += $(outbase).koc
63 $$(outbase).koc +| $$(obj) $$(kbsrc_output) $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
64 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
66 $(kbsrc_cmds)
68 %$$(QUIET2)$$(APPEND) -in '$(dep)' '' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_' '--insert-command=$(obj)' 'endef'
69 $$(basename $$(notdir $$(obj))).o: $$(obj)
70 endef # def_target_source_rule_v3plus_objcache
72 else # NO_COMPILE_CMDS_DEPS
74 ## Generates the rules for building a specific object and the aliases.
75 # for building a source file.
76 # @param $(obj) The object file.
77 define def_target_source_rule_v3plus
78 $$(obj) + $$(kbsrc_output) +| $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
79 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
80 ifndef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
81 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $(kbsrc_output) $(kbsrc_output_maybe)
82 endif
84 $(kbsrc_cmds)
86 $$(basename $$(notdir $$(obj))).o: $$(obj)
87 endef # def_target_source_rule_v3plus
89 ## Generates the rules for building a specific object and the aliases, kObjCache variant.
90 # for building a source file.
91 # @param $(obj) The object file.
92 define def_target_source_rule_v3plus_objcache
93 _OUT_FILES += $(outbase).koc
94 $$(outbase).koc +| $$(obj) $$(kbsrc_output) $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
95 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
97 $(kbsrc_cmds)
99 $$(basename $$(notdir $$(obj))).o: $$(obj)
100 endef # def_target_source_rule_v3plus_objcache
102 endif # NO_COMPILE_CMDS_DEPS
103 $(eval-opt-var def_target_source_rule_v3plus)
104 $(eval-opt-var def_target_source_rule_v3plus_objcache)
108 ## Legacy legacy legacy - start
111 ## Wrapper
112 ifndef NO_COMPILE_CMDS_DEPS
113 if1of ($(KMK_FEATURES),dot-must-make)
114 _DEP_COMPILE_CMDS =
115 # for debugging: $$(warning MUST_MAKE=$$$$(comp-cmds-ex $$$$($(target)_$(subst :,_,$(source))_CMDS_PREV_), $$$$(commands $$@)) -> $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE))
116 else
117 _DEP_COMPILE_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $(obj)),FORCE)
118 endif
119 else
120 _DEP_COMPILE_CMDS =
121 endif
123 ## Generates the rules for building a specific object, and the aliases - legacy version.
124 # for building a source file.
125 # @param $(obj) The object file.
126 define def_target_source_rule
127 ifndef NO_COMPILE_CMDS_DEPS
128 $(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
129 endif
130 ifneq ($(TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE),)
131 _OUT_FILES += $(outbase).koc
132 $(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
133 $($(target)_$(source)_DEPEND_) $(value _DEP_COMPILE_CMDS) \
134 | $($(target)_$(source)_DEPORD_) $(target_intermediate_vars)
135 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
136 else
137 $(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
138 $($(target)_$(source)_DEPEND_) $(value _DEP_COMPILE_CMDS) \
139 | $($(target)_$(source)_DEPORD_) $(target_intermediate_vars)
140 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
141 ifndef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
142 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
143 endif
144 endif
146 $($(target)_$(source)_CMDS_)
148 ifndef NO_COMPILE_CMDS_DEPS
149 ifdef KBUILD_HAVE_OPTIMIZED_APPEND
150 %$$(QUIET2)$$(APPEND) -in '$(dep)' \
151 '' \
152 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_' \
153 '--insert-command=$(obj)' \
154 'endef'
155 else
156 %$$(QUIET2)$$(APPEND) -n '$(dep)' '' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_'
157 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(obj)'
158 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
159 endif
160 endif
162 $(basename $(notdir $(obj))).o: $(obj)
164 ## @todo make this 'local cmds,output,output_maybe,depend and depord' in 0.2.x or when a new kb-src-one is added.
165 $(target)_$(source)_CMDS_ :=
166 $(target)_$(source)_OUTPUT_ :=
167 $(target)_$(source)_OUTPUT_MAYBE_ :=
168 $(target)_$(source)_DEPEND_ :=
169 $(target)_$(source)_DEPORD_ :=
170 endef # def_target_source_rule
171 $(eval-opt-var def_target_source_rule)
173 ## Legacy legacy legacy - end
177 ## wrapper the link command dependency check.
178 ifndef NO_LINK_CMDS_DEPS
179 if1of ($(KMK_FEATURES),dot-must-make)
180 _DEP_LINK_CMDS =
181 else
182 _DEP_LINK_CMDS = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $(out)),FORCE)
183 endif
184 else
185 _DEP_LINK_CMDS =
186 endif
188 ## Generate the link rule for a target.
189 # @param $(target) The normalized target name.
190 # @param $(dirdep) Directories we depend upon begin created before linking.
191 # @param $(dep) The name of the dependency file.
192 # @param $(out)
193 # @param $($(target)_2_OUTPUT) Output files from the link.
194 # @param $($(target)_2_OUTPUT_MAYBE) Output files that the link may perhaps create.
195 # @param $($(target)_2_OUTPUT_MAYBE_PRECIOUS) Output files that the link may perhaps create but shouldn't be deleted.
196 # @param $($(target)_2_DEPEND) Dependencies.
197 # @param $($(target)_2_DEPORD) Dependencies which should only affect build order.
198 # @param $(cmds) The link commands.
199 # @param $($(target)_CMDS_PREV_) The link commands from the previous run.
200 define def_link_rule
201 $$(call KB_FN_ASSERT_ABSPATH,out)
202 ifndef NO_LINK_CMDS_DEPS
203 $(out): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $$@),FORCE)
204 endif
205 $(out) \
206 + $($(target)_2_OUTPUT) \
207 + $($(target)_2_OUTPUT_DEBUG_FILES) \
208 + $($(target)_2_OUTPUT_DEBUG_DIRS) \
209 +| $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) : \
210 $$$$($(target)_2_DEPEND) \
211 $(value _DEP_LINK_CMDS) \
213 $$$$($(target)_2_DEPORD)
214 %$$(call MSG_LINK,$(target),$$@,$(tool_do))
215 $$(QUIET)$$(RM) -f -- $(dep) $(out) $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_DEBUG_FILES)
216 ifdef $(target)_2_OUTPUT_DEBUG_DIRS
217 $$(QUIET)$$(RM) -Rf -- $($(target)_2_OUTPUT_DEBUG_DIRS)
218 endif
220 $(cmds)
222 ifndef NO_LINK_CMDS_DEPS
223 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
224 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
225 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
226 endif
228 $(basename $(notdir $(out))):: $(out)
230 endef # def_link_rule
231 $(eval-opt-var def_link_rule)
234 ## Generate the link & lib install rule
235 # Implicit parameters: target, out, $(target)_1_STAGE_TARGET, mode,
236 # pre_install_cmds, post_install_cmds
237 define def_link_install_rule
238 $$(call KB_FN_ASSERT_ABSPATH,$(target)_1_INST_TARGET)
239 $($(target)_1_INST_TARGET): $(out) | $$$$(dir $$$$@)
240 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
241 $(pre_install_cmds)
243 $$(QUIET)$$(INSTALL) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
244 $(post_install_cmds)
246 endef
249 ## Generate the link & lib stage installation rule
250 # Implicit parameters: target, out, $(target)_1_STAGE_TARGET, mode,
251 # pre_install_cmds, post_install_cmds
252 define def_link_stage_rule
253 $$(call KB_FN_ASSERT_ABSPATH,$(target)_1_STAGE_TARGET)
254 $($(target)_1_STAGE_TARGET): $(out) | $$$$(dir $$$$@)
255 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
256 $(pre_install_cmds)
258 $$(QUIET)$$(INSTALL_STAGING) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
259 $(post_install_cmds)
262 $(basename $(notdir $(out))):: $($(target)_1_STAGE_TARGET)
264 endef
267 ## def_src_handler_*
269 # @{
270 define def_src_handler_c
271 local type := C
272 $(kb-src-one 4)
273 endef
275 define def_src_handler_cxx
276 local type := CXX
277 $(kb-src-one 4)
278 endef
280 define def_src_handler_objc
281 local type := OBJC
282 $(kb-src-one 4)
283 endef
285 define def_src_handler_objcxx
286 local type := OBJCXX
287 $(kb-src-one 4)
288 endef
290 define def_src_handler_asm
291 local type := AS
292 $(kb-src-one 4)
293 endef
295 define def_src_handler_rc
296 local type := RC
297 $(kb-src-one 4)
298 endef
300 ifdef KMK_WITH_QUOTING
301 define def_src_handler_obj
302 ifeq ($(defpath),)
303 $(target)_2_OBJS += $(source)
304 else
305 $(target)_2_OBJS += $(qabspathex ,$(source), $(defpath))
306 endif
307 endef
308 else
309 define def_src_handler_obj
310 ifeq ($(defpath),)
311 $(target)_2_OBJS += $(source)
312 else
313 $(target)_2_OBJS += $(abspathex $(source), $(defpath))
314 endif
315 endef
316 endif
317 ## @}
319 ## Handle one source.
321 define def_src_handler_one
322 local suff := $(suffix $(source))
323 local src_handler := $(firstword $(filter $(suff):%, $($(target)_$(source)_SRC_HANDLERS) $($(source)_SRC_HANDLERS) $(target_src_handlers) ))
324 local handler := $(patsubst $(suff):%,%,$(src_handler))
325 ifneq ($(handler),)
326 $(evalvalctx $(handler))
327 else
328 othersrc += $(source)
329 endif
330 endef # def_src_handler_one
332 ## Generic macro for processing all target sources.
333 # @param $(target) Normalized target name.
334 # @param $(defpath)
335 # @param much-more...
336 # @returns othersrc, $(target)_2_OBJS, ++
337 ifdef KMK_WITH_QUOTING
338 define def_target_sources
339 local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
340 $(foreachfile source,\
341 $($(target)_SOURCES)\
342 $($(target)_SOURCES.$(bld_trg))\
343 $($(target)_SOURCES.$(bld_trg).$(bld_type))\
344 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
345 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch).$(bld_type))\
346 $($(target)_SOURCES.$(bld_trg_arch))\
347 $($(target)_SOURCES.$(bld_trg_cpu))\
348 $($(target)_SOURCES.$(bld_type))\
349 ,$(evalvalctx def_src_handler_one) )
351 $(foreachfile source,\
352 $($(target)_GEN_SOURCES_)\
353 $($(target)_GEN_SOURCES_.$(bld_trg))\
354 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_type))\
355 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
356 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch).$(bld_type))\
357 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
358 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
359 $($(target)_GEN_SOURCES_.$(bld_type))\
360 ,$(evalvalctx def_src_handler_one) )
361 endef # def_target_sources
362 else
363 define def_target_sources
364 local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
365 $(foreach source,\
366 $($(target)_SOURCES)\
367 $($(target)_SOURCES.$(bld_trg))\
368 $($(target)_SOURCES.$(bld_trg).$(bld_type))\
369 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
370 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch).$(bld_type))\
371 $($(target)_SOURCES.$(bld_trg_arch))\
372 $($(target)_SOURCES.$(bld_trg_cpu))\
373 $($(target)_SOURCES.$(bld_type))\
374 ,$(evalvalctx def_src_handler_one) )
376 $(foreach source,\
377 $($(target)_GEN_SOURCES_)\
378 $($(target)_GEN_SOURCES_.$(bld_trg))\
379 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_type))\
380 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
381 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch).$(bld_type))\
382 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
383 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
384 $($(target)_GEN_SOURCES_.$(bld_type))\
385 ,$(evalvalctx def_src_handler_one) )
386 endef # def_target_sources
387 endif
388 $(eval-opt-var def_target_sources)
392 # Install a debug directory.
393 # @param debug_dir The directory name.
394 define def_link_install_debug_dir_rule
395 local dir := $(debug_inst_path)/$(debug_inst2)$(debug_dir)
396 $$(call KB_FN_ASSERT_ABSPATH,dir)
397 $$(dir): | $$$$(dir $$$$(patsubst %/,%,$$$$@))
398 %$$(call MSG_INST_DIR,$$@)
399 $$(QUIET)$$(MKDIR) -p -- $$@
400 $(target)_2_DEBUG_$(debug_var)_TARGET_DIRS += $$(dir)
401 endef # def_link_install_debug_dir_rule
404 # Install a debug file.
405 # @param debug_file Src=>Dst file pair.
406 define def_link_install_debug_file_rule
407 local dst := $(debug_inst_path)/$(debug_inst2)$(word 2, $(subst =>,$(SP),$(debug_file)))
408 $$(call KB_FN_ASSERT_ABSPATH,dst)
409 local src := $(word 1, $(subst =>,$(SP),$(debug_file)))
410 $$(call KB_FN_ASSERT_ABSPATH,src)
411 $$(dst): $$(src) | $$$$(dir $$$$@)
412 %$$(call MSG_INST_FILE,$$<,$$@)
413 $$(QUIET)$(debug_install_cmd) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $$< $$@
414 $(target)_2_DEBUG_$(debug_var)_TARGET_FILES += $$(dst)
415 endef # def_link_install_debug_file_rule
418 # Install debug info to $(debug_inst), where debug_inst can be a directory or
419 # file (just like $(inst) and $(stage). Used for both staging and installing.
420 define def_target_install_only_debug
421 if "$(substr $(debug_inst),-1,1)" == "/"
422 if "$(debug_inst)" == "./"
423 local debug_inst2 :=
424 else
425 local debug_inst2 := $(debug_inst)
426 endif
427 local debug_dirs := $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_DIRS))
428 ifneq ($(strip $(root $(debug_dirs))),)
429 $(error kBuild: Bad tool? debug_dirs='$(debug_dirs)', expected all to be under '$(outbase)')
430 endif
431 local debug_files := $(foreach file, $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_FILES)) \
432 ,$($(target)_0_OUTDIR)/$(file)=>$(file))
433 else
434 local debug_notdir:= $(notdir $(debug_inst))
435 local debug_inst2 := $(dir $(debug_inst))
436 local debug_files := $(call TOOL_$(tool)_$(tool_do)_DEBUG_INSTALL_FN,$(out),$(outbase),$(debug_notdir))
437 local debug_dirs := $(filter %/,$(debug_files))
438 local debug_files := $(filter-out %/,$(debug_files))
439 endif
440 $(foreach debug_dir, $(debug_dirs), $(eval $(def_link_install_debug_dir_rule)))
441 $(foreach debug_file, $(debug_files), $(eval $(def_link_install_debug_file_rule)))
442 endef
445 ## Generic macro for generating the install rule(s) for a target.
447 # @param $(target) Normalized target name.
448 # @param $(out) The output file.
449 # @param $(typevar) The name of the variable with all the root targets of its type.
450 # @param $(target_type_mode) The default file mode implied by the target type.
451 define def_target_install_only
452 if1of ($($(target)_1_INSTTYPE) $($(target)_1_DEBUG_INSTTYPE), both stage)
453 # Determin common variables.
454 local mode := $(firstword \
455 $($(target)_MODE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
456 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
457 $($(target)_MODE.$(bld_trg).$(bld_type)) \
458 $($(target)_MODE.$(bld_trg_arch)) \
459 $($(target)_MODE.$(bld_trg)) \
460 $($(target)_MODE.$(bld_type)) \
461 $($(target)_MODE) \
462 $(target_type_mode) )
463 local uid := $(firstword \
464 $($(target)_UID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
465 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
466 $($(target)_UID.$(bld_trg).$(bld_type)) \
467 $($(target)_UID.$(bld_trg_arch)) \
468 $($(target)_UID.$(bld_trg)) \
469 $($(target)_UID.$(bld_type)) \
470 $($(target)_UID) )
471 local gid := $(firstword \
472 $($(target)_GID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
473 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
474 $($(target)_GID.$(bld_trg).$(bld_type)) \
475 $($(target)_GID.$(bld_trg_arch)) \
476 $($(target)_GID.$(bld_trg)) \
477 $($(target)_GID.$(bld_type)) \
478 $($(target)_GID) )
479 local pre_install_cmds := $(evalcall def_fn_prop_get_first_defined,PRE_INST_CMDS)
480 local post_install_cmds := $(evalcall def_fn_prop_get_first_defined,POST_INST_CMDS)
481 endif
483 ifneq ($($(target)_1_INSTTYPE),none)
484 # Generate the rules
485 ifeq ($($(target)_1_INSTTYPE),both)
486 $(eval $(def_link_install_rule))
487 _INSTALLS_FILES += $($(target)_1_INST_TARGET)
488 endif
489 $(eval $(def_link_stage_rule))
490 _STAGE_FILES += $($(target)_1_STAGE_TARGET)
491 $(typevar) += $($(target)_1_STAGE_TARGET)
492 else # INSTTYPE == none
493 $(typevar) += $(out)
494 endif # INSTTYPE == none
496 # Install debug info.
497 $(target)_2_DEBUG_STAGE_TARGET_DIRS :=
498 $(target)_2_DEBUG_STAGE_TARGET_FILES :=
499 $(target)_2_DEBUG_INSTALL_TARGET_DIRS :=
500 $(target)_2_DEBUG_INSTALL_TARGET_FILES :=
502 if ( defined($(target)_2_OUTPUT_DEBUG_DIRS) \
503 || defined($(target)_2_OUTPUT_DEBUG_FILES) ) \
504 && "$($(target)_1_DEBUG_INSTTYPE)" != "none"
505 local mode := $(if $(mode),$(mode)$(COMMA)a-x,0644)
507 ifeq ($($(target)_1_DEBUG_INSTTYPE),both)
508 local debug_inst_path := $(PATH_INS)
509 local debug_install_cmd := $(INSTALL)
510 local debug_var := INSTALL
511 $(foreach debug_inst, $($(target)_1_DEBUG_INST), $(evalvalctx def_target_install_only_debug))
512 endif
514 local debug_inst_path := $(PATH_STAGE)
515 local debug_install_cmd := $(INSTALL_STAGING)
516 local debug_var := STAGE
517 if1of ($($(target)_1_DEBUG_INSTTYPE), stage both)
518 $(foreach debug_inst, $($(target)_1_DEBUG_STAGE), $(evalvalctx def_target_install_only_debug))
519 endif
520 if1of ($($(target)_1_INSTTYPE), stage both)
521 ifndef debug_nostage
522 $(foreach debug_inst,$($(target)_1_STAGE), $(evalvalctx def_target_install_only_debug))
523 endif
524 endif
526 _DEBUG_STAGE_DIRS += $($(target)_2_DEBUG_STAGE_TARGET_DIRS)
527 _DEBUG_STAGE_FILES += $($(target)_2_DEBUG_STAGE_TARGET_FILES)
528 _DEBUG_INSTALL_DIRS += $($(target)_2_DEBUG_INSTALL_TARGET_DIRS)
529 _DEBUG_INSTALL_FILES += $($(target)_2_DEBUG_INSTALL_TARGET_FILES)
531 $(basename $(notdir $(out))):: $($(target)_2_DEBUG_STAGE_TARGET_DIRS) $($(target)_2_DEBUG_STAGE_TARGET_FILES)
532 endif
534 endef # def_target_install_only
539 # LIBRARIES
542 ## Library (one).
543 # @param $(target) Normalized library (target) name.
544 define def_lib
545 # library basics
546 ## @todo prefix
547 local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
548 local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
549 local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
550 local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
551 local tool := $(call _TARGET_TOOL,$(target),AR)
552 ifeq ($(tool),)
553 $(error kBuild: Library target $(target) does not have a tool defined!)
554 endif
555 local name := $(firstword\
556 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
557 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
558 $($(target)_NAME.$(bld_trg).$(bld_type))\
559 $($(target)_NAME.$(bld_trg_arch))\
560 $($(target)_NAME.$(bld_trg))\
561 $($(target)_NAME.$(bld_type))\
562 $($(target)_NAME)\
563 $(target))
564 local outbase := $(call TARGET_BASE,$(name),$(target))
565 $(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
566 $(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
567 local suff := $(firstword\
568 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
569 $($(target)_LIBSUFF.$(bld_trg))\
570 $($(target)_LIBSUFF)\
571 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
572 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
573 $(TOOL_$(tool)_ARLIBSUFF)\
574 $(SUFF_LIB))
575 local out := $(outbase)$(suff)
576 local defpath := $($(target)_DEFPATH)
577 ifeq ($(defpath),)
578 local defpath := $($(target)_PATH)
579 endif
580 $(target)_1_TARGET:= $(out)
581 $(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
582 # no local here - must be writable across some foreachs.
583 othersrc :=
584 $(target)_2_OBJS :=
585 $(target)_2_INTERMEDIATES =
587 # kObjCache.
588 ifdef KBUILD_USE_KOBJCACHE
589 ifneq ($($(target)_KOBJCACHE),)
590 local use_objcache := 1
591 else
592 local use_objcache :=
593 endif
594 local use_objcache :=
595 endif
597 # Target level intermediates (before units!).
598 local target_intermediate_vars := $$$$($(target)_2_INTERMEDIATES) $(foreach var, \
599 $(target)_INTERMEDIATES \
600 $(target)_INTERMEDIATES.$(bld_trg) \
601 $(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch) \
602 $(target)_INTERMEDIATES.$(bld_trg_arch) \
603 $(target)_INTERMEDIATES.$(bld_trg_cpu) \
604 $(target)_INTERMEDIATES.$(bld_type) \
605 ,$(if-expr defined($(var)),$$$$($(var)),))
607 # Do units pre source callouts.
608 local units := \
609 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
610 $($(target)_USES.$(bld_trg_arch))\
611 $($(target)_USES.$(bld_trg))\
612 $($(target)_USES.$(bld_type))\
613 $($(target)_USES)
614 $(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
615 $(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
617 # source -> object
618 $(evalval def_target_sources)
620 # library linking
621 local tool := $(call _TARGET_TOOL,$(target),AR)
622 local name := $(firstword\
623 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
624 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
625 $($(target)_NAME.$(bld_trg).$(bld_type))\
626 $($(target)_NAME.$(bld_trg_arch))\
627 $($(target)_NAME.$(bld_trg))\
628 $($(target)_NAME.$(bld_type))\
629 $($(target)_NAME)\
630 $(target))
631 local outbase := $(call TARGET_BASE,$(name),$(target))
632 local flags :=\
633 $(TOOL_$(tool)_ARFLAGS)\
634 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
635 $(ARFLAGS)\
636 $(ARFLAGS.$(bld_type))\
637 $($(target)_ARFLAGS)\
638 $($(target)_ARFLAGS.$(bld_type)) \
639 $($(target)_ARFLAGS.$(bld_trg)) \
640 $($(target)_ARFLAGS.$(bld_trg_arch)) \
641 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
642 $($(target)_ARFLAGS.$(bld_trg_cpu))
643 local dirdep := $(call DIRDEP,$(dir $(out)))
644 local deps := \
645 $($(target)_DEPS.$(bld_trg_cpu)) \
646 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
647 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
648 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
649 $($(target)_DEPS.$(bld_trg_arch)) \
650 $($(target)_DEPS.$(bld_trg)) \
651 $($(target)_DEPS.$(bld_type)) \
652 $($(target)_DEPS) \
653 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
654 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
655 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
656 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
657 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
658 $($(target)_LNK_DEPS.$(bld_trg)) \
659 $($(target)_LNK_DEPS.$(bld_type)) \
660 $($(target)_LNK_DEPS)
661 local orderdeps := \
662 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
663 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
664 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
665 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
666 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
667 $($(target)_ORDERDEPS.$(bld_trg)) \
668 $($(target)_ORDERDEPS.$(bld_type)) \
669 $($(target)_ORDERDEPS) \
670 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
671 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
672 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
673 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
674 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
675 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
676 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
677 $($(target)_LNK_ORDERDEPS)
679 # Adjust paths if we got a default path.
680 ifneq ($(defpath),)
681 local deps := $(abspathex $(deps),$(defpath))
682 local orderdeps := $(abspathex $(orderdeps),$(defpath))
683 othersrc := $(abspathex $(othersrc),$(defpath))
684 endif
687 # Custom pre-link actions.
688 local pre_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,PRE_CMDS,$(NLTAB))
689 local post_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,POST_CMDS,$(NLTAB))
691 # eliminate this guy?
692 local objs = $($(target)_2_OBJS)
694 # dependency file
695 local dep := $(out)$(SUFF_DEP)
696 ifndef NO_LINK_CMDS_DEPS
697 _DEPFILES_INCLUDED += $(dep)
698 ifdef KB_HAVE_INCLUDEDEP_QUEUE
699 includedep-queue $(dep)
700 else
701 includedep $(dep)
702 endif
703 endif
705 # check that the tool is defined.
706 ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
707 $(warning kBuild: tools: \
708 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
709 2 $($(target)_$(source)TOOL.$(bld_trg)) \
710 3 $($(target)_$(source)TOOL) \
711 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
712 5 $($(target)_TOOL.$(bld_trg)) \
713 6 $($(target)_TOOL) \
714 7 $($(source)TOOL) \
715 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
716 9 $($(source)TOOL.$(bld_trg)) \
717 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
718 11 $(TOOL.$(bld_trg)) \
719 12 $(TOOL) )
720 $(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
721 endif
723 # call the tool
724 local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
725 ifneq ($(pre_cmds),)
726 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
727 endif
728 ifneq ($(post_cmds),)
729 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
730 endif
731 $(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
732 $(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
733 $(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE_PRECIOUS)
734 $(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_2_OBJS)
735 $(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
737 # generate the link rule.
738 $(eval $(def_link_rule))
740 # installing and globals.
741 local target_type_mode := a+r,u+w
742 $(evalval def_target_install_only)
744 _OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
745 _CLEAN_FILES += $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_cpu)) $($(target)_CLEAN.$(bld_type))
746 _DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
747 _OBJS += $($(target)_2_OBJS)
749 endef # def_lib
750 $(eval-opt-var def_lib)
752 # Process libraries
753 typevar := _LIBS
754 tool_do := LINK_LIBRARY
755 mode := 0644
756 $(foreach target, $(_ALL_LIBRARIES), $(evalvalctx def_lib))
758 ifdef KBUILD_PROFILE_SELF
759 $(evalcall def_profile_self, done library targets)
760 endif
764 # Link operations.
768 # Link prolog
770 # @param $(target) Normalized target name.
771 # @param $(EXT) EXE,DLL,SYS.
772 # @param $(typevar) The name of the variable with all the root targets of its type.
773 define def_link_common
774 # basics
775 local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
776 local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_$(bld_trg_base_var)))
777 local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_$(bld_trg_base_var)_ARCH))
778 local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_$(bld_trg_base_var)_CPU))
780 local tool := $(call _TARGET_TOOL,$(target),LD)
781 local name := $(firstword\
782 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
783 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
784 $($(target)_NAME.$(bld_trg).$(bld_type))\
785 $($(target)_NAME.$(bld_trg_arch))\
786 $($(target)_NAME.$(bld_trg))\
787 $($(target)_NAME.$(bld_type))\
788 $($(target)_NAME)\
789 $(target))
790 local outbase := $(call TARGET_BASE,$(name),$(target))
791 $(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
792 $(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
793 local suff := $(firstword \
794 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
795 $($(target)_$(EXT)SUFF.$(bld_trg))\
796 $($(target)_$(EXT)SUFF)\
797 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
798 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg))\
799 $(TOOL_$(tool)_LD$(EXT)SUFF)\
800 $($(EXTPRE)SUFF_$(EXT)) )
801 local out := $(outbase)$(suff)
802 $(target)_1_TARGET:= $(out)
803 $(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
804 local defpath := $($(target)_DEFPATH)
805 ifeq ($(defpath),)
806 local defpath := $($(target)_PATH)
807 endif
808 # no local here - must be writable across some foreachs.
809 othersrc :=
810 $(target)_2_OBJS :=
811 $(target)_2_INTERMEDIATES =
813 # kObjCache.
814 ifdef KBUILD_USE_KOBJCACHE
815 ifneq ($($(target)_KOBJCACHE),)
816 local use_objcache := 1
817 else
818 local use_objcache :=
819 endif
820 local use_objcache :=
821 endif
823 # Target level intermediates (before units!).
824 local target_intermediate_vars := $$$$($(target)_2_INTERMEDIATES) $(foreach var, \
825 $(target)_INTERMEDIATES \
826 $(target)_INTERMEDIATES.$(bld_trg) \
827 $(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch) \
828 $(target)_INTERMEDIATES.$(bld_trg_arch) \
829 $(target)_INTERMEDIATES.$(bld_trg_cpu) \
830 $(target)_INTERMEDIATES.$(bld_type) \
831 ,$(if-expr defined($(var)),$$$$($(var)),))
833 # Do units pre source callouts.
834 local units := \
835 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
836 $($(target)_USES.$(bld_trg_arch))\
837 $($(target)_USES.$(bld_trg))\
838 $($(target)_USES.$(bld_type))\
839 $($(target)_USES)
840 $(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
841 $(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
843 # source -> object
844 $(evalval def_target_sources)
846 # more link stuff.
847 local tool := $(call _TARGET_TOOL,$(target),LD)
848 local name := $(firstword\
849 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
850 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
851 $($(target)_NAME.$(bld_trg).$(bld_type))\
852 $($(target)_NAME.$(bld_trg_arch))\
853 $($(target)_NAME.$(bld_trg))\
854 $($(target)_NAME.$(bld_type))\
855 $($(target)_NAME)\
856 $(target))
857 local outbase := $(call TARGET_BASE,$(name),$(target))
858 local flags :=\
859 $(TOOL_$(tool)_LDFLAGS)\
860 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
861 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
862 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
863 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
864 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
865 $(foreach sdk, $(SDKS) \
866 $(SDKS.$(bld_type)) \
867 $(SDKS.$(bld_trg)) \
868 $(SDKS.$(bld_trg_arch)) \
869 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
870 $(SDK_$(sdk)_LDFLAGS)\
871 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
872 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
873 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
874 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
875 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
876 $(LDFLAGS)\
877 $(LDFLAGS.$(bld_type))\
878 $(LDFLAGS.$(bld_trg))\
879 $(LDFLAGS.$(bld_trg_arch))\
880 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
881 $(LDFLAGS.$(bld_trg_cpu))\
882 $(foreach sdk, $($(target)_SDKS) \
883 $($(target)_SDKS.$(bld_type)) \
884 $($(target)_SDKS.$(bld_trg)) \
885 $($(target)_SDKS.$(bld_trg_arch)) \
886 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
887 $(SDK_$(sdk)_LDFLAGS)\
888 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
889 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
890 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
891 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
892 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
893 $($(target)_LDFLAGS)\
894 $($(target)_LDFLAGS.$(bld_type))\
895 $($(target)_LDFLAGS.$(bld_trg))\
896 $($(target)_LDFLAGS.$(bld_trg_arch))\
897 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
898 $($(target)_LDFLAGS.$(bld_trg_cpu))
900 local targetsdks := \
901 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch))\
902 $($(target)_SDKS.$(bld_trg_arch))\
903 $($(target)_SDKS.$(bld_trg))\
904 $($(target)_SDKS.$(bld_type))\
905 $($(target)_SDKS)
906 local globalsdks := \
907 $(SDKS.$(bld_trg).$(bld_trg_arch))\
908 $(SDKS.$(bld_trg_arch))\
909 $(SDKS.$(bld_trg))\
910 $(SDKS.$(bld_type))\
911 $(SDKS)
912 # Note! Global EARLY_LIBS and LATE_LIBS variables are ignored.
913 ## @todo ignore global LIBS and most other global properties.
914 local libs :=\
915 $($(target)_EARLY_LIBS.$(bld_trg_cpu))\
916 $($(target)_EARLY_LIBS.$(bld_trg).$(bld_trg_arch))\
917 $($(target)_EARLY_LIBS.$(bld_trg_arch))\
918 $($(target)_EARLY_LIBS.$(bld_trg))\
919 $($(target)_EARLY_LIBS.$(bld_type))\
920 $($(target)_EARLY_LIBS)\
921 $(foreach sdk, $(targetsdks) $(globalsdks),\
922 $(SDK_$(sdk)_EARLY_LIBS.$(bld_trg_cpu))\
923 $(SDK_$(sdk)_EARLY_LIBS.$(bld_trg).$(bld_trg_arch))\
924 $(SDK_$(sdk)_EARLY_LIBS.$(bld_trg_arch))\
925 $(SDK_$(sdk)_EARLY_LIBS.$(bld_trg))\
926 $(SDK_$(sdk)_EARLY_LIBS.$(bld_type))\
927 $(SDK_$(sdk)_EARLY_LIBS))\
928 $(TOOL_$(tool)_EARLY_LIBS.$(bld_trg_cpu))\
929 $(TOOL_$(tool)_EARLY_LIBS.$(bld_trg).$(bld_trg_arch))\
930 $(TOOL_$(tool)_EARLY_LIBS.$(bld_trg_arch))\
931 $(TOOL_$(tool)_EARLY_LIBS.$(bld_trg))\
932 $(TOOL_$(tool)_EARLY_LIBS.$(bld_type))\
933 $(TOOL_$(tool)_EARLY_LIBS)\
935 $($(target)_LIBS.$(bld_trg_cpu))\
936 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
937 $($(target)_LIBS.$(bld_trg_arch))\
938 $($(target)_LIBS.$(bld_trg))\
939 $($(target)_LIBS.$(bld_type))\
940 $($(target)_LIBS)\
941 $(foreach sdk, $(targetsdks),\
942 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
943 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
944 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
945 $(SDK_$(sdk)_LIBS.$(bld_trg))\
946 $(SDK_$(sdk)_LIBS.$(bld_type))\
947 $(SDK_$(sdk)_LIBS))\
948 $(LIBS.$(bld_trg_cpu))\
949 $(LIBS.$(bld_trg).$(bld_trg_arch))\
950 $(LIBS.$(bld_trg_arch))\
951 $(LIBS.$(bld_trg))\
952 $(LIBS.$(bld_type))\
953 $(LIBS)\
954 $(foreach sdk, $(globalsdks),\
955 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
956 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
957 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
958 $(SDK_$(sdk)_LIBS.$(bld_trg))\
959 $(SDK_$(sdk)_LIBS.$(bld_type))\
960 $(SDK_$(sdk)_LIBS))\
961 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
962 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
963 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
964 $(TOOL_$(tool)_LIBS.$(bld_trg))\
965 $(TOOL_$(tool)_LIBS.$(bld_type))\
966 $(TOOL_$(tool)_LIBS)\
968 $($(target)_LATE_LIBS.$(bld_trg_cpu))\
969 $($(target)_LATE_LIBS.$(bld_trg).$(bld_trg_arch))\
970 $($(target)_LATE_LIBS.$(bld_trg_arch))\
971 $($(target)_LATE_LIBS.$(bld_trg))\
972 $($(target)_LATE_LIBS.$(bld_type))\
973 $($(target)_LATE_LIBS)\
974 $(foreach sdk, $(targetsdks) $(globalsdks),\
975 $(SDK_$(sdk)_LATE_LIBS.$(bld_trg_cpu))\
976 $(SDK_$(sdk)_LATE_LIBS.$(bld_trg).$(bld_trg_arch))\
977 $(SDK_$(sdk)_LATE_LIBS.$(bld_trg_arch))\
978 $(SDK_$(sdk)_LATE_LIBS.$(bld_trg))\
979 $(SDK_$(sdk)_LATE_LIBS.$(bld_type))\
980 $(SDK_$(sdk)_LATE_LIBS))\
981 $(TOOL_$(tool)_LATE_LIBS.$(bld_trg_cpu))\
982 $(TOOL_$(tool)_LATE_LIBS.$(bld_trg).$(bld_trg_arch))\
983 $(TOOL_$(tool)_LATE_LIBS.$(bld_trg_arch))\
984 $(TOOL_$(tool)_LATE_LIBS.$(bld_trg))\
985 $(TOOL_$(tool)_LATE_LIBS.$(bld_type))\
986 $(TOOL_$(tool)_LATE_LIBS)
987 local libpath :=\
988 $($(target)_LIBPATH.$(bld_trg_cpu))\
989 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
990 $($(target)_LIBPATH.$(bld_trg_arch))\
991 $($(target)_LIBPATH.$(bld_trg))\
992 $($(target)_LIBPATH.$(bld_type))\
993 $($(target)_LIBPATH)\
994 $(foreach sdk, $(targetsdks),\
995 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
996 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
997 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
998 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
999 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1000 $(SDK_$(sdk)_LIBPATH))\
1001 $(LIBPATH.$(bld_trg_cpu))\
1002 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
1003 $(LIBPATH.$(bld_trg_arch))\
1004 $(LIBPATH.$(bld_trg))\
1005 $(LIBPATH.$(bld_type))\
1006 $(LIBPATH)\
1007 $(foreach sdk, $(globalsdks),\
1008 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1009 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1010 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1011 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1012 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1013 $(SDK_$(sdk)_LIBPATH))\
1014 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1015 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
1016 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1017 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1018 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
1019 $(TOOL_$(tool)_LIBPATH)
1020 local dirdep := $(call DIRDEP,$(dir $(out)))
1021 local deps := \
1022 $($(target)_DEPS.$(bld_trg_cpu)) \
1023 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
1024 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
1025 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
1026 $($(target)_DEPS.$(bld_trg_arch)) \
1027 $($(target)_DEPS.$(bld_trg)) \
1028 $($(target)_DEPS.$(bld_type)) \
1029 $($(target)_DEPS) \
1030 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
1031 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
1032 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
1033 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
1034 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
1035 $($(target)_LNK_DEPS.$(bld_trg)) \
1036 $($(target)_LNK_DEPS.$(bld_type)) \
1037 $($(target)_LNK_DEPS)
1038 local orderdeps := \
1039 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
1040 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
1041 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
1042 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
1043 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
1044 $($(target)_ORDERDEPS.$(bld_trg)) \
1045 $($(target)_ORDERDEPS.$(bld_type)) \
1046 $($(target)_ORDERDEPS) \
1047 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
1048 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
1049 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
1050 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
1051 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
1052 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
1053 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
1054 $($(target)_LNK_ORDERDEPS)
1056 # Adjust paths if we got a default path.
1057 ifneq ($(defpath),)
1058 ifdef KMK_WITH_QUOTING
1059 local libpath := $(qabspathex ,$(libpath),$(defpath))
1060 local deps := $(qabspathex ,$(deps),$(defpath))
1061 local orderdeps := $(qabspathex ,$(orderdeps),$(defpath))
1062 othersrc := $(qabspathex ,$(othersrc),$(defpath))
1063 else
1064 local libpath := $(abspathex $(libpath),$(defpath))
1065 local deps := $(abspathex $(deps),$(defpath))
1066 local orderdeps := $(abspathex $(orderdeps),$(defpath))
1067 othersrc := $(abspathex $(othersrc),$(defpath))
1068 endif
1069 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
1070 endif
1072 # Debug info.
1073 local ld_debug := $(evalcall def_fn_prop_get_first_defined,LD_DEBUG)
1074 local debug_inst := $(evalcall def_fn_prop_get_first_defined,DEBUG_INST)
1075 local debug_stage := $(evalcall def_fn_prop_get_first_defined,DEBUG_STAGE)
1076 local debug_nostage := $(evalcall def_fn_prop_get_first_word,DEBUG_NOSTAGE)
1078 # Custom pre/post-link actions.
1079 local pre_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,PRE_CMDS,$(NLTAB))
1080 local post_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,POST_CMDS,$(NLTAB))
1082 # eliminate this guy?
1083 local objs = $($(target)_2_OBJS)
1085 # dependency file
1086 local dep := $(outbase)$(SUFF_DEP)
1087 ifndef NO_LINK_CMDS_DEPS
1088 _DEPFILES_INCLUDED += $(dep)
1089 ifdef KB_HAVE_INCLUDEDEP_QUEUE
1090 includedep-queue $(dep)
1091 else
1092 includedep $(dep)
1093 endif
1094 endif
1096 # check that the tool is defined.
1097 ifndef TOOL_$(tool)_$(tool_do)_CMDS
1098 $(warning kBuild: tools: \
1099 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1100 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1101 3 $($(target)_$(source)TOOL) \
1102 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1103 5 $($(target)_TOOL.$(bld_trg)) \
1104 6 $($(target)_TOOL) \
1105 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1106 8 $($(source)TOOL.$(bld_trg)) \
1107 9 $($(source)TOOL) \
1108 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1109 11 $(TOOL.$(bld_trg)) \
1110 12 $(TOOL) )
1111 $(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1112 endif
1114 # call the tool
1115 local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
1116 ifneq ($(pre_cmds),)
1117 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
1118 endif
1119 ifneq ($(post_cmds),)
1120 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
1121 endif
1122 $(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1123 $(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
1124 $(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE_PRECIOUS)
1125 if1of ($(ld_debug), split)
1126 $(target)_2_OUTPUT_DEBUG_FILES := $(filter-out %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
1127 $(target)_2_OUTPUT_DEBUG_DIRS := $(filter %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
1128 else
1129 $(target)_2_OUTPUT_DEBUG_FILES :=
1130 $(target)_2_OUTPUT_DEBUG_DIRS :=
1131 endif
1132 $(target)_2_DEPEND := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_2_OBJS)
1133 $(target)_2_DEPORD := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
1135 # generate the link rule.
1136 $(eval $(def_link_rule))
1138 # installation targets
1139 local target_type_mode :=
1140 $(evalval def_target_install_only)
1142 # Update globals.
1143 _OBJS += $($(target)_2_OBJS)
1144 _OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $($(target)_2_OUTPUT_DEBUG_FILES) $(out)
1145 _CLEAN_FILES += $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_cpu)) $($(target)_CLEAN.$(bld_type))
1146 _DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
1147 _INSTALLS_FILES += $(INSTARGET_$(target))
1149 endef # def_link_common
1150 $(eval-opt-var def_link_common)
1154 # BLDPROGS
1157 # Process build programs.
1158 EXT := EXE
1159 EXTPRE := HOST
1160 tool_do := LINK_PROGRAM
1161 typevar := _BLDPROGS
1162 mode := 0755
1163 bld_trg_base_var := HOST
1164 $(foreach target, $(_ALL_BLDPROGS), $(evalvalctx def_link_common))
1166 ifdef KBUILD_PROFILE_SELF
1167 $(evalcall def_profile_self, done build program targets)
1168 endif
1172 # DLLS
1175 # Process dlls
1176 EXT := DLL
1177 EXTPRE :=
1178 tool_do := LINK_DLL
1179 typevar := _DLLS
1180 mode := 0644
1181 bld_trg_base_var := TARGET
1182 $(foreach target, $(_ALL_DLLS), $(evalvalctx def_link_common))
1184 ifdef KBUILD_PROFILE_SELF
1185 $(evalcall def_profile_self, done dll targets)
1186 endif
1190 # IMPORT LIBRARIES
1192 # - On OS/2 and windows these are libraries.
1193 # - On other platforms they are fake DLLs.
1195 EXTPRE :=
1196 typevar := _IMPORT_LIBS
1197 mode := 0644
1198 bld_trg_base_var := TARGET
1199 ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
1200 EXT := LIB
1201 tool_do := LINK_LIBRARY
1202 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_lib))
1203 else
1204 EXT := DLL
1205 tool_do := LINK_DLL
1206 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_link_common))
1207 endif
1209 ifdef KBUILD_PROFILE_SELF
1210 $(evalcall def_profile_self, done import library targets)
1211 endif
1215 # PROGRAMS
1218 # Process programs
1219 EXT := EXE
1220 EXTPRE :=
1221 tool_do := LINK_PROGRAM
1222 typevar := _PROGRAMS
1223 mode := 0755
1224 bld_trg_base_var := TARGET
1225 $(foreach target, $(_ALL_PROGRAMS), $(evalvalctx def_link_common))
1227 ifdef KBUILD_PROFILE_SELF
1228 $(evalcall def_profile_self, done program targets)
1229 endif
1233 # SYSMODS
1236 # Process sysmods
1237 EXT := SYS
1238 EXTPRE :=
1239 tool_do := LINK_SYSMOD
1240 typevar := _SYSMODS
1241 mode := 0644
1242 bld_trg_base_var := TARGET
1243 $(foreach target, $(_ALL_SYSMODS), $(evalvalctx def_link_common))
1245 ifdef KBUILD_PROFILE_SELF
1246 $(evalcall def_profile_self, done sysmod targets)
1247 endif
1251 # MISCBINS
1254 # Process MISCBINS
1255 EXT := BIN
1256 EXTPRE :=
1257 tool_do := LINK_MISCBIN
1258 typevar := _MISCBINS
1259 mode := 0644
1260 bld_trg_base_var := TARGET
1261 $(foreach target, $(_ALL_MISCBINS), $(evalvalctx def_link_common))
1263 ifdef KBUILD_PROFILE_SELF
1264 $(evalcall def_profile_self, done misc binary targets)
1265 endif