1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
4 # ar-y-$(ar) is provided by the user
5 # $(ar) is the path of the static library, and the variable contains
6 # the list of sources. Several ar-y-$(ar) can be present.
8 # list all ar builds requested by user
9 all-ar := $(patsubst ar-y-%,%,$(filter ar-y-%,$(.VARIABLES)))
11 # add them to the list of targets
12 all-targets += $(all-ar)
14 # for each ar, create the following variables:
15 # out-$(ar) = output path of the arcutable
16 # pre-$(ar) = list of prerequisites for this arcutable
17 # Some source files need intermediate objects, we define these variables
18 # for them too, and add them in a list: $(all-iobj).
19 # Last, we add the generated files in $(all-clean-file).
20 $(foreach ar,$(all-ar),\
21 $(eval out-$(ar) := $(dir $(ar))) \
22 $(eval pre-$(ar) := ) \
23 $(foreach src,$(ar-y-$(ar)), \
24 $(if $(call is_cc_source,$(src)), \
25 $(eval iobj := $(call src2iobj,$(src),$(out-$(ar)))) \
26 $(eval pre-$(iobj) := $(src)) \
27 $(eval all-iobj += $(iobj)) \
28 $(eval all-clean-file += $(iobj)) \
29 $(eval pre-$(ar) += $(iobj)) \
31 $(if $(call is_obj_source,$(src)),\
32 $(eval pre-$(ar) += $(src)) \
34 $(error "unsupported source format: $(src)"))) \
36 $(eval all-clean-file += $(ar)) \
39 # link several *.o files into a static libary
42 ar_cmd = ar crsD $(2) $(1)
44 # print line used to ar object files
46 ar_print_cmd = echo $(call protect_quote,$(call ar_cmd,$1,$2))
48 ar_print_cmd = echo " AR $(2)"
51 all-clean-file += $(all-ar)