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
RevLine 
[72]1# $Id: footer-pass2-compiling-targets.kmk 3135 2018-03-01 18:45:26Z bird $
2## @file
[2521]3# kBuild - Footer - Target lists - Pass 2 - Compiling Targets.
[72]4#
[1547]5
6#
[3121]7# Copyright (c) 2004-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
[72]8#
9# This file is part of kBuild.
10#
11# kBuild is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
[106]13# the Free Software Foundation; either version source of the License, or
[72]14# (at your option) any later version.
15#
16# kBuild is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with kBuild; if not, write to the Free Software
[353]23# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
[72]24#
25#
[1547]26# As a special exception you are granted permission to include this file, via
[1599]27# the kmk include directive, as you wish without this in itself causing the
28# resulting makefile, program or whatever to be covered by the GPL license.
[1547]29# This exception does not however invalidate any other reasons why the makefile,
30# program, whatever should not be covered the GPL.
31#
32#
[72]33
34
35#
[73]36# Object processing.
37#
[72]38
[380]39## wrapper the compile command dependency check.
40ifndef NO_COMPILE_CMDS_DEPS
[2026]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
[380]47else
[730]48 _DEP_COMPILE_CMDS =
[380]49endif
50
[2026]51
[3135]52## Temporary for the compile rule below.
53if "$(KBUILD_KMK_REVISION)" >= 3134
54 KBUILD_HAVE_OPTIMIZED_APPEND := 1
55endif
56
57
[749]58## Generates the rules for building a specific object, and the aliases
[380]59# for building a source file.
[353]60# @param $(obj) The object file.
[380]61define def_target_source_rule
[2026]62ifndef NO_COMPILE_CMDS_DEPS
63$(obj): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_CMDS_PREV_),$$(commands $$@),FORCE)
64endif
[1012]65ifdef TOOL_$(tool)_COMPILE_$(type)_USES_KOBJCACHE
[2196]66_OUT_FILES += $(outbase).koc
[1030]67$(outbase).koc +| $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_$(source)_OUTPUT_MAYBE_) : \
[1007]68 $($(target)_$(source)_DEPEND_) \
[1456]69 $(value _DEP_COMPILE_CMDS) \
[1007]70 | \
[1426]71 $($(target)_$(source)_DEPORD_) \
[2355]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))
[1496]78 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[1007]79else
[1030]80$(obj) + $($(target)_$(source)_OUTPUT_) +| $($(target)_$(source)_OUTPUT_MAYBE_) : \
[380]81 $($(target)_$(source)_DEPEND_) \
[1456]82 $(value _DEP_COMPILE_CMDS) \
[380]83 | \
[1426]84 $($(target)_$(source)_DEPORD_) \
[2355]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))
[1496]91 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
[2952]92ifndef TOOL_$(tool)_COMPILE_$(type)_DONT_PURGE_OUTPUT
[1599]93 $$(QUIET)$$(RM) -f -- $(dep) $(obj) $($(target)_$(source)_OUTPUT_) $($(target)_OUTPUT_MAYBE_)
[1007]94endif
[1012]95endif
[412]96
[380]97$($(target)_$(source)_CMDS_)
98
99ifndef NO_COMPILE_CMDS_DEPS
[3135]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_'
[1496]108 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(obj)'
109 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
[3135]110 endif
[770]111endif
[380]112
[749]113$(basename $(notdir $(obj))).o: $(obj)
114$(basename $(notdir $(obj))).obj: $(obj)
[1496]115
[2234]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.
[1496]117$(target)_$(source)_CMDS_ :=
[2234]118$(target)_$(source)_OUTPUT_ :=
119$(target)_$(source)_OUTPUT_MAYBE_ :=
120$(target)_$(source)_DEPEND_ :=
121$(target)_$(source)_DEPORD_ :=
[1936]122endef # def_target_source_rule
123$(eval-opt-var def_target_source_rule)
[205]124
[353]125
[380]126## wrapper the link command dependency check.
[1502]127ifndef NO_LINK_CMDS_DEPS
[2026]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
[380]133else
[730]134 _DEP_LINK_CMDS =
[380]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)
[2234]142# @param $($(target)_2_OUTPUT) Output files from the link.
143# @param $($(target)_2_OUTPUT_MAYBE) Output files that the link may perhaps create.
[2795]144# @param $($(target)_2_OUTPUT_MAYBE_PRECIOUS) Output files that the link may perhaps create but shouldn't be deleted.
[2234]145# @param $($(target)_2_DEPEND) Dependencies.
146# @param $($(target)_2_DEPORD) Dependencies which should only affect build order.
[1496]147# @param $(cmds) The link commands.
[380]148# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
149define def_link_rule
[2531]150$$(call KB_FN_ASSERT_ABSPATH,out)
[2026]151ifndef NO_LINK_CMDS_DEPS
152$(out): .MUST_MAKE = $$(comp-cmds-ex $$($(target)_CMDS_PREV_),$$(commands $$@),FORCE)
153endif
[2523]154$(out) \
155+ $($(target)_2_OUTPUT) \
156+ $($(target)_2_OUTPUT_DEBUG_FILES) \
157+ $($(target)_2_OUTPUT_DEBUG_DIRS) \
[2795]158+| $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) : \
[2234]159 $$$$($(target)_2_DEPEND) \
[1456]160 $(value _DEP_LINK_CMDS) \
[380]161 | \
[2234]162 $$$$($(target)_2_DEPORD)
[1496]163 %$$(call MSG_LINK,$(target),$$@,$(tool_do))
[2523]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
[412]168
[1496]169$(cmds)
[380]170
[524]171ifndef NO_LINK_CMDS_DEPS
[1496]172 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_CMDS_PREV_'
173 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
174 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
[770]175endif
[380]176
[1686]177$(basename $(notdir $(out))):: $(out)
[719]178
[1936]179endef # def_link_rule
180$(eval-opt-var def_link_rule)
[380]181
182
183## Generate the link & lib install rule
[2475]184# Implicit parameters: target, out, $(target)_1_STAGE_TARGET, mode,
185# pre_install_cmds, post_install_cmds
[380]186define def_link_install_rule
[2531]187$$(call KB_FN_ASSERT_ABSPATH,$(target)_1_INST_TARGET)
[2488]188$($(target)_1_INST_TARGET): $(out) | $$$$(dir $$$$@)
[1496]189 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
[2475]190 $(pre_install_cmds)
191
[2225]192 $$(QUIET)$$(INSTALL) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
[2475]193 $(post_install_cmds)
[719]194
[2475]195endef
[380]196
[2475]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
[2531]202$$(call KB_FN_ASSERT_ABSPATH,$(target)_1_STAGE_TARGET)
[2488]203$($(target)_1_STAGE_TARGET): $(out) | $$$$(dir $$$$@)
[2475]204 %$$(call MSG_INST_TRG,$(target),$(out),$$@)
205 $(pre_install_cmds)
206
[2479]207 $$(QUIET)$$(INSTALL_STAGING) $(if $(mode),-m $(mode)) $(if $(uid),-o $(uid)) $(if $(gid),-g $(gid)) -- $(out) $$@
[2475]208 $(post_install_cmds)
209
210
211$(basename $(notdir $(out))):: $($(target)_1_STAGE_TARGET)
212
213endef
214
215
[1424]216## def_src_handler_*
217#
218# @{
219define def_src_handler_c
[1496]220local type := C
[1795]221 $(kb-src-one 2)
[1424]222endef
[73]223
[1424]224define def_src_handler_cxx
[1496]225local type := CXX
[1795]226 $(kb-src-one 2)
[1424]227endef
[73]228
[1424]229define def_src_handler_objc
[1496]230local type := OBJC
[1795]231 $(kb-src-one 2)
[1424]232endef
[1256]233
[2356]234define def_src_handler_objcxx
[2359]235local type := OBJCXX
[2356]236 $(kb-src-one 2)
237endef
238
[1424]239define def_src_handler_asm
[1496]240local type := AS
[1795]241 $(kb-src-one 2)
[1424]242endef
[353]243
[1424]244define def_src_handler_rc
[1496]245local type := RC
[1795]246 $(kb-src-one 2)
[1424]247endef
[641]248
[1424]249define def_src_handler_obj
[1434]250ifeq ($(defpath),)
[2080]251 $(target)_2_OBJS += $(source)
252else
253 $(target)_2_OBJS += $(abspathex $(source), $(defpath))
254endif
255endef
[1424]256## @}
[73]257
[1424]258## Handle one source.
259# .
260define def_src_handler_one
[1496]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))
[1424]264ifneq ($(handler),)
[1625]265 $(evalvalctx $(handler))
[1424]266else
[1434]267 othersrc += $(source)
[1424]268endif
[2475]269endef # def_src_handler_one
[73]270
[1424]271## Generic macro for processing all target sources.
272# @param $(target) Normalized target name.
273# @param $(defpath)
274# @param much-more...
[2236]275# @returns othersrc, $(target)_2_OBJS, ++
[1424]276define def_target_sources
[1496]277local target_src_handlers := $($(target)_SRC_HANDLERS) $(KBUILD_SRC_HANDLERS)
[1424]278$(foreach source,\
[1429]279 $($(target)_SOURCES)\
280 $($(target)_SOURCES.$(bld_trg))\
[2433]281 $($(target)_SOURCES.$(bld_trg).$(bld_type))\
[1429]282 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch))\
[2433]283 $($(target)_SOURCES.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[1429]284 $($(target)_SOURCES.$(bld_trg_arch))\
285 $($(target)_SOURCES.$(bld_trg_cpu))\
286 $($(target)_SOURCES.$(bld_type))\
[2762]287 ,$(evalvalctx def_src_handler_one) )
[1621]288
289$(foreach source,\
290 $($(target)_GEN_SOURCES_)\
291 $($(target)_GEN_SOURCES_.$(bld_trg))\
[2433]292 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_type))\
[1621]293 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch))\
[2433]294 $($(target)_GEN_SOURCES_.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[1621]295 $($(target)_GEN_SOURCES_.$(bld_trg_arch))\
296 $($(target)_GEN_SOURCES_.$(bld_trg_cpu))\
297 $($(target)_GEN_SOURCES_.$(bld_type))\
[2762]298 ,$(evalvalctx def_src_handler_one) )
[1936]299endef # def_target_sources
300$(eval-opt-var def_target_sources)
[1424]301
302
[2475]303##
[2523]304# Install a debug directory.
305# @param debug_dir The directory name.
306define def_link_install_debug_dir_rule
[2535]307local dir := $(debug_inst_path)/$(debug_inst2)$(debug_dir)
[2531]308$$(call KB_FN_ASSERT_ABSPATH,dir)
[2523]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##
[2531]316# Install a debug file.
[2523]317# @param debug_file Src=>Dst file pair.
318define def_link_install_debug_file_rule
[2535]319local dst := $(debug_inst_path)/$(debug_inst2)$(word 2, $(subst =>,$(SP),$(debug_file)))
[2531]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 $$$$@)
[2535]324 %$$(call MSG_INST_FILE,$$<,$$@)
[2523]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##
[2531]330# Install debug info to $(debug_inst), where debug_inst can be a directory or
[2523]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)" == "./"
[2535]335 local debug_inst2 :=
336 else
337 local debug_inst2 := $(debug_inst)
[2523]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
[2535]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))
[2523]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
[2475]357## Generic macro for generating the install rule(s) for a target.
[219]358#
[353]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.
[2481]362# @param $(target_type_mode) The default file mode implied by the target type.
[2475]363define def_target_install_only
[2551]364if1of ($($(target)_1_INSTTYPE) $($(target)_1_DEBUG_INSTTYPE), both stage)
365 # Determin common variables.
[2225]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)) \
[2483]373 $($(target)_MODE) \
374 $(target_type_mode) )
[2225]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) )
[2475]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)
[2551]393endif
[219]394
[2551]395ifneq ($($(target)_1_INSTTYPE),none)
[2475]396 # Generate the rules
397 ifeq ($($(target)_1_INSTTYPE),both)
[353]398$(eval $(def_link_install_rule))
[2475]399 _INSTALLS_FILES += $($(target)_1_INST_TARGET)
[1697]400 endif
[2475]401$(eval $(def_link_stage_rule))
402 _STAGE_FILES += $($(target)_1_STAGE_TARGET)
403 $(typevar) += $($(target)_1_STAGE_TARGET)
404else # INSTTYPE == none
[1697]405 $(typevar) += $(out)
[2475]406endif # INSTTYPE == none
[353]407
[2523]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
[2762]423 $(foreach debug_inst, $($(target)_1_DEBUG_INST), $(evalvalctx def_target_install_only_debug))
[2523]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)
[2762]430 $(foreach debug_inst, $($(target)_1_DEBUG_STAGE), $(evalvalctx def_target_install_only_debug))
[2523]431 endif
432 if1of ($($(target)_1_INSTTYPE), stage both)
433 ifndef debug_nostage
[2762]434 $(foreach debug_inst,$($(target)_1_STAGE), $(evalvalctx def_target_install_only_debug))
[2523]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
[2475]446endef # def_target_install_only
[353]447
[219]448
449
450#
[72]451# LIBRARIES
[73]452#
[72]453
454## Library (one).
[74]455# @param $(target) Normalized library (target) name.
[72]456define def_lib
[145]457# library basics
[222]458## @todo prefix
[1504]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))
[1496]463local tool := $(call _TARGET_TOOL,$(target),AR)
[78]464ifeq ($(tool),)
[353]465$(error kBuild: Library target $(target) does not have a tool defined!)
[78]466endif
[1496]467local name := $(firstword\
[2433]468 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]469 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]470 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]471 $($(target)_NAME.$(bld_trg_arch))\
472 $($(target)_NAME.$(bld_trg))\
473 $($(target)_NAME.$(bld_type))\
474 $($(target)_NAME)\
475 $(target))
[1496]476local outbase := $(call TARGET_BASE,$(name),$(target))
[2239]477$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
[2436]478$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
[1496]479local suff := $(firstword\
[481]480 $($(target)_LIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]481 $($(target)_LIBSUFF.$(bld_trg))\
[126]482 $($(target)_LIBSUFF)\
[481]483 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg).$(bld_trg_arch))\
[221]484 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]485 $(TOOL_$(tool)_ARLIBSUFF)\
[353]486 $(SUFF_LIB))
[1496]487local out := $(outbase)$(suff)
[2434]488local defpath := $($(target)_DEFPATH)
489ifeq ($(defpath),)
490 local defpath := $($(target)_PATH)
491endif
[2238]492$(target)_1_TARGET:= $(out)
[2436]493$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
[1496]494# no local here - must be writable across some foreachs.
495othersrc :=
[2236]496$(target)_2_OBJS :=
[145]497
[1672]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)
[2762]505$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
[2952]506$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
[1672]507
[145]508# source -> object
[1496]509$(evalval def_target_sources)
[145]510
511# library linking
[1496]512local tool := $(call _TARGET_TOOL,$(target),AR)
513local name := $(firstword\
[2433]514 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]515 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]516 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]517 $($(target)_NAME.$(bld_trg_arch))\
518 $($(target)_NAME.$(bld_trg))\
519 $($(target)_NAME.$(bld_type))\
520 $($(target)_NAME)\
521 $(target))
[1496]522local outbase := $(call TARGET_BASE,$(name),$(target))
523local flags :=\
[74]524 $(TOOL_$(tool)_ARFLAGS)\
[221]525 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]526 $(ARFLAGS)\
[221]527 $(ARFLAGS.$(bld_type))\
[74]528 $($(target)_ARFLAGS)\
[481]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))
[1496]534local dirdep := $(call DIRDEP,$(dir $(out)))
[1702]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)
[72]569
[725]570# Adjust paths if we got a default path.
571ifneq ($(defpath),)
[1496]572 local deps := $(abspathex $(deps),$(defpath))
573 local orderdeps := $(abspathex $(orderdeps),$(defpath))
[1472]574 othersrc := $(abspathex $(othersrc),$(defpath))
[725]575endif
576
[859]577
578# Custom pre-link actions.
[3128]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))
[859]581
[1424]582# eliminate this guy?
[2236]583local objs = $($(target)_2_OBJS)
[1424]584
[380]585# dependency file
[1496]586local dep := $(out)$(SUFF_DEP)
[524]587ifndef NO_LINK_CMDS_DEPS
[1798]588 _DEPFILES_INCLUDED += $(dep)
589 ifdef KB_HAVE_INCLUDEDEP_QUEUE
590 includedep-queue $(dep)
[1795]591 else
[1798]592 includedep $(dep)
[1795]593 endif
[380]594endif
[72]595
[380]596# check that the tool is defined.
597ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
598$(warning kBuild: tools: \
[481]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) )
[380]611$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
612endif
613
614# call the tool
[2523]615local cmds := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
[859]616ifneq ($(pre_cmds),)
[1496]617 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
[859]618endif
619ifneq ($(post_cmds),)
[2523]620 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
[859]621endif
[2234]622$(target)_2_OUTPUT := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
623$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE)
[2795]624$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT_MAYBE_PRECIOUS)
[2236]625$(target)_2_DEPEND := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $($(target)_2_OBJS)
[2234]626$(target)_2_DEPORD := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep) $(orderdeps)
[380]627
[412]628# generate the link rule.
[380]629$(eval $(def_link_rule))
630
[2475]631# installing and globals.
[2483]632local target_type_mode := a+r,u+w
[2475]633$(evalval def_target_install_only)
634
[2795]635_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
[2475]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
[1936]641$(eval-opt-var def_lib)
[72]642
643# Process libraries
[859]644typevar := _LIBS
[776]645tool_do := LINK_LIBRARY
[380]646mode := 0644
[2762]647$(foreach target, $(_ALL_LIBRARIES), $(evalvalctx def_lib))
[72]648
[988]649ifdef KBUILD_PROFILE_SELF
[2008]650 $(evalcall def_profile_self, done library targets)
[988]651endif
[72]652
[988]653
[72]654#
[353]655# Link operations.
[72]656#
657
[353]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.
[380]664define def_link_common
[353]665# basics
[1504]666local bld_type := $(firstword $($(target)_BLD_TYPE) $(KBUILD_TYPE))
[1496]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))
[145]670
[1496]671local tool := $(call _TARGET_TOOL,$(target),LD)
672local name := $(firstword\
[2433]673 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]674 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]675 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]676 $($(target)_NAME.$(bld_trg_arch))\
677 $($(target)_NAME.$(bld_trg))\
678 $($(target)_NAME.$(bld_type))\
679 $($(target)_NAME)\
680 $(target))
[1496]681local outbase := $(call TARGET_BASE,$(name),$(target))
[2239]682$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
[2436]683$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
[2143]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)) )
[1496]692local out := $(outbase)$(suff)
[2238]693$(target)_1_TARGET:= $(out)
[2436]694$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)
[2434]695local defpath := $($(target)_DEFPATH)
696ifeq ($(defpath),)
697 local defpath := $($(target)_PATH)
698endif
[1496]699# no local here - must be writable across some foreachs.
700othersrc :=
[2236]701$(target)_2_OBJS :=
[353]702
[1672]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)
[2762]710$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre))
[2952]711$(foreach unit,$(units),$(evalvalctx def_unit_$(unit)_target_pre_2))
[1672]712
[145]713# source -> object
[1496]714$(evalval def_target_sources)
[145]715
[744]716# more link stuff.
[1496]717local tool := $(call _TARGET_TOOL,$(target),LD)
718local name := $(firstword\
[2433]719 $($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
[889]720 $($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
[2433]721 $($(target)_NAME.$(bld_trg).$(bld_type))\
[889]722 $($(target)_NAME.$(bld_trg_arch))\
723 $($(target)_NAME.$(bld_trg))\
724 $($(target)_NAME.$(bld_type))\
725 $($(target)_NAME)\
726 $(target))
[1496]727local outbase := $(call TARGET_BASE,$(name),$(target))
728local flags :=\
[74]729 $(TOOL_$(tool)_LDFLAGS)\
[221]730 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
731 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
732 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
[481]733 $(TOOL_$(tool)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]734 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[1242]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)))\
[74]746 $(LDFLAGS)\
[221]747 $(LDFLAGS.$(bld_type))\
748 $(LDFLAGS.$(bld_trg))\
749 $(LDFLAGS.$(bld_trg_arch))\
[481]750 $(LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[221]751 $(LDFLAGS.$(bld_trg_cpu))\
[1242]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)))\
[74]763 $($(target)_LDFLAGS)\
[221]764 $($(target)_LDFLAGS.$(bld_type))\
765 $($(target)_LDFLAGS.$(bld_trg))\
766 $($(target)_LDFLAGS.$(bld_trg_arch))\
[481]767 $($(target)_LDFLAGS.$(bld_trg).$(bld_trg_arch))\
[353]768 $($(target)_LDFLAGS.$(bld_trg_cpu))
[1496]769local libs :=\
[221]770 $($(target)_LIBS.$(bld_trg_cpu))\
[481]771 $($(target)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]772 $($(target)_LIBS.$(bld_trg_arch))\
773 $($(target)_LIBS.$(bld_trg))\
774 $($(target)_LIBS.$(bld_type))\
[74]775 $($(target)_LIBS)\
[592]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),\
[353]781 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]782 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]783 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
784 $(SDK_$(sdk)_LIBS.$(bld_trg))\
785 $(SDK_$(sdk)_LIBS.$(bld_type))\
786 $(SDK_$(sdk)_LIBS))\
[221]787 $(LIBS.$(bld_trg_cpu))\
[481]788 $(LIBS.$(bld_trg).$(bld_trg_arch))\
[221]789 $(LIBS.$(bld_trg_arch))\
790 $(LIBS.$(bld_trg))\
791 $(LIBS.$(bld_type))\
[74]792 $(LIBS)\
[592]793 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
794 $(SDKS.$(bld_trg_arch)) \
795 $(SDKS.$(bld_trg)) \
796 $(SDKS.$(bld_type)) \
797 $(SDKS),\
[353]798 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
[481]799 $(SDK_$(sdk)_LIBS.$(bld_trg).$(bld_trg_arch))\
[353]800 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
801 $(SDK_$(sdk)_LIBS.$(bld_trg))\
802 $(SDK_$(sdk)_LIBS.$(bld_type))\
803 $(SDK_$(sdk)_LIBS))\
[221]804 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
[481]805 $(TOOL_$(tool)_LIBS.$(bld_trg).$(bld_trg_arch))\
[221]806 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
807 $(TOOL_$(tool)_LIBS.$(bld_trg))\
808 $(TOOL_$(tool)_LIBS.$(bld_type))\
[353]809 $(TOOL_$(tool)_LIBS)
[1496]810local libpath :=\
[221]811 $($(target)_LIBPATH.$(bld_trg_cpu))\
[481]812 $($(target)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]813 $($(target)_LIBPATH.$(bld_trg_arch))\
814 $($(target)_LIBPATH.$(bld_trg))\
815 $($(target)_LIBPATH.$(bld_type))\
[74]816 $($(target)_LIBPATH)\
[592]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),\
[353]822 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]823 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]824 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
825 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
826 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
827 $(SDK_$(sdk)_LIBPATH))\
[221]828 $(LIBPATH.$(bld_trg_cpu))\
[481]829 $(LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]830 $(LIBPATH.$(bld_trg_arch))\
831 $(LIBPATH.$(bld_trg))\
832 $(LIBPATH.$(bld_type))\
[74]833 $(LIBPATH)\
[592]834 $(foreach sdk, $(SDKS.$(bld_trg).$(bld_trg_arch)) \
835 $(SDKS.$(bld_trg_arch)) \
836 $(SDKS.$(bld_trg)) \
837 $(SDKS.$(bld_type)) \
838 $(SDKS),\
[353]839 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
[481]840 $(SDK_$(sdk)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[353]841 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
842 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
843 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
844 $(SDK_$(sdk)_LIBPATH))\
[221]845 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
[481]846 $(TOOL_$(tool)_LIBPATH.$(bld_trg).$(bld_trg_arch))\
[221]847 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
848 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
849 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[353]850 $(TOOL_$(tool)_LIBPATH)
[1496]851local dirdep := $(call DIRDEP,$(dir $(out)))
[1702]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)
[353]886
[725]887# Adjust paths if we got a default path.
888ifneq ($(defpath),)
[1496]889 local libpath := $(abspathex $(libpath),$(defpath))
890 local deps := $(abspathex $(deps),$(defpath))
891 local orderdeps := $(abspathex $(orderdeps),$(defpath))
[1472]892 othersrc := $(abspathex $(othersrc),$(defpath))
[1755]893 # libs are not subject to this because of the the -l<lib> stuff. Use $(<target>_DEFPATH)/lib if relative to current dir!
[725]894endif
895
[2523]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
[2475]902# Custom pre/post-link actions.
[3128]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))
[72]905
[1424]906# eliminate this guy?
[2236]907local objs = $($(target)_2_OBJS)
[1424]908
[380]909# dependency file
[1496]910local dep := $(outbase)$(SUFF_DEP)
[524]911ifndef NO_LINK_CMDS_DEPS
[2188]912 _DEPFILES_INCLUDED += $(dep)
[1798]913 ifdef KB_HAVE_INCLUDEDEP_QUEUE
914 includedep-queue $(dep)
[1795]915 else
[1798]916 includedep $(dep)
[1795]917 endif
[380]918endif
[353]919
[380]920# check that the tool is defined.
921ifndef TOOL_$(tool)_$(tool_do)_CMDS
922$(warning kBuild: tools: \
[481]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) )
[380]935$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
936endif
[353]937
[380]938# call the tool
[1496]939local cmds := $(TOOL_$(tool)_$(tool_do)_CMDS)
[859]940ifneq ($(pre_cmds),)
[1496]941 local cmds := $(TAB)$(pre_cmds)$(NL)$(TAB)$(cmds)
[859]942endif
943ifneq ($(post_cmds),)
[1496]944 local cmds := $(cmds)$(NL)$(TAB)$(post_cmds)
[859]945endif
[2523]946$(target)_2_OUTPUT := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
947$(target)_2_OUTPUT_MAYBE := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE)
[2795]948$(target)_2_OUTPUT_MAYBE_PRECIOUS := $(TOOL_$(tool)_$(tool_do)_OUTPUT_MAYBE_PRECIOUS)
[2523]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)
[353]958
[412]959# generate the link rule.
[380]960$(eval $(def_link_rule))
961
[2523]962# installation targets
963local target_type_mode :=
964$(evalval def_target_install_only)
[412]965
[380]966# Update globals.
[2236]967_OBJS += $($(target)_2_OBJS)
[2795]968_OUT_FILES += $($(target)_2_OUTPUT) $($(target)_2_OUTPUT_MAYBE) $($(target)_2_OUTPUT_MAYBE_PRECIOUS) $(out)
[905]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))
[827]971_INSTALLS_FILES += $(INSTARGET_$(target))
[353]972
[1936]973endef # def_link_common
974$(eval-opt-var def_link_common)
[353]975
976
977#
978# BLDPROGS
979#
980
981# Process build programs.
982EXT := EXE
983EXTPRE := HOST
[380]984tool_do := LINK_PROGRAM
[353]985typevar := _BLDPROGS
[380]986mode := 0755
[353]987bld_trg_base_var := PLATFORM
[2762]988$(foreach target, $(_ALL_BLDPROGS), $(evalvalctx def_link_common))
[353]989
[988]990ifdef KBUILD_PROFILE_SELF
[2008]991 $(evalcall def_profile_self, done build program targets)
[988]992endif
[353]993
994
995#
996# DLLS
997#
998
[189]999# Process dlls
[353]1000EXT := DLL
1001EXTPRE :=
[380]1002tool_do := LINK_DLL
[353]1003typevar := _DLLS
[830]1004mode := 0644
[353]1005bld_trg_base_var := TARGET
[2762]1006$(foreach target, $(_ALL_DLLS), $(evalvalctx def_link_common))
[74]1007
[988]1008ifdef KBUILD_PROFILE_SELF
[2008]1009 $(evalcall def_profile_self, done dll targets)
[988]1010endif
[74]1011
[988]1012
[72]1013#
[830]1014# IMPORT LIBRARIES
[72]1015#
[219]1016# - On OS/2 and windows these are libraries.
[189]1017# - On other platforms they are fake DLLs.
[830]1018#
1019EXTPRE :=
1020typevar := _IMPORT_LIBS
1021mode := 0644
1022bld_trg_base_var := TARGET
[1504]1023ifeq ($(filter-out nt os2 win win64 win32,$(KBUILD_TARGET)),)
[830]1024 EXT := LIB
1025 tool_do := LINK_LIBRARY
[2762]1026 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_lib))
[189]1027else
[830]1028 EXT := DLL
1029 tool_do := LINK_DLL
[2762]1030 $(foreach target, $(_ALL_IMPORT_LIBS), $(evalvalctx def_link_common))
[189]1031endif
[72]1032
[988]1033ifdef KBUILD_PROFILE_SELF
[2008]1034 $(evalcall def_profile_self, done import library targets)
[988]1035endif
[189]1036
[988]1037
[189]1038#
1039# PROGRAMS
1040#
1041
[353]1042# Process programs
1043EXT := EXE
1044EXTPRE :=
[380]1045tool_do := LINK_PROGRAM
[353]1046typevar := _PROGRAMS
[380]1047mode := 0755
[353]1048bld_trg_base_var := TARGET
[2762]1049$(foreach target, $(_ALL_PROGRAMS), $(evalvalctx def_link_common))
[130]1050
[988]1051ifdef KBUILD_PROFILE_SELF
[2008]1052 $(evalcall def_profile_self, done program targets)
[988]1053endif
[130]1054
[189]1055
[72]1056#
[83]1057# SYSMODS
[72]1058#
1059
[130]1060# Process sysmods
[353]1061EXT := SYS
1062EXTPRE :=
[380]1063tool_do := LINK_SYSMOD
[353]1064typevar := _SYSMODS
[380]1065mode := 0644
[353]1066bld_trg_base_var := TARGET
[2762]1067$(foreach target, $(_ALL_SYSMODS), $(evalvalctx def_link_common))
[83]1068
[988]1069ifdef KBUILD_PROFILE_SELF
[2008]1070 $(evalcall def_profile_self, done sysmod targets)
[988]1071endif
[83]1072
[988]1073
[72]1074#
[2084]1075# MISCBINS
1076#
1077
1078# Process MISCBINS
1079EXT := BIN
1080EXTPRE :=
1081tool_do := LINK_MISCBIN
1082typevar := _MISCBINS
1083mode := 0644
1084bld_trg_base_var := TARGET
[2762]1085$(foreach target, $(_ALL_MISCBINS), $(evalvalctx def_link_common))
[2084]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.