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

Last change on this file since 3256 was 3256, checked in by bird, 7 years ago

GXX3.kmk,footer*.kmk: Turns out pch + kObjCache actually does help with build performance. Working on making the kObjCache bits more flexible by introducing a target level use_objcache variable during expansion.

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