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

Last change on this file since 3278 was 3278, 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.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 39.6 KB
Line 
1# $Id: footer-pass2-compiling-targets.kmk 3278 2019-01-04 17:08:23Z bird $
2## @file
3# kBuild - Footer - Target lists - Pass 2 - Compiling Targets.
4#
5
6#
7# Copyright (c) 2004-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
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
13# the Free Software Foundation; either version source of the License, or
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
23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24#
25#
26# As a special exception you are granted permission to include this file, via
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.
29# This exception does not however invalidate any other reasons why the makefile,
30# program, whatever should not be covered the GPL.
31#
32#
33
34
35#
36# Object processing.
37#
38
39ifndef NO_COMPILE_CMDS_DEPS
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
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
119else
120 _DEP_COMPILE_CMDS =
121endif
122
123## Generates the rules for building a specific object, and the aliases - legacy version.
124# for building a source file.
125# @param $(obj) The object file.
126define def_target_source_rule
127ifndef NO_COMPILE_CMDS_DEPS
128$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
129endif
130ifneq ($(TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE),)
131_OUT_FILES += $(outbase).koc
132$(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
133 $($(target)_$(source)_DEPEND_) $(value _DEP_COMPILE_CMDS) \
134 | $($(target)_$(source)_DEPORD_) $(target_intermediate_vars)
135 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
136else
137$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
138 $($(target)_$(source)_DEPEND_) $(value _DEP_COMPILE_CMDS)
139 | $($(target)_$(source)_DEPORD_) $(target_intermediate_vars)
140 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
141ifndef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
142 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
143endif
144endif
145
146$($(target)_$(source)_CMDS_)
147
148ifndef NO_COMPILE_CMDS_DEPS
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_'
157 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(obj)'
158 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
159 endif
160endif
161
162$(basename $(notdir $(obj))).o: $(obj)
163
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.
165$(target)_$(source)_CMDS_ :=
166$(target)_$(source)_OUTPUT_ :=
167$(target)_$(source)_OUTPUT_MAYBE_ :=
168$(target)_$(source)_DEPEND_ :=
169$(target)_$(source)_DEPORD_ :=
170endef # def_target_source_rule
171$(eval-opt-var def_target_source_rule)
172##
173## Legacy legacy legacy - end
174
175
176
177## wrapper the link command dependency check.
178ifndef NO_LINK_CMDS_DEPS
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
184else
185 _DEP_LINK_CMDS =
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)
193# @param $($(target)_2_OUTPUT) Output files from the link.
194# @param $($(target)_2_OUTPUT_MAYBE) Output files that the link may perhaps create.
195# @param $($(target)_2_OUTPUT_MAYBE_PRECIOUS) Output files that the link may perhaps create but shouldn't be deleted.
196# @param $($(target)_2_DEPEND) Dependencies.
197# @param $($(target)_2_DEPORD) Dependencies which should only affect build order.
198# @param $(cmds) The link commands.
199# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
200define def_link_rule
201$$(call KB_FN_ASSERT_ABSPATH,out)
202ifndef NO_LINK_CMDS_DEPS
203$(out): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $$@),FORCE)
204endif
205$(out) \
206+ $($(target)_2_OUTPUT) \
207+ $($(target)_2_OUTPUT_DEBUG_FILES) \
208+ $($(target)_2_OUTPUT_DEBUG_DIRS) \
209+| $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) : \
210 $$$$($(target)_2_DEPEND) \
211 $(value _DEP_LINK_CMDS) \
212 | \
213 $$$$($(target)_2_DEPORD)
214 %$$(call MSG_LINK,$(target),$$@,$(tool_do))
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
219
220$(cmds)
221
222ifndef NO_LINK_CMDS_DEPS
223 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
224 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
225 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
226endif
227
228$(basename $(notdir $(out))):: $(out)
229
230endef # def_link_rule
231$(eval-opt-var def_link_rule)
232
233
234## Generate the link & lib install rule
235# Implicit parameters: target, out, $(target)_1_STAGE_TARGET, mode,
236# pre_install_cmds, post_install_cmds
237define def_link_install_rule
238$$(call KB_FN_ASSERT_ABSPATH,$(target)_1_INST_TARGET)
239$($(target)_1_INST_TARGET): $(out) | $$$$(dir $$$$@)
240 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
241 $(pre_install_cmds)
242
243 $$(QUIET)$$(INSTALL) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
244 $(post_install_cmds)
245
246endef
247
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
253$$(call KB_FN_ASSERT_ABSPATH,$(target)_1_STAGE_TARGET)
254$($(target)_1_STAGE_TARGET): $(out) | $$$$(dir $$$$@)
255 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
256 $(pre_install_cmds)
257
258 $$(QUIET)$$(INSTALL_STAGING) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
259 $(post_install_cmds)
260
261
262$(basename $(notdir $(out))):: $($(target)_1_STAGE_TARGET)
263
264endef
265
266
267## def_src_handler_*
268#
269# @{
270define def_src_handler_c
271local type := C
272 $(kb-src-one 3)
273endef
274
275define def_src_handler_cxx
276local type := CXX
277 $(kb-src-one 3)
278endef
279
280define def_src_handler_objc
281local type := OBJC
282 $(kb-src-one 3)
283endef
284
285define def_src_handler_objcxx
286local type := OBJCXX
287 $(kb-src-one 3)
288endef
289
290define def_src_handler_asm
291local type := AS
292 $(kb-src-one 3)
293endef
294
295define def_src_handler_rc
296local type := RC
297 $(kb-src-one 3)
298endef
299
300define def_src_handler_obj
301ifeq ($(defpath),)
302 $(target)_2_OBJS += $(source)
303else
304 $(target)_2_OBJS += $(abspathex $(source), $(defpath))
305endif
306endef
307## @}
308
309## Handle one source.
310# .
311define def_src_handler_one
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))
315ifneq ($(handler),)
316 $(evalvalctx $(handler))
317else
318 othersrc += $(source)
319endif
320endef # def_src_handler_one
321
322## Generic macro for processing all target sources.
323# @param $(target) Normalized target name.
324# @param $(defpath)
325# @param much-more...
326# @returns othersrc, $(target)_2_OBJS, ++
327define def_target_sources
328local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
329$(foreach source,\
330 $($(target)_SOURCES)\
331 $($(target)_SOURCES.$(bld_trg))\
332 $($(target)_SOURCES.$(bld_trg).$(bld_type))\
333 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
334 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch).$(bld_type))\
335 $($(target)_SOURCES.$(bld_trg_arch))\
336 $($(target)_SOURCES.$(bld_trg_cpu))\
337 $($(target)_SOURCES.$(bld_type))\
338 ,$(evalvalctx def_src_handler_one) )
339
340$(foreach source,\
341 $($(target)_GEN_SOURCES_)\
342 $($(target)_GEN_SOURCES_.$(bld_trg))\
343 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_type))\
344 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
345 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch).$(bld_type))\
346 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
347 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
348 $($(target)_GEN_SOURCES_.$(bld_type))\
349 ,$(evalvalctx def_src_handler_one) )
350endef # def_target_sources
351$(eval-opt-var def_target_sources)
352
353
354##
355# Install a debug directory.
356# @param debug_dir The directory name.
357define def_link_install_debug_dir_rule
358local dir := $(debug_inst_path)/$(debug_inst2)$(debug_dir)
359$$(call KB_FN_ASSERT_ABSPATH,dir)
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##
367# Install a debug file.
368# @param debug_file Src=>Dst file pair.
369define def_link_install_debug_file_rule
370local dst := $(debug_inst_path)/$(debug_inst2)$(word 2, $(subst =>,$(SP),$(debug_file)))
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 $$$$@)
375 %$$(call MSG_INST_FILE,$$<,$$@)
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##
381# Install debug info to $(debug_inst), where debug_inst can be a directory or
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)" == "./"
386 local debug_inst2 :=
387 else
388 local debug_inst2 := $(debug_inst)
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
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))
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
408## Generic macro for generating the install rule(s) for a target.
409#
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.
413# @param $(target_type_mode) The default file mode implied by the target type.
414define def_target_install_only
415if1of ($($(target)_1_INSTTYPE) $($(target)_1_DEBUG_INSTTYPE), both stage)
416 # Determin common variables.
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)) \
424 $($(target)_MODE) \
425 $(target_type_mode) )
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) )
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)
444endif
445
446ifneq ($($(target)_1_INSTTYPE),none)
447 # Generate the rules
448 ifeq ($($(target)_1_INSTTYPE),both)
449$(eval $(def_link_install_rule))
450 _INSTALLS_FILES += $($(target)_1_INST_TARGET)
451 endif
452$(eval $(def_link_stage_rule))
453 _STAGE_FILES += $($(target)_1_STAGE_TARGET)
454 $(typevar) += $($(target)_1_STAGE_TARGET)
455else # INSTTYPE == none
456 $(typevar) += $(out)
457endif # INSTTYPE == none
458
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
474 $(foreach debug_inst, $($(target)_1_DEBUG_INST), $(evalvalctx def_target_install_only_debug))
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)
481 $(foreach debug_inst, $($(target)_1_DEBUG_STAGE), $(evalvalctx def_target_install_only_debug))
482 endif
483 if1of ($($(target)_1_INSTTYPE), stage both)
484 ifndef debug_nostage
485 $(foreach debug_inst,$($(target)_1_STAGE), $(evalvalctx def_target_install_only_debug))
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
497endef # def_target_install_only
498
499
500
501#
502# LIBRARIES
503#
504
505## Library (one).
506# @param $(target) Normalized library (target) name.
507define def_lib
508# library basics
509## @todo prefix
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))
514local tool := $(call _TARGET_TOOL,$(target),AR)
515ifeq ($(tool),)
516$(error kBuild: Library target $(target) does not have a tool defined!)
517endif
518local name := $(firstword\
519 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
520 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
521 $($(target)_NAME.$(bld_trg).$(bld_type))\
522 $($(target)_NAME.$(bld_trg_arch))\
523 $($(target)_NAME.$(bld_trg))\
524 $($(target)_NAME.$(bld_type))\
525 $($(target)_NAME)\
526 $(target))
527local outbase := $(call TARGET_BASE,$(name),$(target))
528$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
529$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
530local suff := $(firstword\
531 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
532 $($(target)_LIBSUFF.$(bld_trg))\
533 $($(target)_LIBSUFF)\
534 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
535 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
536 $(TOOL_$(tool)_ARLIBSUFF)\
537 $(SUFF_LIB))
538local out := $(outbase)$(suff)
539local defpath := $($(target)_DEFPATH)
540ifeq ($(defpath),)
541 local defpath := $($(target)_PATH)
542endif
543$(target)_1_TARGET:= $(out)
544$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
545# no local here - must be writable across some foreachs.
546othersrc :=
547$(target)_2_OBJS :=
548
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
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)
577$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
578$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
579
580# source -> object
581$(evalval def_target_sources)
582
583# library linking
584local tool := $(call _TARGET_TOOL,$(target),AR)
585local name := $(firstword\
586 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
587 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
588 $($(target)_NAME.$(bld_trg).$(bld_type))\
589 $($(target)_NAME.$(bld_trg_arch))\
590 $($(target)_NAME.$(bld_trg))\
591 $($(target)_NAME.$(bld_type))\
592 $($(target)_NAME)\
593 $(target))
594local outbase := $(call TARGET_BASE,$(name),$(target))
595local flags :=\
596 $(TOOL_$(tool)_ARFLAGS)\
597 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
598 $(ARFLAGS)\
599 $(ARFLAGS.$(bld_type))\
600 $($(target)_ARFLAGS)\
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))
606local dirdep := $(call DIRDEP,$(dir $(out)))
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)
641
642# Adjust paths if we got a default path.
643ifneq ($(defpath),)
644 local deps := $(abspathex $(deps),$(defpath))
645 local orderdeps := $(abspathex $(orderdeps),$(defpath))
646 othersrc := $(abspathex $(othersrc),$(defpath))
647endif
648
649
650# Custom pre-link actions.
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))
653
654# eliminate this guy?
655local objs = $($(target)_2_OBJS)
656
657# dependency file
658local dep := $(out)$(SUFF_DEP)
659ifndef NO_LINK_CMDS_DEPS
660 _DEPFILES_INCLUDED += $(dep)
661 ifdef KB_HAVE_INCLUDEDEP_QUEUE
662 includedep-queue $(dep)
663 else
664 includedep $(dep)
665 endif
666endif
667
668# check that the tool is defined.
669ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
670$(warning kBuild: tools: \
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) )
683$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
684endif
685
686# call the tool
687local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
688ifneq ($(pre_cmds),)
689 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
690endif
691ifneq ($(post_cmds),)
692 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
693endif
694$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
695$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
696$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE_PRECIOUS)
697$(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_2_OBJS)
698$(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
699
700# generate the link rule.
701$(eval $(def_link_rule))
702
703# installing and globals.
704local target_type_mode := a+r,u+w
705$(evalval def_target_install_only)
706
707_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
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
713$(eval-opt-var def_lib)
714
715# Process libraries
716typevar := _LIBS
717tool_do := LINK_LIBRARY
718mode := 0644
719$(foreach target, $(_ALL_LIBRARIES), $(evalvalctx def_lib))
720
721ifdef KBUILD_PROFILE_SELF
722 $(evalcall def_profile_self, done library targets)
723endif
724
725
726#
727# Link operations.
728#
729
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.
736define def_link_common
737# basics
738local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
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))
742
743local tool := $(call _TARGET_TOOL,$(target),LD)
744local name := $(firstword\
745 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
746 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
747 $($(target)_NAME.$(bld_trg).$(bld_type))\
748 $($(target)_NAME.$(bld_trg_arch))\
749 $($(target)_NAME.$(bld_trg))\
750 $($(target)_NAME.$(bld_type))\
751 $($(target)_NAME)\
752 $(target))
753local outbase := $(call TARGET_BASE,$(name),$(target))
754$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
755$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
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)) )
764local out := $(outbase)$(suff)
765$(target)_1_TARGET:= $(out)
766$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
767local defpath := $($(target)_DEFPATH)
768ifeq ($(defpath),)
769 local defpath := $($(target)_PATH)
770endif
771# no local here - must be writable across some foreachs.
772othersrc :=
773$(target)_2_OBJS :=
774
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
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)
803$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
804$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
805
806# source -> object
807$(evalval def_target_sources)
808
809# more link stuff.
810local tool := $(call _TARGET_TOOL,$(target),LD)
811local name := $(firstword\
812 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
813 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
814 $($(target)_NAME.$(bld_trg).$(bld_type))\
815 $($(target)_NAME.$(bld_trg_arch))\
816 $($(target)_NAME.$(bld_trg))\
817 $($(target)_NAME.$(bld_type))\
818 $($(target)_NAME)\
819 $(target))
820local outbase := $(call TARGET_BASE,$(name),$(target))
821local flags :=\
822 $(TOOL_$(tool)_LDFLAGS)\
823 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
824 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
825 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
826 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
827 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
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)))\
839 $(LDFLAGS)\
840 $(LDFLAGS.$(bld_type))\
841 $(LDFLAGS.$(bld_trg))\
842 $(LDFLAGS.$(bld_trg_arch))\
843 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
844 $(LDFLAGS.$(bld_trg_cpu))\
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)))\
856 $($(target)_LDFLAGS)\
857 $($(target)_LDFLAGS.$(bld_type))\
858 $($(target)_LDFLAGS.$(bld_trg))\
859 $($(target)_LDFLAGS.$(bld_trg_arch))\
860 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
861 $($(target)_LDFLAGS.$(bld_trg_cpu))
862local libs :=\
863 $($(target)_LIBS.$(bld_trg_cpu))\
864 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
865 $($(target)_LIBS.$(bld_trg_arch))\
866 $($(target)_LIBS.$(bld_trg))\
867 $($(target)_LIBS.$(bld_type))\
868 $($(target)_LIBS)\
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),\
874 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
875 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
876 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
877 $(SDK_$(sdk)_LIBS.$(bld_trg))\
878 $(SDK_$(sdk)_LIBS.$(bld_type))\
879 $(SDK_$(sdk)_LIBS))\
880 $(LIBS.$(bld_trg_cpu))\
881 $(LIBS.$(bld_trg).$(bld_trg_arch))\
882 $(LIBS.$(bld_trg_arch))\
883 $(LIBS.$(bld_trg))\
884 $(LIBS.$(bld_type))\
885 $(LIBS)\
886 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
887 $(SDKS.$(bld_trg_arch)) \
888 $(SDKS.$(bld_trg)) \
889 $(SDKS.$(bld_type)) \
890 $(SDKS),\
891 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
892 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
893 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
894 $(SDK_$(sdk)_LIBS.$(bld_trg))\
895 $(SDK_$(sdk)_LIBS.$(bld_type))\
896 $(SDK_$(sdk)_LIBS))\
897 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
898 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
899 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
900 $(TOOL_$(tool)_LIBS.$(bld_trg))\
901 $(TOOL_$(tool)_LIBS.$(bld_type))\
902 $(TOOL_$(tool)_LIBS)
903local libpath :=\
904 $($(target)_LIBPATH.$(bld_trg_cpu))\
905 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
906 $($(target)_LIBPATH.$(bld_trg_arch))\
907 $($(target)_LIBPATH.$(bld_trg))\
908 $($(target)_LIBPATH.$(bld_type))\
909 $($(target)_LIBPATH)\
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),\
915 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
916 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
917 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
918 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
919 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
920 $(SDK_$(sdk)_LIBPATH))\
921 $(LIBPATH.$(bld_trg_cpu))\
922 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
923 $(LIBPATH.$(bld_trg_arch))\
924 $(LIBPATH.$(bld_trg))\
925 $(LIBPATH.$(bld_type))\
926 $(LIBPATH)\
927 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
928 $(SDKS.$(bld_trg_arch)) \
929 $(SDKS.$(bld_trg)) \
930 $(SDKS.$(bld_type)) \
931 $(SDKS),\
932 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
933 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
934 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
935 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
936 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
937 $(SDK_$(sdk)_LIBPATH))\
938 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
939 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
940 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
941 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
942 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
943 $(TOOL_$(tool)_LIBPATH)
944local dirdep := $(call DIRDEP,$(dir $(out)))
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)
979
980# Adjust paths if we got a default path.
981ifneq ($(defpath),)
982 local libpath := $(abspathex $(libpath),$(defpath))
983 local deps := $(abspathex $(deps),$(defpath))
984 local orderdeps := $(abspathex $(orderdeps),$(defpath))
985 othersrc := $(abspathex $(othersrc),$(defpath))
986 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
987endif
988
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
995# Custom pre/post-link actions.
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))
998
999# eliminate this guy?
1000local objs = $($(target)_2_OBJS)
1001
1002# dependency file
1003local dep := $(outbase)$(SUFF_DEP)
1004ifndef NO_LINK_CMDS_DEPS
1005 _DEPFILES_INCLUDED += $(dep)
1006 ifdef KB_HAVE_INCLUDEDEP_QUEUE
1007 includedep-queue $(dep)
1008 else
1009 includedep $(dep)
1010 endif
1011endif
1012
1013# check that the tool is defined.
1014ifndef TOOL_$(tool)_$(tool_do)_CMDS
1015$(warning kBuild: tools: \
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) )
1028$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1029endif
1030
1031# call the tool
1032local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
1033ifneq ($(pre_cmds),)
1034 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
1035endif
1036ifneq ($(post_cmds),)
1037 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
1038endif
1039$(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1040$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
1041$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE_PRECIOUS)
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)
1051
1052# generate the link rule.
1053$(eval $(def_link_rule))
1054
1055# installation targets
1056local target_type_mode :=
1057$(evalval def_target_install_only)
1058
1059# Update globals.
1060_OBJS += $($(target)_2_OBJS)
1061_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
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))
1064_INSTALLS_FILES += $(INSTARGET_$(target))
1065
1066endef # def_link_common
1067$(eval-opt-var def_link_common)
1068
1069
1070#
1071# BLDPROGS
1072#
1073
1074# Process build programs.
1075EXT := EXE
1076EXTPRE := HOST
1077tool_do := LINK_PROGRAM
1078typevar := _BLDPROGS
1079mode := 0755
1080bld_trg_base_var := PLATFORM
1081$(foreach target, $(_ALL_BLDPROGS), $(evalvalctx def_link_common))
1082
1083ifdef KBUILD_PROFILE_SELF
1084 $(evalcall def_profile_self, done build program targets)
1085endif
1086
1087
1088#
1089# DLLS
1090#
1091
1092# Process dlls
1093EXT := DLL
1094EXTPRE :=
1095tool_do := LINK_DLL
1096typevar := _DLLS
1097mode := 0644
1098bld_trg_base_var := TARGET
1099$(foreach target, $(_ALL_DLLS), $(evalvalctx def_link_common))
1100
1101ifdef KBUILD_PROFILE_SELF
1102 $(evalcall def_profile_self, done dll targets)
1103endif
1104
1105
1106#
1107# IMPORT LIBRARIES
1108#
1109# - On OS/2 and windows these are libraries.
1110# - On other platforms they are fake DLLs.
1111#
1112EXTPRE :=
1113typevar := _IMPORT_LIBS
1114mode := 0644
1115bld_trg_base_var := TARGET
1116ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
1117 EXT := LIB
1118 tool_do := LINK_LIBRARY
1119 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_lib))
1120else
1121 EXT := DLL
1122 tool_do := LINK_DLL
1123 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_link_common))
1124endif
1125
1126ifdef KBUILD_PROFILE_SELF
1127 $(evalcall def_profile_self, done import library targets)
1128endif
1129
1130
1131#
1132# PROGRAMS
1133#
1134
1135# Process programs
1136EXT := EXE
1137EXTPRE :=
1138tool_do := LINK_PROGRAM
1139typevar := _PROGRAMS
1140mode := 0755
1141bld_trg_base_var := TARGET
1142$(foreach target, $(_ALL_PROGRAMS), $(evalvalctx def_link_common))
1143
1144ifdef KBUILD_PROFILE_SELF
1145 $(evalcall def_profile_self, done program targets)
1146endif
1147
1148
1149#
1150# SYSMODS
1151#
1152
1153# Process sysmods
1154EXT := SYS
1155EXTPRE :=
1156tool_do := LINK_SYSMOD
1157typevar := _SYSMODS
1158mode := 0644
1159bld_trg_base_var := TARGET
1160$(foreach target, $(_ALL_SYSMODS), $(evalvalctx def_link_common))
1161
1162ifdef KBUILD_PROFILE_SELF
1163 $(evalcall def_profile_self, done sysmod targets)
1164endif
1165
1166
1167#
1168# MISCBINS
1169#
1170
1171# Process MISCBINS
1172EXT := BIN
1173EXTPRE :=
1174tool_do := LINK_MISCBIN
1175typevar := _MISCBINS
1176mode := 0644
1177bld_trg_base_var := TARGET
1178$(foreach target, $(_ALL_MISCBINS), $(evalvalctx def_link_common))
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.