initial revision
[ucgine.git] / mk / ucgine-shlib-vars.mk
1 #
2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 #     * Redistributions of source code must retain the above copyright
8 #       notice, this list of conditions and the following disclaimer.
9 #     * Redistributions in binary form must reproduce the above copyright
10 #       notice, this list of conditions and the following disclaimer in the
11 #       documentation and/or other materials provided with the distribution.
12 #     * Neither the name of the University of California, Berkeley nor the
13 #       names of its contributors may be used to endorse or promote products
14 #       derived from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 # shlib-y-$(shlib) is provided by the user
29 #   $(shlib) is the path of the shared library, and the variable
30 #   contains the list of sources. Several shlib-y-$(shlib) can be
31 #   present.
32
33 # list all shlib builds requested by user
34 all-shlib := $(patsubst shlib-y-%,%,$(filter shlib-y-%,$(.VARIABLES)))
35
36 # add them to the list of targets
37 all-targets += $(all-shlib)
38
39 # for each shlib, create the following variables:
40 #   out-$(shlib) = output path of the shlibcutable
41 #   pre-$(shlib) = list of prerequisites for this shlibcutable
42 # Some source files need intermediate objects, we define these variables
43 # for them too, and add them in a list: $(all-iobj).
44 # Last, we add the generated files in $(all-clean-file).
45 $(foreach shlib,$(all-shlib),\
46         $(eval out-$(shlib) := $(dir $(shlib))) \
47         $(eval pre-$(shlib) := ) \
48         $(foreach src,$(shlib-y-$(shlib)), \
49                 $(if $(call is_cc_source,$(src)), \
50                         $(eval iobj := $(call src2iobj,$(src),$(out-$(shlib)))) \
51                         $(eval pre-$(iobj) := $(src)) \
52                         $(eval all-iobj += $(iobj)) \
53                         $(eval all-clean-file += $(iobj)) \
54                         $(eval pre-$(shlib) += $(iobj)) \
55                 , \
56                 $(if $(call is_obj_source,$(src)),\
57                         $(eval pre-$(shlib) += $(src)) \
58                 , \
59                 $(error "unsupported source format: $(src)"))) \
60         )\
61         $(eval all-clean-file += $(shlib)) \
62 )
63
64 # link several *.o files into a shared libary
65 #   $1: sources (*.o)
66 #   $2: dst (xyz.so)
67 shlib_cmd = $(CC) $(LDFLAGS) $(ldflags-$(2)) -shared -o $(2) $(1)
68
69 # print line used to shlib object files
70 ifeq ($(V),1)
71 shlib_print_cmd = echo $(call protect_quote,$(call shlib_cmd,$1,$2))
72 else
73 shlib_print_cmd = echo "  SHLIB $(2)"
74 endif
75
76 all-clean-file += $(all-shlib)