forked from part-cw/lambdanative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.sh
272 lines (258 loc) · 6.2 KB
/
package.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# procedures to handle download and compilation of packages
tmp_install=$SYS_TMPDIR/tmp_install
package_from_source()
{
pkg_here=`pwd`
if [ -d $tmp_install ]; then
rm -rf $tmp_install
fi
mkdir $tmp_install
for files in $@; do
cp $files $tmp_install
done
cd $tmp_install
}
package_copy_to_cache()
{
rmifexists $1
mkdir -p $1
cp -R ./* $1
}
package_valid()
{
pkg_valid_file="$1"
pkg_valid_hash=$2
pkg_valid=no
if [ -f $pkg ]; then
if [ $SYS_HOSTPLATFORM = openbsd ]; then
if [ `sha1 -q $pkg_valid_file` = "$pkg_valid_hash" ]; then
pkg_valid=yes
fi
else
if [ `shasum $pkg_valid_file | cut -f 1 -d " "` = "$pkg_valid_hash" ]; then
pkg_valid=yes
fi
fi
fi
echo $pkg_valid
}
package_unpack()
{
pkg_unpack_file=$1
echo " => extracting $pkg_unpack_file.."
pkg_unpack_extension=`echo "${pkg_unpack_file}" | sed 's/.*\.//'`
case $pkg_unpack_extension in
zip)
asserttool unzip
unzip -qq $pkg_unpack_file
;;
tar)
asserttool tar
tar xf $pkg_unpack_file
;;
gz|tgz)
asserttool tar
tar zxf $pkg_unpack_file
;;
bz|bz2)
asserttool tar
tar jxf $pkg_unpack_file
;;
lz)
asserttool lzip
lzip -dc $pkg_unpack_file | tar xf -
;;
xz|txz)
asserttool tar
tar Jxf $pkg_unpack_file
;;
*)
assert "UNKNOWN package format $1"
;;
esac
}
package_patch()
{
echo " => patching source..."
pkg_patches=`ls -1 ../*.patch 2> /dev/null`
for p in $pkg_patches; do
if [ ! "X$p" = "X" ] && [ -f $p ]; then
echo " => applying patches from $p"
veval "patch -p0 --ignore-whitespace < $p"
asserterror $? "patching failed"
fi
done
}
package_download_git()
{
if [ $SYS_HOSTPLATFORM = win32 ]; then
pkg_git_url=`echo "$1" | sed 's/^git:/http:/'`
else
pkg_git_url=$1
fi
pkg_git_hash=$2
pkg_git_branch=$3
if [ ! "X$pkg_git_branch" = "X" ]; then
pkg_git_branch="-b $pkg_git_branch"
fi
pkg_git_file="$SYS_PREFIXROOT/packages/"`basename $pkg_git_url`"-$pkg_git_hash.tgz"
if [ -d $tmp_install ]; then
rm -rf $tmp_install
fi
mkdir $tmp_install
assertfile $tmp_install
pkg_here=`pwd`
cd $tmp_install
if [ ! -f $pkg_git_file ]; then
echo " => cloning ${pkg_git_url}.."
veval "git clone $pkg_git_branch $pkg_git_url"
asserterror $? "repository cloning failed [$pkg_git_url]"
cd *
if [ ! "X$pkg_git_hash" = "X" ]; then
veval "git checkout $pkg_git_hash"
asserterror $? "repository checkout failed [$pkg_git_url]"
else
echo " == "`git log | head -n 1`
fi
git submodule init && git submodule update
cd ..
veval "tar -zcvf $pkg_git_file *"
assertfile "$pkg_git_file"
cd *
else
assertfile "$pkg_git_file"
package_unpack "$pkg_git_file"
asserterror $? "package extraction failed [$pkg_git_file]"
cd *
fi
cp $pkg_here/*.patch $tmp_install 2> /dev/null
}
package_download_ball()
{
pkg_url=$1
pkg_hash=$2
pkg=$SYS_PREFIXROOT/packages/`basename $pkg_url`
if [ $SYS_HOSTPLATFORM = openbsd ]; then
asserttool sha1
else
asserttool shasum
fi
if [ `package_valid "$pkg" $pkg_hash` = no ]; then
echo " => downloading ${pkg_url}.."
rmifexists $pkg
asserttool wget
wget_quiet=-q
if [ ! "X$SYS_VERBOSE" = "X" ]; then
wget_quiet=
fi
wget $pkg_url $wget_quiet -O $pkg
if [ ! $? = 0 ]; then
echo "WARNING: wget failed, retrying without certificate check.."
rmifexists $pkg
wget $pkg_url $wget_quiet --no-check-certificate -O $pkg
fi
asserterror $? "download of $pkg_url failed"
if [ $SYS_HOSTPLATFORM = openbsd ]; then
echo " == hash "`sha1 -q $pkg`
else
echo " == hash "`shasum $pkg | cut -f 1 -d " "`
fi
if [ `package_valid "$pkg" $pkg_hash` = no ]; then
rmifexists $pkg
assert "Unable to proceed! package download failed (checksum error)"
fi
fi
assertfile $pkg
if [ -d $tmp_install ]; then
rm -rf $tmp_install
fi
mkdir $tmp_install
assertfile $tmp_install
pkg_here=`pwd`
cd $tmp_install
package_unpack $pkg
asserterror $? "package extraction failed [$pkg]"
cd *
cp $pkg_here/*.patch $tmp_install 2> /dev/null
}
package_download()
{
pkg_dnl_hdr=`echo "$1" | cut -f 1 -d ":"`
pkg_dnl_ext=`echo "$1" | sed 's/.*\.//'`
case $pkg_dnl_ext in
git)
package_download_git $@
;;
*)
case $pkg_dnl_hdr in
git)
package_download_git $@
;;
*)
package_download_ball $@
;;
esac
;;
esac
}
package_configure()
{
echo " => configuring source.."
pkg_conf_opt=$@
pkg_ccdir=`echo "$SYS_CC" | cut -f 1 -d " "`
pkg_ccdir=`dirname ${pkg_ccdir}`
veval "\
CHOST=$SYS_ARCH \
PKG_CONFIG_PATH=$SYS_PREFIX/lib/pkgconfig \
PATH=\"$SYS_PREFIX/bin:${pkg_ccdir}:$PATH\" \
LDFLAGS=-L$SYS_PREFIX/lib \
LD_LIBRARY_PATH=$SYS_PREFIX/lib \
CPPFLAGS=-I$SYS_PREFIX/include \
CC=\"$SYS_CC -I$SYS_PREFIX/include -L$SYS_PREFIX/lib\" \
AR=\"$SYS_AR\" \
RANLIB=\"$SYS_RANLIB\" \
NM=\"$SYS_NM\" \
LD=\"$SYS_LD\" \
AS=\"$SYS_AS\" \
CPP=\"$SYS_CPP\" \
OBJCOPY=\"$SYS_OBJCOPY\" \
STRIP=\"$SYS_STRIP\" \
GPROF=\"$SYS_GPROF\" \
READELF=\"$SYS_READELF\" \
OBJDUMP=\"$SYS_OBJDUMP\" \
./configure --prefix=$SYS_PREFIX $pkg_conf_opt "
asserterror $? "configure failed"
}
package_make()
{
pkg_make=make
if [ ! "X"`which gmake 2> /dev/null` = "X" ]; then
vecho " == found gmake, using instead of make"
pkg_make="gmake -j 9"
fi
pkg_make_opt=$@
pkg_ccdir=`echo "$SYS_CC" | cut -f 1 -d " "`
pkg_ccdir=`dirname ${pkg_ccdir}`
echo " => compiling source.."
veval "\
CHOST=$SYS_ARCH \
PKG_CONFIG_PATH=$SYS_PREFIX/lib/pkgconfig \
PATH=\"$SYS_PREFIX/bin:${pkg_ccdir}:$PATH\" \
LDFLAGS=-L$SYS_PREFIX/lib \
LD_LIBRARY_PATH=$SYS_PREFIX/lib \
CPPFLAGS=-I$SYS_PREFIX/include \
CC=\"$SYS_CC -I$SYS_PREFIX/include -L$SYS_PREFIX/lib\" \
AR=$SYS_AR \
RANLIB=$SYS_RANLIB \
$pkg_make $pkg_make_opt"
asserterror $? "$pkg_make failed"
}
package_cleanup()
{
echo " => cleaning up.."
cd $pkg_here
if [ -d $tmp_install ]; then
rm -rf $tmp_install
fi
}
#eof