blob: e0b46c429e322acb9ac439548bb72fa6f1953cc7 (
plain)
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
|
#!/bin/sh
# Rebuild FPGA bit files
# Copyright (c) 2010-2012 Michael Buesch <m@bues.ch>
# Licensed under the GNU/GPL v2+
basedir="$(dirname "$0")"
[ "$(echo -n "$basedir" | cut -c1)" = "/" ] || basedir="$PWD/$basedir"
srcdir="$basedir/src"
bindir="$basedir/bin"
die()
{
echo "$*" >&2
exit 1
}
terminate()
{
die "Interrupted."
}
trap terminate TERM INT
usage()
{
echo "Usage: build.sh [OPTIONS] [TARGETS]"
echo
echo "Options:"
echo " -h|--help Show this help text"
echo " -v|--verbose Verbose build"
echo
echo "Targets:"
echo "Specify the names of the targets to build, or leave blank to rebuild all."
}
# Parse commandline
verbose=0
targets="/"
while [ $# -gt 0 ]; do
[ "$1" = "-h" -o "$1" = "--help" ] && {
usage
exit 0
}
[ "$1" = "-v" -o "$1" = "--verbose" ] && {
verbose=1
shift
continue
}
target="$(basename "$1" .bit)"
# Add to list
targets="${targets}${target}/"
shift
done
[ "$targets" = "/" ] && targets=
bitparser()
{
python "$basedir/../bitfile.py" "$@" ||\
die "Failed to execute bitparser"
}
should_build() # $1=target
{
target="$1"
[ "$target" = "template" ] && return 1
[ -z "$targets" ] && return 0
echo "$targets" | grep -qe '/'"$target"'/'
}
# Check if the payload of two bitfiles matches
bitfile_is_equal() # $1=file1, $2=file2
{
[ -r $1 -a -r $2 ] || return 1
bitparser "$1" NOACTION # Test if bitparser works
sum1="$(bitparser "$1" GETPAYLOAD | sha1sum -b - | awk '{print $1;}')"
sum2="$(bitparser "$2" GETPAYLOAD | sha1sum -b - | awk '{print $1;}')"
[ "$sum1" = "$sum2" ]
}
# $1=src-directory
warning_filter()
{
local filterfile="$1/warning.filter"
local warn_regex='^WARNING'
[ -r "$filterfile" ] || {
# Show all warnings
grep -e "$warn_regex"
return 0
}
# Remove blacklisted warnings
local discard_regexes="$(cat "$filterfile")"
grep -e "$warn_regex" | while read line; do
local discard=
for discard_regex in $discard_regexes; do
echo "$line" | grep -qe "$discard_regex" && {
discard=1
break
}
done
[ -z "$discard" ] && echo "$line"
done
}
for src in $srcdir/*; do
[ -d "$src" ] || continue
srcname="$(basename $src)"
logfile="$basedir/$srcname.build.log"
should_build "$srcname" || continue
echo "Building $srcname..."
make -C "$src/" clean >/dev/null ||\
die "FAILED to clean $srcname."
if [ $verbose -eq 0 ]; then
make -C "$src/" all > "$logfile" || {
cat "$logfile"
die "FAILED to build $srcname."
}
cat "$logfile" | warning_filter "$src"
else
make -C "$src/" all ||\
die "FAILED to build $srcname."
fi
new="$src/$srcname.bit"
old="$bindir/$srcname.bit"
if bitfile_is_equal "$old" "$new"; then
echo "Bitfile for target $srcname did not change"
else
cp -f "$new" "$old"
fi
make -C "$src/" clean > /dev/null ||\
die "FAILED to clean $srcname."
rm -f "$logfile"
done
echo "Successfully built all images."
exit 0
|