mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
build system: rm unused variable declarations from Mamfiles
Now that the Make Abstract Machine files are maintained manually and not generated automatically, unused variables are an annoying distraction -- and there are many. But the language/format is very simple and very parseable using shell, awk, etc. -- so this was easy to automate. All variables are declared with 'setv' and they are used if an expansion of the form ${varname} exists (the braces are mandatory in Mamfiles). bin/Mamfile_rm_unused_vars: - Added for reference and future use. src/*/*/Mamfile: - Remove all unused 'setv' variable declarations.
This commit is contained in:
parent
7b59fb805c
commit
43dfe3c8fa
8 changed files with 30 additions and 201 deletions
30
bin/Mamfile_rm_unused_vars
Executable file
30
bin/Mamfile_rm_unused_vars
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env sh
|
||||
IFS=''; set -fCu # safe mode: no split/glob = no quoting headaches
|
||||
CCn='
|
||||
' # newline
|
||||
let() { return $((!($1))); }
|
||||
|
||||
# Remove unused variable definitions from a Mamfile.
|
||||
# Usage: Mamfile_rm_unused_vars <Mamfile >Mamfile.new
|
||||
#
|
||||
# Should work on all current POSIX compliant shells.
|
||||
# By Martijn Dekker <martijn@inlv.org>, 2021. Public domain.
|
||||
#
|
||||
# All variables are declared with 'setv' and they are used if an expansion
|
||||
# of the form ${varname} exists (the braces are mandatory in Mamfiles).
|
||||
|
||||
mamfile=$(let $# && cat "$1" || cat)
|
||||
vars=$(printf '%s\n' $mamfile | awk '$1 == "setv" { print $2; }')
|
||||
rm_unused_ere=
|
||||
IFS=$CCn; for varname in $vars; do IFS=
|
||||
case $mamfile in
|
||||
*"\${$varname}"* )
|
||||
;;
|
||||
* ) # add with '|' separator for Extended Regular Expression
|
||||
rm_unused_ere="${rm_unused_ere:+$rm_unused_ere|}setv[[:blank:]]+$varname([[:blank:]]|$)" ;;
|
||||
esac
|
||||
done
|
||||
case $rm_unused_ere in
|
||||
'') printf '%s\n' $mamfile ;;
|
||||
*) printf '%s\n' $mamfile | grep -vE $rm_unused_ere ;;
|
||||
esac
|
Loading…
Add table
Add a link
Reference in a new issue