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

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

kmk_append: Extended it with an -i parameter that enables looking for --insert-variable=xxx and --inserv-command=xxx. This allows us to merge the kmk_builtin_append commands at the end of each compilation, which significantly (e.g. 1m4s -> 37s) speeds up builds on windows and its dead slow file system.

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