blob: 80f86494b5ce3aa8e78836c308150e7e5cd9465a [file] [log] [blame]
Leonardo Sandoval70f74002020-09-11 12:50:19 -05001#
2# Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7# Convenience function for adding build definitions
8# $(eval $(call add_define,BAR_DEFINES,FOO)) will have:
9# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
10# inside the BAR_DEFINES variable.
11define add_define
12$(1) += -D$(2)$(if $(value $(2)),=$(value $(2)),)
13endef
14
15# Convenience function for verifying option has a boolean value
16# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
17define assert_boolean
18$(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean))
19endef
20
21# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to
22# $(2) and assign the sequence to $(1)
23define CREATE_SEQ
24$(if $(word $(2), $($(1))),\
25 $(eval $(1) += $(words $($(1))))\
26 $(eval $(1) := $(filter-out 0,$($(1)))),\
27 $(eval $(1) += $(words $($(1))))\
28 $(call CREATE_SEQ,$(1),$(2))\
29)
30endef
Soby Mathewdb9e0772023-05-05 10:51:57 +010031
32# Convenience function to check for a given linker option. An call to
33# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker
34define ld_option
35 $(shell if $(LD) $(1) -v >/dev/null 2>&1; then echo $(1); fi )
36endef