diff --git a/scripts/readme.md b/scripts/readme.md index 79263ce5b..e32c948fe 100644 --- a/scripts/readme.md +++ b/scripts/readme.md @@ -7,6 +7,9 @@ If the zmk-config repo contains a `combos.dtsi` file, the script will also automatically update the `MAX_COMBOS_PER_KEY` and `MAX_KEYS_PER_COMBO` settings for all boards, depending on the combos specified in `combos.dtsi`. +If the `west.yml` contains any modules other than `ZMK`, the script will look for them in +`HOST_MODULES_DIR` and automatically enable them for the build. + ## Build steps ### 1. Clone the ZMK repository @@ -43,10 +46,10 @@ The build script can be used to install either a "docker" or a "local" toolchain. If unsure, I recommend using the docker toolchain. Depending on your installation choice, do **one** of the following: -1. Install Docker or Podman (recommended) and, if using Podman, configure the +1. Install `yq` and `Docker` or `Podman` (recommended). If using Podman, configure the docker registry. On Debian or Ubuntu, you can do both by running: ```bash - sudo apt-get install podman + sudo apt-get install podman yq echo 'unqualified-search-registries = ["docker.io"]' > $XDG_CONFIG_HOME/containers/registries.conf ``` 2. Install a local diff --git a/scripts/zmk_build.sh b/scripts/zmk_build.sh index db44101d7..4cbb14ccd 100755 --- a/scripts/zmk_build.sh +++ b/scripts/zmk_build.sh @@ -16,6 +16,10 @@ while [[ $# -gt 0 ]]; do MULTITHREAD="true" ;; + --no-multithread) + MULTITHREAD="false" + ;; + -c | --clear-cache) CLEAR_CACHE="true" ;; @@ -27,6 +31,13 @@ while [[ $# -gt 0 ]]; do shift ;; + # comma or space separated list of modules (use quotes if space separated) + # if ommitted, will compile list of modules in west.yml + --modules) + MODULES="$2" + shift + ;; + -v | --version) ZEPHYR_VERSION="$2" shift @@ -79,24 +90,36 @@ done # Set defaults [[ -z $ZEPHYR_VERSION ]] && ZEPHYR_VERSION="3.5" [[ -z $RUNWITH_DOCKER ]] && RUNWITH_DOCKER="true" +[[ -z $MULTITHREAD ]] && MULTITHREAD="true" [[ -z $OUTPUT_DIR ]] && OUTPUT_DIR="$WINHOME/Downloads" [[ -z $LOG_DIR ]] && LOG_DIR="/tmp" [[ -z $HOST_ZMK_DIR ]] && HOST_ZMK_DIR="$HOME/zmk" +[[ -z $HOST_MODULES_DIR ]] && HOST_MODULES_DIR="$HOME/zmk-modules" [[ -z $HOST_CONFIG_DIR ]] && HOST_CONFIG_DIR="$HOME/zmk-config" [[ -z $DOCKER_ZMK_DIR ]] && DOCKER_ZMK_DIR="/workspace/zmk" +[[ -z $DOCKER_MODULES_DIR ]] && DOCKER_MODULES_DIR="/workspace/zmk-modules" [[ -z $DOCKER_CONFIG_DIR ]] && DOCKER_CONFIG_DIR="/workspace/zmk-config" -# [[ -z $BOARDS ]] && BOARDS="$(grep '^[[:space:]]*\-[[:space:]]*board:' $HOST_CONFIG_DIR/build.yaml | sed 's/^.*: *//')" [[ -z $BOARDS ]] && BOARDS="$(yq -r '.include[].board' $HOST_CONFIG_DIR/build.yaml)" +[[ -z $MODULES ]] && MODULES="$(yq -r '.manifest.projects[].name | + select(. != "zmk")' $HOST_CONFIG_DIR/config/west.yml)" [[ -z $CLEAR_CACHE ]] && CLEAR_CACHE="false" DOCKER_IMG="zmkfirmware/zmk-dev-arm:$ZEPHYR_VERSION" DOCKER_BIN="$SUDO podman" +echo "Configured modules: $(MODULES" +MODULES=$( + echo $MODULES | + sed -z 's/[, \n]/;/g' | # use ; as separator + sed -r "s|([^;]*);|${DOCKER_MODULES_DIR}/\1;|g" | # insert modules root path + sed 's/;$/\n/' # remove final ; +) + # +-------------------------+ # | AUTOMATE CONFIG OPTIONS | # +-------------------------+ @@ -135,6 +158,7 @@ if [[ $RUNWITH_DOCKER = true ]]; then DOCKER_CMD="$DOCKER_BIN run --rm \ --mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \ --mount type=bind,source=$HOST_CONFIG_DIR,target=$DOCKER_CONFIG_DIR,readonly \ + --mount type=bind,source=$HOST_MODULES_DIR,target=$DOCKER_MODULES_DIR,readonly \ --mount type=volume,source=zmk-root-user-$ZEPHYR_VERSION,target=/root \ --mount type=volume,source=zmk-zephyr-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/zephyr \ --mount type=volume,source=zmk-zephyr-modules-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/modules \ @@ -173,7 +197,7 @@ compile_board() { [[ $MULTITHREAD = "true" ]] || echo -en "\n$(tput setaf 2)Building $1... $(tput sgr0)" [[ $MULTITHREAD = "true" ]] && echo -e "$(tput setaf 2)Building $1... $(tput sgr0)" $DOCKER_PREFIX west build -d "build/$BUILD_DIR" -b $1 $WEST_OPTS \ - -- -DZMK_CONFIG="$CONFIG_DIR" -Wno-dev >"$LOGFILE" 2>&1 + -- -DZMK_CONFIG="$CONFIG_DIR" -DZMK_EXTRA_MODULES="$MODULES" -Wno-dev >"$LOGFILE" 2>&1 if [[ $? -eq 0 ]]; then [[ $MULTITHREAD = "true" ]] || echo "$(tput setaf 2)done$(tput sgr0)" echo "Build log saved to \"$LOGFILE\"."