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

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

kmk,footer-pass2-compiling-targets.kmk: Optimize def_target_source_rule and the associated kb-src-one function. This ditches the .obj aliases, so use .o instead. [oops]

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