forked from foss-for-synopsys-dwc-arc-processors/toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharc-versions.sh
executable file
·180 lines (148 loc) · 5.13 KB
/
arc-versions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env bash
# Script to specify versions of tools to use.
# Copyright (C) 2012-2016 Synopsys Inc.
# Contributor Jeremy Bennett <[email protected]>
# Contributor Anton Kolesov <[email protected]>
# This script is sourced to specify the versions of tools to be built.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
# 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, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
# Usage:
# arc-versions.sh [--auto-checkout | --no-auto-checkout]
# [--auto-pull | --no-auto-pull]
# [--uclibc | --no-uclibc]
# The environment variable ${ARC_GNU} should point to the directory within
# which the GIT trees live.
# The environment variable ${LINUXDIR} should point to the Linux root
# directory (only used if --uclibc is set).
# We checkout the desired branch for each tool. Note that these must exist or
# we fail.
# Default options
autocheckout="--auto-checkout"
autopull="--auto-pull"
uclibc_arg="--uclibc"
# Parse options
until
opt=$1
case ${opt} in
--auto-checkout | --no-auto-checkout)
autocheckout=$1
;;
--auto-pull | --no-auto-pull)
autopull=$1
;;
--uclibc | --no-uclibc)
uclibc_arg=$1
;;
?*)
echo "Usage: arc-versions.sh [--auto-checkout | --no-auto-checkout]"
echo " [--auto-pull | --no-auto-pull]"
echo " [--uclibc | --no-uclibc]"
exit 1
;;
*)
;;
esac
[ "x${opt}" = "x" ]
do
shift
done
# That should be a separate variable to allow for a straightforward creation of
# new releases, where we want default to point to release, instead of dev
# branch.
default_toolchain_config=arc-2016.03-em
# Specify the default versions to use as a string <tool>:<branch>. Those are
# taken from the checkout configuration file. Only actually matters if
# --auto-checkout is set.
if [ -z "$CHECKOUT_CONFIG" ]
then
CHECKOUT_CONFIG=$default_toolchain_config
fi
if echo "$CHECKOUT_CONFIG" | grep -qFe /
then
# This is file path
source "$CHECKOUT_CONFIG"
else
# This is configuration name
source "$ARC_GNU/toolchain/config/$CHECKOUT_CONFIG.sh"
fi
# Disable linux if needed
if [ "x${uclibc_arg}" != "x--uclibc" ]
then
linux=""
fi
# It is not safe to "pull" in the initial state, because if repository is
# currently in detached state (e.g. on a tag), then pull will fail. It is also
# not safe to checkout before fetching data, because it might be required to
# checkout branch/tag that hasn't been fetched from remote yet. Thus the
# sequence of actions is following:
# 1. Fetch
# 2. Checkout the branch/tag
# 3. Pull unless we are in a detached HEAD state.
# Steps 1 and 3 are only used if we have --auto-pull enabled.
# Step 2 is only used if we have --auto-checkout enabled.
# All this will go horribly wrong if you leave uncommitted changes lying
# around or if you change the remote. Nothing then but to sort it out by hand!
for version in ${cgen} ${binutils} ${gcc} ${gdb} ${newlib} ${uclibc} ${linux}
do
tool=`echo ${version} | cut -d ':' -f 1`
branch=`echo ${version} | cut -d ':' -f 2`
echo "Checking out branch/tag ${branch} of ${tool}"
# Kludge, because Linux has its own environment variable. Note that the
# tool can only "linux" if --uclibc is set above.
if [ "${tool}" = "linux" ]
then
cd ${LINUXDIR}
else
cd ${ARC_GNU}/${tool}
fi
if [ "x${autopull}" = "x--auto-pull" ]
then
# Fetch any new tags and branches.
# Note the usage of --all. Without this option and without explicit
# remote name `git fetch` will succeed only if there is remote named
# "origin", and it will fetch only it (which might be really not what
# is desired). And if there is no remote named "origin" then `git
# fetch` will fail even if there is only a single remote in git
# configuration.
echo " fetching tags"
if ! git fetch --tags --all
then
exit 1
fi
fi
if [ "x${autocheckout}" = "x--auto-checkout" ]
then
echo " checking out ${branch}"
if ! git checkout ${branch}
then
exit 1
fi
fi
if [ "x${autopull}" = "x--auto-pull" ]
then
# Only update to latest if we are not in detached HEAD mode.
# If tree is in detahed state, output differs between Git versions:
# Git >=2.4 prints: *(HEAD detached at <tag_name>)
# Git 1.8-2.3 prints: * (detached from <tag_name>)
# Git <1.8 prints: * (no branch)
if ! git branch | grep -q -e '\* (HEAD detached at .*)' \
-e '\* (detached from .*)' -e '\* (no branch)'
then
echo " pulling latest version"
if ! git pull
then
exit 1
fi
fi
fi
done
# vim: noexpandtab sts=4 ts=8: