mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 16:52:14 +02:00
env: Avoid using GNU features in awk
GNU has a very useful third argument to match() but this is not supported in the POSIX awk. Update the code to cope, so that the script is POSIX-compliant. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Mark Kettenis <mark.kettenis@xs4all.nl>
This commit is contained in:
@@ -21,29 +21,39 @@ BEGIN {
|
|||||||
|
|
||||||
# Skip empty lines, as these are generated by the clang preprocessor
|
# Skip empty lines, as these are generated by the clang preprocessor
|
||||||
NF {
|
NF {
|
||||||
|
do_output = 0
|
||||||
|
|
||||||
# Quote quotes
|
# Quote quotes
|
||||||
gsub("\"", "\\\"")
|
gsub("\"", "\\\"")
|
||||||
|
|
||||||
|
# Avoid using the non-POSIX third parameter to match(), by splitting
|
||||||
|
# the work into several steps.
|
||||||
|
has_var = match($0, "^([^ \t=][^ =]*)=(.*)$")
|
||||||
|
|
||||||
# Is this the start of a new environment variable?
|
# Is this the start of a new environment variable?
|
||||||
if (match($0, "^([^ \t=][^ =]*)=(.*)$", arr)) {
|
if (has_var) {
|
||||||
if (length(env) != 0) {
|
if (length(env) != 0) {
|
||||||
# Record the value of the variable now completed
|
# Record the value of the variable now completed
|
||||||
vars[var] = env
|
vars[var] = env
|
||||||
|
do_output = 1
|
||||||
}
|
}
|
||||||
var = arr[1]
|
|
||||||
env = arr[2]
|
# Collect the variable name. The value follows the '='
|
||||||
|
match($0, "^([^ \t=][^ =]*)=")
|
||||||
|
var = substr($0, 1, RLENGTH - 1)
|
||||||
|
env = substr($0, RLENGTH + 1)
|
||||||
|
|
||||||
# Deal with += which concatenates the new string to the existing
|
# Deal with += which concatenates the new string to the existing
|
||||||
# variable
|
# variable. Again we are careful to use POSIX match()
|
||||||
if (length(env) != 0 && match(var, "^(.*)[+]$", var_arr))
|
if (length(env) != 0 && match(var, "^(.*)[+]$")) {
|
||||||
{
|
plusname = substr(var, RSTART, RLENGTH - 1)
|
||||||
# Allow var\+=val to indicate that the variable name is
|
# Allow var\+=val to indicate that the variable name is
|
||||||
# var+ and this is not actually a concatenation
|
# var+ and this is not actually a concatenation
|
||||||
if (substr(var_arr[1], length(var_arr[1])) == "\\") {
|
if (substr(plusname, length(plusname)) == "\\") {
|
||||||
# Drop the backslash
|
# Drop the backslash
|
||||||
sub(/\\[+]$/, "+", var)
|
sub(/\\[+]$/, "+", var)
|
||||||
} else {
|
} else {
|
||||||
var = var_arr[1]
|
var = plusname
|
||||||
env = vars[var] env
|
env = vars[var] env
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,9 +75,10 @@ END {
|
|||||||
# empty it is not set.
|
# empty it is not set.
|
||||||
if (length(env) != 0) {
|
if (length(env) != 0) {
|
||||||
vars[var] = env
|
vars[var] = env
|
||||||
|
do_output = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length(vars) != 0) {
|
if (do_output) {
|
||||||
printf("%s", "#define CONFIG_EXTRA_ENV_TEXT \"")
|
printf("%s", "#define CONFIG_EXTRA_ENV_TEXT \"")
|
||||||
|
|
||||||
# Print out all the variables
|
# Print out all the variables
|
||||||
|
Reference in New Issue
Block a user