blob: 823cc1b446cc91ac8c90e3d6ee41dc3a613d32e2 [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#
Alexander Amelkin68a967d2018-02-02 12:01:13 +030018
Alexander Amelkin88a7fe62019-07-17 18:11:32 +030019# Check if 'column' command is present
Patrick Williams6acb6102022-05-31 09:25:55 -050020COLUMN_CMD=$(which column || true)
21if [ -z "$COLUMN_CMD" ]; then
Alexander Amelkin88a7fe62019-07-17 18:11:32 +030022 # If it is not, use 'cat'
Patrick Williams6acb6102022-05-31 09:25:55 -050023 COLUMN=( "$(which cat)" )
24else
25 EXPAND_CMD=$(which expand || true)
26 if [ -n "$EXPAND_CMD" ]; then
27 COLUMN=( "sh" "-c" "$COLUMN_CMD | $EXPAND_CMD" )
28 else
29 COLUMN=( "$COLUMN_CMD" )
30 fi
Alexander Amelkin88a7fe62019-07-17 18:11:32 +030031fi
32
Alexander Amelkin68a967d2018-02-02 12:01:13 +030033machine() {
Patrick Williams2c0e2b62022-04-01 09:22:59 -050034 local target=$1
35 local build_dir=$2
36 local cfg name tmpl
37 local configs
Maksym Sloykof1977932020-12-08 22:11:38 +000038
Roy Yang67d50902024-05-17 20:47:29 +000039 # zsh requires wordsplit so that variable expansion behaves like bash
40 if [ -n "$ZSH_NAME" ]; then
41 setopt local_options shwordsplit
42 fi
43 if which find > /dev/null 2>&1; then
Patrick Williamscbcd6f42022-03-30 10:32:22 -050044 configs="$(find meta-* -path "*/conf/machine/*.conf")"
Roy Yang67d50902024-05-17 20:47:29 +000045 else
46 configs=$(ls -1 meta-*/meta-*/conf/machine/*.conf meta-*/conf/machine/*.conf)
47 fi
Patrick Williamscbcd6f42022-03-30 10:32:22 -050048 # Add qemu machines.
49 configs="$configs $(ls -1 poky/meta/conf/machine/qemu*.conf)"
Maksym Sloykof1977932020-12-08 22:11:38 +000050
Patrick Williams2c0e2b62022-04-01 09:22:59 -050051 for cfg in $configs; do
52 name=${cfg##*/}
53 name=${name%.conf}
54 tmpl=${cfg%/machine/*.conf}
Patrick Williamsaef98092021-02-19 19:45:05 -060055
Patrick Williamscbcd6f42022-03-30 10:32:22 -050056 if [ "$tmpl" = "poky/meta/conf" ]; then
57 # This is a QEMU machine, use phosphor defaults.
58 tmpl="meta-phosphor/conf"
59 else
60 # Skip any machines that don't support meta-phosphor.
Patrick Williamsbb789d52022-09-09 09:47:35 -050061 if [ ! -e "$tmpl/templates/default/bblayers.conf.sample" ]; then
Patrick Williamscbcd6f42022-03-30 10:32:22 -050062 continue
63 fi
Patrick Williamsbb789d52022-09-09 09:47:35 -050064 if ! grep -q "##OEROOT##/meta-phosphor" "$tmpl/templates/default/bblayers.conf.sample"; then
Patrick Williamscbcd6f42022-03-30 10:32:22 -050065 continue
66 fi
Patrick Williamsaef98092021-02-19 19:45:05 -060067 fi
68
Patrick Williams2c0e2b62022-04-01 09:22:59 -050069 # If a target is specified, then check for a match,
70 # otherwise just list what we've discovered
71 if [ -n "$target" ]; then
72 if [ "${name}" = "${target}" ]; then
73 echo "Machine ${target} found in ${tmpl%/conf}"
74 mkdir -p "${build_dir}"
Patrick Williamsbb789d52022-09-09 09:47:35 -050075 TEMPLATECONF="${tmpl}/templates/default" source \
Patrick Williams2c0e2b62022-04-01 09:22:59 -050076 oe-init-build-env "${build_dir}"
Alexander Filippovd70e7e82019-05-21 15:45:26 +030077
Patrick Williams08b6cec2022-11-18 10:30:50 -060078 if [ "$(cat conf/templateconf.cfg)" = "${tmpl}/templates/default" ]; then
Patrick Williams2c0e2b62022-04-01 09:22:59 -050079 sed "s/^\(MACHINE\s*[?:]*\s*=\s*\).*$/\1\"${target}\"/" \
80 -i conf/local.conf
81 fi
82 return
83 fi
Patrick Williamsaef98092021-02-19 19:45:05 -060084 else
Patrick Williams2c0e2b62022-04-01 09:22:59 -050085 echo "${name}"
86 fi
87 done
Alexander Amelkin68a967d2018-02-02 12:01:13 +030088
Patrick Williams2c0e2b62022-04-01 09:22:59 -050089 [ -n "$target" ] && echo "No such machine!" >&2 && return 1
Alexander Amelkin68a967d2018-02-02 12:01:13 +030090}
91
92if [ -z "$1" ]; then
Roy Yang67d50902024-05-17 20:47:29 +000093 echo Target machine must be specified. Use one of:
94 echo
95 machine | sort | sed "s/qemu[^[:space:]]*//" | "${COLUMN[@]}"
Patrick Williamscf270c12024-09-04 10:45:23 -040096 exit
Alexander Amelkin68a967d2018-02-02 12:01:13 +030097fi
98
Patrick Williamscf270c12024-09-04 10:45:23 -040099if [ -z "$ZSH_NAME" ] && [ "$(basename -- "$0")" = "setup" ]; then
100 echo The script must be sourced, not executed
101 exit 1
102fi
103
104bld_dir=$2
105if [ -z "$2" ]; then
106 bld_dir="build/$1"
107fi
108machine "$1" "$bld_dir"