From 4309e6ab76528a8e64343148d81caa2d231c8c13 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <thinkyhead@users.noreply.github.com>
Date: Mon, 22 Jan 2024 23:31:04 -0600
Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Fix=20build?=
 =?UTF-8?q?=5Fall=5Fexamples?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 buildroot/bin/build_all_examples | 6 ++++--
 buildroot/bin/build_example      | 6 ++++--
 buildroot/bin/mfutil             | 3 +--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/buildroot/bin/build_all_examples b/buildroot/bin/build_all_examples
index a6d6ede47d..a77259bb36 100755
--- a/buildroot/bin/build_all_examples
+++ b/buildroot/bin/build_all_examples
@@ -14,7 +14,9 @@
 # build_all_examples [...] branch [resume-from]
 #
 
-. mfutil
+HERE=`dirname $0`
+
+. "$HERE/mfutil"
 
 GITREPO=https://github.com/MarlinFirmware/Configurations.git
 STAT_FILE=./.pio/.buildall
@@ -123,7 +125,7 @@ CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/
 for CONF in $CONF_TREE ; do
 
   # Get a config's directory name
-  DIR=$( echo $CONF | sed "s|$TMP/config/examples/||" )
+  DIR=$( echo $CONF | "$SED" "s|$TMP/config/examples/||" )
 
   # If looking for a config, skip others
   [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue
diff --git a/buildroot/bin/build_example b/buildroot/bin/build_example
index a8878e8d9f..dabc4c572c 100755
--- a/buildroot/bin/build_example
+++ b/buildroot/bin/build_example
@@ -5,7 +5,9 @@
 # Usage: build_example internal config-home config-folder
 #
 
-. mfutil
+HERE=`dirname $0`
+
+. "$HERE/mfutil"
 
 # Require 'internal' as the first argument
 [[ "$1" == "internal" ]] || { echo "Don't call this script directly, use build_all_examples instead." ; exit 1 ; }
@@ -36,6 +38,6 @@ unset IFS; set +f
 echo -e "\n#define NO_CONTROLLER_CUSTOM_WIRING_WARNING" >> Marlin/Configuration.h
 
 echo "Building the firmware now..."
-$HERE/mftest -s -a -n1 || { echo "Failed"; exit 1; }
+"$HERE/mftest" -s -a -n1 || { echo "Failed"; exit 1; }
 
 echo "Success"
diff --git a/buildroot/bin/mfutil b/buildroot/bin/mfutil
index 75a2791cfe..1699dd9adf 100755
--- a/buildroot/bin/mfutil
+++ b/buildroot/bin/mfutil
@@ -7,13 +7,12 @@
 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=$(command -v gsed 2>/dev/null || command -v sed 2>/dev/null)
+SED=$(which gsed sed | head -n1)
 [[ -z "$SED" ]] && { echo "No sed found, please install sed" ; exit 1 ; }
 
 OPEN=$( which gnome-open xdg-open open | head -n1 )
 
 SELF=`basename "$0"`
-HERE=`dirname "$0"`
 
 # Check if called in the right location
 [[ -e "Marlin/src" ]] || { echo -e "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF $1" ; exit ; }