2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
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.
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.
28 # ar-y-$(ar) is provided by the user
29 # $(ar) is the path of the static library, and the variable contains
30 # the list of sources. Several ar-y-$(ar) can be present.
32 # list all ar builds requested by user
33 all-ar := $(patsubst ar-y-%,%,$(filter ar-y-%,$(.VARIABLES)))
35 # add them to the list of targets
36 all-targets += $(all-ar)
38 # for each ar, create the following variables:
39 # out-$(ar) = output path of the arcutable
40 # pre-$(ar) = list of prerequisites for this arcutable
41 # Some source files need intermediate objects, we define these variables
42 # for them too, and add them in a list: $(all-iobj).
43 # Last, we add the generated files in $(all-clean-file).
44 $(foreach ar,$(all-ar),\
45 $(eval out-$(ar) := $(dir $(ar))) \
46 $(eval pre-$(ar) := ) \
47 $(foreach src,$(ar-y-$(ar)), \
48 $(if $(call is_cc_source,$(src)), \
49 $(eval iobj := $(call src2iobj,$(src),$(out-$(ar)))) \
50 $(eval pre-$(iobj) := $(src)) \
51 $(eval all-iobj += $(iobj)) \
52 $(eval all-clean-file += $(iobj)) \
53 $(eval pre-$(ar) += $(iobj)) \
55 $(if $(call is_obj_source,$(src)),\
56 $(eval pre-$(ar) += $(src)) \
58 $(error "unsupported source format: $(src)"))) \
60 $(eval all-clean-file += $(ar)) \
63 # link several *.o files into a static libary
66 ar_cmd = ar crsD $(2) $(1)
68 # print line used to ar object files
70 ar_print_cmd = echo $(call protect_quote,$(call ar_cmd,$1,$2))
72 ar_print_cmd = echo " AR $(2)"
75 all-clean-file += $(all-ar)