1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
4 # shlib-y-$(shlib) is provided by the user
5 # $(shlib) is the path of the shared library, and the variable
6 # contains the list of sources. Several shlib-y-$(shlib) can be
9 # list all shlib builds requested by user
10 all-shlib := $(patsubst shlib-y-%,%,$(filter shlib-y-%,$(.VARIABLES)))
12 # add them to the list of targets
13 all-targets += $(all-shlib)
15 # for each shlib, create the following variables:
16 # out-$(shlib) = output path of the shlibcutable
17 # pre-$(shlib) = list of prerequisites for this shlibcutable
18 # Some source files need intermediate objects, we define these variables
19 # for them too, and add them in a list: $(all-iobj).
20 # Last, we add the generated files in $(all-clean-file).
21 $(foreach shlib,$(all-shlib),\
22 $(eval out-$(shlib) := $(dir $(shlib))) \
23 $(eval pre-$(shlib) := ) \
24 $(foreach src,$(shlib-y-$(shlib)), \
25 $(if $(call is_cc_source,$(src)), \
26 $(eval iobj := $(call src2iobj,$(src),$(out-$(shlib)))) \
27 $(eval pre-$(iobj) := $(src)) \
28 $(eval all-iobj += $(iobj)) \
29 $(eval all-clean-file += $(iobj)) \
30 $(eval pre-$(shlib) += $(iobj)) \
32 $(if $(call is_obj_source,$(src)),\
33 $(eval pre-$(shlib) += $(src)) \
35 $(error "unsupported source format: $(src)"))) \
37 $(eval all-clean-file += $(shlib)) \
40 # link several *.o files into a shared libary
43 shlib_cmd = $(CC) $(LDFLAGS) $(ldflags-$(2)) -shared -o $(2) $(1)
45 # print line used to shlib object files
47 shlib_print_cmd = echo $(call protect_quote,$(call shlib_cmd,$1,$2))
49 shlib_print_cmd = echo " SHLIB $(2)"
52 all-clean-file += $(all-shlib)