diff --git a/buildroot/bin/mftest b/buildroot/bin/mftest index e586b0aae3..b6f78e4f42 100755 --- a/buildroot/bin/mftest +++ b/buildroot/bin/mftest @@ -41,7 +41,6 @@ env shortcuts: tree due esp lin lp8|lpc8 lp9|lpc9 m128 m256|mega stm|f1 f4 f7 s6 TESTPATH=buildroot/tests STATE_FILE="./.pio/.mftestrc" -SED=$(which gsed sed | head -n1) shopt -s extglob nocasematch diff --git a/buildroot/bin/mfutil b/buildroot/bin/mfutil index 1699dd9adf..e9ee57fb9e 100755 --- a/buildroot/bin/mfutil +++ b/buildroot/bin/mfutil @@ -4,11 +4,9 @@ # # Check dependencies -which curl 1>/dev/null 2>&1 || { echo "curl not found! Please install it."; exit ; } -which git 1>/dev/null 2>&1 || { echo "git not found! Please install it."; exit ; } - -SED=$(which gsed sed | head -n1) -[[ -z "$SED" ]] && { echo "No sed found, please install sed" ; exit 1 ; } +which curl &>/dev/null || { echo "curl not found! Please install it."; exit 1 ; } +which git &>/dev/null || { echo "git not found! Please install it."; exit 1 ; } +which sed &>/dev/null || { echo "sed not found! Please install it."; exit 1 ; } OPEN=$( which gnome-open xdg-open open | head -n1 ) diff --git a/buildroot/bin/opt_disable b/buildroot/bin/opt_disable index 0444e1b773..8b36bc1f34 100755 --- a/buildroot/bin/opt_disable +++ b/buildroot/bin/opt_disable @@ -3,13 +3,34 @@ # exit on first failure set -e -SED=$(which gsed sed | head -n1) +# Get SED_CMD, SED_I, and the BSDSED flag +. $(dirname $0)/opt_sed for opt in "$@" ; do DID=0 ; FOUND=0 - for FN in Configuration Configuration_adv; do - "${SED}" -i "/^\(\s*\)\(#define\s\+${opt}\b\s\?\)\(\s\s\)\?/{s//\1\/\/\2/;h};\${x;/./{x;q0};x;q9}" Marlin/$FN.h && DID=1 - ((DID||FOUND)) || { grep -E "^\s*//\s*#define\s+${opt}\b" Marlin/$FN.h >/dev/null && FOUND=1 ; } + 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 diff --git a/buildroot/bin/opt_enable b/buildroot/bin/opt_enable index f9be82cbd1..292b4952d7 100755 --- a/buildroot/bin/opt_enable +++ b/buildroot/bin/opt_enable @@ -3,13 +3,34 @@ # exit on first failure set -e -SED=$(which gsed sed | head -n1) +# Get SED_CMD, SED_I, and the BSDSED flag +. $(dirname $0)/opt_sed for opt in "$@" ; do DID=0 ; FOUND=0 - for FN in Configuration Configuration_adv; do - "${SED}" -i "/^\(\s*\)\/\/\(\s*\)\(#define\s\+${opt}\b\)\( \?\)/{s//\1\2\3\4\4\4/;h};\${x;/./{x;q0};x;q9}" Marlin/$FN.h && DID=1 - ((DID||FOUND)) || { grep -E "^\s*#define\s+${opt}\b" Marlin/$FN.h >/dev/null && FOUND=1 ; } + for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do + if [[ $BSDSED ]]; then + # BSD sed version (macOS) + "${SED_CMD}" "${SED_I[@]}" \ + "/^[[:space:]]*\/\/[[:space:]]*#define[[:space:]]+${opt}\b/{ + s/^[[:space:]]*\/\/[[:space:]]*\(#define[[:space:]]+${opt}\b\)[[:space:]]*/\1 / + h + \$b end + } + \$!b + :end + x + /./{ x; q0; } + x + q1" \ + $FN && DID=1 + else + # GNU sed version + "${SED_CMD}" "${SED_I[@]}" \ + "/^\(\s*\)\/\/\(\s*\)\(#define\s\+${opt}\b\)\( \?\)/{s//\1\2\3\4\4\4/;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 diff --git a/buildroot/bin/opt_find b/buildroot/bin/opt_find index a7c8fd9d71..bab9da0e46 100755 --- a/buildroot/bin/opt_find +++ b/buildroot/bin/opt_find @@ -23,8 +23,8 @@ esac while [[ $# > 0 ]]; do DID=0 - for FN in Configuration Configuration_adv; do - FOUND=$( grep -HEn "^\s*${COMM}#define\s+[A-Z0-9_]*${1}" "Marlin/$FN.h" 2>/dev/null ) + for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do + FOUND=$( grep -HEn "^\s*${COMM}#define\s+[A-Z0-9_]*${1}" $FN 2>/dev/null ) [[ -n "$FOUND" ]] && { echo "$FOUND" ; DID=1 ; } done ((DID)) || { echo "ERROR: ${MYNAME} - No ${TYPE}match for ${1}" ; exit 9; } diff --git a/buildroot/bin/opt_sed b/buildroot/bin/opt_sed new file mode 100755 index 0000000000..d6075add01 --- /dev/null +++ b/buildroot/bin/opt_sed @@ -0,0 +1,9 @@ +# Detect sed version +SED_CMD="sed" +SED_I=(-i) +if command -v gsed >/dev/null 2>&1; then + SED_CMD="gsed" +elif [[ "$(uname)" == "Darwin" ]]; then + SED_I=(-i '') + BSDSED=1 +fi diff --git a/buildroot/bin/opt_set b/buildroot/bin/opt_set index b9935512a4..d58cfc3d14 100755 --- a/buildroot/bin/opt_set +++ b/buildroot/bin/opt_set @@ -3,12 +3,33 @@ # exit on first failure set -e -SED=$(which gsed sed | head -n1) +# Get SED_CMD, SED_I, and the BSDSED flag +. $(dirname $0)/opt_sed while [[ $# > 1 ]]; do DID=0 - for FN in Configuration Configuration_adv; do - "${SED}" -i "/^\(\s*\)\/*\s*\(#define\s\+${1}\b\) *\(.*\)$/{s//\1\2 ${2} \/\/ \3/;h};\${x;/./{x;q0};x;q9}" Marlin/$FN.h && DID=1 + for FN in Marlin/Configuration.h Marlin/Configuration_adv.h; do + if [[ $BSDSED ]]; then + # BSD sed version (macOS) + $SED_CMD "${SED_I[@]}" \ + "/^[[:space:]]*\/\{0,2\}[[:space:]]*#define[[:space:]]+${1}\b/{ + s/^[[:space:]]*\/\{0,2\}[[:space:]]*\(#define[[:space:]]+${1}\b\)[[:space:]]*.*/\1 ${2} \/\/ &/ + h + \$b end + } + \$!b + :end + x + /./{ x; q0; } + x + q1" \ + $FN && DID=1 + else + # GNU sed version + $SED_CMD "${SED_I[@]}" \ + "/^\(\s*\)\/\{0,2\}\s*\(#define\s\+${1}\b\)\s*\(.*\)$/{s//\1\2 ${2} \/\/ \3/;h};\${x;/./{x;q0};x;q1}" \ + $FN && DID=1 + fi done ((DID)) || eval "echo '#define ${1} ${2}' >>Marlin/Configuration.h" || diff --git a/buildroot/bin/pins_set b/buildroot/bin/pins_set deleted file mode 100755 index 216eabc076..0000000000 --- a/buildroot/bin/pins_set +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -IFS='/' read -r -a PINPATH <<< "$1" -DIR=${PINPATH[0]} -NAM=${PINPATH[1]} - -SED=$(which gsed sed | head -n1) - -shift -while [[ $# > 1 ]]; do - PIN=$1 ; VAL=$2 - FOUT="${DIR}/pins_${NAM}.h" - eval "${SED} -i '/^[[:blank:]]*\(\/\/\)*[[:blank:]]*\(#define \+${PIN}\b\).*$/{s//\2 ${VAL}/;h};\${x;/./{x;q0};x;q9}' Marlin/src/pins/${FOUT}" || - (echo "ERROR: pins_set Can't find ${PIN} in ${FOUT}" >&2 && exit 9) - shift 2 -done diff --git a/buildroot/share/git/mfhelp b/buildroot/share/git/mfhelp index aff34b866f..cbdd6ec4ef 100755 --- a/buildroot/share/git/mfhelp +++ b/buildroot/share/git/mfhelp @@ -40,7 +40,6 @@ Modify Configuration.h / Configuration_adv.h: Modify pins files: - pins_set ............. Set the value of a pin in a pins file pinsformat.py ........ Python script to format pins files THIS diff --git a/buildroot/share/git/mfprep b/buildroot/share/git/mfprep index 7446895c6b..4554bdc441 100755 --- a/buildroot/share/git/mfprep +++ b/buildroot/share/git/mfprep @@ -9,7 +9,6 @@ # so at every release be sure to create a dev- tag and publish it to origin. # -SED=$(which gsed sed | head -n1) SELF=`basename "$0"` DRYRUN=0 diff --git a/buildroot/tests/DUE b/buildroot/tests/DUE index 3c4876b44e..ca225d87dd 100755 --- a/buildroot/tests/DUE +++ b/buildroot/tests/DUE @@ -37,11 +37,10 @@ exec_test $1 $2 "RAMPS4DUE_EFB with ABL (Bilinear), ExtUI, S-Curve, many options # RADDS with BLTouch, ABL(B), 3 x Z auto-align # restore_configs -opt_set MOTHERBOARD BOARD_RADDS Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z3_DRIVER_TYPE A4988 +opt_set MOTHERBOARD BOARD_RADDS Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z3_DRIVER_TYPE A4988 \ + X_MAX_PIN -1 Y_MAX_PIN -1 opt_enable ENDSTOPPULLUPS BLTOUCH AUTO_BED_LEVELING_BILINEAR \ Z_STEPPER_AUTO_ALIGN Z_STEPPER_ALIGN_STEPPER_XY Z_SAFE_HOMING -pins_set ramps/RAMPS X_MAX_PIN -1 -pins_set ramps/RAMPS Y_MAX_PIN -1 exec_test $1 $2 "RADDS with ABL (Bilinear), Triple Z Axis, Z_STEPPER_AUTO_ALIGN, E_DUAL_STEPPER_DRIVERS" "$3" # diff --git a/buildroot/tests/teensy35 b/buildroot/tests/teensy35 index c7830aeaac..0fd1c5820d 100755 --- a/buildroot/tests/teensy35 +++ b/buildroot/tests/teensy35 @@ -106,9 +106,8 @@ exec_test $1 $2 "Teensy 3.5/3.6 COREXZ | BACKLASH" "$3" # Enable Dual Z with Dual Z endstops # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY35_36 Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z2_MIN_PIN 2 +opt_set MOTHERBOARD BOARD_TEENSY35_36 Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z2_MIN_PIN 2 X_MAX_PIN -1 opt_enable Z_MULTI_ENDSTOPS -pins_set ramps/RAMPS X_MAX_PIN -1 exec_test $1 $2 "Dual Z with Dual Z endstops" "$3" # Clean up diff --git a/buildroot/tests/teensy41 b/buildroot/tests/teensy41 index 894abc15b9..fc50957b25 100755 --- a/buildroot/tests/teensy41 +++ b/buildroot/tests/teensy41 @@ -105,9 +105,8 @@ exec_test $1 $2 "Teensy 4.0/4.1 COREXZ" "$3" # Enable Dual Z with Dual Z endstops # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY41 Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z2_MIN_PIN 2 +opt_set MOTHERBOARD BOARD_TEENSY41 Z_DRIVER_TYPE A4988 Z2_DRIVER_TYPE A4988 Z2_MIN_PIN 2 X_MAX_PIN -1 opt_enable Z_MULTI_ENDSTOPS -pins_set ramps/RAMPS X_MAX_PIN -1 exec_test $1 $2 "Dual Z with Dual Z endstops" "$3" # Clean up