blob: 57b3ded72b63777a2b7a3934fb72432b82065254 [file] [log] [blame]
Alexander Amelkin68a967d2018-02-02 12:01:13 +03001#!/bin/sh
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
Alexander Amelkin68a967d2018-02-02 12:01:13 +030019 echo The script must be sourced, not executed
20 exit 1
21fi
22
Alexander Amelkin88a7fe62019-07-17 18:11:32 +030023# Check if 'column' command is present
24COLUMN=`which column`
25if [ -z "$COLUMN" ]; then
26 # If it is not, use 'cat'
27 COLUMN=`which cat`
28fi
29
Alexander Amelkin68a967d2018-02-02 12:01:13 +030030machine() {
31 local target=$1
Amithash Prasad80d844b2018-09-26 17:39:24 -070032 local build_dir=$2
Alexander Filippovd70e7e82019-05-21 15:45:26 +030033 local cfg name tmpl
Maksym Sloykof1977932020-12-08 22:11:38 +000034 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 Filippovd70e7e82019-05-21 15:45:26 +030047 name=${cfg##*/}
48 name=${name%.conf}
49 tmpl=${cfg%/machine/*.conf}
50 # If a target is specified, then check for a match,
51 # otherwise just list what we've discovered
52 if [ -n "$target" ]; then
53 if [ "${name}" = "${target}" ]; then
54 echo "Machine ${target} found in ${tmpl%/conf}"
Andrew Jefferyab714a22020-04-19 20:56:08 +093055 mkdir -p ${build_dir}
Alexander Filippovd70e7e82019-05-21 15:45:26 +030056 TEMPLATECONF="${tmpl}" source \
57 oe-init-build-env ${build_dir}
58
59 if [ "$(cat conf/templateconf.cfg)" = "${tmpl}" ]; then
Alexander Filippovb5b5bc12019-06-13 11:56:55 +030060 sed "s/^\(MACHINE\s*[?:]*\s*=\s*\).*$/\1\"${target}\"/" \
Alexander Filippovd70e7e82019-05-21 15:45:26 +030061 -i conf/local.conf
Alexander Amelkin68a967d2018-02-02 12:01:13 +030062 fi
Alexander Filippovd70e7e82019-05-21 15:45:26 +030063 return
Dave Cobbley194ff4f2018-08-22 21:40:54 -040064 fi
Patrick Williams42c0f8b2020-04-02 13:11:52 -050065 elif test -e $tmpl/bblayers.conf.sample && \
66 grep -q "##OEROOT##/meta-phosphor" $tmpl/bblayers.conf.sample;
67 then
Alexander Filippovd70e7e82019-05-21 15:45:26 +030068 echo "${name}"
69 fi
Alexander Amelkin68a967d2018-02-02 12:01:13 +030070 done
71
72 [ -n "$target" ] && echo "No such machine!"
73}
74
75if [ -z "$1" ]; then
76 echo Target machine must be specified. Use one of:
77 echo
Alexander Amelkin88a7fe62019-07-17 18:11:32 +030078 (echo qemuarm; machine) | sort | $COLUMN
Alexander Amelkin68a967d2018-02-02 12:01:13 +030079elif [ "$1" = "qemuarm" ]; then
80 source openbmc-env
Alexander Amelkin363dccc2018-03-05 16:47:05 +030081else
Amithash Prasad80d844b2018-09-26 17:39:24 -070082 bld_dir=$2
83 if [ -z "$2" ]; then
Andrew Jefferyab714a22020-04-19 20:56:08 +093084 bld_dir="build/$1"
Amithash Prasad80d844b2018-09-26 17:39:24 -070085 fi
86 machine $1 $bld_dir
Alexander Amelkin68a967d2018-02-02 12:01:13 +030087fi
88