#!/bin/sh
# -*- mode: shell-script-mode; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# Copyright (C) 2012-13 O.S. Systems Software LTDA.
# Authored-by:  Otavio Salvador <otavio@ossystems.com.br>
# Adopted to Angstrom:  Khem Raj <raj.khem@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
echo "Check ubuntu toolchain..."
./prebuilts/scripts/ubuntu_scripts/setup_toolchain_for_ubuntu.sh ./prebuilts/toolchains/ubuntu20.04
./prebuilts/scripts/ubuntu_scripts/setup_toolchain_for_ubuntu.sh ./prebuilts/toolchains/ubuntu18.04

. prebuilts/scripts/setup-environment-internal

# current not use virtual branch, no need add-layer meta-selinux
if false; then
bitbake -e | grep DISTRO_FEATURES | grep selinux  --color   > /dev/null

if [ $? -eq 0 ]; then

    cat ../prebuilts/scripts/conf/bblayers.conf | grep meta-selinux > /dev/null
    if [ $? -ne 0 ]; then
        bitbake-layers add-layer -F ../layers/meta-selinux  > /dev/null
        if [ $? -eq 0 ]; then
            echo "add new layers success"
        else
            echo "add new layres fail"
	    exit 1
        fi
    fi
else
    echo "machine is $MACHINE"
    sed -i '/meta-selinux/d' ../prebuilts/scripts/conf/bblayers.conf
fi
fi

#  add meta-maxlinear layers for machine equipped with maxlinear wifi6 chip
bitbake -e | grep MACHINE_FEATURES | grep wav654  --color   > /dev/null
if [ $? -eq 0 ]; then
    cat ../prebuilts/scripts/conf/bblayers.conf | grep meta-maxlinear > /dev/null
    if [ $? -ne 0 ]; then
        bitbake-layers add-layer -F ../layers/meta-maxlinear  > /dev/null
        if [ $? -eq 0 ]; then
            echo "add new layers success"
        else
            echo "add new layres fail"
            exit 1
        fi
    fi
fi

work_dir=$PWD

cd $work_dir
