Lines Matching +full:- +full:- +full:shell
1 # SPDX-License-Identifier: GPL-2.0
9 # nl-escape
11 # Usage: escape = $(call nl-escape[,escape])
17 nl-escape = $(if $(1),$(1),m822df3020w6a44id34bt574ctac44eb9f4n)
19 # escape-nl
21 # Usage: escaped-text = $(call escape-nl,text[,escape])
23 # GNU make's $(shell ...) function converts to a
31 # $(call unescape-nl...)
33 escape-nl = $(subst $(newline),$(call nl-escape,$(2)),$(1))
35 # unescape-nl
37 # Usage: text = $(call unescape-nl,escaped-text[,escape])
39 # See escape-nl.
41 unescape-nl = $(subst $(call nl-escape,$(2)),$(newline),$(1))
43 # shell-escape-nl
45 # Usage: $(shell some-command | $(call shell-escape-nl[,escape]))
47 # Use this to escape newlines from within a shell call;
51 # in an `awk' program that is delimited by shell
52 # single-quotes, so be wary of the characters
55 define shell-escape-nl
56 awk 'NR==1 {t=$$0} NR>1 {t=t "$(nl-escape)" $$0} END {printf t}'
59 # shell-unescape-nl
61 # Usage: $(shell some-command | $(call shell-unescape-nl[,escape]))
63 # Use this to unescape newlines from within a shell call;
68 # delimited by shell single-quotes, so be wary
71 # (The bash shell has a bug where `{gsub(...),...}' is
75 define shell-unescape-nl
76 awk 'NR==1 {t=$$0} NR>1 {t=t "\n" $$0} END { gsub(/$(nl-escape)/,"\n",t); printf t }'
79 # escape-for-shell-sq
81 # Usage: embeddable-text = $(call escape-for-shell-sq,text)
84 # embedding in a shell string that is delimited by
85 # single-quotes.
87 escape-for-shell-sq = $(subst ','\'',$(1))
89 # shell-sq
91 # Usage: single-quoted-and-escaped-text = $(call shell-sq,text)
93 shell-sq = '$(escape-for-shell-sq)'
95 # shell-wordify
97 # Usage: wordified-text = $(call shell-wordify,text)
107 # | echo $(call shell-wordify,$(text))
111 # (this is in constrast to a `$(shell ...)' function call,
115 # that works as a shell word, regardless of whether or
119 # an intrictate shell command substitution is constructed
120 # to render the text as a single line; when the shell
125 # produces the same results as the `$(shell-sq)' function.
127 shell-wordify = $(if $(findstring $(newline),$(1)),$(_sw-esc-nl),$(shell-sq))
128 define _sw-esc-nl
129 "$$(echo $(call escape-nl,$(shell-sq),$(2)) | $(call shell-unescape-nl,$(2)))"
132 # is-absolute
134 # Usage: bool-value = $(call is-absolute,path)
136 is-absolute = $(shell echo $(shell-sq) | grep -q ^/ && echo y)
140 # Usage: absolute-executable-path-or-empty = $(call lookup,path)
142 # (It's necessary to use `sh -c' because GNU make messes up by
145 lookup = $(call unescape-nl,$(shell sh -c $(_l-sh)))
146 _l-sh = $(call shell-sq,command -v $(shell-sq) | $(call shell-escape-nl,))
148 # is-executable
150 # Usage: bool-value = $(call is-executable,path)
152 # (It's necessary to use `sh -c' because GNU make messes up by
155 is-executable = $(call _is-executable-helper,$(shell-sq))
156 _is-executable-helper = $(shell sh -c $(_is-executable-sh))
157 _is-executable-sh = $(call shell-sq,test -f $(1) -a -x $(1) && echo y)
159 # get-executable
161 # Usage: absolute-executable-path-or-empty = $(call get-executable,path)
164 # the `command -v' is defined by POSIX, but it's not
169 get-executable = $(if $(1),$(if $(is-absolute),$(_ge-abspath),$(lookup)))
170 _ge-abspath = $(if $(is-executable),$(1))
172 # get-supplied-or-default-executable
174 # Usage: absolute-executable-path-or-empty = $(call get-executable-or-default,variable,default)
176 define get-executable-or-default
179 _ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2)))