source: trunk/kBuild/footer-pass2-compiling-targets.kmk@ 2803

Last change on this file since 2803 was 2795, checked in by bird, 10 years ago

footer-pass2-compiling-targets.kmk,VCC100*: Introducing linker output variable OUTPUT_MAYBE_PRECIOUS for files that shouldn't be unconditionally deleted prior to linking. This way it's possible to keep the PATH_STAGE_LIB copy of an import library and only update it when there are real changes to the exports of the DLL we're linking, thus avoiding a relinking cascade.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 35.7 KB
RevLine 
[72]1# $Id: footer-pass2-compiling-targets.kmk 2795 2015-09-15 23:35:37Z bird $
2## @file
[2521]3# kBuild - Footer - Target lists - Pass 2 - Compiling Targets.
[72]4#
[1547]5
6#
[2726]7# Copyright (c) 2004-2014 knut st. osmundsen <bird-kBuild-spam-xiv@anduin.net>
[72]8#
9# This file is part of kBuild.
10#
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
[106]13# the Free Software Foundation; either version source of the License, or
[72]14# (at your option) any later version.
15#
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.
20#
21# You should have received a copy of the GNU General Public License
22# along with kBuild; if not, write to the Free Software
[353]23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
[72]24#
25#
[1547]26# As a special exception you are granted permission to include this file, via
[1599]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.
[1547]29# This exception does not however invalidate any other reasons why the makefile,
30# program, whatever should not be covered the GPL.
31#
32#
[72]33
34
35#
[73]36# Object processing.
37#
[72]38
[380]39## wrapper the compile command dependency check.
40ifndef NO_COMPILE_CMDS_DEPS
[2026]41 if1of ($(KMK_FEATURES),dot-must-make)
42 _DEP_COMPILE_CMDS =
43 # for debugging: $$(warning MUST_MAKE=$$$$(comp-cmds-ex $$$$($(target)_$(subst :,_,$(source))_CMDS_PREV_), $$$$(commands $$@)) -> $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE))
44 else
45 _DEP_COMPILE_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $(obj)),FORCE)
46 endif
[380]47else
[730]48 _DEP_COMPILE_CMDS =
[380]49endif
50
[2026]51
[749]52## Generates the rules for building a specific object, and the aliases
[380]53# for building a source file.
[353]54# @param $(obj) The object file.
[380]55define def_target_source_rule
[2026]56ifndef NO_COMPILE_CMDS_DEPS
57$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
58endif
[1012]59ifdef TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE
[2196]60_OUT_FILES += $(outbase).koc
[1030]61$(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
[1007]62 $($(target)_$(source)_DEPEND_) \
[1456]63 $(value _DEP_COMPILE_CMDS) \
[1007]64 | \
[1426]65 $($(target)_$(source)_DEPORD_) \
[2355]66 $$$$($(target)_INTERMEDIATES) \
67 $$$$($(target)_INTERMEDIATES.$(bld_trg)) \
68 $$$$($(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch)) \
69 $$$$($(target)_INTERMEDIATES.$(bld_trg_arch)) \
70 $$$$($(target)_INTERMEDIATES.$(bld_trg_cpu)) \
71 $$$$($(target)_INTERMEDIATES.$(bld_type))
[1496]72 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[1007]73else
[1030]74$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
[380]75 $($(target)_$(source)_DEPEND_) \
[1456]76 $(value _DEP_COMPILE_CMDS) \
[380]77 | \
[1426]78 $($(target)_$(source)_DEPORD_) \
[2355]79 $$$$($(target)_INTERMEDIATES) \
80 $$$$($(target)_INTERMEDIATES.$(bld_trg)) \
81 $$$$($(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch)) \
82 $$$$($(target)_INTERMEDIATES.$(bld_trg_arch)) \
83 $$$$($(target)_INTERMEDIATES.$(bld_trg_cpu)) \
84 $$$$($(target)_INTERMEDIATES.$(bld_type))
[1496]85 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[1012]86ifdef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
[1599]87 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
[1007]88endif
[1012]89endif
[412]90
[380]91$($(target)_$(source)_CMDS_)
92
93ifndef NO_COMPILE_CMDS_DEPS
[1496]94 %$$(QUIET2)$$(APPEND) '$(dep)'
[1520]95 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_CMDS_PREV_'
[1496]96 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(obj)'
97 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
[770]98endif
[380]99
[749]100$(basename $(notdir $(obj))).o: $(obj)
101$(basename $(notdir $(obj))).obj: $(obj)
[1496]102
[2234]103## @todo make this 'local cmds,output,output_maybe,depend and depord' in 0.2.x or when a new kb-src-one is added.
[1496]104$(target)_$(source)_CMDS_ :=
[2234]105$(target)_$(source)_OUTPUT_ :=
106$(target)_$(source)_OUTPUT_MAYBE_ :=
107$(target)_$(source)_DEPEND_ :=
108$(target)_$(source)_DEPORD_ :=
[1936]109endef # def_target_source_rule
110$(eval-opt-var def_target_source_rule)
[205]111
[353]112
[380]113## wrapper the link command dependency check.
[1502]114ifndef NO_LINK_CMDS_DEPS
[2026]115 if1of ($(KMK_FEATURES),dot-must-make)
116 _DEP_LINK_CMDS =
117 else
118 _DEP_LINK_CMDS = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $(out)),FORCE)
119 endif
[380]120else
[730]121 _DEP_LINK_CMDS =
[380]122endif
123
124## Generate the link rule for a target.
125# @param $(target) The normalized target name.
126# @param $(dirdep) Directories we depend upon begin created before linking.
127# @param $(dep) The name of the dependency file.
128# @param $(out)
[2234]129# @param $($(target)_2_OUTPUT) Output files from the link.
130# @param $($(target)_2_OUTPUT_MAYBE) Output files that the link may perhaps create.
[2795]131# @param $($(target)_2_OUTPUT_MAYBE_PRECIOUS) Output files that the link may perhaps create but shouldn't be deleted.
[2234]132# @param $($(target)_2_DEPEND) Dependencies.
133# @param $($(target)_2_DEPORD) Dependencies which should only affect build order.
[1496]134# @param $(cmds) The link commands.
[380]135# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
136define def_link_rule
[2531]137$$(call KB_FN_ASSERT_ABSPATH,out)
[2026]138ifndef NO_LINK_CMDS_DEPS
139$(out): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $$@),FORCE)
140endif
[2523]141$(out) \
142+ $($(target)_2_OUTPUT) \
143+ $($(target)_2_OUTPUT_DEBUG_FILES) \
144+ $($(target)_2_OUTPUT_DEBUG_DIRS) \
[2795]145+| $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) : \
[2234]146 $$$$($(target)_2_DEPEND) \
[1456]147 $(value _DEP_LINK_CMDS) \
[380]148 | \
[2234]149 $$$$($(target)_2_DEPORD)
[1496]150 %$$(call MSG_LINK,$(target),$$@,$(tool_do))
[2523]151 $$(QUIET)$$(RM) -f -- $(dep) $(out) $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_DEBUG_FILES)
152ifdef $(target)_2_OUTPUT_DEBUG_DIRS
153 $$(QUIET)$$(RM) -Rf -- $($(target)_2_OUTPUT_DEBUG_DIRS)
154endif
[412]155
[1496]156$(cmds)
[380]157
[524]158ifndef NO_LINK_CMDS_DEPS
[1496]159 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
160 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
161 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
[770]162endif
[380]163
[1686]164$(basename $(notdir $(out))):: $(out)
[719]165
[1936]166endef # def_link_rule
167$(eval-opt-var def_link_rule)
[380]168
169
170## Generate the link & lib install rule
[2475]171# Implicit parameters: target, out, $(target)_1_STAGE_TARGET, mode,
172# pre_install_cmds, post_install_cmds
[380]173define def_link_install_rule
[2531]174$$(call KB_FN_ASSERT_ABSPATH,$(target)_1_INST_TARGET)
[2488]175$($(target)_1_INST_TARGET): $(out) | $$$$(dir $$$$@)
[1496]176 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
[2475]177 $(pre_install_cmds)
178
[2225]179 $$(QUIET)$$(INSTALL) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
[2475]180 $(post_install_cmds)
[719]181
[2475]182endef
[380]183
[2475]184
185## Generate the link & lib stage installation rule
186# Implicit parameters: target, out, $(target)_1_STAGE_TARGET, mode,
187# pre_install_cmds, post_install_cmds
188define def_link_stage_rule
[2531]189$$(call KB_FN_ASSERT_ABSPATH,$(target)_1_STAGE_TARGET)
[2488]190$($(target)_1_STAGE_TARGET): $(out) | $$$$(dir $$$$@)
[2475]191 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
192 $(pre_install_cmds)
193
[2479]194 $$(QUIET)$$(INSTALL_STAGING) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
[2475]195 $(post_install_cmds)
196
197
198$(basename $(notdir $(out))):: $($(target)_1_STAGE_TARGET)
199
200endef
201
202
[1424]203## def_src_handler_*
204#
205# @{
206define def_src_handler_c
[1496]207local type := C
[1795]208 $(kb-src-one 2)
[1424]209endef
[73]210
[1424]211define def_src_handler_cxx
[1496]212local type := CXX
[1795]213 $(kb-src-one 2)
[1424]214endef
[73]215
[1424]216define def_src_handler_objc
[1496]217local type := OBJC
[1795]218 $(kb-src-one 2)
[1424]219endef
[1256]220
[2356]221define def_src_handler_objcxx
[2359]222local type := OBJCXX
[2356]223 $(kb-src-one 2)
224endef
225
[1424]226define def_src_handler_asm
[1496]227local type := AS
[1795]228 $(kb-src-one 2)
[1424]229endef
[353]230
[1424]231define def_src_handler_rc
[1496]232local type := RC
[1795]233 $(kb-src-one 2)
[1424]234endef
[641]235
[1424]236define def_src_handler_obj
[1434]237ifeq ($(defpath),)
[2080]238 $(target)_2_OBJS += $(source)
239else
240 $(target)_2_OBJS += $(abspathex $(source), $(defpath))
241endif
242endef
[1424]243## @}
[73]244
[1424]245## Handle one source.
246# .
247define def_src_handler_one
[1496]248local suff := $(suffix $(source))
249local src_handler := $(firstword $(filter $(suff):%, $($(target)_$(source)_SRC_HANDLERS) $($(source)_SRC_HANDLERS) $(target_src_handlers) ))
250local handler := $(patsubst $(suff):%,%,$(src_handler))
[1424]251ifneq ($(handler),)
[1625]252 $(evalvalctx $(handler))
[1424]253else
[1434]254 othersrc += $(source)
[1424]255endif
[2475]256endef # def_src_handler_one
[73]257
[1424]258## Generic macro for processing all target sources.
259# @param $(target) Normalized target name.
260# @param $(defpath)
261# @param much-more...
[2236]262# @returns othersrc, $(target)_2_OBJS, ++
[1424]263define def_target_sources
[1496]264local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
[1424]265$(foreach source,\
[1429]266 $($(target)_SOURCES)\
267 $($(target)_SOURCES.$(bld_trg))\
[2433]268 $($(target)_SOURCES.$(bld_trg).$(bld_type))\
[1429]269 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
[2433]270 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[1429]271 $($(target)_SOURCES.$(bld_trg_arch))\
272 $($(target)_SOURCES.$(bld_trg_cpu))\
273 $($(target)_SOURCES.$(bld_type))\
[2762]274 ,$(evalvalctx def_src_handler_one) )
[1621]275
276$(foreach source,\
277 $($(target)_GEN_SOURCES_)\
278 $($(target)_GEN_SOURCES_.$(bld_trg))\
[2433]279 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_type))\
[1621]280 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
[2433]281 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[1621]282 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
283 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
284 $($(target)_GEN_SOURCES_.$(bld_type))\
[2762]285 ,$(evalvalctx def_src_handler_one) )
[1936]286endef # def_target_sources
287$(eval-opt-var def_target_sources)
[1424]288
289
[2475]290##
[2523]291# Install a debug directory.
292# @param debug_dir The directory name.
293define def_link_install_debug_dir_rule
[2535]294local dir := $(debug_inst_path)/$(debug_inst2)$(debug_dir)
[2531]295$$(call KB_FN_ASSERT_ABSPATH,dir)
[2523]296$$(dir): | $$$$(dir $$$$(patsubst %/,%,$$$$@))
297 %$$(call MSG_INST_DIR,$$@)
298 $$(QUIET)$$(MKDIR) -p -- $$@
299$(target)_2_DEBUG_$(debug_var)_TARGET_DIRS += $$(dir)
300endef # def_link_install_debug_dir_rule
301
302##
[2531]303# Install a debug file.
[2523]304# @param debug_file Src=>Dst file pair.
305define def_link_install_debug_file_rule
[2535]306local dst := $(debug_inst_path)/$(debug_inst2)$(word 2, $(subst =>,$(SP),$(debug_file)))
[2531]307$$(call KB_FN_ASSERT_ABSPATH,dst)
308local src := $(word 1, $(subst =>,$(SP),$(debug_file)))
309$$(call KB_FN_ASSERT_ABSPATH,src)
310$$(dst): $$(src) | $$$$(dir $$$$@)
[2535]311 %$$(call MSG_INST_FILE,$$<,$$@)
[2523]312 $$(QUIET)$(debug_install_cmd) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $$< $$@
313$(target)_2_DEBUG_$(debug_var)_TARGET_FILES += $$(dst)
314endef # def_link_install_debug_file_rule
315
316##
[2531]317# Install debug info to $(debug_inst), where debug_inst can be a directory or
[2523]318# file (just like $(inst) and $(stage). Used for both staging and installing.
319define def_target_install_only_debug
320if "$(substr $(debug_inst),-1,1)" == "/"
321 if "$(debug_inst)" == "./"
[2535]322 local debug_inst2 :=
323 else
324 local debug_inst2 := $(debug_inst)
[2523]325 endif
326 local debug_dirs := $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_DIRS))
327 ifneq ($(strip $(root $(debug_dirs))),)
328 $(error kBuild: Bad tool? debug_dirs='$(debug_dirs)', expected all to be under '$(outbase)')
329 endif
330 local debug_files := $(foreach file, $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_FILES)) \
331 ,$($(target)_0_OUTDIR)/$(file)=>$(file))
332else
[2535]333 local debug_notdir:= $(notdir $(debug_inst))
334 local debug_inst2 := $(dir $(debug_inst))
335 local debug_files := $(call TOOL_$(tool)_$(tool_do)_DEBUG_INSTALL_FN,$(out),$(outbase),$(debug_notdir))
[2523]336 local debug_dirs := $(filter %/,$(debug_files))
337 local debug_files := $(filter-out %/,$(debug_files))
338endif
339$(foreach debug_dir, $(debug_dirs), $(eval $(def_link_install_debug_dir_rule)))
340$(foreach debug_file, $(debug_files), $(eval $(def_link_install_debug_file_rule)))
341endef
342
343
[2475]344## Generic macro for generating the install rule(s) for a target.
[219]345#
[353]346# @param $(target) Normalized target name.
347# @param $(out) The output file.
348# @param $(typevar) The name of the variable with all the root targets of its type.
[2481]349# @param $(target_type_mode) The default file mode implied by the target type.
[2475]350define def_target_install_only
[2551]351if1of ($($(target)_1_INSTTYPE) $($(target)_1_DEBUG_INSTTYPE), both stage)
352 # Determin common variables.
[2225]353 local mode := $(firstword \
354 $($(target)_MODE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
355 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
356 $($(target)_MODE.$(bld_trg).$(bld_type)) \
357 $($(target)_MODE.$(bld_trg_arch)) \
358 $($(target)_MODE.$(bld_trg)) \
359 $($(target)_MODE.$(bld_type)) \
[2483]360 $($(target)_MODE) \
361 $(target_type_mode) )
[2225]362 local uid := $(firstword \
363 $($(target)_UID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
364 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
365 $($(target)_UID.$(bld_trg).$(bld_type)) \
366 $($(target)_UID.$(bld_trg_arch)) \
367 $($(target)_UID.$(bld_trg)) \
368 $($(target)_UID.$(bld_type)) \
369 $($(target)_UID) )
370 local gid := $(firstword \
371 $($(target)_GID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
372 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
373 $($(target)_GID.$(bld_trg).$(bld_type)) \
374 $($(target)_GID.$(bld_trg_arch)) \
375 $($(target)_GID.$(bld_trg)) \
376 $($(target)_GID.$(bld_type)) \
377 $($(target)_GID) )
[2475]378 local pre_install_cmds := $(evalcall def_fn_prop_get_first_defined,PRE_INST_CMDS)
379 local post_install_cmds := $(evalcall def_fn_prop_get_first_defined,POST_INST_CMDS)
[2551]380endif
[219]381
[2551]382ifneq ($($(target)_1_INSTTYPE),none)
[2475]383 # Generate the rules
384 ifeq ($($(target)_1_INSTTYPE),both)
[353]385$(eval $(def_link_install_rule))
[2475]386 _INSTALLS_FILES += $($(target)_1_INST_TARGET)
[1697]387 endif
[2475]388$(eval $(def_link_stage_rule))
389 _STAGE_FILES += $($(target)_1_STAGE_TARGET)
390 $(typevar) += $($(target)_1_STAGE_TARGET)
391else # INSTTYPE == none
[1697]392 $(typevar) += $(out)
[2475]393endif # INSTTYPE == none
[353]394
[2523]395# Install debug info.
396$(target)_2_DEBUG_STAGE_TARGET_DIRS :=
397$(target)_2_DEBUG_STAGE_TARGET_FILES :=
398$(target)_2_DEBUG_INSTALL_TARGET_DIRS :=
399$(target)_2_DEBUG_INSTALL_TARGET_FILES :=
400
401if ( defined($(target)_2_OUTPUT_DEBUG_DIRS) \
402 || defined($(target)_2_OUTPUT_DEBUG_FILES) ) \
403 && "$($(target)_1_DEBUG_INSTTYPE)" != "none"
404 local mode := $(if $(mode),$(mode)$(COMMA)a-x,0644)
405
406 ifeq ($($(target)_1_DEBUG_INSTTYPE),both)
407 local debug_inst_path := $(PATH_INS)
408 local debug_install_cmd := $(INSTALL)
409 local debug_var := INSTALL
[2762]410 $(foreach debug_inst, $($(target)_1_DEBUG_INST), $(evalvalctx def_target_install_only_debug))
[2523]411 endif
412
413 local debug_inst_path := $(PATH_STAGE)
414 local debug_install_cmd := $(INSTALL_STAGING)
415 local debug_var := STAGE
416 if1of ($($(target)_1_DEBUG_INSTTYPE), stage both)
[2762]417 $(foreach debug_inst, $($(target)_1_DEBUG_STAGE), $(evalvalctx def_target_install_only_debug))
[2523]418 endif
419 if1of ($($(target)_1_INSTTYPE), stage both)
420 ifndef debug_nostage
[2762]421 $(foreach debug_inst,$($(target)_1_STAGE), $(evalvalctx def_target_install_only_debug))
[2523]422 endif
423 endif
424
425 _DEBUG_STAGE_DIRS += $($(target)_2_DEBUG_STAGE_TARGET_DIRS)
426 _DEBUG_STAGE_FILES += $($(target)_2_DEBUG_STAGE_TARGET_FILES)
427 _DEBUG_INSTALL_DIRS += $($(target)_2_DEBUG_INSTALL_TARGET_DIRS)
428 _DEBUG_INSTALL_FILES += $($(target)_2_DEBUG_INSTALL_TARGET_FILES)
429
430 $(basename $(notdir $(out))):: $($(target)_2_DEBUG_STAGE_TARGET_DIRS) $($(target)_2_DEBUG_STAGE_TARGET_FILES)
431endif
432
[2475]433endef # def_target_install_only
[353]434
[219]435
436
437#
[72]438# LIBRARIES
[73]439#
[72]440
441## Library (one).
[74]442# @param $(target) Normalized library (target) name.
[72]443define def_lib
[145]444# library basics
[222]445## @todo prefix
[1504]446local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
447local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
448local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
449local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
[1496]450local tool := $(call _TARGET_TOOL,$(target),AR)
[78]451ifeq ($(tool),)
[353]452$(error kBuild: Library target $(target) does not have a tool defined!)
[78]453endif
[1496]454local name := $(firstword\
[2433]455 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]456 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]457 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]458 $($(target)_NAME.$(bld_trg_arch))\
459 $($(target)_NAME.$(bld_trg))\
460 $($(target)_NAME.$(bld_type))\
461 $($(target)_NAME)\
462 $(target))
[1496]463local outbase := $(call TARGET_BASE,$(name),$(target))
[2239]464$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
[2436]465$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
[1496]466local suff := $(firstword\
[481]467 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]468 $($(target)_LIBSUFF.$(bld_trg))\
[126]469 $($(target)_LIBSUFF)\
[481]470 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]471 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]472 $(TOOL_$(tool)_ARLIBSUFF)\
[353]473 $(SUFF_LIB))
[1496]474local out := $(outbase)$(suff)
[2434]475local defpath := $($(target)_DEFPATH)
476ifeq ($(defpath),)
477 local defpath := $($(target)_PATH)
478endif
[2238]479$(target)_1_TARGET:= $(out)
[2436]480$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
[1496]481# no local here - must be writable across some foreachs.
482othersrc :=
[2236]483$(target)_2_OBJS :=
[145]484
[1672]485# Do units pre source callouts.
486local units := \
487 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
488 $($(target)_USES.$(bld_trg_arch))\
489 $($(target)_USES.$(bld_trg))\
490 $($(target)_USES.$(bld_type))\
491 $($(target)_USES)
[2762]492$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
[1672]493
[145]494# source -> object
[1496]495$(evalval def_target_sources)
[145]496
497# library linking
[1496]498local tool := $(call _TARGET_TOOL,$(target),AR)
499local name := $(firstword\
[2433]500 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]501 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]502 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]503 $($(target)_NAME.$(bld_trg_arch))\
504 $($(target)_NAME.$(bld_trg))\
505 $($(target)_NAME.$(bld_type))\
506 $($(target)_NAME)\
507 $(target))
[1496]508local outbase := $(call TARGET_BASE,$(name),$(target))
509local flags :=\
[74]510 $(TOOL_$(tool)_ARFLAGS)\
[221]511 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]512 $(ARFLAGS)\
[221]513 $(ARFLAGS.$(bld_type))\
[74]514 $($(target)_ARFLAGS)\
[481]515 $($(target)_ARFLAGS.$(bld_type)) \
516 $($(target)_ARFLAGS.$(bld_trg)) \
517 $($(target)_ARFLAGS.$(bld_trg_arch)) \
518 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
519 $($(target)_ARFLAGS.$(bld_trg_cpu))
[1496]520local dirdep := $(call DIRDEP,$(dir $(out)))
[1702]521local deps := \
522 $($(target)_DEPS.$(bld_trg_cpu)) \
523 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
524 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
525 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
526 $($(target)_DEPS.$(bld_trg_arch)) \
527 $($(target)_DEPS.$(bld_trg)) \
528 $($(target)_DEPS.$(bld_type)) \
529 $($(target)_DEPS) \
530 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
531 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
532 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
533 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
534 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
535 $($(target)_LNK_DEPS.$(bld_trg)) \
536 $($(target)_LNK_DEPS.$(bld_type)) \
537 $($(target)_LNK_DEPS)
538local orderdeps := \
539 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
540 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
541 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
542 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
543 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
544 $($(target)_ORDERDEPS.$(bld_trg)) \
545 $($(target)_ORDERDEPS.$(bld_type)) \
546 $($(target)_ORDERDEPS) \
547 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
548 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
549 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
550 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
551 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
552 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
553 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
554 $($(target)_LNK_ORDERDEPS)
[72]555
[725]556# Adjust paths if we got a default path.
557ifneq ($(defpath),)
[1496]558 local deps := $(abspathex $(deps),$(defpath))
559 local orderdeps := $(abspathex $(orderdeps),$(defpath))
[1472]560 othersrc := $(abspathex $(othersrc),$(defpath))
[725]561endif
562
[859]563
564# Custom pre-link actions.
[2475]565local pre_cmds := $(evalcall def_fn_prop_get_first_defined,PRE_CMDS)
566local post_cmds := $(evalcall def_fn_prop_get_first_defined,POST_CMDS)
[859]567
[1424]568# eliminate this guy?
[2236]569local objs = $($(target)_2_OBJS)
[1424]570
[380]571# dependency file
[1496]572local dep := $(out)$(SUFF_DEP)
[524]573ifndef NO_LINK_CMDS_DEPS
[1798]574 _DEPFILES_INCLUDED += $(dep)
575 ifdef KB_HAVE_INCLUDEDEP_QUEUE
576 includedep-queue $(dep)
[1795]577 else
[1798]578 includedep $(dep)
[1795]579 endif
[380]580endif
[72]581
[380]582# check that the tool is defined.
583ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
584$(warning kBuild: tools: \
[481]585 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
586 2 $($(target)_$(source)TOOL.$(bld_trg)) \
587 3 $($(target)_$(source)TOOL) \
588 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
589 5 $($(target)_TOOL.$(bld_trg)) \
590 6 $($(target)_TOOL) \
591 7 $($(source)TOOL) \
592 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
593 9 $($(source)TOOL.$(bld_trg)) \
594 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
595 11 $(TOOL.$(bld_trg)) \
596 12 $(TOOL) )
[380]597$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
598endif
599
600# call the tool
[2523]601local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
[859]602ifneq ($(pre_cmds),)
[1496]603 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
[859]604endif
605ifneq ($(post_cmds),)
[2523]606 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
[859]607endif
[2234]608$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
609$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
[2795]610$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE_PRECIOUS)
[2236]611$(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_2_OBJS)
[2234]612$(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
[380]613
[412]614# generate the link rule.
[380]615$(eval $(def_link_rule))
616
[2475]617# installing and globals.
[2483]618local target_type_mode := a+r,u+w
[2475]619$(evalval def_target_install_only)
620
[2795]621_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
[2475]622_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))
623_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))
624_OBJS += $($(target)_2_OBJS)
625
626endef # def_lib
[1936]627$(eval-opt-var def_lib)
[72]628
629# Process libraries
[859]630typevar := _LIBS
[776]631tool_do := LINK_LIBRARY
[380]632mode := 0644
[2762]633$(foreach target, $(_ALL_LIBRARIES), $(evalvalctx def_lib))
[72]634
[988]635ifdef KBUILD_PROFILE_SELF
[2008]636 $(evalcall def_profile_self, done library targets)
[988]637endif
[72]638
[988]639
[72]640#
[353]641# Link operations.
[72]642#
643
[353]644##
645# Link prolog
646#
647# @param $(target) Normalized target name.
648# @param $(EXT) EXE,DLL,SYS.
649# @param $(typevar) The name of the variable with all the root targets of its type.
[380]650define def_link_common
[353]651# basics
[1504]652local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
[1496]653local bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
654local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
655local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
[145]656
[1496]657local tool := $(call _TARGET_TOOL,$(target),LD)
658local name := $(firstword\
[2433]659 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]660 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]661 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]662 $($(target)_NAME.$(bld_trg_arch))\
663 $($(target)_NAME.$(bld_trg))\
664 $($(target)_NAME.$(bld_type))\
665 $($(target)_NAME)\
666 $(target))
[1496]667local outbase := $(call TARGET_BASE,$(name),$(target))
[2239]668$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
[2436]669$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
[2143]670local suff := $(firstword \
671 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
672 $($(target)_$(EXT)SUFF.$(bld_trg))\
673 $($(target)_$(EXT)SUFF)\
674 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
675 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg))\
676 $(TOOL_$(tool)_LD$(EXT)SUFF)\
677 $($(EXTPRE)SUFF_$(EXT)) )
[1496]678local out := $(outbase)$(suff)
[2238]679$(target)_1_TARGET:= $(out)
[2436]680$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
[2434]681local defpath := $($(target)_DEFPATH)
682ifeq ($(defpath),)
683 local defpath := $($(target)_PATH)
684endif
[1496]685# no local here - must be writable across some foreachs.
686othersrc :=
[2236]687$(target)_2_OBJS :=
[353]688
[1672]689# Do units pre source callouts.
690local units := \
691 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
692 $($(target)_USES.$(bld_trg_arch))\
693 $($(target)_USES.$(bld_trg))\
694 $($(target)_USES.$(bld_type))\
695 $($(target)_USES)
[2762]696$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
[1672]697
[145]698# source -> object
[1496]699$(evalval def_target_sources)
[145]700
[744]701# more link stuff.
[1496]702local tool := $(call _TARGET_TOOL,$(target),LD)
703local name := $(firstword\
[2433]704 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]705 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]706 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]707 $($(target)_NAME.$(bld_trg_arch))\
708 $($(target)_NAME.$(bld_trg))\
709 $($(target)_NAME.$(bld_type))\
710 $($(target)_NAME)\
711 $(target))
[1496]712local outbase := $(call TARGET_BASE,$(name),$(target))
713local flags :=\
[74]714 $(TOOL_$(tool)_LDFLAGS)\
[221]715 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
716 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
717 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]718 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]719 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[1242]720 $(foreach sdk, $(SDKS) \
721 $(SDKS.$(bld_type)) \
722 $(SDKS.$(bld_trg)) \
723 $(SDKS.$(bld_trg_arch)) \
724 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
725 $(SDK_$(sdk)_LDFLAGS)\
726 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
727 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
728 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
729 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
730 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]731 $(LDFLAGS)\
[221]732 $(LDFLAGS.$(bld_type))\
733 $(LDFLAGS.$(bld_trg))\
734 $(LDFLAGS.$(bld_trg_arch))\
[481]735 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]736 $(LDFLAGS.$(bld_trg_cpu))\
[1242]737 $(foreach sdk, $($(target)_SDKS) \
738 $($(target)_SDKS.$(bld_type)) \
739 $($(target)_SDKS.$(bld_trg)) \
740 $($(target)_SDKS.$(bld_trg_arch)) \
741 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
742 $(SDK_$(sdk)_LDFLAGS)\
743 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
744 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
745 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
746 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
747 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]748 $($(target)_LDFLAGS)\
[221]749 $($(target)_LDFLAGS.$(bld_type))\
750 $($(target)_LDFLAGS.$(bld_trg))\
751 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]752 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]753 $($(target)_LDFLAGS.$(bld_trg_cpu))
[1496]754local libs :=\
[221]755 $($(target)_LIBS.$(bld_trg_cpu))\
[481]756 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]757 $($(target)_LIBS.$(bld_trg_arch))\
758 $($(target)_LIBS.$(bld_trg))\
759 $($(target)_LIBS.$(bld_type))\
[74]760 $($(target)_LIBS)\
[592]761 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
762 $($(target)_SDKS.$(bld_trg_arch)) \
763 $($(target)_SDKS.$(bld_trg)) \
764 $($(target)_SDKS.$(bld_type)) \
765 $($(target)_SDKS),\
[353]766 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]767 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]768 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
769 $(SDK_$(sdk)_LIBS.$(bld_trg))\
770 $(SDK_$(sdk)_LIBS.$(bld_type))\
771 $(SDK_$(sdk)_LIBS))\
[221]772 $(LIBS.$(bld_trg_cpu))\
[481]773 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]774 $(LIBS.$(bld_trg_arch))\
775 $(LIBS.$(bld_trg))\
776 $(LIBS.$(bld_type))\
[74]777 $(LIBS)\
[592]778 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
779 $(SDKS.$(bld_trg_arch)) \
780 $(SDKS.$(bld_trg)) \
781 $(SDKS.$(bld_type)) \
782 $(SDKS),\
[353]783 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]784 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]785 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
786 $(SDK_$(sdk)_LIBS.$(bld_trg))\
787 $(SDK_$(sdk)_LIBS.$(bld_type))\
788 $(SDK_$(sdk)_LIBS))\
[221]789 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]790 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]791 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
792 $(TOOL_$(tool)_LIBS.$(bld_trg))\
793 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]794 $(TOOL_$(tool)_LIBS)
[1496]795local libpath :=\
[221]796 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]797 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]798 $($(target)_LIBPATH.$(bld_trg_arch))\
799 $($(target)_LIBPATH.$(bld_trg))\
800 $($(target)_LIBPATH.$(bld_type))\
[74]801 $($(target)_LIBPATH)\
[592]802 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
803 $($(target)_SDKS.$(bld_trg_arch)) \
804 $($(target)_SDKS.$(bld_trg)) \
805 $($(target)_SDKS.$(bld_type)) \
806 $($(target)_SDKS),\
[353]807 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]808 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]809 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
810 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
811 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
812 $(SDK_$(sdk)_LIBPATH))\
[221]813 $(LIBPATH.$(bld_trg_cpu))\
[481]814 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]815 $(LIBPATH.$(bld_trg_arch))\
816 $(LIBPATH.$(bld_trg))\
817 $(LIBPATH.$(bld_type))\
[74]818 $(LIBPATH)\
[592]819 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
820 $(SDKS.$(bld_trg_arch)) \
821 $(SDKS.$(bld_trg)) \
822 $(SDKS.$(bld_type)) \
823 $(SDKS),\
[353]824 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]825 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]826 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
827 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
828 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
829 $(SDK_$(sdk)_LIBPATH))\
[221]830 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]831 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]832 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
833 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
834 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]835 $(TOOL_$(tool)_LIBPATH)
[1496]836local dirdep := $(call DIRDEP,$(dir $(out)))
[1702]837local deps := \
838 $($(target)_DEPS.$(bld_trg_cpu)) \
839 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
840 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
841 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
842 $($(target)_DEPS.$(bld_trg_arch)) \
843 $($(target)_DEPS.$(bld_trg)) \
844 $($(target)_DEPS.$(bld_type)) \
845 $($(target)_DEPS) \
846 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
847 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
848 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
849 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
850 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
851 $($(target)_LNK_DEPS.$(bld_trg)) \
852 $($(target)_LNK_DEPS.$(bld_type)) \
853 $($(target)_LNK_DEPS)
854local orderdeps := \
855 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
856 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
857 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
858 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
859 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
860 $($(target)_ORDERDEPS.$(bld_trg)) \
861 $($(target)_ORDERDEPS.$(bld_type)) \
862 $($(target)_ORDERDEPS) \
863 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
864 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
865 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
866 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
867 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
868 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
869 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
870 $($(target)_LNK_ORDERDEPS)
[353]871
[725]872# Adjust paths if we got a default path.
873ifneq ($(defpath),)
[1496]874 local libpath := $(abspathex $(libpath),$(defpath))
875 local deps := $(abspathex $(deps),$(defpath))
876 local orderdeps := $(abspathex $(orderdeps),$(defpath))
[1472]877 othersrc := $(abspathex $(othersrc),$(defpath))
[1755]878 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
[725]879endif
880
[2523]881# Debug info.
882local ld_debug := $(evalcall def_fn_prop_get_first_defined,LD_DEBUG)
883local debug_inst := $(evalcall def_fn_prop_get_first_defined,DEBUG_INST)
884local debug_stage := $(evalcall def_fn_prop_get_first_defined,DEBUG_STAGE)
885local debug_nostage := $(evalcall def_fn_prop_get_first_word,DEBUG_NOSTAGE)
886
[2475]887# Custom pre/post-link actions.
[2523]888local pre_cmds := $(evalcall def_fn_prop_get_first_defined,PRE_CMDS)
889local post_cmds := $(evalcall def_fn_prop_get_first_defined,POST_CMDS)
[72]890
[1424]891# eliminate this guy?
[2236]892local objs = $($(target)_2_OBJS)
[1424]893
[380]894# dependency file
[1496]895local dep := $(outbase)$(SUFF_DEP)
[524]896ifndef NO_LINK_CMDS_DEPS
[2188]897 _DEPFILES_INCLUDED += $(dep)
[1798]898 ifdef KB_HAVE_INCLUDEDEP_QUEUE
899 includedep-queue $(dep)
[1795]900 else
[1798]901 includedep $(dep)
[1795]902 endif
[380]903endif
[353]904
[380]905# check that the tool is defined.
906ifndef TOOL_$(tool)_$(tool_do)_CMDS
907$(warning kBuild: tools: \
[481]908 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
909 2 $($(target)_$(source)TOOL.$(bld_trg)) \
910 3 $($(target)_$(source)TOOL) \
911 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
912 5 $($(target)_TOOL.$(bld_trg)) \
913 6 $($(target)_TOOL) \
914 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
915 8 $($(source)TOOL.$(bld_trg)) \
916 9 $($(source)TOOL) \
917 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
918 11 $(TOOL.$(bld_trg)) \
919 12 $(TOOL) )
[380]920$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
921endif
[353]922
[380]923# call the tool
[1496]924local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
[859]925ifneq ($(pre_cmds),)
[1496]926 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
[859]927endif
928ifneq ($(post_cmds),)
[1496]929 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
[859]930endif
[2523]931$(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
932$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
[2795]933$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE_PRECIOUS)
[2523]934if1of ($(ld_debug), split)
935 $(target)_2_OUTPUT_DEBUG_FILES := $(filter-out %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
936 $(target)_2_OUTPUT_DEBUG_DIRS := $(filter %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
937else
938 $(target)_2_OUTPUT_DEBUG_FILES :=
939 $(target)_2_OUTPUT_DEBUG_DIRS :=
940endif
941$(target)_2_DEPEND := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_2_OBJS)
942$(target)_2_DEPORD := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
[353]943
[412]944# generate the link rule.
[380]945$(eval $(def_link_rule))
946
[2523]947# installation targets
948local target_type_mode :=
949$(evalval def_target_install_only)
[412]950
[380]951# Update globals.
[2236]952_OBJS += $($(target)_2_OBJS)
[2795]953_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
[905]954_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))
955_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))
[827]956_INSTALLS_FILES += $(INSTARGET_$(target))
[353]957
[1936]958endef # def_link_common
959$(eval-opt-var def_link_common)
[353]960
961
962#
963# BLDPROGS
964#
965
966# Process build programs.
967EXT := EXE
968EXTPRE := HOST
[380]969tool_do := LINK_PROGRAM
[353]970typevar := _BLDPROGS
[380]971mode := 0755
[353]972bld_trg_base_var := PLATFORM
[2762]973$(foreach target, $(_ALL_BLDPROGS), $(evalvalctx def_link_common))
[353]974
[988]975ifdef KBUILD_PROFILE_SELF
[2008]976 $(evalcall def_profile_self, done build program targets)
[988]977endif
[353]978
979
980#
981# DLLS
982#
983
[189]984# Process dlls
[353]985EXT := DLL
986EXTPRE :=
[380]987tool_do := LINK_DLL
[353]988typevar := _DLLS
[830]989mode := 0644
[353]990bld_trg_base_var := TARGET
[2762]991$(foreach target, $(_ALL_DLLS), $(evalvalctx def_link_common))
[74]992
[988]993ifdef KBUILD_PROFILE_SELF
[2008]994 $(evalcall def_profile_self, done dll targets)
[988]995endif
[74]996
[988]997
[72]998#
[830]999# IMPORT LIBRARIES
[72]1000#
[219]1001# - On OS/2 and windows these are libraries.
[189]1002# - On other platforms they are fake DLLs.
[830]1003#
1004EXTPRE :=
1005typevar := _IMPORT_LIBS
1006mode := 0644
1007bld_trg_base_var := TARGET
[1504]1008ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
[830]1009 EXT := LIB
1010 tool_do := LINK_LIBRARY
[2762]1011 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_lib))
[189]1012else
[830]1013 EXT := DLL
1014 tool_do := LINK_DLL
[2762]1015 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_link_common))
[189]1016endif
[72]1017
[988]1018ifdef KBUILD_PROFILE_SELF
[2008]1019 $(evalcall def_profile_self, done import library targets)
[988]1020endif
[189]1021
[988]1022
[189]1023#
1024# PROGRAMS
1025#
1026
[353]1027# Process programs
1028EXT := EXE
1029EXTPRE :=
[380]1030tool_do := LINK_PROGRAM
[353]1031typevar := _PROGRAMS
[380]1032mode := 0755
[353]1033bld_trg_base_var := TARGET
[2762]1034$(foreach target, $(_ALL_PROGRAMS), $(evalvalctx def_link_common))
[130]1035
[988]1036ifdef KBUILD_PROFILE_SELF
[2008]1037 $(evalcall def_profile_self, done program targets)
[988]1038endif
[130]1039
[189]1040
[72]1041#
[83]1042# SYSMODS
[72]1043#
1044
[130]1045# Process sysmods
[353]1046EXT := SYS
1047EXTPRE :=
[380]1048tool_do := LINK_SYSMOD
[353]1049typevar := _SYSMODS
[380]1050mode := 0644
[353]1051bld_trg_base_var := TARGET
[2762]1052$(foreach target, $(_ALL_SYSMODS), $(evalvalctx def_link_common))
[83]1053
[988]1054ifdef KBUILD_PROFILE_SELF
[2008]1055 $(evalcall def_profile_self, done sysmod targets)
[988]1056endif
[83]1057
[988]1058
[72]1059#
[2084]1060# MISCBINS
1061#
1062
1063# Process MISCBINS
1064EXT := BIN
1065EXTPRE :=
1066tool_do := LINK_MISCBIN
1067typevar := _MISCBINS
1068mode := 0644
1069bld_trg_base_var := TARGET
[2762]1070$(foreach target, $(_ALL_MISCBINS), $(evalvalctx def_link_common))
[2084]1071
1072ifdef KBUILD_PROFILE_SELF
1073 $(evalcall def_profile_self, done misc binary targets)
1074endif
1075
Note: See TracBrowser for help on using the repository browser.