1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: scripts/core-functions.in
3 # Copyright (C) 2004 - 2024 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 # mktemp alias if the host-system does require -t
14 __mktemp=`mktemp 2>/dev/null`
15 if [ -z "${__mktemp}" ]; then
17 `which mktemp` -t tmp "$@"
24 # translates a architecture name as of uname into the verbose t2 name
27 sed -e "s/arm.*/arm/; s/aarch64/arm64/; s/parisc/hppa/; s/ppc/powerpc/" \
28 -e "s/sh.$/superh/; s/i.86/x86/; s/x86_64/x86-64/"
31 # translates a architecture name os of t2 into the short uname name
34 local regex="-e s/x86$/i386/ -e s/powerpc/ppc/ -e s/x86-64/x86_64/ \
35 -e s/blackfin/bfin/ -e s/superh/sh/"
36 [ $SDECFG_KERNEL = "darwin" ] || regex="$regex -e s/arm64/aarch64/"
40 # translate a architecture to the 32bit subset
43 sed 's/[-_]*64//; s/aarch/arm/; s/x86/i686/; s/loongarch/loongarch32/'
47 [[ "$1" -le 0 ]] && return
56 for u in s m h d y; do
58 local div=${units[$u]}
59 [ "$div" ] && x=$((i % div))
60 s=`printf "%d$u${s:+:$s}" $x`
62 [ $u != s -a $u != m ] && s=${s%:*}
69 # revert the order of the tokens
72 while [ $# -gt 0 ]; do
79 # This functions append, insert or remove values in variables:
81 # var_append PATH ":" "$HOME/bin"
82 # var_insert CC_WRAPPER_INSERT " " "-O3"
83 # var_remove CC_WRAPPER_INSERT " " "-O3"
85 # var_remove_regex CC_WRAPPER_INSERT " " "-O.*"
87 # var_insert_before_regex patchfiles " " "mypatch.diff" ".*\/foo.diff"
89 # 1st Parameter: Variable Name
90 # 2nd Parameter: Delimiter Text
91 # 3rd Parameter: Value (or regex)
92 # 4th Parameter: regex for insert_before
95 eval "[ \"\$$1\" ] && $1=\"\${$1}$2\"" || true
96 eval "$1=\"\${$1}\$3\""
99 eval "[ \"\$$1\" ] && $1=\"$2\$$1\"" || true
100 eval "$1=\"\$3\$$1\""
105 eval '[ "$'$1'" = "$3" ] && '$1'="" || true'
106 eval $1'="${'$1'//$a$b$a/$2}"'
107 eval $1'="${'$1'%$a$b}"'
108 eval $1'="${'$1'#$b$a}"'
111 eval "$1=\"\`echo \"\$$1\" | gawk -- ' { split(\$0, a, \"$2\"); for (c1=c2=1; c1 in a; c1++) if ( a[c1] !~ /^$3\\\$/ ) b[c2++]=a[c1]; for (c1=1; c1 in b; c1++) printf \"%s%s\", (c1 > 0 ? \"$2\" : \"\"), b[c1]; }'\`\""
113 var_insert_before_regex() {
114 eval "$1=\"\`echo \"\$$1\" | gawk -- '{ split(\$0, a, \"$2\"); for (d=c1=c2=1; c1 in a; c1++) { if ( d && a[c1] ~ /^$4\\\$/ ) { b[c2++]=\"$3\"; d=0; } b[c2++]=a[c1]; } if (d) b[c2++]=\"$3\"; for (c1=1; c1 in b; c1++) printf \"%s%s\", (c1 > 0 ? \"$2\" : \"\"), b[c1]; }'\`\""