/
build-all
executable file
·134 lines (114 loc) · 3.21 KB
/
build-all
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
#! /bin/bash
set -e
set +h
JUST_TESTING=0
while getopts "s:e:n" OPT ; do
case "$OPT" in
s) START="$OPTARG";;
e) END="$OPTARG";;
n) JUST_TESTING=1;;
?) echo "Unknown options; exiting" ; exit 3;;
esac
done
if [ -z $START ] ; then
echo
echo " Usage: $0 -s <start-section> -e <end-section>"
echo
exit 1
fi
if [ -z $END ] ; then
echo
echo " Usage: $0 -s <start-section> -e <end-section>"
echo
END=$START
fi
echo "Building [$START, $END] (inclusive; testing? $JUST_TESTING)..."
HAS_STARTED=0
STARTING_CHAPTER=5
START_PHASE=$(echo $START | cut -d '.' -f 1)
START_NUM=$( echo $START | cut -d '.' -f 2)
END_PHASE=$( echo $END | cut -d '.' -f 1)
END_NUM=$( echo $END | cut -d '.' -f 2)
IN_END_PHASE=0
#echo " start-phase: $START_PHASE"
#echo " start-num: $START_NUM"
#echo " end-phase: $END_PHASE"
#echo " end-num: $END_NUM"
for PHASE in $(seq $STARTING_CHAPTER 9) b0 b1 b2 ; do
if [ 0 -eq $HAS_STARTED ] ; then
if [ $PHASE != $START_PHASE ] ; then
echo "(skipping phase $PHASE)"
continue
fi
fi
# Terminate properly.
if [ 1 -eq $IN_END_PHASE ] ; then
if [ $PHASE != $END_PHASE ] ; then exit ; fi
fi
if [ $PHASE = $END_PHASE ] ; then IN_END_PHASE=1 ; fi
# At this point, the phase matches (e.g., 6.xy or 7.nm).
for SCRIPT_INDEX in $(seq 0 99) ; do
# Doing the check isolates the check; otherwise, has to be done in multiple places.
#echo "==== SCRIPT_NUM: $SCRIPT_NUM ===="
#echo "---- END_NUM: $END_NUM ===="
# Logic:
# if ( hasn't-started ), then skip if phase doesn't match.
# else, if phase matches, set (has-started = TRUE).
# if ( has-started ),
# if ( phase == end-phase )
# if ( SCRIPT_NUM > END_NUM ), then EXIT,
# Run script.
SCRIPT_NUM=$SCRIPT_INDEX
if [ 10 -gt $SCRIPT_NUM ] ; then SCRIPT_NUM="0${SCRIPT_INDEX}" ; fi
CURRENT="${PHASE}.${SCRIPT_NUM}"
if [ 0 -eq $HAS_STARTED ] ; then
#echo "At start? Current: $CURRENT, Start: $START"
if [ $CURRENT = $START ] ; then
#echo " (starting at $CURRENT)"
HAS_STARTED=1
else
continue
#echo " (skipping current $CURRENT)"
fi
echo ">>> Started."
fi
if [ 1 -eq $HAS_STARTED ] ; then
#echo " ( phase: $PHASE)"
#echo " (end-phase: $END_PHASE)"
if [ $PHASE = $END_PHASE ] ; then
if [ "$SCRIPT_INDEX" -gt "$END_NUM" ] ; then
#echo "Reached END."
exit
fi
fi
fi
SCRIPT=$(echo ${CURRENT}*)
SCRIPT_GUARD=".guard-${SCRIPT}"
if [ ! -e $SCRIPT ] ; then continue ; fi
if [ 1 -eq $JUST_TESTING ] ; then
rm -f $SCRIPT_GUARD
touch $SCRIPT_GUARD
date '+%s' > $SCRIPT_GUARD # Write to file.
date '+%s' >> $SCRIPT_GUARD # Append to file.
else
if [ -f $SCRIPT_GUARD ] ; then
SCRIPT_GUARD_LINE_COUNT=$(wc -l $SCRIPT_GUARD | cut -d ' ' -f 1)
if [ 2 -le $SCRIPT_GUARD_LINE_COUNT ] ; then
echo " Skipping $SCRIPT (already built)."
continue
else
rm -f $SCRIPT_GUARD
touch $SCRIPT_GUARD
fi
fi
#if [ -z "${MAKEFLAGS}" ] ; then
#echo " Building $SCRIPT (no MAKEFLAGS)..."
#else
#echo " Building $SCRIPT (MAKEFLAGS: ${MAKEFLAGS})..."
#fi
date '+%s' > $SCRIPT_GUARD # Write to file.
time ./build $SCRIPT
date '+%s' >> $SCRIPT_GUARD # Append to file.
fi
done
done