Chris Kay | 2c09bf6 | 2024-04-09 16:30:52 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | |
| 7 | space := |
| 8 | space := $(space) $(space) |
| 9 | comma := , |
| 10 | |
| 11 | null := � |
| 12 | |
| 13 | compat-path = $(subst $(space),$(null),$(1)) |
| 14 | decompat-path = $(subst $(null), ,$(1)) |
| 15 | |
| 16 | absolute-path = $(call decompat-path,$(abspath $(call compat-path,$(1)))) |
| 17 | real-path = $(call decompat-path,$(realpath $(call compat-path,$(1)))) |
| 18 | |
| 19 | file-name = $(call decompat-path,$(notdir $(call compat-path,$(1)))) |
| 20 | directory-name = $(call decompat-path,$(dir $(call compat-path,$(1)))) |
| 21 | |
| 22 | escape-shell = '$(subst ','\'',$(1))' |
Chris Kay | d397277 | 2024-05-29 22:09:26 +0000 | [diff] [blame] | 23 | |
| 24 | # |
| 25 | # Upper-case a string value. |
| 26 | # |
| 27 | # Parameters: |
| 28 | # |
| 29 | # - $(1): The string to upper-case. |
| 30 | # |
| 31 | # Example usage: |
| 32 | # |
| 33 | # $(call uppercase,HeLlO wOrLd) # "HELLO WORLD" |
| 34 | # |
| 35 | |
| 36 | uppercase = $(shell echo $(call escape-shell,$(1)) | tr '[:lower:]' '[:upper:]') |
| 37 | |
| 38 | # |
| 39 | # Lower-case a string value. |
| 40 | # |
| 41 | # Parameters: |
| 42 | # |
| 43 | # - $(1): The string to lower-case. |
| 44 | # |
| 45 | # Example usage: |
| 46 | # |
| 47 | # $(call lowercase,HeLlO wOrLd) # "hello world" |
| 48 | # |
| 49 | |
| 50 | lowercase = $(shell echo $(call escape-shell,$(1)) | tr '[:upper:]' '[:lower:]') |
Chris Kay | 0fda3ab | 2024-05-29 22:16:31 +0000 | [diff] [blame] | 51 | |
| 52 | # |
| 53 | # Determine the "truthiness" of a value. |
| 54 | # |
| 55 | # Parameters: |
| 56 | # |
| 57 | # - $(1): The value to determine the truthiness of. |
| 58 | # |
| 59 | # A value is considered to be falsy if it is: |
| 60 | # |
| 61 | # - empty, or |
| 62 | # - equal to "0", "N", "NO", "F" or "FALSE" after upper-casing. |
| 63 | # |
| 64 | # If the value is truthy then the value is returned as-is, otherwise no value |
| 65 | # is returned. |
| 66 | # |
| 67 | # Example usage: |
| 68 | # |
| 69 | # truthy := y |
| 70 | # truthy-bool := $(call bool,$(truthy)) # "y" |
| 71 | # |
| 72 | # falsy := n |
| 73 | # falsy-bool := $(call bool,$(falsy)) # <empty> |
| 74 | # |
| 75 | |
| 76 | bool = $(filter-out 0 n no f false,$(call lowercase,$(1))) |
| 77 | |
| 78 | # |
| 79 | # Determine the "truthiness" of a value, returning 0 or 1. |
| 80 | # |
| 81 | # Parameters: |
| 82 | # |
| 83 | # - $(1): The value to determine the truthiness of. |
| 84 | # |
| 85 | # A value is considered to be falsy if it is: |
| 86 | # |
| 87 | # - empty, or |
| 88 | # - equal to "0", "N", "NO", "F" or "FALSE" after upper-casing. |
| 89 | # |
| 90 | # If the value is truthy then the value is returned as-is, otherwise no value |
| 91 | # is returned. |
| 92 | # |
| 93 | # Example usage: |
| 94 | # |
| 95 | # truthy := y |
| 96 | # truthy-bool := $(call bool,$(truthy)) # "1" |
| 97 | # |
| 98 | # falsy := n |
| 99 | # falsy-bool := $(call bool,$(falsy)) # "0" |
| 100 | # |
| 101 | |
| 102 | bool-01 = $(if $(call bool,$(1)),1,0) |