Leonardo Sandoval | 667fd72 | 2020-09-11 12:50:19 -0500 | [diff] [blame] | 1 | # |
Govindraj Raja | 1421d77 | 2023-05-05 09:15:43 -0500 | [diff] [blame] | 2 | # Copyright (c) 2015-2023, ARM Limited and Contributors. All rights reserved. |
Leonardo Sandoval | 667fd72 | 2020-09-11 12:50:19 -0500 | [diff] [blame] | 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. |
| 11 | define add_define |
| 12 | $(1) += -D$(2)$(if $(value $(2)),=$(value $(2)),) |
| 13 | endef |
| 14 | |
| 15 | # Convenience function for verifying option has a boolean value |
| 16 | # $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 |
| 17 | define assert_boolean |
| 18 | $(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean)) |
| 19 | endef |
| 20 | |
Shruti Gupta | c973b2a | 2023-07-12 12:10:54 +0100 | [diff] [blame] | 21 | 0-9 := 0 1 2 3 4 5 6 7 8 9 |
| 22 | |
| 23 | # Function to verify that a given option $(1) contains a numeric value |
| 24 | define assert_numeric |
| 25 | $(if $($(1)),,$(error $(1) must not be empty)) |
| 26 | $(eval __numeric := $($(1))) |
| 27 | $(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) |
| 28 | $(if $(__numeric),$(error $(1) must be numeric)) |
| 29 | endef |
| 30 | |
| 31 | # Convenience function for verifying options have numeric values |
| 32 | # $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values |
| 33 | define assert_numerics |
| 34 | $(foreach num,$1,$(eval $(call assert_numeric,$(num)))) |
| 35 | endef |
| 36 | |
Leonardo Sandoval | 667fd72 | 2020-09-11 12:50:19 -0500 | [diff] [blame] | 37 | # CREATE_SEQ is a recursive function to create sequence of numbers from 1 to |
| 38 | # $(2) and assign the sequence to $(1) |
| 39 | define CREATE_SEQ |
| 40 | $(if $(word $(2), $($(1))),\ |
| 41 | $(eval $(1) += $(words $($(1))))\ |
| 42 | $(eval $(1) := $(filter-out 0,$($(1)))),\ |
| 43 | $(eval $(1) += $(words $($(1))))\ |
| 44 | $(call CREATE_SEQ,$(1),$(2))\ |
| 45 | ) |
| 46 | endef |
Soby Mathew | 25d9e2f | 2023-05-05 10:51:57 +0100 | [diff] [blame] | 47 | |
| 48 | # Convenience function to check for a given linker option. An call to |
| 49 | # $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker |
| 50 | define ld_option |
| 51 | $(shell if $(LD) $(1) -v >/dev/null 2>&1; then echo $(1); fi ) |
| 52 | endef |
Govindraj Raja | 1421d77 | 2023-05-05 09:15:43 -0500 | [diff] [blame] | 53 | |
| 54 | # Convenience function to check for a given compiler option. An call to |
| 55 | # $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler |
| 56 | define cc_option |
| 57 | $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null >/dev/null 2>&1; then echo $(1); fi ) |
| 58 | endef |
| 59 | |