Patrick Williams | 06ce8af | 2021-10-26 16:18:30 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Alexander Amelkin | 363dccc | 2018-03-05 16:47:05 +0300 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2018, YADRO |
| 4 | # Author: Alexander Amelkin <a.amelkin@yadro.com> |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
Patrick Williams | 512028d | 2020-01-17 10:35:31 -0600 | [diff] [blame] | 18 | if [ -z "$ZSH_NAME" ] && [ "$(basename -- "$0")" = "setup" ]; then |
Patrick Williams | 2c0e2b6 | 2022-04-01 09:22:59 -0500 | [diff] [blame] | 19 | echo The script must be sourced, not executed |
| 20 | exit 1 |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 21 | fi |
| 22 | |
Alexander Amelkin | 88a7fe6 | 2019-07-17 18:11:32 +0300 | [diff] [blame] | 23 | # Check if 'column' command is present |
Patrick Williams | 6acb610 | 2022-05-31 09:25:55 -0500 | [diff] [blame] | 24 | COLUMN_CMD=$(which column || true) |
| 25 | if [ -z "$COLUMN_CMD" ]; then |
Alexander Amelkin | 88a7fe6 | 2019-07-17 18:11:32 +0300 | [diff] [blame] | 26 | # If it is not, use 'cat' |
Patrick Williams | 6acb610 | 2022-05-31 09:25:55 -0500 | [diff] [blame] | 27 | COLUMN=( "$(which cat)" ) |
| 28 | else |
| 29 | EXPAND_CMD=$(which expand || true) |
| 30 | if [ -n "$EXPAND_CMD" ]; then |
| 31 | COLUMN=( "sh" "-c" "$COLUMN_CMD | $EXPAND_CMD" ) |
| 32 | else |
| 33 | COLUMN=( "$COLUMN_CMD" ) |
| 34 | fi |
Alexander Amelkin | 88a7fe6 | 2019-07-17 18:11:32 +0300 | [diff] [blame] | 35 | fi |
| 36 | |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 37 | machine() { |
Patrick Williams | 2c0e2b6 | 2022-04-01 09:22:59 -0500 | [diff] [blame] | 38 | local target=$1 |
| 39 | local build_dir=$2 |
| 40 | local cfg name tmpl |
| 41 | local configs |
Maksym Sloyko | f197793 | 2020-12-08 22:11:38 +0000 | [diff] [blame] | 42 | |
Patrick Williams | cbcd6f4 | 2022-03-30 10:32:22 -0500 | [diff] [blame] | 43 | # zsh requires wordsplit so that variable expansion behaves like bash |
| 44 | if [ -n "$ZSH_NAME" ]; then |
| 45 | setopt local_options shwordsplit |
| 46 | fi |
| 47 | if which find > /dev/null 2>&1; then |
| 48 | configs="$(find meta-* -path "*/conf/machine/*.conf")" |
| 49 | else |
| 50 | configs=$(ls -1 meta-*/meta-*/conf/machine/*.conf meta-*/conf/machine/*.conf) |
| 51 | fi |
| 52 | # Add qemu machines. |
| 53 | configs="$configs $(ls -1 poky/meta/conf/machine/qemu*.conf)" |
Maksym Sloyko | f197793 | 2020-12-08 22:11:38 +0000 | [diff] [blame] | 54 | |
Patrick Williams | 2c0e2b6 | 2022-04-01 09:22:59 -0500 | [diff] [blame] | 55 | for cfg in $configs; do |
| 56 | name=${cfg##*/} |
| 57 | name=${name%.conf} |
| 58 | tmpl=${cfg%/machine/*.conf} |
Patrick Williams | aef9809 | 2021-02-19 19:45:05 -0600 | [diff] [blame] | 59 | |
Patrick Williams | cbcd6f4 | 2022-03-30 10:32:22 -0500 | [diff] [blame] | 60 | if [ "$tmpl" = "poky/meta/conf" ]; then |
| 61 | # This is a QEMU machine, use phosphor defaults. |
| 62 | tmpl="meta-phosphor/conf" |
| 63 | else |
| 64 | # Skip any machines that don't support meta-phosphor. |
| 65 | if [ ! -e "$tmpl/bblayers.conf.sample" ]; then |
| 66 | continue |
| 67 | fi |
| 68 | if ! grep -q "##OEROOT##/meta-phosphor" "$tmpl/bblayers.conf.sample"; then |
| 69 | continue |
| 70 | fi |
Patrick Williams | aef9809 | 2021-02-19 19:45:05 -0600 | [diff] [blame] | 71 | fi |
| 72 | |
Patrick Williams | 2c0e2b6 | 2022-04-01 09:22:59 -0500 | [diff] [blame] | 73 | # If a target is specified, then check for a match, |
| 74 | # otherwise just list what we've discovered |
| 75 | if [ -n "$target" ]; then |
| 76 | if [ "${name}" = "${target}" ]; then |
| 77 | echo "Machine ${target} found in ${tmpl%/conf}" |
| 78 | mkdir -p "${build_dir}" |
| 79 | TEMPLATECONF="${tmpl}" source \ |
| 80 | oe-init-build-env "${build_dir}" |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 81 | |
Patrick Williams | 2c0e2b6 | 2022-04-01 09:22:59 -0500 | [diff] [blame] | 82 | if [ "$(cat conf/templateconf.cfg)" = "${tmpl}" ]; then |
| 83 | sed "s/^\(MACHINE\s*[?:]*\s*=\s*\).*$/\1\"${target}\"/" \ |
| 84 | -i conf/local.conf |
| 85 | fi |
| 86 | return |
| 87 | fi |
Patrick Williams | aef9809 | 2021-02-19 19:45:05 -0600 | [diff] [blame] | 88 | else |
Patrick Williams | 2c0e2b6 | 2022-04-01 09:22:59 -0500 | [diff] [blame] | 89 | echo "${name}" |
| 90 | fi |
| 91 | done |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 92 | |
Patrick Williams | 2c0e2b6 | 2022-04-01 09:22:59 -0500 | [diff] [blame] | 93 | [ -n "$target" ] && echo "No such machine!" >&2 && return 1 |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | if [ -z "$1" ]; then |
Patrick Williams | cbcd6f4 | 2022-03-30 10:32:22 -0500 | [diff] [blame] | 97 | echo Target machine must be specified. Use one of: |
| 98 | echo |
Patrick Williams | 6acb610 | 2022-05-31 09:25:55 -0500 | [diff] [blame] | 99 | machine | sort | sed "s/qemu[^[:space:]]*//" | "${COLUMN[@]}" |
Alexander Amelkin | 363dccc | 2018-03-05 16:47:05 +0300 | [diff] [blame] | 100 | else |
Patrick Williams | 2c0e2b6 | 2022-04-01 09:22:59 -0500 | [diff] [blame] | 101 | bld_dir=$2 |
| 102 | if [ -z "$2" ]; then |
| 103 | bld_dir="build/$1" |
| 104 | fi |
| 105 | machine "$1" "$bld_dir" |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 106 | fi |
| 107 | |