windows_install_prerequisites.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env bash
  2. #
  3. # Setup script to configure an MSYS2 environment for ESP-IDF.
  4. #
  5. # Use of this script is optional, there is also a prebuilt MSYS2 environment available
  6. # which can be downloaded and used as-is.
  7. #
  8. # See https://docs.espressif.com/projects/esp-idf/en/latest/get-started/windows-setup.html for full details.
  9. if [ "$OSTYPE" != "msys" ]; then
  10. echo "This setup script expects to be run from an MSYS2 environment on Windows."
  11. exit 1
  12. fi
  13. if ! [ -x /bin/pacman ]; then
  14. echo "This setup script expects to use the pacman package manager from MSYS2."
  15. exit 1
  16. fi
  17. if [ "$MSYSTEM" != "MINGW32" ]; then
  18. echo "This setup script must be started from the 'MSYS2 MinGW 32-bit' start menu shortcut"
  19. echo "OR by running `cygpath -w /mingw32.exe`"
  20. echo "(The current MSYSTEM mode is $MSYSTEM but it expects it to be MINGW32)"
  21. exit 1
  22. fi
  23. # if update-core still exists, run it to get the latest core MSYS2 system
  24. # (which no longer needs or includes update-core!)
  25. #
  26. # If this step runs, it will require a full restart of MSYS2 before it
  27. # can continue.
  28. [ -x /usr/bin/update-core ] && /usr/bin/update-core
  29. set -e
  30. pacman --noconfirm -Syu # This step may require the terminal to be closed and restarted
  31. pacman --noconfirm -S --needed gettext-devel gcc git make ncurses-devel flex bison gperf vim \
  32. mingw-w64-i686-python-pip mingw-w64-i686-python-cryptography unzip winpty mingw-w64-i686-gcc
  33. # if IDF_PATH is set, install requirements now as well
  34. if [ -n "$IDF_PATH" ]; then
  35. python -m pip install -r "$IDF_PATH/requirements.txt"
  36. fi
  37. # Automatically download precompiled toolchain, unpack at /opt/xtensa-esp32-elf/
  38. TOOLCHAIN_ZIP=xtensa-esp32-elf-gcc8_4_0-esp-2021r1-win32.zip
  39. echo "Downloading precompiled toolchain ${TOOLCHAIN_ZIP}..."
  40. cd ~
  41. curl -LO --retry 10 https://dl.espressif.com/dl/${TOOLCHAIN_ZIP}
  42. mkdir -p /opt
  43. cd /opt
  44. rm -rf /opt/xtensa-esp32-elf # for upgrades
  45. unzip ~/${TOOLCHAIN_ZIP}
  46. rm ~/${TOOLCHAIN_ZIP}
  47. cat > /etc/profile.d/esp32_toolchain.sh << EOF
  48. # This file was created by ESP-IDF windows_install_prerequisites.sh
  49. # and will be overwritten if that script is run again.
  50. export PATH="/opt/xtensa-esp32-elf/bin:\$PATH"
  51. EOF
  52. # clean up pacman package cache to save some disk space
  53. pacman --noconfirm -Scc
  54. cat << EOF
  55. ************************************************
  56. MSYS2 environment is now ready to use ESP-IDF.
  57. 1) Run 'source /etc/profile' to add the toolchain to
  58. your path in this terminal. This command produces no output.
  59. You only need to do this once, future terminals do this
  60. automatically when opened.
  61. 2) After ESP-IDF is set up (see setup guide), edit the file
  62. `cygpath -w /etc/profile`
  63. and add a line to set the variable IDF_PATH so it points to the
  64. IDF directory, ie:
  65. export IDF_PATH=/c/path/to/esp-idf/directory
  66. ************************************************
  67. EOF