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 | # |
Chris Kay | 834cfe1 | 2024-08-06 15:32:57 +0000 | [diff] [blame^] | 25 | # The grouped-target symbol. Grouped targets are not supported on versions of |
| 26 | # GNU Make <= 4.2, which was most recently packaged with Ubuntu 20.04. |
| 27 | # |
| 28 | |
| 29 | & := $(if $(filter grouped-target,$(.FEATURES)),&) |
| 30 | |
| 31 | # |
Chris Kay | d397277 | 2024-05-29 22:09:26 +0000 | [diff] [blame] | 32 | # Upper-case a string value. |
| 33 | # |
| 34 | # Parameters: |
| 35 | # |
| 36 | # - $(1): The string to upper-case. |
| 37 | # |
| 38 | # Example usage: |
| 39 | # |
| 40 | # $(call uppercase,HeLlO wOrLd) # "HELLO WORLD" |
| 41 | # |
| 42 | |
| 43 | uppercase = $(shell echo $(call escape-shell,$(1)) | tr '[:lower:]' '[:upper:]') |
| 44 | |
| 45 | # |
| 46 | # Lower-case a string value. |
| 47 | # |
| 48 | # Parameters: |
| 49 | # |
| 50 | # - $(1): The string to lower-case. |
| 51 | # |
| 52 | # Example usage: |
| 53 | # |
| 54 | # $(call lowercase,HeLlO wOrLd) # "hello world" |
| 55 | # |
| 56 | |
| 57 | lowercase = $(shell echo $(call escape-shell,$(1)) | tr '[:upper:]' '[:lower:]') |
Chris Kay | 0fda3ab | 2024-05-29 22:16:31 +0000 | [diff] [blame] | 58 | |
| 59 | # |
| 60 | # Determine the "truthiness" of a value. |
| 61 | # |
| 62 | # Parameters: |
| 63 | # |
| 64 | # - $(1): The value to determine the truthiness of. |
| 65 | # |
| 66 | # A value is considered to be falsy if it is: |
| 67 | # |
| 68 | # - empty, or |
| 69 | # - equal to "0", "N", "NO", "F" or "FALSE" after upper-casing. |
| 70 | # |
| 71 | # If the value is truthy then the value is returned as-is, otherwise no value |
| 72 | # is returned. |
| 73 | # |
| 74 | # Example usage: |
| 75 | # |
| 76 | # truthy := y |
| 77 | # truthy-bool := $(call bool,$(truthy)) # "y" |
| 78 | # |
| 79 | # falsy := n |
| 80 | # falsy-bool := $(call bool,$(falsy)) # <empty> |
| 81 | # |
| 82 | |
| 83 | bool = $(filter-out 0 n no f false,$(call lowercase,$(1))) |
| 84 | |
| 85 | # |
| 86 | # Determine the "truthiness" of a value, returning 0 or 1. |
| 87 | # |
| 88 | # Parameters: |
| 89 | # |
| 90 | # - $(1): The value to determine the truthiness of. |
| 91 | # |
| 92 | # A value is considered to be falsy if it is: |
| 93 | # |
| 94 | # - empty, or |
| 95 | # - equal to "0", "N", "NO", "F" or "FALSE" after upper-casing. |
| 96 | # |
| 97 | # If the value is truthy then the value is returned as-is, otherwise no value |
| 98 | # is returned. |
| 99 | # |
| 100 | # Example usage: |
| 101 | # |
| 102 | # truthy := y |
| 103 | # truthy-bool := $(call bool,$(truthy)) # "1" |
| 104 | # |
| 105 | # falsy := n |
| 106 | # falsy-bool := $(call bool,$(falsy)) # "0" |
| 107 | # |
| 108 | |
| 109 | bool-01 = $(if $(call bool,$(1)),1,0) |
Chris Kay | a152e75 | 2024-09-26 14:18:04 +0000 | [diff] [blame] | 110 | |
| 111 | # |
| 112 | # Determine whether a variable is defined or not. |
| 113 | # |
| 114 | # Parameters: |
| 115 | # |
| 116 | # - $(1): The variable to check. |
| 117 | # |
| 118 | # Example usage: |
| 119 | # |
| 120 | # xyz-defined := $(call defined,xyz) # <empty> |
| 121 | # |
| 122 | # xyz := |
| 123 | # xyz-defined := $(call defined,xyz) # <non-empty> |
| 124 | # |
| 125 | # xyz := hello |
| 126 | # xyz-defined := $(call defined,xyz) # <non-empty> |
| 127 | # |
| 128 | |
| 129 | defined = $(call bool,$(filter-out undefined,$(origin $(1)))) |