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

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

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.4 KB
Line 
1# $Id: footer-pass2-compiling-targets.kmk 3256 2019-01-02 22:17:28Z 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
59ifneq ($(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# kObjCache.
503ifdef KBUILD_USE_KOBJCACHE
504 ifneq ($($(target)_KOBJCACHE),)
505local use_objcache := 1
506 else
507local use_objcache :=
508 endif
509local use_objcache :=
510endif
511
512# source -> object
513$(evalval def_target_sources)
514
515# library linking
516local tool := $(call _TARGET_TOOL,$(target),AR)
517local name := $(firstword\
518 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
519 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
520 $($(target)_NAME.$(bld_trg).$(bld_type))\
521 $($(target)_NAME.$(bld_trg_arch))\
522 $($(target)_NAME.$(bld_trg))\
523 $($(target)_NAME.$(bld_type))\
524 $($(target)_NAME)\
525 $(target))
526local outbase := $(call TARGET_BASE,$(name),$(target))
527local flags :=\
528 $(TOOL_$(tool)_ARFLAGS)\
529 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
530 $(ARFLAGS)\
531 $(ARFLAGS.$(bld_type))\
532 $($(target)_ARFLAGS)\
533 $($(target)_ARFLAGS.$(bld_type)) \
534 $($(target)_ARFLAGS.$(bld_trg)) \
535 $($(target)_ARFLAGS.$(bld_trg_arch)) \
536 $($(target)_ARFLAGS.$(bld_trg).$(bld_trg_arch)) \
537 $($(target)_ARFLAGS.$(bld_trg_cpu))
538local dirdep := $(call DIRDEP,$(dir $(out)))
539local deps := \
540 $($(target)_DEPS.$(bld_trg_cpu)) \
541 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
542 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
543 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
544 $($(target)_DEPS.$(bld_trg_arch)) \
545 $($(target)_DEPS.$(bld_trg)) \
546 $($(target)_DEPS.$(bld_type)) \
547 $($(target)_DEPS) \
548 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
549 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
550 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
551 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
552 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
553 $($(target)_LNK_DEPS.$(bld_trg)) \
554 $($(target)_LNK_DEPS.$(bld_type)) \
555 $($(target)_LNK_DEPS)
556local orderdeps := \
557 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
558 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
559 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
560 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
561 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
562 $($(target)_ORDERDEPS.$(bld_trg)) \
563 $($(target)_ORDERDEPS.$(bld_type)) \
564 $($(target)_ORDERDEPS) \
565 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
566 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
567 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
568 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
569 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
570 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
571 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
572 $($(target)_LNK_ORDERDEPS)
573
574# Adjust paths if we got a default path.
575ifneq ($(defpath),)
576 local deps := $(abspathex $(deps),$(defpath))
577 local orderdeps := $(abspathex $(orderdeps),$(defpath))
578 othersrc := $(abspathex $(othersrc),$(defpath))
579endif
580
581
582# Custom pre-link actions.
583local pre_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,PRE_CMDS,$(NLTAB))
584local post_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,POST_CMDS,$(NLTAB))
585
586# eliminate this guy?
587local objs = $($(target)_2_OBJS)
588
589# dependency file
590local dep := $(out)$(SUFF_DEP)
591ifndef NO_LINK_CMDS_DEPS
592 _DEPFILES_INCLUDED += $(dep)
593 ifdef KB_HAVE_INCLUDEDEP_QUEUE
594 includedep-queue $(dep)
595 else
596 includedep $(dep)
597 endif
598endif
599
600# check that the tool is defined.
601ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
602$(warning kBuild: tools: \
603 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
604 2 $($(target)_$(source)TOOL.$(bld_trg)) \
605 3 $($(target)_$(source)TOOL) \
606 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
607 5 $($(target)_TOOL.$(bld_trg)) \
608 6 $($(target)_TOOL) \
609 7 $($(source)TOOL) \
610 8 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
611 9 $($(source)TOOL.$(bld_trg)) \
612 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
613 11 $(TOOL.$(bld_trg)) \
614 12 $(TOOL) )
615$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
616endif
617
618# call the tool
619local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
620ifneq ($(pre_cmds),)
621 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
622endif
623ifneq ($(post_cmds),)
624 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
625endif
626$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
627$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
628$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE_PRECIOUS)
629$(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_2_OBJS)
630$(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
631
632# generate the link rule.
633$(eval $(def_link_rule))
634
635# installing and globals.
636local target_type_mode := a+r,u+w
637$(evalval def_target_install_only)
638
639_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
640_CLEAN_FILES += $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_cpu)) $($(target)_CLEAN.$(bld_type))
641_DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
642_OBJS += $($(target)_2_OBJS)
643
644endef # def_lib
645$(eval-opt-var def_lib)
646
647# Process libraries
648typevar := _LIBS
649tool_do := LINK_LIBRARY
650mode := 0644
651$(foreach target, $(_ALL_LIBRARIES), $(evalvalctx def_lib))
652
653ifdef KBUILD_PROFILE_SELF
654 $(evalcall def_profile_self, done library targets)
655endif
656
657
658#
659# Link operations.
660#
661
662##
663# Link prolog
664#
665# @param $(target) Normalized target name.
666# @param $(EXT) EXE,DLL,SYS.
667# @param $(typevar) The name of the variable with all the root targets of its type.
668define def_link_common
669# basics
670local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
671local bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
672local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
673local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
674
675local tool := $(call _TARGET_TOOL,$(target),LD)
676local name := $(firstword\
677 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
678 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
679 $($(target)_NAME.$(bld_trg).$(bld_type))\
680 $($(target)_NAME.$(bld_trg_arch))\
681 $($(target)_NAME.$(bld_trg))\
682 $($(target)_NAME.$(bld_type))\
683 $($(target)_NAME)\
684 $(target))
685local outbase := $(call TARGET_BASE,$(name),$(target))
686$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
687$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
688local suff := $(firstword \
689 $($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
690 $($(target)_$(EXT)SUFF.$(bld_trg))\
691 $($(target)_$(EXT)SUFF)\
692 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
693 $(TOOL_$(tool)_LD$(EXT)SUFF.$(bld_trg))\
694 $(TOOL_$(tool)_LD$(EXT)SUFF)\
695 $($(EXTPRE)SUFF_$(EXT)) )
696local out := $(outbase)$(suff)
697$(target)_1_TARGET:= $(out)
698$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
699local defpath := $($(target)_DEFPATH)
700ifeq ($(defpath),)
701 local defpath := $($(target)_PATH)
702endif
703# no local here - must be writable across some foreachs.
704othersrc :=
705$(target)_2_OBJS :=
706
707# Do units pre source callouts.
708local units := \
709 $($(target)_USES.$(bld_trg).$(bld_trg_arch))\
710 $($(target)_USES.$(bld_trg_arch))\
711 $($(target)_USES.$(bld_trg))\
712 $($(target)_USES.$(bld_type))\
713 $($(target)_USES)
714$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
715$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
716
717# kObjCache.
718ifdef KBUILD_USE_KOBJCACHE
719 ifneq ($($(target)_KOBJCACHE),)
720local use_objcache := 1
721 else
722local use_objcache :=
723 endif
724local use_objcache :=
725endif
726
727# source -> object
728$(evalval def_target_sources)
729
730# more link stuff.
731local tool := $(call _TARGET_TOOL,$(target),LD)
732local name := $(firstword\
733 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
734 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
735 $($(target)_NAME.$(bld_trg).$(bld_type))\
736 $($(target)_NAME.$(bld_trg_arch))\
737 $($(target)_NAME.$(bld_trg))\
738 $($(target)_NAME.$(bld_type))\
739 $($(target)_NAME)\
740 $(target))
741local outbase := $(call TARGET_BASE,$(name),$(target))
742local flags :=\
743 $(TOOL_$(tool)_LDFLAGS)\
744 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
745 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
746 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
747 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
748 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
749 $(foreach sdk, $(SDKS) \
750 $(SDKS.$(bld_type)) \
751 $(SDKS.$(bld_trg)) \
752 $(SDKS.$(bld_trg_arch)) \
753 $(SDKS.$(bld_trg).$(bld_trg_arch)),\
754 $(SDK_$(sdk)_LDFLAGS)\
755 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
756 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
757 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
758 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
759 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
760 $(LDFLAGS)\
761 $(LDFLAGS.$(bld_type))\
762 $(LDFLAGS.$(bld_trg))\
763 $(LDFLAGS.$(bld_trg_arch))\
764 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
765 $(LDFLAGS.$(bld_trg_cpu))\
766 $(foreach sdk, $($(target)_SDKS) \
767 $($(target)_SDKS.$(bld_type)) \
768 $($(target)_SDKS.$(bld_trg)) \
769 $($(target)_SDKS.$(bld_trg_arch)) \
770 $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)),\
771 $(SDK_$(sdk)_LDFLAGS)\
772 $(SDK_$(sdk)_LDFLAGS.$(bld_type))\
773 $(SDK_$(sdk)_LDFLAGS.$(bld_trg))\
774 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_arch))\
775 $(SDK_$(sdk)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
776 $(SDK_$(sdk)_LDFLAGS.$(bld_trg_cpu)))\
777 $($(target)_LDFLAGS)\
778 $($(target)_LDFLAGS.$(bld_type))\
779 $($(target)_LDFLAGS.$(bld_trg))\
780 $($(target)_LDFLAGS.$(bld_trg_arch))\
781 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
782 $($(target)_LDFLAGS.$(bld_trg_cpu))
783local libs :=\
784 $($(target)_LIBS.$(bld_trg_cpu))\
785 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
786 $($(target)_LIBS.$(bld_trg_arch))\
787 $($(target)_LIBS.$(bld_trg))\
788 $($(target)_LIBS.$(bld_type))\
789 $($(target)_LIBS)\
790 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
791 $($(target)_SDKS.$(bld_trg_arch)) \
792 $($(target)_SDKS.$(bld_trg)) \
793 $($(target)_SDKS.$(bld_type)) \
794 $($(target)_SDKS),\
795 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
796 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
797 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
798 $(SDK_$(sdk)_LIBS.$(bld_trg))\
799 $(SDK_$(sdk)_LIBS.$(bld_type))\
800 $(SDK_$(sdk)_LIBS))\
801 $(LIBS.$(bld_trg_cpu))\
802 $(LIBS.$(bld_trg).$(bld_trg_arch))\
803 $(LIBS.$(bld_trg_arch))\
804 $(LIBS.$(bld_trg))\
805 $(LIBS.$(bld_type))\
806 $(LIBS)\
807 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
808 $(SDKS.$(bld_trg_arch)) \
809 $(SDKS.$(bld_trg)) \
810 $(SDKS.$(bld_type)) \
811 $(SDKS),\
812 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
813 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
814 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
815 $(SDK_$(sdk)_LIBS.$(bld_trg))\
816 $(SDK_$(sdk)_LIBS.$(bld_type))\
817 $(SDK_$(sdk)_LIBS))\
818 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
819 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
820 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
821 $(TOOL_$(tool)_LIBS.$(bld_trg))\
822 $(TOOL_$(tool)_LIBS.$(bld_type))\
823 $(TOOL_$(tool)_LIBS)
824local libpath :=\
825 $($(target)_LIBPATH.$(bld_trg_cpu))\
826 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
827 $($(target)_LIBPATH.$(bld_trg_arch))\
828 $($(target)_LIBPATH.$(bld_trg))\
829 $($(target)_LIBPATH.$(bld_type))\
830 $($(target)_LIBPATH)\
831 $(foreach sdk, $($(target)_SDKS.$(bld_trg).$(bld_trg_arch)) \
832 $($(target)_SDKS.$(bld_trg_arch)) \
833 $($(target)_SDKS.$(bld_trg)) \
834 $($(target)_SDKS.$(bld_type)) \
835 $($(target)_SDKS),\
836 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
837 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
838 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
839 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
840 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
841 $(SDK_$(sdk)_LIBPATH))\
842 $(LIBPATH.$(bld_trg_cpu))\
843 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
844 $(LIBPATH.$(bld_trg_arch))\
845 $(LIBPATH.$(bld_trg))\
846 $(LIBPATH.$(bld_type))\
847 $(LIBPATH)\
848 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
849 $(SDKS.$(bld_trg_arch)) \
850 $(SDKS.$(bld_trg)) \
851 $(SDKS.$(bld_type)) \
852 $(SDKS),\
853 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
854 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
855 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
856 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
857 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
858 $(SDK_$(sdk)_LIBPATH))\
859 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
860 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
861 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
862 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
863 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
864 $(TOOL_$(tool)_LIBPATH)
865local dirdep := $(call DIRDEP,$(dir $(out)))
866local deps := \
867 $($(target)_DEPS.$(bld_trg_cpu)) \
868 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
869 $($(target)_DEPS.$(bld_trg).$(bld_trg_arch)) \
870 $($(target)_DEPS.$(bld_trg).$(bld_type)) \
871 $($(target)_DEPS.$(bld_trg_arch)) \
872 $($(target)_DEPS.$(bld_trg)) \
873 $($(target)_DEPS.$(bld_type)) \
874 $($(target)_DEPS) \
875 $($(target)_LNK_DEPS.$(bld_trg_cpu)) \
876 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
877 $($(target)_LNK_DEPS.$(bld_trg).$(bld_trg_arch)) \
878 $($(target)_LNK_DEPS.$(bld_trg).$(bld_type)) \
879 $($(target)_LNK_DEPS.$(bld_trg_arch)) \
880 $($(target)_LNK_DEPS.$(bld_trg)) \
881 $($(target)_LNK_DEPS.$(bld_type)) \
882 $($(target)_LNK_DEPS)
883local orderdeps := \
884 $($(target)_ORDERDEPS.$(bld_trg_cpu)) \
885 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
886 $($(target)_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
887 $($(target)_ORDERDEPS.$(bld_trg).$(bld_type)) \
888 $($(target)_ORDERDEPS.$(bld_trg_arch)) \
889 $($(target)_ORDERDEPS.$(bld_trg)) \
890 $($(target)_ORDERDEPS.$(bld_type)) \
891 $($(target)_ORDERDEPS) \
892 $($(target)_LNK_ORDERDEPS.$(bld_trg_cpu)) \
893 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
894 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_trg_arch)) \
895 $($(target)_LNK_ORDERDEPS.$(bld_trg).$(bld_type)) \
896 $($(target)_LNK_ORDERDEPS.$(bld_trg_arch)) \
897 $($(target)_LNK_ORDERDEPS.$(bld_trg)) \
898 $($(target)_LNK_ORDERDEPS.$(bld_type)) \
899 $($(target)_LNK_ORDERDEPS)
900
901# Adjust paths if we got a default path.
902ifneq ($(defpath),)
903 local libpath := $(abspathex $(libpath),$(defpath))
904 local deps := $(abspathex $(deps),$(defpath))
905 local orderdeps := $(abspathex $(orderdeps),$(defpath))
906 othersrc := $(abspathex $(othersrc),$(defpath))
907 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
908endif
909
910# Debug info.
911local ld_debug := $(evalcall def_fn_prop_get_first_defined,LD_DEBUG)
912local debug_inst := $(evalcall def_fn_prop_get_first_defined,DEBUG_INST)
913local debug_stage := $(evalcall def_fn_prop_get_first_defined,DEBUG_STAGE)
914local debug_nostage := $(evalcall def_fn_prop_get_first_word,DEBUG_NOSTAGE)
915
916# Custom pre/post-link actions.
917local pre_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,PRE_CMDS,$(NLTAB))
918local post_cmds := $(evalcall def_fn_prop_get_all_prefixed_priority_last,POST_CMDS,$(NLTAB))
919
920# eliminate this guy?
921local objs = $($(target)_2_OBJS)
922
923# dependency file
924local dep := $(outbase)$(SUFF_DEP)
925ifndef NO_LINK_CMDS_DEPS
926 _DEPFILES_INCLUDED += $(dep)
927 ifdef KB_HAVE_INCLUDEDEP_QUEUE
928 includedep-queue $(dep)
929 else
930 includedep $(dep)
931 endif
932endif
933
934# check that the tool is defined.
935ifndef TOOL_$(tool)_$(tool_do)_CMDS
936$(warning kBuild: tools: \
937 1 $($(target)_$(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
938 2 $($(target)_$(source)TOOL.$(bld_trg)) \
939 3 $($(target)_$(source)TOOL) \
940 4 $($(target)_TOOL.$(bld_trg).$(bld_trg_arch)) \
941 5 $($(target)_TOOL.$(bld_trg)) \
942 6 $($(target)_TOOL) \
943 7 $($(source)TOOL.$(bld_trg).$(bld_trg_arch)) \
944 8 $($(source)TOOL.$(bld_trg)) \
945 9 $($(source)TOOL) \
946 10 $(TOOL.$(bld_trg).$(bld_trg_arch)) \
947 11 $(TOOL.$(bld_trg)) \
948 12 $(TOOL) )
949$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
950endif
951
952# call the tool
953local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
954ifneq ($(pre_cmds),)
955 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
956endif
957ifneq ($(post_cmds),)
958 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
959endif
960$(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
961$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
962$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE_PRECIOUS)
963if1of ($(ld_debug), split)
964 $(target)_2_OUTPUT_DEBUG_FILES := $(filter-out %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
965 $(target)_2_OUTPUT_DEBUG_DIRS := $(filter %/,$(TOOL_$(tool)_$(tool_do)_OUTPUT_DEBUG))
966else
967 $(target)_2_OUTPUT_DEBUG_FILES :=
968 $(target)_2_OUTPUT_DEBUG_DIRS :=
969endif
970$(target)_2_DEPEND := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $($(target)_2_OBJS)
971$(target)_2_DEPORD := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep) $(orderdeps)
972
973# generate the link rule.
974$(eval $(def_link_rule))
975
976# installation targets
977local target_type_mode :=
978$(evalval def_target_install_only)
979
980# Update globals.
981_OBJS += $($(target)_2_OBJS)
982_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
983_CLEAN_FILES += $($(target)_CLEAN) $($(target)_CLEAN.$(bld_trg)) $($(target)_CLEAN.$(bld_trg).$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_arch)) $($(target)_CLEAN.$(bld_trg_cpu)) $($(target)_CLEAN.$(bld_type))
984_DIRS += $($(target)_BLDDIRS) $($(target)_BLDDIRS.$(bld_trg)) $($(target)_BLDDIRS.$(bld_trg).$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_arch)) $($(target)_BLDDIRS.$(bld_trg_cpu)) $($(target)_BLDDIRS.$(bld_type))
985_INSTALLS_FILES += $(INSTARGET_$(target))
986
987endef # def_link_common
988$(eval-opt-var def_link_common)
989
990
991#
992# BLDPROGS
993#
994
995# Process build programs.
996EXT := EXE
997EXTPRE := HOST
998tool_do := LINK_PROGRAM
999typevar := _BLDPROGS
1000mode := 0755
1001bld_trg_base_var := PLATFORM
1002$(foreach target, $(_ALL_BLDPROGS), $(evalvalctx def_link_common))
1003
1004ifdef KBUILD_PROFILE_SELF
1005 $(evalcall def_profile_self, done build program targets)
1006endif
1007
1008
1009#
1010# DLLS
1011#
1012
1013# Process dlls
1014EXT := DLL
1015EXTPRE :=
1016tool_do := LINK_DLL
1017typevar := _DLLS
1018mode := 0644
1019bld_trg_base_var := TARGET
1020$(foreach target, $(_ALL_DLLS), $(evalvalctx def_link_common))
1021
1022ifdef KBUILD_PROFILE_SELF
1023 $(evalcall def_profile_self, done dll targets)
1024endif
1025
1026
1027#
1028# IMPORT LIBRARIES
1029#
1030# - On OS/2 and windows these are libraries.
1031# - On other platforms they are fake DLLs.
1032#
1033EXTPRE :=
1034typevar := _IMPORT_LIBS
1035mode := 0644
1036bld_trg_base_var := TARGET
1037ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
1038 EXT := LIB
1039 tool_do := LINK_LIBRARY
1040 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_lib))
1041else
1042 EXT := DLL
1043 tool_do := LINK_DLL
1044 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_link_common))
1045endif
1046
1047ifdef KBUILD_PROFILE_SELF
1048 $(evalcall def_profile_self, done import library targets)
1049endif
1050
1051
1052#
1053# PROGRAMS
1054#
1055
1056# Process programs
1057EXT := EXE
1058EXTPRE :=
1059tool_do := LINK_PROGRAM
1060typevar := _PROGRAMS
1061mode := 0755
1062bld_trg_base_var := TARGET
1063$(foreach target, $(_ALL_PROGRAMS), $(evalvalctx def_link_common))
1064
1065ifdef KBUILD_PROFILE_SELF
1066 $(evalcall def_profile_self, done program targets)
1067endif
1068
1069
1070#
1071# SYSMODS
1072#
1073
1074# Process sysmods
1075EXT := SYS
1076EXTPRE :=
1077tool_do := LINK_SYSMOD
1078typevar := _SYSMODS
1079mode := 0644
1080bld_trg_base_var := TARGET
1081$(foreach target, $(_ALL_SYSMODS), $(evalvalctx def_link_common))
1082
1083ifdef KBUILD_PROFILE_SELF
1084 $(evalcall def_profile_self, done sysmod targets)
1085endif
1086
1087
1088#
1089# MISCBINS
1090#
1091
1092# Process MISCBINS
1093EXT := BIN
1094EXTPRE :=
1095tool_do := LINK_MISCBIN
1096typevar := _MISCBINS
1097mode := 0644
1098bld_trg_base_var := TARGET
1099$(foreach target, $(_ALL_MISCBINS), $(evalvalctx def_link_common))
1100
1101ifdef KBUILD_PROFILE_SELF
1102 $(evalcall def_profile_self, done misc binary targets)
1103endif
1104
Note: See TracBrowser for help on using the repository browser.