Skip to content

Commit

Permalink
fix(stm32CubeProg): use BSD getopt for MacOS
Browse files Browse the repository at this point in the history
On MacOS getopt is the BSD based one while other
using the gnu-based getopt.
Then "-o" and long options are not supported

Fixes stm32duino#99

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Jul 15, 2024
1 parent 354699b commit 8fee15e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions stm32CubeProg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -o nounset # Treat unset variables as an error
# set -o xtrace # Print command traces before executing command.

UNAME_OS="$(uname -s)"
STM32CP_CLI=
INTERFACE=
PORT=
Expand Down Expand Up @@ -55,11 +56,21 @@ aborting() {

# parse command line arguments
# options may be followed by one colon to indicate they have a required arg
if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then
echo "Terminating..." >&2
exit 1
fi

case "${UNAME_OS}" in
Darwin*)
echo "Warning: long options not supported due to getopt from FreeBSD usage."
if ! options=$(getopt hi:ef:o:c:r:d:v:p: "$@"); then
echo "Terminating..." >&2
exit 1
fi
;;
*)
if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then
echo "Terminating..." >&2
exit 1
fi
;;
esac
eval set -- "$options"

while true; do
Expand Down Expand Up @@ -109,10 +120,13 @@ while true; do
shift
break
;;
*)
echo "Unknown option $1"
usage 1
;;
esac
done
# Check STM32CubeProgrammer cli availability, fallback to dfu-util if protocol dfu
UNAME_OS="$(uname -s)"
# Check STM32CubeProgrammer cli availability
case "${UNAME_OS}" in
Linux*)
STM32CP_CLI=STM32_Programmer.sh
Expand Down

0 comments on commit 8fee15e

Please sign in to comment.