blob: f05800d9f51ab13a2df95b81a3243f1460655c6f [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 Williams606cc8f2024-09-04 14:22:32 -040055 vendor=${cfg%%/*}
56 vendor=${vendor##meta-}
57 vendor=${vendor%%-openbmc}
Patrick Williamsaef98092021-02-19 19:45:05 -060058
Patrick Williamscbcd6f42022-03-30 10:32:22 -050059 if [ "$tmpl" = "poky/meta/conf" ]; then
60 # This is a QEMU machine, use phosphor defaults.
61 tmpl="meta-phosphor/conf"
62 else
63 # Skip any machines that don't support meta-phosphor.
Patrick Williamsbb789d52022-09-09 09:47:35 -050064 if [ ! -e "$tmpl/templates/default/bblayers.conf.sample" ]; then
Patrick Williamscbcd6f42022-03-30 10:32:22 -050065 continue
66 fi
Patrick Williamsbb789d52022-09-09 09:47:35 -050067 if ! grep -q "##OEROOT##/meta-phosphor" "$tmpl/templates/default/bblayers.conf.sample"; then
Patrick Williamscbcd6f42022-03-30 10:32:22 -050068 continue
69 fi
Patrick Williamsaef98092021-02-19 19:45:05 -060070 fi
71
Patrick Williams2c0e2b62022-04-01 09:22:59 -050072 # If a target is specified, then check for a match,
73 # otherwise just list what we've discovered
74 if [ -n "$target" ]; then
75 if [ "${name}" = "${target}" ]; then
76 echo "Machine ${target} found in ${tmpl%/conf}"
77 mkdir -p "${build_dir}"
Patrick Williamsbb789d52022-09-09 09:47:35 -050078 TEMPLATECONF="${tmpl}/templates/default" source \
Patrick Williams2c0e2b62022-04-01 09:22:59 -050079 oe-init-build-env "${build_dir}"
Alexander Filippovd70e7e82019-05-21 15:45:26 +030080
Patrick Williams08b6cec2022-11-18 10:30:50 -060081 if [ "$(cat conf/templateconf.cfg)" = "${tmpl}/templates/default" ]; then
Patrick Williams2c0e2b62022-04-01 09:22:59 -050082 sed "s/^\(MACHINE\s*[?:]*\s*=\s*\).*$/\1\"${target}\"/" \
83 -i conf/local.conf
84 fi
85 return
86 fi
Patrick Williamsaef98092021-02-19 19:45:05 -060087 else
Patrick Williams606cc8f2024-09-04 14:22:32 -040088 echo "${vendor}/${name}"
Patrick Williams2c0e2b62022-04-01 09:22:59 -050089 fi
90 done
Alexander Amelkin68a967d2018-02-02 12:01:13 +030091
Patrick Williams2c0e2b62022-04-01 09:22:59 -050092 [ -n "$target" ] && echo "No such machine!" >&2 && return 1
Alexander Amelkin68a967d2018-02-02 12:01:13 +030093}
94
95if [ -z "$1" ]; then
Roy Yang67d50902024-05-17 20:47:29 +000096 echo Target machine must be specified. Use one of:
97 echo
Patrick Williams606cc8f2024-09-04 14:22:32 -040098 machine | sed "/qemu[^[:space:]]*/d" | sed "s#.*/##" | sort -h | "${COLUMN[@]}"
99 exit
100fi
101
102if [ "$1" == "machines" ]; then
103 vendors=""
104 for m in $(machine | sort -h | sed "/qemu[^[:space:]]*/d"); do
105 vendor=${m%%/*}
106 machine=${m##*/}
107
108 if [[ ! "$vendors" =~ -$vendor- ]]; then
109 vendors="$vendors -$vendor-"
110 echo "* $vendor"
111 fi
112 echo " * $machine"
113 done
Patrick Williamscf270c12024-09-04 10:45:23 -0400114 exit
Alexander Amelkin68a967d2018-02-02 12:01:13 +0300115fi
116
Patrick Williamscf270c12024-09-04 10:45:23 -0400117if [ -z "$ZSH_NAME" ] && [ "$(basename -- "$0")" = "setup" ]; then
118 echo The script must be sourced, not executed
119 exit 1
120fi
121
122bld_dir=$2
123if [ -z "$2" ]; then
124 bld_dir="build/$1"
125fi
126machine "$1" "$bld_dir"