-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.sh
356 lines (293 loc) · 7.34 KB
/
functions.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# MPlayer/FFmpeg MinGW-w64 Cross Build Environment
# Copyright (c) 2013-2018 Gianluigi Tiesi <[email protected]>
# See LICENSE for licensing informations
topdir=$(cd .. && pwd)
. $(dirname $0)/../../config.sh
# -Werror=implicit-function-declaration
# dangerous because of configure scripts
MBE_COMMON_FLAGS="-D__USE_MINGW_ANSI_STDIO=${__USE_MINGW_ANSI_STDIO:-0} \
-mno-ms-bitfields \
-Werror=format \
-Wno-maybe-uninitialized \
-Wno-error=nonnull \
-Wno-implicit-fallthrough -Wno-misleading-indentation \
-Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable -Wno-unused-parameter \
-Wno-attributes -Wno-unknown-pragmas -Wno-switch"
MBE_CFLAGS="${MBE_COMMON_FLAGS} ${MBE_CFLAGS} -Werror=pointer-to-int-cast -Werror=int-to-pointer-cast"
MBE_CXXFLAGS="${MBE_COMMON_FLAGS} ${MBE_CXXFLAGS}"
shopt -s nullglob
FILENAME=${PACKAGE}-${VERSION}.${EXT}
BUILDDIR=${PACKAGE}-${VERSION}
add_to_cflags()
{
MBE_CFLAGS="${MBE_CFLAGS} $1"
}
add_to_cxxflags()
{
MBE_CXXFLAGS="${MBE_CXXFLAGS} $1"
}
add_to_flags()
{
add_to_cflags $1
add_to_cxxflags $1
}
sanity_check()
{
for dir in bin include lib; do
if [ ! -d ${PREFIX}/$dir ]; then
echo "${PREFIX}/$dir is not a directory"
exit 1
fi
if [ ! -w ${PREFIX}/$dir ]; then
echo "${PREFIX}/$dir is not writable"
exit 1
fi
done
}
sanity_check
export_toolchain()
{
export AR=${CROSS_PREFIX}ar
export RANLIB=${CROSS_PREFIX}ranlib
export STRIP=${CROSS_PREFIX}strip
export CC=${CROSS_PREFIX}gcc
export CXX=${CROSS_PREFIX}g++
}
save_function()
{
local ORIG_FUNC=$(declare -f $1)
local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
eval "$NEWNAME_FUNC"
}
depends()
{
if [ ! -e "${PREFIX}/$1" ]; then
echo "Missing dependency $1"
exit 1
fi
}
pkg_download()
{
test -s ${FILENAME} || wget -c -O ${FILENAME} ${BASEURL}/${FILENAME} || ( rm -f ${FILENAME} ; return 1 )
}
pkg_unpack()
{
if [ -n "${GIT_REPO}" ]; then
test -n "${GIT_BRANCH}" && CLONE_ARGS="-b ${GIT_BRANCH}"
test -d ${BUILDDIR}/.git || ( git clone ${CLONE_ARGS} --recursive ${GIT_REPO} ${BUILDDIR} || return 1 )
return 0
fi
if [ -n "${HG_REPO}" ]; then
test -d ${BUILDDIR}/.hg || ( hg clone ${HG_REPO} ${BUILDDIR} || return 1 )
return 0
fi
if [ -n "${SVN_REPO}" ]; then
test -d ${BUILDDIR}/.svn || ( svn co ${SVN_REPO} ${BUILDDIR} || return 1 )
return 0
fi
test -z ${BASEURL} && return
test -d ${FILENAME} || pkg_download || return 1
case ${FILENAME} in
*.tar.xz)
decomp=J
;;
*.tar.bz2)
decomp=j
;;
*.tar.gz|*.tgz)
decomp=z
;;
esac
rm -fr ${BUILDDIR}
tar -$decomp -xf ${FILENAME}
}
is_cmake()
{
# [ -e CMakeLists.txt ]
[ -n "${CMAKE}" ]
}
pkg_configure_cmake()
{
mkdir cross_build
( cd cross_build && \
CFLAGS="${MBE_CFLAGS} ${CFLAGS}" \
CXXFLAGS="${MBE_CXXFLAGS} ${CXXFLAGS}" \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DCMAKE_TOOLCHAIN_FILE=$topdir/toolchain.cmake \
${CMAKEOPTS} ..
) || return 1
}
pkg_configure()
{
if is_cmake; then
pkg_configure_cmake
return $?
fi
test -n "${FORCE_AUTOGEN}" && rm -f configure
if [ ! -x configure ]; then
if [ -e configure.ac -o -e configure.in ]; then
autoreconf -fi || return 1
else
return 0
fi
fi
# load ac cache
if [ -z ${NOCACHE} ]; then
echo Loading ac cache
. ${topdir}/ac_cache.sh
fi
test -n "${C}" && CONFOPTS="-C ${CONFOPTS}"
CFLAGS="${MBE_CFLAGS} ${CFLAGS}" \
CXXFLAGS="${MBE_CXXFLAGS} ${CXXFLAGS}" \
./configure \
--host=${HOST} \
--prefix=${PREFIX} \
--enable-static \
--disable-shared \
${CONFOPTS} || return 1
}
pre_make_hook()
{
:
}
post_make_hook()
{
:
}
post_install_hook()
{
:
}
pkg_make_target()
{
pre_make_hook
is_cmake && cd cross_build
make ${MAKEOPTS} || return 1
post_make_hook
make ${INSTALL_TARGET:-install} || return 1
post_install_hook
}
apply_patches()
{
test -z "${NP}" || return 0
test -d ${BUILDDIR} || return 0
for p in $(pwd)/patches/*; do
echo "- Appling $(basename $p)"
patch -d ${BUILDDIR} -p1 < $p || return 1
done
}
apply_install()
{
test -d ${BUILDDIR} || return 0
for f in $(pwd)/install/*; do
echo "- Installing $(basename $f)"
install -m644 $f ${BUILDDIR}/
done
}
print_file_name()
{
${CROSS_PREFIX}gcc -print-file-name=$1
}
cmd()
{
echo "- $*"
$*
}
gen_ld_script()
{
lib=${PREFIX}/lib/$1
lib_s="${1:3:-2}_s"
echo "Generating linker script $lib: $2"
mv -f $lib ${PREFIX}/lib/lib$lib_s.a
echo "GROUP ( -l$lib_s $2 )" > $lib
}
make_ld_script()
{
eval $(grep dependency_libs= $1)
eval $(grep old_library= $1)
libname="${old_library:3:-2}_s"
LIBS=""
for lib in $dependency_libs; do
case $lib in
-L*) ;;
-lm) ;;
-lc) ;;
*.la)
lib=$(basename $lib .la)
LIBS="${LIBS} -l${lib:3}"
;;
-l*) LIBS="${LIBS} $lib" ;;
esac
done
test -z "${LIBS}" && return
echo "GROUP ( -l${libname}${LIBS} )"
}
fix_la()
{
test -z "${STATICLIBS}" && return
for lib in ${STATICLIBS}; do
lib_a=${PREFIX}/lib/${lib}.a
lib_s=${PREFIX}/lib/${lib}_s.a
lib_la=${PREFIX}/lib/${lib}.la
test -e $lib_la || continue
echo "Fixing static lib $lib..."
rm -f $lib_s
LDSCRIPT=$(make_ld_script $lib_la)
rm -f $lib_la
test -e $lib_a || continue
test -z "${LDSCRIPT}" && continue
mv -f $lib_a $lib_s
echo ${LDSCRIPT} > $lib_a
done
}
ln_to_cp()
{
# ln -s -> cp -f
find . -type f -name Makefile -exec sed -i -e 's/ln -s/cp -f/g' {} \;
}
pkg_build()
{
pkg_unpack || return 1
apply_patches || return 1
apply_install || return 1
( cd ${BUILDDIR}/${BUILDSUBDIR} && pkg_configure ) || return 1
( cd ${BUILDDIR}/${BUILDSUBDIR} && ln_to_cp )
# stop here if C is set
test -n "${C}" && exit 0
( cd ${BUILDDIR}/${BUILDSUBDIR} && pkg_make_target ) || return 1
fix_la
}
git_clean()
{
test -d ${BUILDDIR} || return 0
( cd ${BUILDDIR} && git reset --hard && git clean -qdfx \
&& git submodule foreach git reset --hard \
&& git submodule foreach git clean -qdfx )
}
hg_clean()
{
test -d ${BUILDDIR} || return 0
( cd ${BUILDDIR} && hg update --clean && hg purge )
}
svn_clean()
{
test -d ${BUILDDIR} || return 0
( svn revert -R ${BUILDDIR} )
}
cmake_clean()
{
test -d ${BUILDDIR} || return 0
( cd ${BUILDDIR} && rm -fr cross_build )
}
distclean()
{
test -d ${BUILDDIR} || return 0
( cd ${BUILDDIR} && ( make distclean > /dev/null 2>&1 || true ) )
}
pkg_clean()
{
rm -fr ${BUILDDIR}
}