node_any: check attribute presence
[protos/libecoli.git] / mk / ecoli-shlib-vars.mk
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
3
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
7 #   present.
8
9 # list all shlib builds requested by user
10 all-shlib := $(patsubst shlib-y-%,%,$(filter shlib-y-%,$(.VARIABLES)))
11
12 # add them to the list of targets
13 all-targets += $(all-shlib)
14
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)) \
31                 , \
32                 $(if $(call is_obj_source,$(src)),\
33                         $(eval pre-$(shlib) += $(src)) \
34                 , \
35                 $(error "unsupported source format: $(src)"))) \
36         )\
37         $(eval all-clean-file += $(shlib)) \
38 )
39
40 # link several *.o files into a shared libary
41 #   $1: sources (*.o)
42 #   $2: dst (xyz.so)
43 shlib_cmd = $(CC) $(LDFLAGS) $(ldflags-$(2)) -shared -o $(2) $(1)
44
45 # print line used to shlib object files
46 ifeq ($(V),1)
47 shlib_print_cmd = echo $(call protect_quote,$(call shlib_cmd,$1,$2))
48 else
49 shlib_print_cmd = echo "  SHLIB $(2)"
50 endif
51
52 all-clean-file += $(all-shlib)