1# 2# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. 3# 4# SPDX-License-Identifier: BSD-3-Clause 5# 6 7space := 8space := $(space) $(space) 9comma := , 10 11null := � 12 13compat-path = $(subst $(space),$(null),$(1)) 14decompat-path = $(subst $(null), ,$(1)) 15 16absolute-path = $(call decompat-path,$(abspath $(call compat-path,$(1)))) 17real-path = $(call decompat-path,$(realpath $(call compat-path,$(1)))) 18 19file-name = $(call decompat-path,$(notdir $(call compat-path,$(1)))) 20directory-name = $(call decompat-path,$(dir $(call compat-path,$(1)))) 21 22escape-shell = '$(subst ','\'',$(1))' 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 36uppercase = $(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 50lowercase = $(shell echo $(call escape-shell,$(1)) | tr '[:upper:]' '[:lower:]') 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 76bool = $(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 102bool-01 = $(if $(call bool,$(1)),1,0) 103