1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-12-11 13:04:35 +00:00
MarlinFirmware/buildroot/bin/opt_disable

37 lines
961 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
# exit on first failure
set -e
# Get SED_CMD, SED_I, and the BSDSED flag
. $(dirname $0)/opt_sed
for opt in "$@" ; do
DID=0 ; FOUND=0
for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do
if [[ $BSDSED ]]; then
# BSD sed version (macOS)
"${SED_CMD}" "${SED_I[@]}" \
"/^[[:space:]]*#define[[:space:]]+${opt}\b/{
s/^[[:space:]]*\(#define[[:space:]]+${opt}\b.*\)/\/\/\1/
h
\$b end
}
\$!b
:end
x
/./{ x; q0; }
x
q1" \
$FN && DID=1
else
# GNU sed version
"${SED_CMD}" "${SED_I[@]}" \
"/^\(\s*\)\(#define\s\+${opt}\b\s\?\)\(\s\s\)\?/{s//\1\/\/\2/;h};\${x;/./{x;q0};x;q1}" \
$FN && DID=1
fi
((DID||FOUND)) || { grep -E "^\s*\/\/#define\s+${opt}\b" $FN >/dev/null && FOUND=1 ; }
done
((DID||FOUND)) || (echo "ERROR: $(basename $0) Can't find ${opt}" >&2 && exit 9)
done