1 |
4 |
danv |
#!/usr/bin/env bash -e
|
2 |
|
|
###############################################################################
|
3 |
|
|
#
|
4 |
|
|
# Copyright (C) 2018
|
5 |
|
|
# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
6 |
|
|
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
7 |
|
|
#
|
8 |
|
|
# This program is free software: you can redistribute it and/or modify
|
9 |
|
|
# it under the terms of the GNU General Public License as published by
|
10 |
|
|
# the Free Software Foundation, either version 3 of the License, or
|
11 |
|
|
# (at your option) any later version.
|
12 |
|
|
#
|
13 |
|
|
# This program is distributed in the hope that it will be useful,
|
14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
# GNU General Public License for more details.
|
17 |
|
|
#
|
18 |
|
|
# You should have received a copy of the GNU General Public License
|
19 |
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
|
|
#
|
21 |
|
|
# $Id$
|
22 |
|
|
#
|
23 |
|
|
###############################################################################
|
24 |
|
|
|
25 |
|
|
#
|
26 |
|
|
# Initialisation script to setup the environment variables for this branch
|
27 |
|
|
#
|
28 |
|
|
|
29 |
|
|
# Make sure it is sourced and no one accidentally gave the script execution rights and just executes it.
|
30 |
|
|
if [[ "$_" == "${0}" ]]; then
|
31 |
|
|
echo "ERROR: Use this command with '. ' or 'source '"
|
32 |
|
|
sleep 1
|
33 |
|
|
return
|
34 |
|
|
fi
|
35 |
|
|
|
36 |
|
|
# check for RADIOHDL_WORK variable , if it not exists:
|
37 |
|
|
# 1) run ". ./init_hdl.sh" in the hdl source dir instead.
|
38 |
|
|
# 2) or set variable manualy
|
39 |
|
|
|
40 |
|
|
if [[ -z "${RADIOHDL_WORK}" ]]; then
|
41 |
|
|
echo "environ variable 'RADIOHDL_WORK' not available"
|
42 |
|
|
echo "source 'init_hdl.sh' script in hdl directory instead of this one"
|
43 |
|
|
echo ". ./init_hdl.sh"
|
44 |
|
|
return
|
45 |
|
|
fi
|
46 |
|
|
|
47 |
|
|
# check if the needed environment variables are available
|
48 |
|
|
for var in "${ALTERA_DIR}" "${MENTOR_DIR}" "${MODELSIM_ALTERA_LIBS_DIR}"
|
49 |
|
|
do
|
50 |
|
|
if [[ -z "$var" ]]; then
|
51 |
|
|
echo "not all needed environ variables are available"
|
52 |
|
|
echo "one of: ALTERA_DIR, MENTOR_DIR, MODELSIM_ALTERA_LIBS_DIR is missing"
|
53 |
|
|
echo "they should be in your bashrc file pointing to the software install dirs"
|
54 |
|
|
return
|
55 |
|
|
fi
|
56 |
|
|
done
|
57 |
|
|
|
58 |
|
|
echo "RadioHDL environment will be setup for" $RADIOHDL_WORK
|
59 |
|
|
|
60 |
|
|
# Figure out where this script is located and set environment variables accordingly
|
61 |
|
|
export RADIOHDL_GEAR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
62 |
|
|
#export RADIOHDL_GEAR=${RADIOHDL_GEAR}
|
63 |
|
|
# setup paths to build and config dir if not already defined by the user.
|
64 |
|
|
#export RADIOHDL_BUILD_DIR=${RADIOHDL_BUILD_DIR:-${RADIOHDL_WORK}/build}
|
65 |
|
|
export RADIOHDL_CONFIG=${RADIOHDL_CONFIG:-${RADIOHDL_GEAR}/config}
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
# Define function to add directories to a given environment variable
|
69 |
|
|
# args: name_of_env_var new_path [new_path ...]
|
70 |
|
|
# Directories are only added when they exist.
|
71 |
|
|
pathadd() {
|
72 |
|
|
for new_dir in ${@:2}
|
73 |
|
|
do
|
74 |
|
|
eval dir_to_add=`echo ${new_dir}`
|
75 |
|
|
if [ -d ${dir_to_add} ] && ! echo ${!1} | grep -E -q "(^|:)$dir_to_add($|:)" ; then
|
76 |
|
|
eval export ${1}=${1:+${!1#:}:}${dir_to_add}
|
77 |
|
|
fi
|
78 |
|
|
done
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
# Extend the PATH and PYTHONPATH variables
|
82 |
|
|
pathadd "PATH" ${RADIOHDL_GEAR}/quartus ${RADIOHDL_GEAR}/ise ${RADIOHDL_GEAR}/modelsim ${RADIOHDL_GEAR}/core
|
83 |
|
|
pathadd "PYTHONPATH" ${RADIOHDL_GEAR}/core ${RADIOHDL_GEAR}/components
|
84 |
|
|
|
85 |
|
|
unset user_components_file
|