footer-pass2-compiling-targets.kmk 39.7 KB
Newer Older
1
# $Id: footer-pass2-compiling-targets.kmk 3285 2019-01-05 03:24:58Z bird $
2 3 4 5 6
## @file
# kBuild - Footer - Target lists - Pass 2 - Compiling Targets.
#

#
7
# Copyright (c) 2004-2019 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#
# This file is part of kBuild.
#
# kBuild is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version source of the License, or
# (at your option) any later version.
#
# kBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kBuild; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# As a special exception you are granted permission to include this file, via
# the kmk include directive, as you wish without this in itself causing the
# resulting makefile, program or whatever to be covered by the GPL license.
# This exception does not however invalidate any other reasons why the makefile,
# program, whatever should not be covered the GPL.
#
#


#
# Object processing.
#

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
ifndef NO_COMPILE_CMDS_DEPS
 ## Generates the rules for building a specific object and the aliases.
 # for building a source file.
 # @param    $(obj)    The object file.
 define def_target_source_rule_v3plus
$$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
$$(obj) + $$(kbsrc_output) +| $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
	%$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
  ifndef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
	$$(QUIET)$$(RM) -f -- $(dep) $(obj) $(kbsrc_output) $(kbsrc_output_maybe)
  endif

$(kbsrc_cmds)

	%$$(QUIET2)$$(APPEND) -in '$(dep)' '' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_' '--insert-command=$(obj)' 'endef'
$$(basename $$(notdir $$(obj))).o: $$(obj)
 endef # def_target_source_rule_v3plus

 ## Generates the rules for building a specific object and the aliases, kObjCache variant.
 # for building a source file.
 # @param    $(obj)    The object file.
 define def_target_source_rule_v3plus_objcache
$$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
_OUT_FILES += $(outbase).koc
$$(outbase).koc +| $$(obj) $$(kbsrc_output) $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
	%$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))

$(kbsrc_cmds)

	%$$(QUIET2)$$(APPEND) -in '$(dep)' '' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_' '--insert-command=$(obj)' 'endef'
$$(basename $$(notdir $$(obj))).o: $$(obj)
 endef # def_target_source_rule_v3plus_objcache

else # NO_COMPILE_CMDS_DEPS

 ## Generates the rules for building a specific object and the aliases.
 # for building a source file.
 # @param    $(obj)    The object file.
 define def_target_source_rule_v3plus
$$(obj) + $$(kbsrc_output) +| $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
	%$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
  ifndef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
	$$(QUIET)$$(RM) -f -- $(dep) $(obj) $(kbsrc_output) $(kbsrc_output_maybe)
  endif

$(kbsrc_cmds)

$$(basename $$(notdir $$(obj))).o: $$(obj)
 endef # def_target_source_rule_v3plus

 ## Generates the rules for building a specific object and the aliases, kObjCache variant.
 # for building a source file.
 # @param    $(obj)    The object file.
 define def_target_source_rule_v3plus_objcache
_OUT_FILES += $(outbase).koc
$$(outbase).koc +| $$(obj) $$(kbsrc_output) $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
	%$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))

$(kbsrc_cmds)

$$(basename $$(notdir $$(obj))).o: $$(obj)
 endef # def_target_source_rule_v3plus_objcache

endif # NO_COMPILE_CMDS_DEPS
$(eval-opt-var def_target_source_rule_v3plus)
$(eval-opt-var def_target_source_rule_v3plus_objcache)


##
## Legacy legacy legacy - start
##

## Wrapper
112 113 114 115 116 117 118 119 120 121 122
ifndef NO_COMPILE_CMDS_DEPS
 if1of ($(KMK_FEATURES),dot-must-make)
  _DEP_COMPILE_CMDS =
  # for debugging:  $$(warning MUST_MAKE=$$$$(comp-cmds-ex $$$$($(target)_$(subst :,_,$(source))_CMDS_PREV_), $$$$(commands $$@)) -> $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE))
 else
  _DEP_COMPILE_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $(obj)),FORCE)
 endif
else
 _DEP_COMPILE_CMDS =
endif

123
## Generates the rules for building a specific object, and the aliases - legacy version.
124 125 126 127 128 129
# for building a source file.
# @param    $(obj)    The object file.
define def_target_source_rule
ifndef NO_COMPILE_CMDS_DEPS
$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
endif
130
ifneq ($(TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE),)
131 132
_OUT_FILES += $(outbase).koc
$(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
133 134
		$($(target)_$(source)_DEPEND_) $(value _DEP_COMPILE_CMDS) \
		| $($(target)_$(source)_DEPORD_) $(target_intermediate_vars)
135 136 137
	%$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
else
$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
138 139
		$($(target)_$(source)_DEPEND_) $(value _DEP_COMPILE_CMDS) \
		| $($(target)_$(source)_DEPORD_) $(target_intermediate_vars)
140
	%$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
141
ifndef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
142 143 144 145 146 147 148
	$$(QUIET)$$(RM) -f -- $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
endif
endif

$($(target)_$(source)_CMDS_)

ifndef NO_COMPILE_CMDS_DEPS
149 150 151 152 153 154 155 156
 ifdef KBUILD_HAVE_OPTIMIZED_APPEND
	%$$(QUIET2)$$(APPEND) -in '$(dep)' \
		'' \
		'define $(target)_$(subst :,_,$(source))_CMDS_PREV_' \
		'--insert-command=$(obj)' \
		'endef'
 else
	%$$(QUIET2)$$(APPEND) -n '$(dep)' '' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_'
157 158
	%$$(QUIET2)$$(APPEND) -c '$(dep)' '$(obj)'
	%$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
159
 endif
160 161 162 163 164 165 166 167 168 169 170 171
endif

$(basename $(notdir $(obj))).o: $(obj)

## @todo make this 'local cmds,output,output_maybe,depend and depord' in 0.2.x or when a new kb-src-one is added.
$(target)_$(source)_CMDS_ :=
$(target)_$(source)_OUTPUT_ :=
$(target)_$(source)_OUTPUT_MAYBE_ :=
$(target)_$(source)_DEPEND_ :=
$(target)_$(source)_DEPORD_ :=
endef # def_target_source_rule
$(eval-opt-var def_target_source_rule)
172 173 174
##
## Legacy legacy legacy - end

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194


## wrapper the link command dependency check.
ifndef NO_LINK_CMDS_DEPS
 if1of ($(KMK_FEATURES),dot-must-make)
  _DEP_LINK_CMDS =
 else
  _DEP_LINK_CMDS = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $(out)),FORCE)
 endif
else
 _DEP_LINK_CMDS =
endif

## Generate the link rule for a target.
# @param    $(target)               The normalized target name.
# @param    $(dirdep)               Directories we depend upon begin created before linking.
# @param    $(dep)                  The name of the dependency file.
# @param    $(out)
# @param    $($(target)_2_OUTPUT)   Output files from the link.
# @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 197 198 199 200 201 202 203 204 205 206 207 208
# @param    $($(target)_2_DEPEND)   Dependencies.
# @param    $($(target)_2_DEPORD)   Dependencies which should only affect build order.
# @param    $(cmds)                 The link commands.
# @param    $($(target)_CMDS_PREV_) The link commands from the previous run.
define def_link_rule
$$(call KB_FN_ASSERT_ABSPATH,out)
ifndef NO_LINK_CMDS_DEPS
$(out): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $$@),FORCE)
endif
$(out) \
+ $($(target)_2_OUTPUT) \
+ $($(target)_2_OUTPUT_DEBUG_FILES) \
+ $($(target)_2_OUTPUT_DEBUG_DIRS) \
209
+| $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) : \
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
		$$$$($(target)_2_DEPEND) \
		$(value _DEP_LINK_CMDS) \
		| \
		$$$$($(target)_2_DEPORD)
	%$$(call MSG_LINK,$(target),$$@,$(tool_do))
	$$(QUIET)$$(RM) -f -- $(dep) $(out) $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_DEBUG_FILES)
ifdef $(target)_2_OUTPUT_DEBUG_DIRS
	$$(QUIET)$$(RM) -Rf -- $($(target)_2_OUTPUT_DEBUG_DIRS)
endif

$(cmds)

ifndef NO_LINK_CMDS_DEPS
	%$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
	%$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
	%$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
endif

$(basename $(notdir $(out))):: $(out)

endef # def_link_rule
$(eval-opt-var def_link_rule)


## Generate the link & lib install rule
# Implicit parameters: target, out, $(target)_1_STAGE_TARGET, mode,
#                      pre_install_cmds, post_install_cmds
define def_link_install_rule
$$(call KB_FN_ASSERT_ABSPATH,$(target)_1_INST_TARGET)
$($(target)_1_INST_TARGET): $(out) | $$$$(dir $$$$@)
	%$$(call MSG_INST_TRG,$(target),$(out),$$@)
	$(pre_install_cmds)

	$$(QUIET)$$(INSTALL) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
	$(post_install_cmds)

endef


## Generate the link & lib stage installation rule
# Implicit parameters: target, out, $(target)_1_STAGE_TARGET, mode,
#                      pre_install_cmds, post_install_cmds
define def_link_stage_rule
$$(call KB_FN_ASSERT_ABSPATH,$(target)_1_STAGE_TARGET)
$($(target)_1_STAGE_TARGET): $(out) | $$$$(dir $$$$@)
	%$$(call MSG_INST_TRG,$(target),$(out),$$@)
	$(pre_install_cmds)

	$$(QUIET)$$(INSTALL_STAGING) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
	$(post_install_cmds)


$(basename $(notdir $(out))):: $($(target)_1_STAGE_TARGET)

endef


## def_src_handler_*
#
# @{
define def_src_handler_c
local type := C
272
 $(kb-src-one 3)
273 274 275 276
endef

define def_src_handler_cxx
local type := CXX
277
 $(kb-src-one 3)
278 279 280 281
endef

define def_src_handler_objc
local type := OBJC
282
 $(kb-src-one 3)
283 284 285 286
endef

define def_src_handler_objcxx
local type := OBJCXX
287
 $(kb-src-one 3)
288 289 290 291
endef

define def_src_handler_asm
local type := AS
292
 $(kb-src-one 3)
293 294 295 296
endef

define def_src_handler_rc
local type := RC
297
 $(kb-src-one 3)
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
endef

define def_src_handler_obj
ifeq ($(defpath),)
 $(target)_2_OBJS += $(source)
else
 $(target)_2_OBJS += $(abspathex $(source), $(defpath))
endif
endef
## @}

## Handle one source.
# .
define def_src_handler_one
local suff := $(suffix $(source))
local src_handler := $(firstword $(filter $(suff):%, $($(target)_$(source)_SRC_HANDLERS) $($(source)_SRC_HANDLERS) $(target_src_handlers) ))
local handler := $(patsubst $(suff):%,%,$(src_handler))
ifneq ($(handler),)
 $(evalvalctx $(handler))
else
 othersrc += $(source)
endif
endef # def_src_handler_one

## Generic macro for processing all target sources.
# @param    $(target)   Normalized target name.
# @param    $(defpath)
# @param    much-more...
# @returns  othersrc, $(target)_2_OBJS, ++
define def_target_sources
local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
$(foreach source,\
	$($(target)_SOURCES)\
	$($(target)_SOURCES.$(bld_trg))\
	$($(target)_SOURCES.$(bld_trg).$(bld_type))\
	$($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
	$($(target)_SOURCES.$(bld_trg).$(bld_trg_arch).$(bld_type))\
	$($(target)_SOURCES.$(bld_trg_arch))\
	$($(target)_SOURCES.$(bld_trg_cpu))\
	$($(target)_SOURCES.$(bld_type))\
338
	,$(evalvalctx def_src_handler_one) )
339 340 341 342 343 344 345 346 347 348

$(foreach source,\
	$($(target)_GEN_SOURCES_)\
	$($(target)_GEN_SOURCES_.$(bld_trg))\
	$($(target)_GEN_SOURCES_.$(bld_trg).$(bld_type))\
	$($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
	$($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch).$(bld_type))\
	$($(target)_GEN_SOURCES_.$(bld_trg_arch))\
	$($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
	$($(target)_GEN_SOURCES_.$(bld_type))\
349
	,$(evalvalctx def_src_handler_one) )
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
endef # def_target_sources
$(eval-opt-var def_target_sources)


##
# Install a debug directory.
# @param    debug_dir           The directory name.
define def_link_install_debug_dir_rule
local dir := $(debug_inst_path)/$(debug_inst2)$(debug_dir)
$$(call KB_FN_ASSERT_ABSPATH,dir)
$$(dir): | $$$$(dir $$$$(patsubst %/,%,$$$$@))
	%$$(call MSG_INST_DIR,$$@)
	$$(QUIET)$$(MKDIR) -p -- $$@
$(target)_2_DEBUG_$(debug_var)_TARGET_DIRS += $$(dir)
endef # def_link_install_debug_dir_rule

##
# Install a debug file.
# @param    debug_file          Src=>Dst file pair.
define def_link_install_debug_file_rule
local dst := $(debug_inst_path)/$(debug_inst2)$(word 2, $(subst =>,$(SP),$(debug_file)))
$$(call KB_FN_ASSERT_ABSPATH,dst)
local src := $(word 1, $(subst =>,$(SP),$(debug_file)))
$$(call KB_FN_ASSERT_ABSPATH,src)
$$(dst): $$(src) | $$$$(dir $$$$@)
	%$$(call MSG_INST_FILE,$$<,$$@)
	$$(QUIET)$(debug_install_cmd) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $$< $$@
$(target)_2_DEBUG_$(debug_var)_TARGET_FILES += $$(dst)
endef # def_link_install_debug_file_rule

##
# Install debug info to $(debug_inst), where debug_inst can be a directory or
# file (just like $(inst) and $(stage).  Used for both staging and installing.
define def_target_install_only_debug
if "$(substr $(debug_inst),-1,1)" == "/"
 if "$(debug_inst)" == "./"
  local debug_inst2 :=
 else
  local debug_inst2 := $(debug_inst)
 endif
 local debug_dirs  := $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_DIRS))
 ifneq ($(strip $(root $(debug_dirs))),)
  $(error kBuild: Bad tool? debug_dirs='$(debug_dirs)', expected all to be under '$(outbase)')
 endif
 local debug_files := $(foreach file, $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_FILES)) \
                        ,$($(target)_0_OUTDIR)/$(file)=>$(file))
else
 local debug_notdir:= $(notdir $(debug_inst))
 local debug_inst2 := $(dir $(debug_inst))
 local debug_files := $(call TOOL_$(tool)_$(tool_do)_DEBUG_INSTALL_FN,$(out),$(outbase),$(debug_notdir))
 local debug_dirs  := $(filter     %/,$(debug_files))
 local debug_files := $(filter-out %/,$(debug_files))
endif
$(foreach debug_dir, $(debug_dirs), $(eval $(def_link_install_debug_dir_rule)))
$(foreach debug_file, $(debug_files), $(eval $(def_link_install_debug_file_rule)))
endef


## Generic macro for generating the install rule(s) for a target.
#
# @param	$(target)   Normalized target name.
# @param	$(out)      The output file.
# @param	$(typevar)  The name of the variable with all the root targets of its type.
# @param	$(target_type_mode) The default file mode implied by the target type.
define def_target_install_only
415 416
if1of ($($(target)_1_INSTTYPE) $($(target)_1_DEBUG_INSTTYPE), both stage)
 # Determin common variables.
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
 local mode := $(firstword \
 	$($(target)_MODE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
 	$($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
 	$($(target)_MODE.$(bld_trg).$(bld_type)) \
 	$($(target)_MODE.$(bld_trg_arch)) \
 	$($(target)_MODE.$(bld_trg)) \
 	$($(target)_MODE.$(bld_type)) \
 	$($(target)_MODE) \
	$(target_type_mode) )
 local uid := $(firstword \
 	$($(target)_UID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
 	$($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
 	$($(target)_UID.$(bld_trg).$(bld_type)) \
 	$($(target)_UID.$(bld_trg_arch)) \
 	$($(target)_UID.$(bld_trg)) \
 	$($(target)_UID.$(bld_type)) \
 	$($(target)_UID) )
 local gid := $(firstword \
 	$($(target)_GID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
 	$($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
 	$($(target)_GID.$(bld_trg).$(bld_type)) \
 	$($(target)_GID.$(bld_trg_arch)) \
 	$($(target)_GID.$(bld_trg)) \
 	$($(target)_GID.$(bld_type)) \
 	$($(target)_GID) )
 local pre_install_cmds  := $(evalcall def_fn_prop_get_first_defined,PRE_INST_CMDS)
 local post_install_cmds := $(evalcall def_fn_prop_get_first_defined,POST_INST_CMDS)
444
endif
445

446
ifneq ($($(target)_1_INSTTYPE),none)
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
 # Generate the rules
 ifeq ($($(target)_1_INSTTYPE),both)
$(eval $(def_link_install_rule))
  _INSTALLS_FILES += $($(target)_1_INST_TARGET)
 endif
$(eval $(def_link_stage_rule))
 _STAGE_FILES += $($(target)_1_STAGE_TARGET)
 $(typevar) += $($(target)_1_STAGE_TARGET)
else  # INSTTYPE == none
 $(typevar) += $(out)
endif # INSTTYPE == none

# Install debug info.
$(target)_2_DEBUG_STAGE_TARGET_DIRS :=
$(target)_2_DEBUG_STAGE_TARGET_FILES :=
$(target)_2_DEBUG_INSTALL_TARGET_DIRS :=
$(target)_2_DEBUG_INSTALL_TARGET_FILES :=

if  (   defined($(target)_2_OUTPUT_DEBUG_DIRS) \
     || defined($(target)_2_OUTPUT_DEBUG_FILES) ) \
 && "$($(target)_1_DEBUG_INSTTYPE)" != "none"
 local mode := $(if $(mode),$(mode)$(COMMA)a-x,0644)

 ifeq ($($(target)_1_DEBUG_INSTTYPE),both)
  local debug_inst_path   := $(PATH_INS)
  local debug_install_cmd := $(INSTALL)
  local debug_var         := INSTALL
474
  $(foreach debug_inst, $($(target)_1_DEBUG_INST), $(evalvalctx def_target_install_only_debug))
475 476 477 478 479 480
 endif

 local debug_inst_path    := $(PATH_STAGE)
 local debug_install_cmd  := $(INSTALL_STAGING)
 local debug_var          := STAGE
 if1of ($($(target)_1_DEBUG_INSTTYPE), stage both)
481
  $(foreach debug_inst, $($(target)_1_DEBUG_STAGE), $(evalvalctx def_target_install_only_debug))
482 483 484
 endif
 if1of ($($(target)_1_INSTTYPE), stage both)
  ifndef debug_nostage
485
   $(foreach debug_inst,$($(target)_1_STAGE), $(evalvalctx def_target_install_only_debug))
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
  endif
 endif

 _DEBUG_STAGE_DIRS    += $($(target)_2_DEBUG_STAGE_TARGET_DIRS)
 _DEBUG_STAGE_FILES   += $($(target)_2_DEBUG_STAGE_TARGET_FILES)
 _DEBUG_INSTALL_DIRS  += $($(target)_2_DEBUG_INSTALL_TARGET_DIRS)
 _DEBUG_INSTALL_FILES += $($(target)_2_DEBUG_INSTALL_TARGET_FILES)

 $(basename $(notdir $(out))):: $($(target)_2_DEBUG_STAGE_TARGET_DIRS) $($(target)_2_DEBUG_STAGE_TARGET_FILES)
endif

endef # def_target_install_only



#
# LIBRARIES
#

## Library (one).
# @param    $(target)   Normalized library (target) name.
define def_lib
# library basics
## @todo prefix
local bld_type    := $(firstword $($(target)_BLD_TYPE)     $(KBUILD_TYPE))
local bld_trg     := $(firstword $($(target)_BLD_TRG)      $(KBUILD_TARGET))
local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(KBUILD_TARGET_CPU))
local tool        := $(call _TARGET_TOOL,$(target),AR)
ifeq ($(tool),)
$(error kBuild: Library target $(target) does not have a tool defined!)
endif
local name        := $(firstword\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg).$(bld_type))\
	$($(target)_NAME.$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg))\
	$($(target)_NAME.$(bld_type))\
	$($(target)_NAME)\
	$(target))
local outbase     := $(call TARGET_BASE,$(name),$(target))
$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
local suff        := $(firstword\
	$($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
	$($(target)_LIBSUFF.$(bld_trg))\
	$($(target)_LIBSUFF)\
	$(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
	$(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
	$(TOOL_$(tool)_ARLIBSUFF)\
	$(SUFF_LIB))
local out         := $(outbase)$(suff)
local defpath     := $($(target)_DEFPATH)
ifeq ($(defpath),)
 local defpath    := $($(target)_PATH)
endif
$(target)_1_TARGET:= $(out)
$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
# no local here - must be writable across some foreachs.
othersrc          :=
$(target)_2_OBJS  :=
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
$(target)_2_INTERMEDIATES =

# kObjCache.
ifdef KBUILD_USE_KOBJCACHE
 ifneq ($($(target)_KOBJCACHE),)
local use_objcache := 1
 else
local use_objcache :=
 endif
local use_objcache :=
endif

# Target level intermediates (before units!).
local target_intermediate_vars := $$$$($(target)_2_INTERMEDIATES) $(foreach var, \
	$(target)_INTERMEDIATES \
	$(target)_INTERMEDIATES.$(bld_trg) \
	$(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch) \
	$(target)_INTERMEDIATES.$(bld_trg_arch) \
	$(target)_INTERMEDIATES.$(bld_trg_cpu) \
	$(target)_INTERMEDIATES.$(bld_type) \
	,$(if-expr defined($(var)),$$$$($(var)),))
569 570 571 572 573 574 575 576

# Do units pre source callouts.
local units       := \
	$($(target)_USES.$(bld_trg).$(bld_trg_arch))\
	$($(target)_USES.$(bld_trg_arch))\
	$($(target)_USES.$(bld_trg))\
	$($(target)_USES.$(bld_type))\
	$($(target)_USES)
577
$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
578
$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650

# source -> object
$(evalval def_target_sources)

# library linking
local tool        := $(call _TARGET_TOOL,$(target),AR)
local name        := $(firstword\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg).$(bld_type))\
	$($(target)_NAME.$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg))\
	$($(target)_NAME.$(bld_type))\
	$($(target)_NAME)\
	$(target))
local outbase     := $(call TARGET_BASE,$(name),$(target))
local flags       :=\
	$(TOOL_$(tool)_ARFLAGS)\
	$(TOOL_$(tool)_ARFLAGS.$(bld_type))\
	$(ARFLAGS)\
	$(ARFLAGS.$(bld_type))\
	$($(target)_ARFLAGS)\
	$($(target)_ARFLAGS.$(bld_type)) \
	$($(target)_ARFLAGS.$(bld_trg)) \
	$($(target)_ARFLAGS.$(bld_trg_arch)) \
	$($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_ARFLAGS.$(bld_trg_cpu))
local dirdep      := $(call DIRDEP,$(dir $(out)))
local deps        := \
	$($(target)_DEPS.$(bld_trg_cpu)) \
	$($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_DEPS.$(bld_trg).$(bld_type)) \
	$($(target)_DEPS.$(bld_trg_arch)) \
	$($(target)_DEPS.$(bld_trg)) \
	$($(target)_DEPS.$(bld_type)) \
	$($(target)_DEPS) \
	$($(target)_LNK_DEPS.$(bld_trg_cpu)) \
	$($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
	$($(target)_LNK_DEPS.$(bld_trg_arch)) \
	$($(target)_LNK_DEPS.$(bld_trg)) \
	$($(target)_LNK_DEPS.$(bld_type)) \
	$($(target)_LNK_DEPS)
local orderdeps   := \
	$($(target)_ORDERDEPS.$(bld_trg_cpu)) \
	$($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
	$($(target)_ORDERDEPS.$(bld_trg_arch)) \
	$($(target)_ORDERDEPS.$(bld_trg)) \
	$($(target)_ORDERDEPS.$(bld_type)) \
	$($(target)_ORDERDEPS) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg)) \
	$($(target)_LNK_ORDERDEPS.$(bld_type)) \
	$($(target)_LNK_ORDERDEPS)

# Adjust paths if we got a default path.
ifneq ($(defpath),)
 local deps       := $(abspathex $(deps),$(defpath))
 local orderdeps  := $(abspathex $(orderdeps),$(defpath))
 othersrc := $(abspathex $(othersrc),$(defpath))
endif


# Custom pre-link actions.
651 652
local pre_cmds  := $(evalcall def_fn_prop_get_all_prefixed_priority_last,PRE_CMDS,$(NLTAB))
local post_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,POST_CMDS,$(NLTAB))
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695

# eliminate this guy?
local objs = $($(target)_2_OBJS)

# dependency file
local dep := $(out)$(SUFF_DEP)
ifndef NO_LINK_CMDS_DEPS
 _DEPFILES_INCLUDED += $(dep)
 ifdef KB_HAVE_INCLUDEDEP_QUEUE
  includedep-queue $(dep)
 else
  includedep $(dep)
 endif
endif

# check that the tool is defined.
ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
$(warning kBuild: tools: \
	1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
	2 $($(target)_$(source)TOOL.$(bld_trg)) \
	3 $($(target)_$(source)TOOL) \
	4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
	5 $($(target)_TOOL.$(bld_trg)) \
	6 $($(target)_TOOL) \
	7 $($(source)TOOL) \
	8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
	9 $($(source)TOOL.$(bld_trg)) \
	10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
	11 $(TOOL.$(bld_trg)) \
	12 $(TOOL) )
$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
endif

# call the tool
local  cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
ifneq ($(pre_cmds),)
 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
endif
ifneq ($(post_cmds),)
 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
endif
$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
696
$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE_PRECIOUS)
697 698 699 700 701 702 703 704 705 706
$(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_2_OBJS)
$(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)

# generate the link rule.
$(eval $(def_link_rule))

# installing and globals.
local target_type_mode := a+r,u+w
$(evalval def_target_install_only)

707
_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
708 709 710 711 712 713 714 715 716 717 718
_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))
_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))
_OBJS += $($(target)_2_OBJS)

endef # def_lib
$(eval-opt-var def_lib)

# Process libraries
typevar := _LIBS
tool_do := LINK_LIBRARY
mode := 0644
719
$(foreach target, $(_ALL_LIBRARIES), $(evalvalctx def_lib))
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773

ifdef KBUILD_PROFILE_SELF
 $(evalcall def_profile_self, done library targets)
endif


#
# Link operations.
#

##
# Link prolog
#
# @param    $(target)   Normalized target name.
# @param    $(EXT)      EXE,DLL,SYS.
# @param    $(typevar)  The name of the variable with all the root targets of its type.
define def_link_common
# basics
local bld_type    := $(firstword $($(target)_BLD_TYPE)     $(KBUILD_TYPE))
local bld_trg     := $(firstword $($(target)_BLD_TRG)      $(BUILD_$(bld_trg_base_var)))
local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(BUILD_$(bld_trg_base_var)_CPU))

local tool        := $(call _TARGET_TOOL,$(target),LD)
local name        := $(firstword\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg).$(bld_type))\
	$($(target)_NAME.$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg))\
	$($(target)_NAME.$(bld_type))\
	$($(target)_NAME)\
	$(target))
local outbase     := $(call TARGET_BASE,$(name),$(target))
$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
local suff := $(firstword \
	$($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
	$($(target)_$(EXT)SUFF.$(bld_trg))\
	$($(target)_$(EXT)SUFF)\
	$(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
	$(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg))\
	$(TOOL_$(tool)_LD$(EXT)SUFF)\
	$($(EXTPRE)SUFF_$(EXT)) )
local out         := $(outbase)$(suff)
$(target)_1_TARGET:= $(out)
$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
local defpath     := $($(target)_DEFPATH)
ifeq ($(defpath),)
 local defpath    := $($(target)_PATH)
endif
# no local here - must be writable across some foreachs.
othersrc          :=
$(target)_2_OBJS  :=
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
$(target)_2_INTERMEDIATES =

# kObjCache.
ifdef KBUILD_USE_KOBJCACHE
 ifneq ($($(target)_KOBJCACHE),)
local use_objcache := 1
 else
local use_objcache :=
 endif
local use_objcache :=
endif

# Target level intermediates (before units!).
local target_intermediate_vars := $$$$($(target)_2_INTERMEDIATES) $(foreach var, \
	$(target)_INTERMEDIATES \
	$(target)_INTERMEDIATES.$(bld_trg) \
	$(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch) \
	$(target)_INTERMEDIATES.$(bld_trg_arch) \
	$(target)_INTERMEDIATES.$(bld_trg_cpu) \
	$(target)_INTERMEDIATES.$(bld_type) \
	,$(if-expr defined($(var)),$$$$($(var)),))
795 796 797 798 799 800 801 802

# Do units pre source callouts.
local units       := \
	$($(target)_USES.$(bld_trg).$(bld_trg_arch))\
	$($(target)_USES.$(bld_trg_arch))\
	$($(target)_USES.$(bld_trg))\
	$($(target)_USES.$(bld_type))\
	$($(target)_USES)
803
$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
804
$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995

# source -> object
$(evalval def_target_sources)

# more link stuff.
local tool        := $(call _TARGET_TOOL,$(target),LD)
local name        := $(firstword\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg).$(bld_type))\
	$($(target)_NAME.$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg))\
	$($(target)_NAME.$(bld_type))\
	$($(target)_NAME)\
	$(target))
local outbase     := $(call TARGET_BASE,$(name),$(target))
local flags       :=\
	$(TOOL_$(tool)_LDFLAGS)\
	$(TOOL_$(tool)_LDFLAGS.$(bld_type))\
	$(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
	$(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
	$(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
	$(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
	$(foreach sdk, $(SDKS) \
	               $(SDKS.$(bld_type)) \
	               $(SDKS.$(bld_trg)) \
	               $(SDKS.$(bld_trg_arch)) \
	               $(SDKS.$(bld_trg).$(bld_trg_arch)),\
		$(SDK_$(sdk)_LDFLAGS)\
		$(SDK_$(sdk)_LDFLAGS.$(bld_type))\
		$(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
		$(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
		$(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
		$(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
	$(LDFLAGS)\
	$(LDFLAGS.$(bld_type))\
	$(LDFLAGS.$(bld_trg))\
	$(LDFLAGS.$(bld_trg_arch))\
	$(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
	$(LDFLAGS.$(bld_trg_cpu))\
	$(foreach sdk, $($(target)_SDKS) \
	               $($(target)_SDKS.$(bld_type)) \
	               $($(target)_SDKS.$(bld_trg)) \
	               $($(target)_SDKS.$(bld_trg_arch)) \
	               $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
		$(SDK_$(sdk)_LDFLAGS)\
		$(SDK_$(sdk)_LDFLAGS.$(bld_type))\
		$(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
		$(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
		$(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
		$(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
	$($(target)_LDFLAGS)\
	$($(target)_LDFLAGS.$(bld_type))\
	$($(target)_LDFLAGS.$(bld_trg))\
	$($(target)_LDFLAGS.$(bld_trg_arch))\
	$($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
	$($(target)_LDFLAGS.$(bld_trg_cpu))
local libs        :=\
	$($(target)_LIBS.$(bld_trg_cpu))\
	$($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
	$($(target)_LIBS.$(bld_trg_arch))\
	$($(target)_LIBS.$(bld_trg))\
	$($(target)_LIBS.$(bld_type))\
	$($(target)_LIBS)\
	$(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
		       $($(target)_SDKS.$(bld_trg_arch)) \
		       $($(target)_SDKS.$(bld_trg)) \
		       $($(target)_SDKS.$(bld_type)) \
		       $($(target)_SDKS),\
		$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
		$(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
		$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
		$(SDK_$(sdk)_LIBS.$(bld_trg))\
		$(SDK_$(sdk)_LIBS.$(bld_type))\
		$(SDK_$(sdk)_LIBS))\
	$(LIBS.$(bld_trg_cpu))\
	$(LIBS.$(bld_trg).$(bld_trg_arch))\
	$(LIBS.$(bld_trg_arch))\
	$(LIBS.$(bld_trg))\
	$(LIBS.$(bld_type))\
	$(LIBS)\
	$(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
	               $(SDKS.$(bld_trg_arch)) \
	               $(SDKS.$(bld_trg)) \
	               $(SDKS.$(bld_type)) \
	               $(SDKS),\
		$(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
		$(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
		$(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
		$(SDK_$(sdk)_LIBS.$(bld_trg))\
		$(SDK_$(sdk)_LIBS.$(bld_type))\
		$(SDK_$(sdk)_LIBS))\
	$(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
	$(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
	$(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
	$(TOOL_$(tool)_LIBS.$(bld_trg))\
	$(TOOL_$(tool)_LIBS.$(bld_type))\
	$(TOOL_$(tool)_LIBS)
local libpath    :=\
	$($(target)_LIBPATH.$(bld_trg_cpu))\
	$($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
	$($(target)_LIBPATH.$(bld_trg_arch))\
	$($(target)_LIBPATH.$(bld_trg))\
	$($(target)_LIBPATH.$(bld_type))\
	$($(target)_LIBPATH)\
	$(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
		       $($(target)_SDKS.$(bld_trg_arch)) \
		       $($(target)_SDKS.$(bld_trg)) \
		       $($(target)_SDKS.$(bld_type)) \
		       $($(target)_SDKS),\
		$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
		$(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
		$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
		$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
		$(SDK_$(sdk)_LIBPATH.$(bld_type))\
		$(SDK_$(sdk)_LIBPATH))\
	$(LIBPATH.$(bld_trg_cpu))\
	$(LIBPATH.$(bld_trg).$(bld_trg_arch))\
	$(LIBPATH.$(bld_trg_arch))\
	$(LIBPATH.$(bld_trg))\
	$(LIBPATH.$(bld_type))\
	$(LIBPATH)\
	$(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
	               $(SDKS.$(bld_trg_arch)) \
	               $(SDKS.$(bld_trg)) \
	               $(SDKS.$(bld_type)) \
	               $(SDKS),\
		$(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
		$(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
		$(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
		$(SDK_$(sdk)_LIBPATH.$(bld_trg))\
		$(SDK_$(sdk)_LIBPATH.$(bld_type))\
		$(SDK_$(sdk)_LIBPATH))\
	$(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
	$(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
	$(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
	$(TOOL_$(tool)_LIBPATH.$(bld_trg))\
	$(TOOL_$(tool)_LIBPATH.$(bld_type))\
	$(TOOL_$(tool)_LIBPATH)
local dirdep      := $(call DIRDEP,$(dir $(out)))
local deps        := \
	$($(target)_DEPS.$(bld_trg_cpu)) \
	$($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_DEPS.$(bld_trg).$(bld_type)) \
	$($(target)_DEPS.$(bld_trg_arch)) \
	$($(target)_DEPS.$(bld_trg)) \
	$($(target)_DEPS.$(bld_type)) \
	$($(target)_DEPS) \
	$($(target)_LNK_DEPS.$(bld_trg_cpu)) \
	$($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
	$($(target)_LNK_DEPS.$(bld_trg_arch)) \
	$($(target)_LNK_DEPS.$(bld_trg)) \
	$($(target)_LNK_DEPS.$(bld_type)) \
	$($(target)_LNK_DEPS)
local orderdeps   := \
	$($(target)_ORDERDEPS.$(bld_trg_cpu)) \
	$($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
	$($(target)_ORDERDEPS.$(bld_trg_arch)) \
	$($(target)_ORDERDEPS.$(bld_trg)) \
	$($(target)_ORDERDEPS.$(bld_type)) \
	$($(target)_ORDERDEPS) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
	$($(target)_LNK_ORDERDEPS.$(bld_trg)) \
	$($(target)_LNK_ORDERDEPS.$(bld_type)) \
	$($(target)_LNK_ORDERDEPS)

# Adjust paths if we got a default path.
ifneq ($(defpath),)
 local libpath    := $(abspathex $(libpath),$(defpath))
 local deps       := $(abspathex $(deps),$(defpath))
 local orderdeps  := $(abspathex $(orderdeps),$(defpath))
 othersrc := $(abspathex $(othersrc),$(defpath))
 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
endif

# Debug info.
local ld_debug      := $(evalcall def_fn_prop_get_first_defined,LD_DEBUG)
local debug_inst    := $(evalcall def_fn_prop_get_first_defined,DEBUG_INST)
local debug_stage   := $(evalcall def_fn_prop_get_first_defined,DEBUG_STAGE)
local debug_nostage := $(evalcall def_fn_prop_get_first_word,DEBUG_NOSTAGE)

# Custom pre/post-link actions.
996 997
local pre_cmds      := $(evalcall def_fn_prop_get_all_prefixed_priority_last,PRE_CMDS,$(NLTAB))
local post_cmds     := $(evalcall def_fn_prop_get_all_prefixed_priority_last,POST_CMDS,$(NLTAB))
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040

# eliminate this guy?
local objs = $($(target)_2_OBJS)

# dependency file
local dep := $(outbase)$(SUFF_DEP)
ifndef NO_LINK_CMDS_DEPS
 _DEPFILES_INCLUDED += $(dep)
 ifdef KB_HAVE_INCLUDEDEP_QUEUE
  includedep-queue $(dep)
 else
  includedep $(dep)
 endif
endif

# check that the tool is defined.
ifndef TOOL_$(tool)_$(tool_do)_CMDS
$(warning kBuild: tools: \
	1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
	2 $($(target)_$(source)TOOL.$(bld_trg)) \
	3 $($(target)_$(source)TOOL) \
	4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
	5 $($(target)_TOOL.$(bld_trg)) \
	6 $($(target)_TOOL) \
	7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
	8 $($(source)TOOL.$(bld_trg)) \
	9 $($(source)TOOL) \
	10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
	11 $(TOOL.$(bld_trg)) \
	12 $(TOOL) )
$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
endif

# call the tool
local cmds   := $(TOOL_$(tool)_$(tool_do)_CMDS)
ifneq ($(pre_cmds),)
 local cmds  := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
endif
ifneq ($(post_cmds),)
 local cmds  := $(cmds)$(NL)$(TAB)$(post_cmds)
endif
$(target)_2_OUTPUT              := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
$(target)_2_OUTPUT_MAYBE        := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
1041
$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE_PRECIOUS)
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
if1of ($(ld_debug), split)
 $(target)_2_OUTPUT_DEBUG_FILES := $(filter-out %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
 $(target)_2_OUTPUT_DEBUG_DIRS  := $(filter     %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
else
 $(target)_2_OUTPUT_DEBUG_FILES :=
 $(target)_2_OUTPUT_DEBUG_DIRS  :=
endif
$(target)_2_DEPEND              := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_2_OBJS)
$(target)_2_DEPORD              := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)

# generate the link rule.
$(eval $(def_link_rule))

# installation targets
local target_type_mode :=
$(evalval def_target_install_only)

# Update globals.
_OBJS += $($(target)_2_OBJS)
1061
_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
_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))
_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))
_INSTALLS_FILES += $(INSTARGET_$(target))

endef # def_link_common
$(eval-opt-var def_link_common)


#
# BLDPROGS
#

# Process build programs.
EXT     := EXE
EXTPRE  := HOST
tool_do := LINK_PROGRAM
typevar := _BLDPROGS
mode    := 0755
bld_trg_base_var := PLATFORM
1081
$(foreach target, $(_ALL_BLDPROGS), $(evalvalctx def_link_common))
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098

ifdef KBUILD_PROFILE_SELF
 $(evalcall def_profile_self, done build program targets)
endif


#
# DLLS
#

# Process dlls
EXT     := DLL
EXTPRE  :=
tool_do := LINK_DLL
typevar := _DLLS
mode    := 0644
bld_trg_base_var := TARGET
1099
$(foreach target, $(_ALL_DLLS), $(evalvalctx def_link_common))
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118

ifdef KBUILD_PROFILE_SELF
 $(evalcall def_profile_self, done dll targets)
endif


#
# IMPORT LIBRARIES
#
#   - On OS/2 and windows these are libraries.
#   - On other platforms they are fake DLLs.
#
EXTPRE  :=
typevar := _IMPORT_LIBS
mode    := 0644
bld_trg_base_var := TARGET
ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
 EXT     := LIB
 tool_do := LINK_LIBRARY
1119
 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_lib))
1120 1121 1122
else
 EXT     := DLL
 tool_do := LINK_DLL
1123
 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_link_common))
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
endif

ifdef KBUILD_PROFILE_SELF
 $(evalcall def_profile_self, done import library targets)
endif


#
# PROGRAMS
#

# Process programs
EXT     := EXE
EXTPRE  :=
tool_do := LINK_PROGRAM
typevar := _PROGRAMS
mode    := 0755
bld_trg_base_var := TARGET
1142
$(foreach target, $(_ALL_PROGRAMS), $(evalvalctx def_link_common))
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159

ifdef KBUILD_PROFILE_SELF
 $(evalcall def_profile_self, done program targets)
endif


#
# SYSMODS
#

# Process sysmods
EXT     := SYS
EXTPRE  :=
tool_do := LINK_SYSMOD
typevar := _SYSMODS
mode    := 0644
bld_trg_base_var := TARGET
1160
$(foreach target, $(_ALL_SYSMODS), $(evalvalctx def_link_common))
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177

ifdef KBUILD_PROFILE_SELF
 $(evalcall def_profile_self, done sysmod targets)
endif


#
# MISCBINS
#

# Process MISCBINS
EXT     := BIN
EXTPRE  :=
tool_do := LINK_MISCBIN
typevar := _MISCBINS
mode    := 0644
bld_trg_base_var := TARGET
1178
$(foreach target, $(_ALL_MISCBINS), $(evalvalctx def_link_common))
1179 1180 1181 1182 1183

ifdef KBUILD_PROFILE_SELF
 $(evalcall def_profile_self, done misc binary targets)
endif