From 9699eb198ea7d2ba1a2e95f7278344ede301de58 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 23 Oct 2020 22:58:48 -0700 Subject: [PATCH] refactor kaleidoscope-builder.conf to make it possible to extract the probing tools that have platform-specific implementations --- etc/kaleidoscope-builder.conf | 107 ++++++++++++++-------------------- 1 file changed, 44 insertions(+), 63 deletions(-) diff --git a/etc/kaleidoscope-builder.conf b/etc/kaleidoscope-builder.conf index ac55dac8..aa5865b3 100644 --- a/etc/kaleidoscope-builder.conf +++ b/etc/kaleidoscope-builder.conf @@ -31,74 +31,73 @@ uname_S=$(uname -s 2>/dev/null || echo not) uname_O=$(uname -o 2>/dev/null || echo not) find_device_port() { + if [ -n "${DEVICE_PORT}" ]; then + echo "DEVICE_PORT=\"${DEVICE_PORT}\" predefined." + return + fi + find_device_vid_pid - DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-linux-udev" - if [[ "${DEVICE_PORT}" = "" ]]; then + if [ "${uname_S}" = "Darwin" ]; then + DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-macos" DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID})" + elif [ "${uname_O}" = "Cygwin" ]; then + DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-windows.ps1" + DEVICE_PORT="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID} -Format Cygwin)" + DEVICE_COM_PORT="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID} -Format COM)" + elif [ "${uname_S}" = "FreeBSD" ]; then + DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-freebsd" + DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER})" else - echo "DEVICE_PORT=\"${DEVICE_PORT}\" predefined." + DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-linux-udev" + DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID})" fi } reset_device_cmd() { if [ -z ${NO_RESET} ]; then - stty -F ${DEVICE_PORT} 1200 hupcl + if [ "${uname_S}" = "Darwin" ]; then + /bin/stty -f ${DEVICE_PORT} 1200 + elif [ "${uname_S}" = "FreeBSD" ]; then + /bin/stty -f ${DEVICE_PORT} 1200 + + elif [ "${uname_O}" = "Cygwin" ]; then + cmd /c mode ${DEVICE_COM_PORT} baud=1200 + else + stty -F ${DEVICE_PORT} 1200 hupcl + fi fi } find_bootloader_ports() { - find_device_vid_pid - : "${BOOTLOADER_VID:=${VID}}" - DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-linux-udev" - if [[ "${DEVICE_PORT_BOOTLOADER}" = "" ]]; then - DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID})" - else + if [ -n "${DEVICE_PORT_BOOTLOADER}" ]; then echo "DEVICE_PORT_BOOTLOADER=\"${DEVICE_PORT_BOOTLOADER}\" predefined." + return fi -} - -if [ "${uname_S}" = "Darwin" ]; then - find_device_port() { - DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-macos" - DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID})" - } - - reset_device_cmd() { - /bin/stty -f ${DEVICE_PORT} 1200 - } - - find_bootloader_ports() { - find_device_vid_pid - : "${BOOTLOADER_VID:=${VID}}" + find_device_vid_pid + : "${BOOTLOADER_VID:=${VID}}" + if [ "${uname_S}" = "Darwin" ]; then DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-macos" - if [[ "${DEVICE_PORT_BOOTLOADER}" = "" ]]; then - DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID})" - else - echo "DEVICE_PORT_BOOTLOADER=\"${DEVICE_PORT_BOOTLOADER}\" predefined." - fi - } - -elif [ "${uname_S}" = "FreeBSD" ]; then + DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID})" + elif [ "${uname_O}" = "Cygwin" ]; then + DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-windows.ps1" + DEVICE_PORT_BOOTLOADER="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID} -Format COM)" + elif [ "${uname_S}" = "FreeBSD" ]; then + DEVICE_PORT_PROBER="${KALEIDOSCPE_BIN_DIR}/find-device-port-freebsd" + DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER})" - find_device_port() { - DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-freebsd" - DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER})" - } + else - reset_device_cmd() { - /bin/stty -f ${DEVICE_PORT} 1200 - } + DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-linux-udev" + DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID})" + fi +} +if [ "${uname_S}" = "FreeBSD" ]; then : "${AVR_SIZE:=/usr/local/bin/avr-size}" : "${AVR_NM:=/usr/local/bin/avr-nm}" : "${AVR_OBJDUMP:=/usr/local/bin/avr-objdump}" - find_bootloader_ports() { - DEVICE_PORT_PROBER="${KALEIDOSCPE_BIN_DIR}/find-device-port-freebsd" - DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER})" - } - if [ "${ARCH}" = "virtual" ]; then : "${COMPILER_PATH:=/usr/local/bin/}" fi @@ -125,22 +124,4 @@ elif [ "${uname_O}" = "Cygwin" ]; then TMPDIR="$(realpath --relative-to=./ ${TMPDIR})" - find_device_port() { - find_device_vid_pid - DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-windows.ps1" - DEVICE_PORT="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID} -Format Cygwin)" - DEVICE_COM_PORT="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID} -Format COM)" - } - - reset_device_cmd() { - cmd /c mode ${DEVICE_COM_PORT} baud=1200 - } - - find_bootloader_ports() { - find_device_vid_pid - : "${BOOTLOADER_VID:=${VID}}" - DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-windows.ps1" - DEVICE_PORT_BOOTLOADER="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID} -Format COM)" - } - fi