mfenvs 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env bash
  2. #
  3. # mfenvs Print the current board and environment information
  4. # Output -> "SHORT_NAME (###): [ env1 env2 env3 ... ]"
  5. #
  6. [[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; }
  7. which pio >/dev/null || { echo "Make sure 'pio' is in your execution PATH." ; exit 1 ; }
  8. errout() { echo -e "\033[0;31m$1\033[0m" ; }
  9. case $(uname | tr '[:upper:]' '[:lower:]') in
  10. darwin) SYS='mac' ;;
  11. *linux) SYS='lin' ;;
  12. win*) SYS='win' ;;
  13. msys*) SYS='win' ;;
  14. cygwin*) SYS='win' ;;
  15. mingw*) SYS='win' ;;
  16. *) SYS='uni' ;;
  17. esac
  18. ACODE='/^[[:space:]]*#define[[:space:]]MOTHERBOARD[[:space:]]/ { sub(/^BOARD_/, "", $3); print $3 }'
  19. MB=$(awk "$ACODE" Marlin/Configuration.h 2>/dev/null)
  20. [[ -z $MB ]] && MB=$(awk "$ACODE" Marlin/Config.h 2>/dev/null)
  21. [[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
  22. BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
  23. BNUM=$( sed -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
  24. [[ -z $BNUM ]] && { echo "Error - Can't find BOARD_$MB in core/boards.h." ; exit 1 ; }
  25. ENVS=( $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+(env|$SYS):[^ ]+" | grep -oE "(env|$SYS):[^ ]+" | sed -E "s/(env|$SYS)://" ) )
  26. [[ -z $ENVS ]] && { errout "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
  27. ECOUNT=${#ENVS[*]}
  28. [[ $ECOUNT == 1 ]] && EOUT=$ENVS || EOUT="${ENVS[@]}"
  29. echo "$MB ($BNUM): [ $EOUT ]"