-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.functions
196 lines (160 loc) · 4.2 KB
/
build.functions
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
#==================== put your favorites functions there ===============================
function wait_or_break
{
echo -n "
<press enter to retry, or ctrl+c to exit>
> "
read
clear
}
function arg_parse
#-----------------
{
echo
echo "[ $0 ] accepts config for :"
echo "--------------------------------------"
python3.7 <<END
import sys,os
with open("$0.conf","w") as conf:
envkeys = list( os.environ.keys() )
envkeys.sort()
for kw in envkeys:
if kw.startswith('DEFAULT_'):
var = kw[8:]
info = f'\t{var}={os.getenv(var)}, default is "{os.getenv(kw)}"'
#print(info)
print(f"export {var}=\${{var:-\${kw}}}", file=conf)
END
. $0.conf
for cnf in $(env|grep ^DEFAULT_ | cut -f1 -d= | cut -c9-| sort)
do
echo " " $(env |grep ^$cnf=)
done
echo
}
function set_source_tree
{
export ROOT=$(dirname $(realpath "$0") )
cd $ROOT
echo "
Setting source tree in [$ROOT] for [$SRC]"
while true
do
[ -d $SRC ] && break
cd $ARCHIVES
IS_XZ=false
IS_ZIP=false
IS_GZ=false
if echo "$SRC_URL"|grep -q xz$
then
IS_XZ=true
EXT="tar.xz"
fi
if echo "$SRC_URL"|grep -q zip$
then
IS_ZIP=true
EXT="zip"
fi
if echo "$SRC_URL"|grep -q gz$
then
IS_GZ=true
EXT="tar.gz"
fi
corrupt=true
ARCHIVE="${ARCHIVES}/${SRC}.${EXT}"
if md5sum -c ${ARCHIVE}.md5 2>/dev/null
then
echo " * Archive $ARCHIVE.md5 validated"
else
echo " * Can't validate archive with $ARCHIVE.md5"
echo " * Getting source code from [$SRC_URL] into cache folder [$ARCHIVE]"
wget $SRC_URL -O$ARCHIVE
fi
cd $ROOT
if $IS_XZ
then
if tar xvf $ARCHIVE | pv -w 60 -p -l -s $1 >/dev/null
then
md5sum $ARCHIVE > $ARCHIVE.md5
corrupt=false
break
fi
fi
if $IS_ZIP
then
if unzip $ARCHIVE | pv -w 60 -p -l -s $1 >/dev/null
then
md5sum $ARCHIVE > $ARCHIVE.md5
corrupt=false
break
fi
fi
if $IS_GZ
then
if tar xvfz $ARCHIVE | pv -w 60 -p -l -s $1 >/dev/null
then
md5sum $ARCHIVE > $ARCHIVE.md5
corrupt=false
break
fi
fi
if $corrupt
then
echo "is $ARCHIVE corrupted ?"
wait_or_break
fi
done
#export ROOT=$ROOT
export SRC=$SRC
export ORIGIN=$ROOT/$SRC
cd $ORIGIN
}
function register_pdk
{
if echo $1 | grep -q PDK_
then
echo export $1="$2"
touch $SDK/built.${BITS}.env
grep -v $1 $SDK/built.${BITS}.env > $SDK/built.new
echo export $1="$2" >> $SDK/built.new
mv -v $SDK/built.${BITS}.env $SDK/built.${BITS}.bak
sort $SDK/built.new | uniq > $SDK/built.${BITS}.env
rm -vf $SDK/built.new
echo " * Package $1 added to sdk.env, you may want to reload"
else
echo "usage: register_pdk PDK_key value"
fi
}
function patch_me
{
echo "
Patching source tree if required"
if [ -f "$ORIGIN/PDK_PATCHED" ]
then
echo " * All Patches already applied"
else
cd $ROOT/$SRC
if [ -f $ROOT/$SRC.patchset/overlay.tar.bz2 ]
then
echo " * Applying overlay [$ORIGIN.patchset/overlay.tar.bz2]"
echo -n " Overwritten files : "
/bin/tar xvpjf $ROOT/$SRC.patchset/overlay.tar.bz2 | wc -l
else
echo " * no overlay [$ORIGIN.patchset/overlay.tar.bz2] found to apply"
fi
if find $ORIGIN.patchset/ |grep -q diff$
then
for patch in $(find $ROOT/$SRC.patchset/*.diff)
do
echo -n "
Applying patch : $patch "
patch -p1 < $patch
echo
done
else
echo " * no patch to apply"
fi
touch PDK_PATCHED
fi
}