1559a980c52d3b83ff552d7f301b2205ef527858
[protos/libecoli.git] / mk / ecoli-slink-vars.mk
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
3
4 # create a symbolic link of a file
5 # slink-y-$(slink) is provided by the user
6 #   $(slink) is the path of the directory containing the destination
7 #   files, and the variable contains the path of the files to linked. Several
8 #   slink-y-$(slink) can be present.
9
10 # list all path requested by user
11 _all-slink := $(patsubst slink-y-%,%,$(filter slink-y-%,$(.VARIABLES)))
12 all-slink :=
13
14 # for each slink, create the following variables:
15 #   out-$(slink) = output path of the executable
16 #   pre-$(slink) = list of prerequisites for this executable
17 # We also add the files in $(all-slink).
18 $(foreach slink,$(_all-slink),\
19         $(if $(notdir $(slink)), \
20                 $(if $(call compare,$(words $(slink-y-$(slink))),1), \
21                         $(error "only one source file is allowed in slink-y-$(slink)")) \
22                 $(eval dst := $(dir $(slink))$(notdir $(slink-y-$(slink)))) \
23                 $(eval out-$(slink) := $(dir $(slink))) \
24                 $(eval pre-$(slink) := $(slink-y-$(slink))) \
25                 $(eval all-slink += $(dst)) \
26         , \
27                 $(foreach src,$(slink-y-$(slink)),\
28                         $(eval dst := $(slink)$(notdir $(src))) \
29                         $(eval out-$(slink) := $(slink)) \
30                         $(eval pre-$(dst) := $(src)) \
31                         $(eval all-slink += $(dst)) \
32                 ) \
33         ) \
34 )
35
36 # add them to the list of targets and clean
37 all-targets += $(all-slink)
38 all-clean-file += $(all-slink)
39
40 # convert format of executable from elf to ihex
41 #   $1: source executable (elf)
42 #   $2: destination file
43 slink_cmd = $(LN) -nsf $(abspath $(1)) $(2)
44
45 # print line used to convert executable format
46 ifeq ($(V),1)
47 slink_print_cmd = echo $(call protect_quote,$(call slink_cmd,$1,$2))
48 else
49 slink_print_cmd = echo "  SLINK $(2)"
50 endif