blob: 5655bfa8175ebb1773c05376d7746701d914aa07 [file] [log] [blame]
Patrick Williams06ce8af2021-10-26 16:18:30 -05001#!/bin/bash
Alexander Amelkin363dccc2018-03-05 16:47:05 +03002#
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 Williams512028d2020-01-17 10:35:31 -060018if [ -z "$ZSH_NAME" ] && [ "$(basename -- "$0")" = "setup" ]; then
Patrick Williams2c0e2b62022-04-01 09:22:59 -050019 echo The script must be sourced, not executed
20 exit 1
Alexander Amelkin68a967d2018-02-02 12:01:13 +030021fi
22
Alexander Amelkin88a7fe62019-07-17 18:11:32 +030023# Check if 'column' command is present
Patrick Williamsa469a0f2021-02-19 15:07:44 -060024COLUMN=$(which column || true)
Alexander Amelkin88a7fe62019-07-17 18:11:32 +030025if [ -z "$COLUMN" ]; then
26 # If it is not, use 'cat'
Patrick Williamsa469a0f2021-02-19 15:07:44 -060027 COLUMN=$(which cat)
Alexander Amelkin88a7fe62019-07-17 18:11:32 +030028fi
29
Alexander Amelkin68a967d2018-02-02 12:01:13 +030030machine() {
Patrick Williams2c0e2b62022-04-01 09:22:59 -050031 local target=$1
32 local build_dir=$2
33 local cfg name tmpl
34 local configs
Maksym Sloykof1977932020-12-08 22:11:38 +000035
Patrick Williamscbcd6f42022-03-30 10:32:22 -050036 # 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 # Add qemu machines.
46 configs="$configs $(ls -1 poky/meta/conf/machine/qemu*.conf)"
Maksym Sloykof1977932020-12-08 22:11:38 +000047
Patrick Williams2c0e2b62022-04-01 09:22:59 -050048 for cfg in $configs; do
49 name=${cfg##*/}
50 name=${name%.conf}
51 tmpl=${cfg%/machine/*.conf}
Patrick Williamsaef98092021-02-19 19:45:05 -060052
Patrick Williamscbcd6f42022-03-30 10:32:22 -050053 if [ "$tmpl" = "poky/meta/conf" ]; then
54 # This is a QEMU machine, use phosphor defaults.
55 tmpl="meta-phosphor/conf"
56 else
57 # Skip any machines that don't support meta-phosphor.
58 if [ ! -e "$tmpl/bblayers.conf.sample" ]; then
59 continue
60 fi
61 if ! grep -q "##OEROOT##/meta-phosphor" "$tmpl/bblayers.conf.sample"; then
62 continue
63 fi
Patrick Williamsaef98092021-02-19 19:45:05 -060064 fi
65
Patrick Williams2c0e2b62022-04-01 09:22:59 -050066 # If a target is specified, then check for a match,
67 # otherwise just list what we've discovered
68 if [ -n "$target" ]; then
69 if [ "${name}" = "${target}" ]; then
70 echo "Machine ${target} found in ${tmpl%/conf}"
71 mkdir -p "${build_dir}"
72 TEMPLATECONF="${tmpl}" source \
73 oe-init-build-env "${build_dir}"
Alexander Filippovd70e7e82019-05-21 15:45:26 +030074
Patrick Williams2c0e2b62022-04-01 09:22:59 -050075 if [ "$(cat conf/templateconf.cfg)" = "${tmpl}" ]; then
76 sed "s/^\(MACHINE\s*[?:]*\s*=\s*\).*$/\1\"${target}\"/" \
77 -i conf/local.conf
78 fi
79 return
80 fi
Patrick Williamsaef98092021-02-19 19:45:05 -060081 else
Patrick Williams2c0e2b62022-04-01 09:22:59 -050082 echo "${name}"
83 fi
84 done
Alexander Amelkin68a967d2018-02-02 12:01:13 +030085
Patrick Williams2c0e2b62022-04-01 09:22:59 -050086 [ -n "$target" ] && echo "No such machine!" >&2 && return 1
Alexander Amelkin68a967d2018-02-02 12:01:13 +030087}
88
89if [ -z "$1" ]; then
Patrick Williamscbcd6f42022-03-30 10:32:22 -050090 echo Target machine must be specified. Use one of:
91 echo
92 machine | sort | $COLUMN
Alexander Amelkin363dccc2018-03-05 16:47:05 +030093else
Patrick Williams2c0e2b62022-04-01 09:22:59 -050094 bld_dir=$2
95 if [ -z "$2" ]; then
96 bld_dir="build/$1"
97 fi
98 machine "$1" "$bld_dir"
Alexander Amelkin68a967d2018-02-02 12:01:13 +030099fi
100