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