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

Last change on this file since 3500 was 3415, checked in by bird, 5 years ago

kmk: Fixed mixup from r2433 where _TARGET_TOOL was extended but the builtin source handling functions wasn't. For instance, using _TOOLS, _TOOLS.amd64 and _TOOLS.x86, we would end up with the first when compiling and one of the latter two when linking. Also replaced a few legacy BUILD_PLATFORM* with KBUILD_HOST* variable names in the footers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.8 KB
RevLine 
[72]1# $Id: footer-pass2-compiling-targets.kmk 3415 2020-08-20 23:43:33Z bird $
2## @file
[2521]3# kBuild - Footer - Target lists - Pass 2 - Compiling Targets.
[72]4#
[1547]5
6#
[3285]7# Copyright (c) 2004-2019 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
[3284]94$$(outbase).koc +| $$(obj) $$(kbsrc_output) $$(kbsrc_output_maybe) : $$(kbsrc_depend) | $$(kbsrc_depord) $(target_intermediate_vars)
[3278]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
[3280]137$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
[3279]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
[3415]272 $(kb-src-one 4)
[1424]273endef
[73]274
[1424]275define def_src_handler_cxx
[1496]276local type := CXX
[3415]277 $(kb-src-one 4)
[1424]278endef
[73]279
[1424]280define def_src_handler_objc
[1496]281local type := OBJC
[3415]282 $(kb-src-one 4)
[1424]283endef
[1256]284
[2356]285define def_src_handler_objcxx
[2359]286local type := OBJCXX
[3415]287 $(kb-src-one 4)
[2356]288endef
289
[1424]290define def_src_handler_asm
[1496]291local type := AS
[3415]292 $(kb-src-one 4)
[1424]293endef
[353]294
[1424]295define def_src_handler_rc
[1496]296local type := RC
[3415]297 $(kb-src-one 4)
[1424]298endef
[641]299
[3344]300ifdef KMK_WITH_QUOTING
[1424]301define def_src_handler_obj
[1434]302ifeq ($(defpath),)
[2080]303 $(target)_2_OBJS += $(source)
304else
[3344]305 $(target)_2_OBJS += $(qabspathex ,$(source), $(defpath))
306endif
307endef
308else
309define def_src_handler_obj
310ifeq ($(defpath),)
311 $(target)_2_OBJS += $(source)
312else
[2080]313 $(target)_2_OBJS += $(abspathex $(source), $(defpath))
314endif
315endef
[3344]316endif
[1424]317## @}
[73]318
[1424]319## Handle one source.
320# .
321define def_src_handler_one
[1496]322local suff := $(suffix $(source))
323local src_handler := $(firstword $(filter $(suff):%, $($(target)_$(source)_SRC_HANDLERS) $($(source)_SRC_HANDLERS) $(target_src_handlers) ))
324local handler := $(patsubst $(suff):%,%,$(src_handler))
[1424]325ifneq ($(handler),)
[1625]326 $(evalvalctx $(handler))
[1424]327else
[1434]328 othersrc += $(source)
[1424]329endif
[2475]330endef # def_src_handler_one
[73]331
[1424]332## Generic macro for processing all target sources.
333# @param $(target) Normalized target name.
334# @param $(defpath)
335# @param much-more...
[2236]336# @returns othersrc, $(target)_2_OBJS, ++
[3344]337ifdef KMK_WITH_QUOTING
[1424]338define def_target_sources
[1496]339local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
[3344]340$(foreachfile source,\
341 $($(target)_SOURCES)\
342 $($(target)_SOURCES.$(bld_trg))\
343 $($(target)_SOURCES.$(bld_trg).$(bld_type))\
344 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
345 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch).$(bld_type))\
346 $($(target)_SOURCES.$(bld_trg_arch))\
347 $($(target)_SOURCES.$(bld_trg_cpu))\
348 $($(target)_SOURCES.$(bld_type))\
349 ,$(evalvalctx def_src_handler_one) )
350
351$(foreachfile source,\
352 $($(target)_GEN_SOURCES_)\
353 $($(target)_GEN_SOURCES_.$(bld_trg))\
354 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_type))\
355 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
356 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch).$(bld_type))\
357 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
358 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
359 $($(target)_GEN_SOURCES_.$(bld_type))\
360 ,$(evalvalctx def_src_handler_one) )
361endef # def_target_sources
362else
363define def_target_sources
364local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
[1424]365$(foreach source,\
[1429]366 $($(target)_SOURCES)\
367 $($(target)_SOURCES.$(bld_trg))\
[2433]368 $($(target)_SOURCES.$(bld_trg).$(bld_type))\
[1429]369 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
[2433]370 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[1429]371 $($(target)_SOURCES.$(bld_trg_arch))\
372 $($(target)_SOURCES.$(bld_trg_cpu))\
373 $($(target)_SOURCES.$(bld_type))\
[2762]374 ,$(evalvalctx def_src_handler_one) )
[1621]375
376$(foreach source,\
377 $($(target)_GEN_SOURCES_)\
378 $($(target)_GEN_SOURCES_.$(bld_trg))\
[2433]379 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_type))\
[1621]380 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
[2433]381 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[1621]382 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
383 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
384 $($(target)_GEN_SOURCES_.$(bld_type))\
[2762]385 ,$(evalvalctx def_src_handler_one) )
[1936]386endef # def_target_sources
[3344]387endif
[1936]388$(eval-opt-var def_target_sources)
[1424]389
390
[2475]391##
[2523]392# Install a debug directory.
393# @param debug_dir The directory name.
394define def_link_install_debug_dir_rule
[2535]395local dir := $(debug_inst_path)/$(debug_inst2)$(debug_dir)
[2531]396$$(call KB_FN_ASSERT_ABSPATH,dir)
[2523]397$$(dir): | $$$$(dir $$$$(patsubst %/,%,$$$$@))
398 %$$(call MSG_INST_DIR,$$@)
399 $$(QUIET)$$(MKDIR) -p -- $$@
400$(target)_2_DEBUG_$(debug_var)_TARGET_DIRS += $$(dir)
401endef # def_link_install_debug_dir_rule
402
403##
[2531]404# Install a debug file.
[2523]405# @param debug_file Src=>Dst file pair.
406define def_link_install_debug_file_rule
[2535]407local dst := $(debug_inst_path)/$(debug_inst2)$(word 2, $(subst =>,$(SP),$(debug_file)))
[2531]408$$(call KB_FN_ASSERT_ABSPATH,dst)
409local src := $(word 1, $(subst =>,$(SP),$(debug_file)))
410$$(call KB_FN_ASSERT_ABSPATH,src)
411$$(dst): $$(src) | $$$$(dir $$$$@)
[2535]412 %$$(call MSG_INST_FILE,$$<,$$@)
[2523]413 $$(QUIET)$(debug_install_cmd) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $$< $$@
414$(target)_2_DEBUG_$(debug_var)_TARGET_FILES += $$(dst)
415endef # def_link_install_debug_file_rule
416
417##
[2531]418# Install debug info to $(debug_inst), where debug_inst can be a directory or
[2523]419# file (just like $(inst) and $(stage). Used for both staging and installing.
420define def_target_install_only_debug
421if "$(substr $(debug_inst),-1,1)" == "/"
422 if "$(debug_inst)" == "./"
[2535]423 local debug_inst2 :=
424 else
425 local debug_inst2 := $(debug_inst)
[2523]426 endif
427 local debug_dirs := $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_DIRS))
428 ifneq ($(strip $(root $(debug_dirs))),)
429 $(error kBuild: Bad tool? debug_dirs='$(debug_dirs)', expected all to be under '$(outbase)')
430 endif
431 local debug_files := $(foreach file, $(patsubst $($(target)_0_OUTDIR)/%,%,$($(target)_2_OUTPUT_DEBUG_FILES)) \
432 ,$($(target)_0_OUTDIR)/$(file)=>$(file))
433else
[2535]434 local debug_notdir:= $(notdir $(debug_inst))
435 local debug_inst2 := $(dir $(debug_inst))
436 local debug_files := $(call TOOL_$(tool)_$(tool_do)_DEBUG_INSTALL_FN,$(out),$(outbase),$(debug_notdir))
[2523]437 local debug_dirs := $(filter %/,$(debug_files))
438 local debug_files := $(filter-out %/,$(debug_files))
439endif
440$(foreach debug_dir, $(debug_dirs), $(eval $(def_link_install_debug_dir_rule)))
441$(foreach debug_file, $(debug_files), $(eval $(def_link_install_debug_file_rule)))
442endef
443
444
[2475]445## Generic macro for generating the install rule(s) for a target.
[219]446#
[353]447# @param $(target) Normalized target name.
448# @param $(out) The output file.
449# @param $(typevar) The name of the variable with all the root targets of its type.
[2481]450# @param $(target_type_mode) The default file mode implied by the target type.
[2475]451define def_target_install_only
[2551]452if1of ($($(target)_1_INSTTYPE) $($(target)_1_DEBUG_INSTTYPE), both stage)
453 # Determin common variables.
[2225]454 local mode := $(firstword \
455 $($(target)_MODE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
456 $($(target)_MODE.$(bld_trg).$(bld_trg_arch)) \
457 $($(target)_MODE.$(bld_trg).$(bld_type)) \
458 $($(target)_MODE.$(bld_trg_arch)) \
459 $($(target)_MODE.$(bld_trg)) \
460 $($(target)_MODE.$(bld_type)) \
[2483]461 $($(target)_MODE) \
462 $(target_type_mode) )
[2225]463 local uid := $(firstword \
464 $($(target)_UID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
465 $($(target)_UID.$(bld_trg).$(bld_trg_arch)) \
466 $($(target)_UID.$(bld_trg).$(bld_type)) \
467 $($(target)_UID.$(bld_trg_arch)) \
468 $($(target)_UID.$(bld_trg)) \
469 $($(target)_UID.$(bld_type)) \
470 $($(target)_UID) )
471 local gid := $(firstword \
472 $($(target)_GID.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
473 $($(target)_GID.$(bld_trg).$(bld_trg_arch)) \
474 $($(target)_GID.$(bld_trg).$(bld_type)) \
475 $($(target)_GID.$(bld_trg_arch)) \
476 $($(target)_GID.$(bld_trg)) \
477 $($(target)_GID.$(bld_type)) \
478 $($(target)_GID) )
[2475]479 local pre_install_cmds := $(evalcall def_fn_prop_get_first_defined,PRE_INST_CMDS)
480 local post_install_cmds := $(evalcall def_fn_prop_get_first_defined,POST_INST_CMDS)
[2551]481endif
[219]482
[2551]483ifneq ($($(target)_1_INSTTYPE),none)
[2475]484 # Generate the rules
485 ifeq ($($(target)_1_INSTTYPE),both)
[353]486$(eval $(def_link_install_rule))
[2475]487 _INSTALLS_FILES += $($(target)_1_INST_TARGET)
[1697]488 endif
[2475]489$(eval $(def_link_stage_rule))
490 _STAGE_FILES += $($(target)_1_STAGE_TARGET)
491 $(typevar) += $($(target)_1_STAGE_TARGET)
492else # INSTTYPE == none
[1697]493 $(typevar) += $(out)
[2475]494endif # INSTTYPE == none
[353]495
[2523]496# Install debug info.
497$(target)_2_DEBUG_STAGE_TARGET_DIRS :=
498$(target)_2_DEBUG_STAGE_TARGET_FILES :=
499$(target)_2_DEBUG_INSTALL_TARGET_DIRS :=
500$(target)_2_DEBUG_INSTALL_TARGET_FILES :=
501
502if ( defined($(target)_2_OUTPUT_DEBUG_DIRS) \
503 || defined($(target)_2_OUTPUT_DEBUG_FILES) ) \
504 && "$($(target)_1_DEBUG_INSTTYPE)" != "none"
505 local mode := $(if $(mode),$(mode)$(COMMA)a-x,0644)
506
507 ifeq ($($(target)_1_DEBUG_INSTTYPE),both)
508 local debug_inst_path := $(PATH_INS)
509 local debug_install_cmd := $(INSTALL)
510 local debug_var := INSTALL
[2762]511 $(foreach debug_inst, $($(target)_1_DEBUG_INST), $(evalvalctx def_target_install_only_debug))
[2523]512 endif
513
514 local debug_inst_path := $(PATH_STAGE)
515 local debug_install_cmd := $(INSTALL_STAGING)
516 local debug_var := STAGE
517 if1of ($($(target)_1_DEBUG_INSTTYPE), stage both)
[2762]518 $(foreach debug_inst, $($(target)_1_DEBUG_STAGE), $(evalvalctx def_target_install_only_debug))
[2523]519 endif
520 if1of ($($(target)_1_INSTTYPE), stage both)
521 ifndef debug_nostage
[2762]522 $(foreach debug_inst,$($(target)_1_STAGE), $(evalvalctx def_target_install_only_debug))
[2523]523 endif
524 endif
525
526 _DEBUG_STAGE_DIRS += $($(target)_2_DEBUG_STAGE_TARGET_DIRS)
527 _DEBUG_STAGE_FILES += $($(target)_2_DEBUG_STAGE_TARGET_FILES)
528 _DEBUG_INSTALL_DIRS += $($(target)_2_DEBUG_INSTALL_TARGET_DIRS)
529 _DEBUG_INSTALL_FILES += $($(target)_2_DEBUG_INSTALL_TARGET_FILES)
530
531 $(basename $(notdir $(out))):: $($(target)_2_DEBUG_STAGE_TARGET_DIRS) $($(target)_2_DEBUG_STAGE_TARGET_FILES)
532endif
533
[2475]534endef # def_target_install_only
[353]535
[219]536
537
538#
[72]539# LIBRARIES
[73]540#
[72]541
542## Library (one).
[74]543# @param $(target) Normalized library (target) name.
[72]544define def_lib
[145]545# library basics
[222]546## @todo prefix
[1504]547local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
548local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_TARGET))
549local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
550local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_TARGET_CPU))
[1496]551local tool := $(call _TARGET_TOOL,$(target),AR)
[78]552ifeq ($(tool),)
[353]553$(error kBuild: Library target $(target) does not have a tool defined!)
[78]554endif
[1496]555local name := $(firstword\
[2433]556 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]557 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]558 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]559 $($(target)_NAME.$(bld_trg_arch))\
560 $($(target)_NAME.$(bld_trg))\
561 $($(target)_NAME.$(bld_type))\
562 $($(target)_NAME)\
563 $(target))
[1496]564local outbase := $(call TARGET_BASE,$(name),$(target))
[2239]565$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
[2436]566$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
[1496]567local suff := $(firstword\
[481]568 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]569 $($(target)_LIBSUFF.$(bld_trg))\
[126]570 $($(target)_LIBSUFF)\
[481]571 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]572 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]573 $(TOOL_$(tool)_ARLIBSUFF)\
[353]574 $(SUFF_LIB))
[1496]575local out := $(outbase)$(suff)
[2434]576local defpath := $($(target)_DEFPATH)
577ifeq ($(defpath),)
578 local defpath := $($(target)_PATH)
579endif
[2238]580$(target)_1_TARGET:= $(out)
[2436]581$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
[1496]582# no local here - must be writable across some foreachs.
583othersrc :=
[2236]584$(target)_2_OBJS :=
[3284]585$(target)_2_INTERMEDIATES =
[145]586
[3278]587# kObjCache.
588ifdef KBUILD_USE_KOBJCACHE
589 ifneq ($($(target)_KOBJCACHE),)
590local use_objcache := 1
591 else
592local use_objcache :=
593 endif
594local use_objcache :=
595endif
596
[3285]597# Target level intermediates (before units!).
598local target_intermediate_vars := $$$$($(target)_2_INTERMEDIATES) $(foreach var, \
599 $(target)_INTERMEDIATES \
600 $(target)_INTERMEDIATES.$(bld_trg) \
601 $(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch) \
602 $(target)_INTERMEDIATES.$(bld_trg_arch) \
603 $(target)_INTERMEDIATES.$(bld_trg_cpu) \
604 $(target)_INTERMEDIATES.$(bld_type) \
605 ,$(if-expr defined($(var)),$$$$($(var)),))
606
[1672]607# Do units pre source callouts.
608local units := \
609 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
610 $($(target)_USES.$(bld_trg_arch))\
611 $($(target)_USES.$(bld_trg))\
612 $($(target)_USES.$(bld_type))\
613 $($(target)_USES)
[2762]614$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
[2952]615$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
[1672]616
[145]617# source -> object
[1496]618$(evalval def_target_sources)
[145]619
620# library linking
[1496]621local tool := $(call _TARGET_TOOL,$(target),AR)
622local name := $(firstword\
[2433]623 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]624 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]625 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]626 $($(target)_NAME.$(bld_trg_arch))\
627 $($(target)_NAME.$(bld_trg))\
628 $($(target)_NAME.$(bld_type))\
629 $($(target)_NAME)\
630 $(target))
[1496]631local outbase := $(call TARGET_BASE,$(name),$(target))
632local flags :=\
[74]633 $(TOOL_$(tool)_ARFLAGS)\
[221]634 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]635 $(ARFLAGS)\
[221]636 $(ARFLAGS.$(bld_type))\
[74]637 $($(target)_ARFLAGS)\
[481]638 $($(target)_ARFLAGS.$(bld_type)) \
639 $($(target)_ARFLAGS.$(bld_trg)) \
640 $($(target)_ARFLAGS.$(bld_trg_arch)) \
641 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
642 $($(target)_ARFLAGS.$(bld_trg_cpu))
[1496]643local dirdep := $(call DIRDEP,$(dir $(out)))
[1702]644local deps := \
645 $($(target)_DEPS.$(bld_trg_cpu)) \
646 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
647 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
648 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
649 $($(target)_DEPS.$(bld_trg_arch)) \
650 $($(target)_DEPS.$(bld_trg)) \
651 $($(target)_DEPS.$(bld_type)) \
652 $($(target)_DEPS) \
653 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
654 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
655 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
656 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
657 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
658 $($(target)_LNK_DEPS.$(bld_trg)) \
659 $($(target)_LNK_DEPS.$(bld_type)) \
660 $($(target)_LNK_DEPS)
661local orderdeps := \
662 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
663 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
664 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
665 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
666 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
667 $($(target)_ORDERDEPS.$(bld_trg)) \
668 $($(target)_ORDERDEPS.$(bld_type)) \
669 $($(target)_ORDERDEPS) \
670 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
671 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
672 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
673 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
674 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
675 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
676 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
677 $($(target)_LNK_ORDERDEPS)
[72]678
[725]679# Adjust paths if we got a default path.
680ifneq ($(defpath),)
[1496]681 local deps := $(abspathex $(deps),$(defpath))
682 local orderdeps := $(abspathex $(orderdeps),$(defpath))
[1472]683 othersrc := $(abspathex $(othersrc),$(defpath))
[725]684endif
685
[859]686
687# Custom pre-link actions.
[3128]688local pre_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,PRE_CMDS,$(NLTAB))
689local post_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,POST_CMDS,$(NLTAB))
[859]690
[1424]691# eliminate this guy?
[2236]692local objs = $($(target)_2_OBJS)
[1424]693
[380]694# dependency file
[1496]695local dep := $(out)$(SUFF_DEP)
[524]696ifndef NO_LINK_CMDS_DEPS
[1798]697 _DEPFILES_INCLUDED += $(dep)
698 ifdef KB_HAVE_INCLUDEDEP_QUEUE
699 includedep-queue $(dep)
[1795]700 else
[1798]701 includedep $(dep)
[1795]702 endif
[380]703endif
[72]704
[380]705# check that the tool is defined.
706ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
707$(warning kBuild: tools: \
[481]708 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
709 2 $($(target)_$(source)TOOL.$(bld_trg)) \
710 3 $($(target)_$(source)TOOL) \
711 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
712 5 $($(target)_TOOL.$(bld_trg)) \
713 6 $($(target)_TOOL) \
714 7 $($(source)TOOL) \
715 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
716 9 $($(source)TOOL.$(bld_trg)) \
717 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
718 11 $(TOOL.$(bld_trg)) \
719 12 $(TOOL) )
[380]720$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
721endif
722
723# call the tool
[2523]724local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
[859]725ifneq ($(pre_cmds),)
[1496]726 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
[859]727endif
728ifneq ($(post_cmds),)
[2523]729 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
[859]730endif
[2234]731$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
732$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
[2795]733$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE_PRECIOUS)
[2236]734$(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_2_OBJS)
[2234]735$(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
[380]736
[412]737# generate the link rule.
[380]738$(eval $(def_link_rule))
739
[2475]740# installing and globals.
[2483]741local target_type_mode := a+r,u+w
[2475]742$(evalval def_target_install_only)
743
[2795]744_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
[2475]745_CLEAN_FILES += $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_cpu)) $($(target)_CLEAN.$(bld_type))
746_DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
747_OBJS += $($(target)_2_OBJS)
748
749endef # def_lib
[1936]750$(eval-opt-var def_lib)
[72]751
752# Process libraries
[859]753typevar := _LIBS
[776]754tool_do := LINK_LIBRARY
[380]755mode := 0644
[2762]756$(foreach target, $(_ALL_LIBRARIES), $(evalvalctx def_lib))
[72]757
[988]758ifdef KBUILD_PROFILE_SELF
[2008]759 $(evalcall def_profile_self, done library targets)
[988]760endif
[72]761
[988]762
[72]763#
[353]764# Link operations.
[72]765#
766
[353]767##
768# Link prolog
769#
770# @param $(target) Normalized target name.
771# @param $(EXT) EXE,DLL,SYS.
772# @param $(typevar) The name of the variable with all the root targets of its type.
[380]773define def_link_common
[353]774# basics
[1504]775local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
[3415]776local bld_trg := $(firstword $($(target)_BLD_TRG) $(KBUILD_$(bld_trg_base_var)))
777local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_$(bld_trg_base_var)_ARCH))
778local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(KBUILD_$(bld_trg_base_var)_CPU))
[145]779
[1496]780local tool := $(call _TARGET_TOOL,$(target),LD)
781local name := $(firstword\
[2433]782 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]783 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]784 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]785 $($(target)_NAME.$(bld_trg_arch))\
786 $($(target)_NAME.$(bld_trg))\
787 $($(target)_NAME.$(bld_type))\
788 $($(target)_NAME)\
789 $(target))
[1496]790local outbase := $(call TARGET_BASE,$(name),$(target))
[2239]791$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
[2436]792$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
[2143]793local suff := $(firstword \
794 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
795 $($(target)_$(EXT)SUFF.$(bld_trg))\
796 $($(target)_$(EXT)SUFF)\
797 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
798 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg))\
799 $(TOOL_$(tool)_LD$(EXT)SUFF)\
800 $($(EXTPRE)SUFF_$(EXT)) )
[1496]801local out := $(outbase)$(suff)
[2238]802$(target)_1_TARGET:= $(out)
[2436]803$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
[2434]804local defpath := $($(target)_DEFPATH)
805ifeq ($(defpath),)
806 local defpath := $($(target)_PATH)
807endif
[1496]808# no local here - must be writable across some foreachs.
809othersrc :=
[2236]810$(target)_2_OBJS :=
[3284]811$(target)_2_INTERMEDIATES =
[353]812
[3278]813# kObjCache.
814ifdef KBUILD_USE_KOBJCACHE
815 ifneq ($($(target)_KOBJCACHE),)
816local use_objcache := 1
817 else
818local use_objcache :=
819 endif
820local use_objcache :=
821endif
822
[3285]823# Target level intermediates (before units!).
824local target_intermediate_vars := $$$$($(target)_2_INTERMEDIATES) $(foreach var, \
825 $(target)_INTERMEDIATES \
826 $(target)_INTERMEDIATES.$(bld_trg) \
827 $(target)_INTERMEDIATES.$(bld_trg).$(bld_trg_arch) \
828 $(target)_INTERMEDIATES.$(bld_trg_arch) \
829 $(target)_INTERMEDIATES.$(bld_trg_cpu) \
830 $(target)_INTERMEDIATES.$(bld_type) \
831 ,$(if-expr defined($(var)),$$$$($(var)),))
832
[1672]833# Do units pre source callouts.
834local units := \
835 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
836 $($(target)_USES.$(bld_trg_arch))\
837 $($(target)_USES.$(bld_trg))\
838 $($(target)_USES.$(bld_type))\
839 $($(target)_USES)
[2762]840$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
[2952]841$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
[1672]842
[145]843# source -> object
[1496]844$(evalval def_target_sources)
[145]845
[744]846# more link stuff.
[1496]847local tool := $(call _TARGET_TOOL,$(target),LD)
848local name := $(firstword\
[2433]849 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]850 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]851 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]852 $($(target)_NAME.$(bld_trg_arch))\
853 $($(target)_NAME.$(bld_trg))\
854 $($(target)_NAME.$(bld_type))\
855 $($(target)_NAME)\
856 $(target))
[1496]857local outbase := $(call TARGET_BASE,$(name),$(target))
858local flags :=\
[74]859 $(TOOL_$(tool)_LDFLAGS)\
[221]860 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
861 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
862 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]863 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]864 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[1242]865 $(foreach sdk, $(SDKS) \
866 $(SDKS.$(bld_type)) \
867 $(SDKS.$(bld_trg)) \
868 $(SDKS.$(bld_trg_arch)) \
869 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
870 $(SDK_$(sdk)_LDFLAGS)\
871 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
872 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
873 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
874 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
875 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]876 $(LDFLAGS)\
[221]877 $(LDFLAGS.$(bld_type))\
878 $(LDFLAGS.$(bld_trg))\
879 $(LDFLAGS.$(bld_trg_arch))\
[481]880 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]881 $(LDFLAGS.$(bld_trg_cpu))\
[1242]882 $(foreach sdk, $($(target)_SDKS) \
883 $($(target)_SDKS.$(bld_type)) \
884 $($(target)_SDKS.$(bld_trg)) \
885 $($(target)_SDKS.$(bld_trg_arch)) \
886 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
887 $(SDK_$(sdk)_LDFLAGS)\
888 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
889 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
890 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
891 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
892 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
[74]893 $($(target)_LDFLAGS)\
[221]894 $($(target)_LDFLAGS.$(bld_type))\
895 $($(target)_LDFLAGS.$(bld_trg))\
896 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]897 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]898 $($(target)_LDFLAGS.$(bld_trg_cpu))
[1496]899local libs :=\
[221]900 $($(target)_LIBS.$(bld_trg_cpu))\
[481]901 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]902 $($(target)_LIBS.$(bld_trg_arch))\
903 $($(target)_LIBS.$(bld_trg))\
904 $($(target)_LIBS.$(bld_type))\
[74]905 $($(target)_LIBS)\
[592]906 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
907 $($(target)_SDKS.$(bld_trg_arch)) \
908 $($(target)_SDKS.$(bld_trg)) \
909 $($(target)_SDKS.$(bld_type)) \
910 $($(target)_SDKS),\
[353]911 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]912 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]913 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
914 $(SDK_$(sdk)_LIBS.$(bld_trg))\
915 $(SDK_$(sdk)_LIBS.$(bld_type))\
916 $(SDK_$(sdk)_LIBS))\
[221]917 $(LIBS.$(bld_trg_cpu))\
[481]918 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]919 $(LIBS.$(bld_trg_arch))\
920 $(LIBS.$(bld_trg))\
921 $(LIBS.$(bld_type))\
[74]922 $(LIBS)\
[592]923 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
924 $(SDKS.$(bld_trg_arch)) \
925 $(SDKS.$(bld_trg)) \
926 $(SDKS.$(bld_type)) \
927 $(SDKS),\
[353]928 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]929 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]930 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
931 $(SDK_$(sdk)_LIBS.$(bld_trg))\
932 $(SDK_$(sdk)_LIBS.$(bld_type))\
933 $(SDK_$(sdk)_LIBS))\
[221]934 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]935 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]936 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
937 $(TOOL_$(tool)_LIBS.$(bld_trg))\
938 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]939 $(TOOL_$(tool)_LIBS)
[1496]940local libpath :=\
[221]941 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]942 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]943 $($(target)_LIBPATH.$(bld_trg_arch))\
944 $($(target)_LIBPATH.$(bld_trg))\
945 $($(target)_LIBPATH.$(bld_type))\
[74]946 $($(target)_LIBPATH)\
[592]947 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
948 $($(target)_SDKS.$(bld_trg_arch)) \
949 $($(target)_SDKS.$(bld_trg)) \
950 $($(target)_SDKS.$(bld_type)) \
951 $($(target)_SDKS),\
[353]952 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]953 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]954 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
955 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
956 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
957 $(SDK_$(sdk)_LIBPATH))\
[221]958 $(LIBPATH.$(bld_trg_cpu))\
[481]959 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]960 $(LIBPATH.$(bld_trg_arch))\
961 $(LIBPATH.$(bld_trg))\
962 $(LIBPATH.$(bld_type))\
[74]963 $(LIBPATH)\
[592]964 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
965 $(SDKS.$(bld_trg_arch)) \
966 $(SDKS.$(bld_trg)) \
967 $(SDKS.$(bld_type)) \
968 $(SDKS),\
[353]969 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]970 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]971 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
972 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
973 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
974 $(SDK_$(sdk)_LIBPATH))\
[221]975 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]976 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]977 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
978 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
979 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]980 $(TOOL_$(tool)_LIBPATH)
[1496]981local dirdep := $(call DIRDEP,$(dir $(out)))
[1702]982local deps := \
983 $($(target)_DEPS.$(bld_trg_cpu)) \
984 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
985 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
986 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
987 $($(target)_DEPS.$(bld_trg_arch)) \
988 $($(target)_DEPS.$(bld_trg)) \
989 $($(target)_DEPS.$(bld_type)) \
990 $($(target)_DEPS) \
991 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
992 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
993 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
994 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
995 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
996 $($(target)_LNK_DEPS.$(bld_trg)) \
997 $($(target)_LNK_DEPS.$(bld_type)) \
998 $($(target)_LNK_DEPS)
999local orderdeps := \
1000 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
1001 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
1002 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
1003 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
1004 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
1005 $($(target)_ORDERDEPS.$(bld_trg)) \
1006 $($(target)_ORDERDEPS.$(bld_type)) \
1007 $($(target)_ORDERDEPS) \
1008 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
1009 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
1010 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
1011 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
1012 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
1013 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
1014 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
1015 $($(target)_LNK_ORDERDEPS)
[353]1016
[725]1017# Adjust paths if we got a default path.
1018ifneq ($(defpath),)
[1496]1019 local libpath := $(abspathex $(libpath),$(defpath))
1020 local deps := $(abspathex $(deps),$(defpath))
1021 local orderdeps := $(abspathex $(orderdeps),$(defpath))
[1472]1022 othersrc := $(abspathex $(othersrc),$(defpath))
[1755]1023 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
[725]1024endif
1025
[2523]1026# Debug info.
1027local ld_debug := $(evalcall def_fn_prop_get_first_defined,LD_DEBUG)
1028local debug_inst := $(evalcall def_fn_prop_get_first_defined,DEBUG_INST)
1029local debug_stage := $(evalcall def_fn_prop_get_first_defined,DEBUG_STAGE)
1030local debug_nostage := $(evalcall def_fn_prop_get_first_word,DEBUG_NOSTAGE)
1031
[2475]1032# Custom pre/post-link actions.
[3128]1033local pre_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,PRE_CMDS,$(NLTAB))
1034local post_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,POST_CMDS,$(NLTAB))
[72]1035
[1424]1036# eliminate this guy?
[2236]1037local objs = $($(target)_2_OBJS)
[1424]1038
[380]1039# dependency file
[1496]1040local dep := $(outbase)$(SUFF_DEP)
[524]1041ifndef NO_LINK_CMDS_DEPS
[2188]1042 _DEPFILES_INCLUDED += $(dep)
[1798]1043 ifdef KB_HAVE_INCLUDEDEP_QUEUE
1044 includedep-queue $(dep)
[1795]1045 else
[1798]1046 includedep $(dep)
[1795]1047 endif
[380]1048endif
[353]1049
[380]1050# check that the tool is defined.
1051ifndef TOOL_$(tool)_$(tool_do)_CMDS
1052$(warning kBuild: tools: \
[481]1053 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1054 2 $($(target)_$(source)TOOL.$(bld_trg)) \
1055 3 $($(target)_$(source)TOOL) \
1056 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
1057 5 $($(target)_TOOL.$(bld_trg)) \
1058 6 $($(target)_TOOL) \
1059 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
1060 8 $($(source)TOOL.$(bld_trg)) \
1061 9 $($(source)TOOL) \
1062 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
1063 11 $(TOOL.$(bld_trg)) \
1064 12 $(TOOL) )
[380]1065$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1066endif
[353]1067
[380]1068# call the tool
[1496]1069local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
[859]1070ifneq ($(pre_cmds),)
[1496]1071 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
[859]1072endif
1073ifneq ($(post_cmds),)
[1496]1074 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
[859]1075endif
[2523]1076$(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1077$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
[2795]1078$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE_PRECIOUS)
[2523]1079if1of ($(ld_debug), split)
1080 $(target)_2_OUTPUT_DEBUG_FILES := $(filter-out %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
1081 $(target)_2_OUTPUT_DEBUG_DIRS := $(filter %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
1082else
1083 $(target)_2_OUTPUT_DEBUG_FILES :=
1084 $(target)_2_OUTPUT_DEBUG_DIRS :=
1085endif
1086$(target)_2_DEPEND := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_2_OBJS)
1087$(target)_2_DEPORD := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
[353]1088
[412]1089# generate the link rule.
[380]1090$(eval $(def_link_rule))
1091
[2523]1092# installation targets
1093local target_type_mode :=
1094$(evalval def_target_install_only)
[412]1095
[380]1096# Update globals.
[2236]1097_OBJS += $($(target)_2_OBJS)
[3304]1098_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $($(target)_2_OUTPUT_DEBUG_FILES) $(out)
[905]1099_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))
1100_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]1101_INSTALLS_FILES += $(INSTARGET_$(target))
[353]1102
[1936]1103endef # def_link_common
1104$(eval-opt-var def_link_common)
[353]1105
1106
1107#
1108# BLDPROGS
1109#
1110
1111# Process build programs.
1112EXT := EXE
1113EXTPRE := HOST
[380]1114tool_do := LINK_PROGRAM
[353]1115typevar := _BLDPROGS
[380]1116mode := 0755
[3415]1117bld_trg_base_var := HOST
[2762]1118$(foreach target, $(_ALL_BLDPROGS), $(evalvalctx def_link_common))
[353]1119
[988]1120ifdef KBUILD_PROFILE_SELF
[2008]1121 $(evalcall def_profile_self, done build program targets)
[988]1122endif
[353]1123
1124
1125#
1126# DLLS
1127#
1128
[189]1129# Process dlls
[353]1130EXT := DLL
1131EXTPRE :=
[380]1132tool_do := LINK_DLL
[353]1133typevar := _DLLS
[830]1134mode := 0644
[353]1135bld_trg_base_var := TARGET
[2762]1136$(foreach target, $(_ALL_DLLS), $(evalvalctx def_link_common))
[74]1137
[988]1138ifdef KBUILD_PROFILE_SELF
[2008]1139 $(evalcall def_profile_self, done dll targets)
[988]1140endif
[74]1141
[988]1142
[72]1143#
[830]1144# IMPORT LIBRARIES
[72]1145#
[219]1146# - On OS/2 and windows these are libraries.
[189]1147# - On other platforms they are fake DLLs.
[830]1148#
1149EXTPRE :=
1150typevar := _IMPORT_LIBS
1151mode := 0644
1152bld_trg_base_var := TARGET
[1504]1153ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
[830]1154 EXT := LIB
1155 tool_do := LINK_LIBRARY
[2762]1156 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_lib))
[189]1157else
[830]1158 EXT := DLL
1159 tool_do := LINK_DLL
[2762]1160 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_link_common))
[189]1161endif
[72]1162
[988]1163ifdef KBUILD_PROFILE_SELF
[2008]1164 $(evalcall def_profile_self, done import library targets)
[988]1165endif
[189]1166
[988]1167
[189]1168#
1169# PROGRAMS
1170#
1171
[353]1172# Process programs
1173EXT := EXE
1174EXTPRE :=
[380]1175tool_do := LINK_PROGRAM
[353]1176typevar := _PROGRAMS
[380]1177mode := 0755
[353]1178bld_trg_base_var := TARGET
[2762]1179$(foreach target, $(_ALL_PROGRAMS), $(evalvalctx def_link_common))
[130]1180
[988]1181ifdef KBUILD_PROFILE_SELF
[2008]1182 $(evalcall def_profile_self, done program targets)
[988]1183endif
[130]1184
[189]1185
[72]1186#
[83]1187# SYSMODS
[72]1188#
1189
[130]1190# Process sysmods
[353]1191EXT := SYS
1192EXTPRE :=
[380]1193tool_do := LINK_SYSMOD
[353]1194typevar := _SYSMODS
[380]1195mode := 0644
[353]1196bld_trg_base_var := TARGET
[2762]1197$(foreach target, $(_ALL_SYSMODS), $(evalvalctx def_link_common))
[83]1198
[988]1199ifdef KBUILD_PROFILE_SELF
[2008]1200 $(evalcall def_profile_self, done sysmod targets)
[988]1201endif
[83]1202
[988]1203
[72]1204#
[2084]1205# MISCBINS
1206#
1207
1208# Process MISCBINS
1209EXT := BIN
1210EXTPRE :=
1211tool_do := LINK_MISCBIN
1212typevar := _MISCBINS
1213mode := 0644
1214bld_trg_base_var := TARGET
[2762]1215$(foreach target, $(_ALL_MISCBINS), $(evalvalctx def_link_common))
[2084]1216
1217ifdef KBUILD_PROFILE_SELF
1218 $(evalcall def_profile_self, done misc binary targets)
1219endif
1220
Note: See TracBrowser for help on using the repository browser.