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 |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 19 | echo The script must be sourced, not executed |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
Alexander Amelkin | 88a7fe6 | 2019-07-17 18:11:32 +0300 | [diff] [blame] | 23 | # Check if 'column' command is present |
Patrick Williams | a469a0f | 2021-02-19 15:07:44 -0600 | [diff] [blame] | 24 | COLUMN=$(which column || true) |
Alexander Amelkin | 88a7fe6 | 2019-07-17 18:11:32 +0300 | [diff] [blame] | 25 | if [ -z "$COLUMN" ]; then |
| 26 | # If it is not, use 'cat' |
Patrick Williams | a469a0f | 2021-02-19 15:07:44 -0600 | [diff] [blame] | 27 | COLUMN=$(which cat) |
Alexander Amelkin | 88a7fe6 | 2019-07-17 18:11:32 +0300 | [diff] [blame] | 28 | fi |
| 29 | |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 30 | machine() { |
| 31 | local target=$1 |
Amithash Prasad | 80d844b | 2018-09-26 17:39:24 -0700 | [diff] [blame] | 32 | local build_dir=$2 |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 33 | local cfg name tmpl |
Maksym Sloyko | f197793 | 2020-12-08 22:11:38 +0000 | [diff] [blame] | 34 | local configs |
| 35 | |
| 36 | # zsh requires wordsplit so that variable expansion behaves like bash |
| 37 | if [ -n "$ZSH_NAME" ]; then |
| 38 | setopt local_options shwordsplit |
| 39 | fi |
| 40 | if which find > /dev/null 2>&1; then |
| 41 | configs=$(find meta-* -path "*/conf/machine/*.conf") |
| 42 | else |
| 43 | configs=$(ls -1 meta-*/meta-*/conf/machine/*.conf meta-*/conf/machine/*.conf) |
| 44 | fi |
| 45 | |
| 46 | for cfg in $configs; do |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 47 | name=${cfg##*/} |
| 48 | name=${name%.conf} |
| 49 | tmpl=${cfg%/machine/*.conf} |
Patrick Williams | aef9809 | 2021-02-19 19:45:05 -0600 | [diff] [blame] | 50 | |
| 51 | # Skip any machines that don't support meta-phosphor. |
Patrick Williams | 06ce8af | 2021-10-26 16:18:30 -0500 | [diff] [blame] | 52 | if [ ! -e "$tmpl/bblayers.conf.sample" ]; then |
Patrick Williams | aef9809 | 2021-02-19 19:45:05 -0600 | [diff] [blame] | 53 | continue |
| 54 | fi |
Patrick Williams | 06ce8af | 2021-10-26 16:18:30 -0500 | [diff] [blame] | 55 | if ! grep -q "##OEROOT##/meta-phosphor" "$tmpl/bblayers.conf.sample"; then |
Patrick Williams | aef9809 | 2021-02-19 19:45:05 -0600 | [diff] [blame] | 56 | continue |
| 57 | fi |
| 58 | |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 59 | # If a target is specified, then check for a match, |
| 60 | # otherwise just list what we've discovered |
| 61 | if [ -n "$target" ]; then |
| 62 | if [ "${name}" = "${target}" ]; then |
| 63 | echo "Machine ${target} found in ${tmpl%/conf}" |
Patrick Williams | 06ce8af | 2021-10-26 16:18:30 -0500 | [diff] [blame] | 64 | mkdir -p "${build_dir}" |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 65 | TEMPLATECONF="${tmpl}" source \ |
Patrick Williams | 06ce8af | 2021-10-26 16:18:30 -0500 | [diff] [blame] | 66 | oe-init-build-env "${build_dir}" |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 67 | |
| 68 | if [ "$(cat conf/templateconf.cfg)" = "${tmpl}" ]; then |
Alexander Filippov | b5b5bc1 | 2019-06-13 11:56:55 +0300 | [diff] [blame] | 69 | sed "s/^\(MACHINE\s*[?:]*\s*=\s*\).*$/\1\"${target}\"/" \ |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 70 | -i conf/local.conf |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 71 | fi |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 72 | return |
Dave Cobbley | 194ff4f | 2018-08-22 21:40:54 -0400 | [diff] [blame] | 73 | fi |
Patrick Williams | aef9809 | 2021-02-19 19:45:05 -0600 | [diff] [blame] | 74 | else |
Alexander Filippov | d70e7e8 | 2019-05-21 15:45:26 +0300 | [diff] [blame] | 75 | echo "${name}" |
| 76 | fi |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 77 | done |
| 78 | |
Zev Weiss | 1ebfa83 | 2022-01-27 21:15:13 -0800 | [diff] [blame^] | 79 | [ -n "$target" ] && echo "No such machine!" >&2 && return 1 |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | if [ -z "$1" ]; then |
| 83 | echo Target machine must be specified. Use one of: |
| 84 | echo |
Alexander Amelkin | 88a7fe6 | 2019-07-17 18:11:32 +0300 | [diff] [blame] | 85 | (echo qemuarm; machine) | sort | $COLUMN |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 86 | elif [ "$1" = "qemuarm" ]; then |
| 87 | source openbmc-env |
Alexander Amelkin | 363dccc | 2018-03-05 16:47:05 +0300 | [diff] [blame] | 88 | else |
Amithash Prasad | 80d844b | 2018-09-26 17:39:24 -0700 | [diff] [blame] | 89 | bld_dir=$2 |
| 90 | if [ -z "$2" ]; then |
Andrew Jeffery | ab714a2 | 2020-04-19 20:56:08 +0930 | [diff] [blame] | 91 | bld_dir="build/$1" |
Amithash Prasad | 80d844b | 2018-09-26 17:39:24 -0700 | [diff] [blame] | 92 | fi |
Patrick Williams | 06ce8af | 2021-10-26 16:18:30 -0500 | [diff] [blame] | 93 | machine "$1" "$bld_dir" |
Alexander Amelkin | 68a967d | 2018-02-02 12:01:13 +0300 | [diff] [blame] | 94 | fi |
| 95 | |