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 # exe-y-$(exe) is provided by the user
29 # $(exe) is the path of the binary, and the variable contains
30 # the list of sources. Several exe-y-$(exe) can be present.
32 # list all exe builds requested by user
33 all-exe := $(patsubst exe-y-%,%,$(filter exe-y-%,$(.VARIABLES)))
35 # add them to the list of targets
36 all-targets += $(all-exe)
38 # for each exe, create the following variables:
39 # out-$(exe) = output path of the executable
40 # pre-$(exe) = list of prerequisites for this executable
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 exe,$(all-exe),\
45 $(eval out-$(exe) := $(dir $(exe))) \
46 $(eval pre-$(exe) := ) \
47 $(foreach src,$(exe-y-$(exe)), \
48 $(if $(call is_cc_source,$(src)), \
49 $(eval iobj := $(call src2iobj,$(src),$(out-$(exe)))) \
50 $(eval pre-$(iobj) := $(src)) \
51 $(eval all-iobj += $(iobj)) \
52 $(eval all-clean-file += $(iobj)) \
53 $(eval pre-$(exe) += $(iobj)) \
55 $(if $(call is_obj_source,$(src)),\
56 $(eval pre-$(exe) += $(src)) \
58 $(if $(call is_alib_source,$(src)),\
59 $(eval pre-$(exe) += $(src)) \
61 $(error "unsupported source format: $(src)")))) \
63 $(eval all-clean-file += $(exe)) \
66 # link several *.o files into a exeary
67 # $1: sources (*.o) (*.a)
69 link_cmd = $(CC) $(LDFLAGS) $(ldflags-$(2)) -o $(2) $(filter %.o,$(1)) \
70 $(filter %.a,$(1)) $(LDLIBS) $(ldlibs-$(2))
72 # print line used to link object files
74 link_print_cmd = echo $(call protect_quote,$(call link_cmd,$1,$2))
76 link_print_cmd = echo " EXE $(2)"
79 all-clean-file += $(all-exe)