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

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

kBuild//*.kmk: Use optimized kmk_builtin_append when availble.

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