|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 | 3 | if ! [ -x "$(command -v python)" ]; then
|
4 |
| - echo "ERROR: python is not installed! Please install python first." |
5 |
| - exit 1 |
| 4 | + echo "ERROR: python is not installed! Please install python first." |
| 5 | + exit 1 |
6 | 6 | fi
|
7 | 7 |
|
8 | 8 | if ! [ -x "$(command -v git)" ]; then
|
9 |
| - echo "ERROR: git is not installed! Please install git first." |
10 |
| - exit 1 |
| 9 | + echo "ERROR: git is not installed! Please install git first." |
| 10 | + exit 1 |
11 | 11 | fi
|
12 | 12 |
|
13 |
| -mkdir -p dist |
| 13 | +TARGET="all" |
| 14 | +BUILD_TYPE="all" |
| 15 | +SKIP_ENV=0 |
| 16 | +COPY_OUT=0 |
| 17 | +DEPLOY_OUT=0 |
14 | 18 |
|
15 |
| -# update components from git |
16 |
| -./tools/update-components.sh |
17 |
| -if [ $? -ne 0 ]; then exit 1; fi |
| 19 | +function print_help() { |
| 20 | + echo "Usage: build.sh [-s] [-A arduino_branch] [-I idf_branch] [-i idf_commit] [-a path] [-t <target>] [-b <build|menuconfig|idf_libs|copy_bootloader|mem_variant>] [config ...]" |
| 21 | + echo " -s Skip installing/updating of ESP-IDF and all components" |
| 22 | + echo " -A Set which branch of arduino-esp32 to be used for compilation" |
| 23 | + echo " -I Set which branch of ESP-IDF to be used for compilation" |
| 24 | + echo " -i Set which commit of ESP-IDF to be used for compilation" |
| 25 | + echo " -d Deploy the build to github arduino-esp32" |
| 26 | + echo " -a Set the arduino-esp32 folder to copy the result to. ex. '$HOME/Arduino/hardware/espressif/esp32'" |
| 27 | + echo " -t Set the build target(chip). ex. 'esp32s3'" |
| 28 | + echo " -b Set the build type. ex. 'build' to build the project and prepare for uploading to a board" |
| 29 | + echo " ... Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. Requires -b" |
| 30 | + exit 1 |
| 31 | +} |
18 | 32 |
|
19 |
| -# install esp-idf and gcc toolchain |
20 |
| -source ./tools/install-esp-idf.sh |
21 |
| -if [ $? -ne 0 ]; then exit 1; fi |
| 33 | +while getopts ":A:I:i:a:t:b:sd" opt; do |
| 34 | + case ${opt} in |
| 35 | + s ) |
| 36 | + SKIP_ENV=1 |
| 37 | + ;; |
| 38 | + d ) |
| 39 | + DEPLOY_OUT=1 |
| 40 | + ;; |
| 41 | + a ) |
| 42 | + export ESP32_ARDUINO="$OPTARG" |
| 43 | + COPY_OUT=1 |
| 44 | + ;; |
| 45 | + A ) |
| 46 | + export AR_BRANCH="$OPTARG" |
| 47 | + ;; |
| 48 | + I ) |
| 49 | + export IDF_BRANCH="$OPTARG" |
| 50 | + ;; |
| 51 | + i ) |
| 52 | + export IDF_COMMIT="$OPTARG" |
| 53 | + ;; |
| 54 | + t ) |
| 55 | + TARGET=$OPTARG |
| 56 | + ;; |
| 57 | + b ) |
| 58 | + b=$OPTARG |
| 59 | + if [ "$b" != "build" ] && |
| 60 | + [ "$b" != "menuconfig" ] && |
| 61 | + [ "$b" != "idf_libs" ] && |
| 62 | + [ "$b" != "copy_bootloader" ] && |
| 63 | + [ "$b" != "mem_variant" ]; then |
| 64 | + print_help |
| 65 | + fi |
| 66 | + BUILD_TYPE="$b" |
| 67 | + ;; |
| 68 | + \? ) |
| 69 | + echo "Invalid option: -$OPTARG" 1>&2 |
| 70 | + print_help |
| 71 | + ;; |
| 72 | + : ) |
| 73 | + echo "Invalid option: -$OPTARG requires an argument" 1>&2 |
| 74 | + print_help |
| 75 | + ;; |
| 76 | + esac |
| 77 | +done |
| 78 | +shift $((OPTIND -1)) |
| 79 | +CONFIGS=$@ |
| 80 | + |
| 81 | +if [ $SKIP_ENV -eq 0 ]; then |
| 82 | + echo "* Installing/Updating ESP-IDF and all components..." |
| 83 | + # update components from git |
| 84 | + ./tools/update-components.sh |
| 85 | + if [ $? -ne 0 ]; then exit 1; fi |
| 86 | + |
| 87 | + # install esp-idf and gcc toolchain |
| 88 | + source ./tools/install-esp-idf.sh |
| 89 | + if [ $? -ne 0 ]; then exit 1; fi |
| 90 | +else |
| 91 | + source ./tools/config.sh |
| 92 | +fi |
22 | 93 |
|
23 |
| -if [ -z $TARGETS ]; then |
24 |
| - TARGETS="esp32s3 esp32c3 esp32s2 esp32" |
| 94 | +if [ "$BUILD_TYPE" != "all" ]; then |
| 95 | + if [ "$TARGET" = "all" ]; then |
| 96 | + echo "ERROR: You need to specify target for non-default builds" |
| 97 | + print_help |
| 98 | + fi |
| 99 | + configs="configs/defconfig.common;configs/defconfig.$TARGET" |
| 100 | + for conf in $CONFIGS; do |
| 101 | + configs="$configs;configs/defconfig.$conf" |
| 102 | + done |
| 103 | + echo "idf.py -DIDF_TARGET=\"$TARGET\" -DSDKCONFIG_DEFAULTS=\"$configs\" $BUILD_TYPE" |
| 104 | + rm -rf build sdkconfig |
| 105 | + idf.py -DIDF_TARGET="$TARGET" -DSDKCONFIG_DEFAULTS="$configs" $BUILD_TYPE |
| 106 | + if [ $? -ne 0 ]; then exit 1; fi |
| 107 | + exit 0 |
25 | 108 | fi
|
26 | 109 |
|
| 110 | +rm -rf build sdkconfig out |
| 111 | + |
27 | 112 | echo $(git -C $AR_COMPS/arduino describe --all --long) > version.txt
|
28 | 113 |
|
29 |
| -rm -rf out build sdkconfig sdkconfig.old |
30 |
| - |
31 |
| -for target in $TARGETS; do |
32 |
| - # configure the build for the target |
33 |
| - rm -rf build sdkconfig sdkconfig.old |
34 |
| - cp "sdkconfig.$target" sdkconfig |
35 |
| - # uncomment next line to access menuconfig |
36 |
| - # idf.py menuconfig |
37 |
| - # build and prepare libs |
38 |
| - idf.py build |
39 |
| - if [ $? -ne 0 ]; then exit 1; fi |
40 |
| - cp sdkconfig "sdkconfig.$target" |
41 |
| - # build bootloaders |
42 |
| - ./tools/build-bootloaders.sh |
43 |
| - if [ $? -ne 0 ]; then exit 1; fi |
| 114 | +for target_json in `jq -c '.targets[]' configs/builds.json`; do |
| 115 | + target=$(echo "$target_json" | jq -c '.target' | tr -d '"') |
| 116 | + |
| 117 | + if [ "$TARGET" != "all" ] && [ "$TARGET" != "$target" ]; then |
| 118 | + echo "* Skipping Target: $target" |
| 119 | + continue |
| 120 | + fi |
| 121 | + |
| 122 | + echo "* Target: $target" |
| 123 | + main_configs="configs/defconfig.common;configs/defconfig.$target" |
| 124 | + |
| 125 | + # Build IDF Libs |
| 126 | + idf_libs_configs="$main_configs" |
| 127 | + for defconf in `echo "$target_json" | jq -c '.idf_libs[]' | tr -d '"'`; do |
| 128 | + idf_libs_configs="$idf_libs_configs;configs/defconfig.$defconf" |
| 129 | + done |
| 130 | + echo "* Build IDF-Libs: $idf_libs_configs" |
| 131 | + rm -rf build sdkconfig |
| 132 | + idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" idf_libs |
| 133 | + if [ $? -ne 0 ]; then exit 1; fi |
| 134 | + |
| 135 | + # Build Bootloaders |
| 136 | + for boot_conf in `echo "$target_json" | jq -c '.bootloaders[]'`; do |
| 137 | + bootloader_configs="$main_configs" |
| 138 | + for defconf in `echo "$boot_conf" | jq -c '.[]' | tr -d '"'`; do |
| 139 | + bootloader_configs="$bootloader_configs;configs/defconfig.$defconf" |
| 140 | + done |
| 141 | + echo "* Build BootLoader: $bootloader_configs" |
| 142 | + rm -rf build sdkconfig |
| 143 | + idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$bootloader_configs" copy_bootloader |
| 144 | + if [ $? -ne 0 ]; then exit 1; fi |
| 145 | + done |
| 146 | + |
| 147 | + # Build Memory Variants |
| 148 | + for mem_conf in `echo "$target_json" | jq -c '.mem_variants[]'`; do |
| 149 | + mem_configs="$main_configs" |
| 150 | + for defconf in `echo "$mem_conf" | jq -c '.[]' | tr -d '"'`; do |
| 151 | + mem_configs="$mem_configs;configs/defconfig.$defconf" |
| 152 | + done |
| 153 | + echo "* Build Memory Variant: $mem_configs" |
| 154 | + rm -rf build sdkconfig |
| 155 | + idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$mem_configs" mem_variant |
| 156 | + if [ $? -ne 0 ]; then exit 1; fi |
| 157 | + done |
44 | 158 | done
|
45 | 159 |
|
46 | 160 | # archive the build
|
47 |
| -./tools/archive-build.sh |
48 |
| -if [ $? -ne 0 ]; then exit 1; fi |
| 161 | +if [ "$TARGET" = "all" ] && [ "$BUILD_TYPE" = "all" ]; then |
| 162 | + ./tools/archive-build.sh |
| 163 | + if [ $? -ne 0 ]; then exit 1; fi |
| 164 | +fi |
49 | 165 |
|
50 |
| -#./tools/copy-to-arduino.sh |
| 166 | +# copy everything to arduino-esp32 installation |
| 167 | +if [ $COPY_OUT -eq 1 ] && [ -d "$ESP32_ARDUINO" ]; then |
| 168 | + ./tools/copy-to-arduino.sh |
| 169 | +fi |
| 170 | + |
| 171 | +if [ $DEPLOY_OUT -eq 1 ]; then |
| 172 | + ./tools/push-to-arduino.sh |
| 173 | +fi |
0 commit comments