1#
2# Copyright (c) 2015 Wind River Systems, Inc.
3#
4# SPDX-License-Identifier: Apache-2.0
5#
6
7# In zsh the value of $0 depends on the FUNCTION_ARGZERO option which is
8# set by default. FUNCTION_ARGZERO, when it is set, sets $0 temporarily
9# to the name of the function/script when executing a shell function or
10# sourcing a script. POSIX_ARGZERO option, when it is set, exposes the
11# original value of $0 in spite of the current FUNCTION_ARGZERO setting.
12#
13# Note: The version of zsh need to be 5.0.6 or above. Any versions below
14# 5.0.6 maybe encounter errors when sourcing this script.
15if [ -n "${ZSH_VERSION:-}" ]; then
16	dir="${(%):-%N}"
17	if [ $options[posixargzero] != "on" ]; then
18		setopt posixargzero
19		name=$(basename -- "$0")
20		unsetopt posixargzero
21	else
22		name=$(basename -- "$0")
23	fi
24else
25	dir="${BASH_SOURCE[0]}"
26	name=$(basename -- "$0")
27fi
28
29if [ "X$name" "==" "Xzephyr-env.sh" ]; then
30    echo "Source this file (do NOT execute it!) to set the Zephyr Kernel environment."
31    exit
32fi
33
34# You can further customize your environment by creating a bash script called
35# .zephyrrc in your home directory. It will be automatically
36# run (if it exists) by this script.
37
38if uname | grep -q "MINGW"; then
39    win_build=1
40    pwd_opt="-W"
41else
42    win_build=0
43    pwd_opt=""
44fi
45
46# identify OS source tree root directory
47export ZEPHYR_BASE=$( builtin cd "$( dirname "$dir" )" > /dev/null && pwd ${pwd_opt})
48unset pwd_opt
49
50scripts_path=${ZEPHYR_BASE}/scripts
51if [ "$win_build" -eq 1 ]; then
52    scripts_path=$(echo "/$scripts_path" | sed 's/\\/\//g' | sed 's/://')
53fi
54unset win_build
55if ! echo "${PATH}" | grep -q "${scripts_path}"; then
56    export PATH=${scripts_path}:${PATH}
57fi
58unset scripts_path
59
60# enable custom environment settings
61zephyr_answer_file=~/zephyr-env_install.bash
62[ -f ${zephyr_answer_file} ] && {
63	echo "Warning: Please rename ~/zephyr-env_install.bash to ~/.zephyrrc"
64	. ${zephyr_answer_file}
65}
66unset zephyr_answer_file
67zephyr_answer_file=~/.zephyrrc
68[ -f ${zephyr_answer_file} ] &&  . ${zephyr_answer_file}
69unset zephyr_answer_file
70