1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
4 # exe-y-$(exe) is provided by the user
5 # $(exe) is the path of the binary, and the variable contains
6 # the list of sources. Several exe-y-$(exe) can be present.
8 # list all exe builds requested by user
9 all-exe := $(patsubst exe-y-%,%,$(filter exe-y-%,$(.VARIABLES)))
11 # add them to the list of targets
12 all-targets += $(all-exe)
14 # for each exe, create the following variables:
15 # out-$(exe) = output path of the executable
16 # pre-$(exe) = list of prerequisites for this executable
17 # Some source files need intermediate objects, we define these variables
18 # for them too, and add them in a list: $(all-iobj).
19 # Last, we add the generated files in $(all-clean-file).
20 $(foreach exe,$(all-exe),\
21 $(eval out-$(exe) := $(dir $(exe))) \
22 $(eval pre-$(exe) := ) \
23 $(foreach src,$(exe-y-$(exe)), \
24 $(if $(call is_cc_source,$(src)), \
25 $(eval iobj := $(call src2iobj,$(src),$(out-$(exe)))) \
26 $(eval pre-$(iobj) := $(src)) \
27 $(eval all-iobj += $(iobj)) \
28 $(eval all-clean-file += $(iobj)) \
29 $(eval pre-$(exe) += $(iobj)) \
31 $(if $(call is_obj_source,$(src)),\
32 $(eval pre-$(exe) += $(src)) \
34 $(if $(call is_alib_source,$(src)),\
35 $(eval pre-$(exe) += $(src)) \
37 $(error "unsupported source format: $(src)")))) \
39 $(eval all-clean-file += $(exe)) \
42 # link several *.o files into a exeary
43 # $1: sources (*.o) (*.a)
45 link_cmd = $(CC) $(LDFLAGS) $(ldflags-$(2)) -o $(2) $(filter %.o,$(1)) \
46 $(filter %.a,$(1)) $(LDLIBS) $(ldlibs-$(2))
48 # print line used to link object files
50 link_print_cmd = echo $(call protect_quote,$(call link_cmd,$1,$2))
52 link_print_cmd = echo " EXE $(2)"
55 all-clean-file += $(all-exe)