-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·359 lines (307 loc) · 11.5 KB
/
build.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
357
358
359
#!/bin/sh
#
# Build script for DracoLinux
# (c) 2008-2012 Ole Andre Rodlie <[email protected]>
#
set +e
OPT=$1
CWD=$(pwd)
DATE="`date +%Y%m%d`"
TAR="/bin/tar"
GET="/bin/ftp"
RUN="."
PATCH="/usr/bin/patch"
AUTOCONF="/usr/bin/autoconf"
DRACOSRC_DIR=$(cd ../../;pwd)
if [ ! -f ${DRACOSRC_DIR}/build.sh ]; then
echo
echo "=> Not part of the build tree"
echo
exit 1
fi
MAKEPKG="sh ${DRACOSRC_DIR}/common/pkgtools/makepkg"
EXPLODEPKG="sh ${DRACOSRC_DIR}/common/pkgtools/explodepkg"
UPGRADEPKG="sh ${DRACOSRC_DIR}/common/pkgtools/upgradepkg"
REMOVEPKG="sh ${DRACOSRC_DIR}/common/pkgtools/removepkg"
DRACOSRC_ZIP=txz
DRACOSRC_TAG=
DRACOSRC_KERNEL=$(uname -r)
DRACOSRC_PROBE_ARCH=$(uname -m)
DRACOSRC_LOG=/var/log/packages
DRACOSRC_CACHE="${DRACOSRC_DIR}/source"
DRACOSRC_PACKAGES="${DRACOSRC_DIR}/packages"
DRACOSRC_PKG_SRC_DIR=${CWD}
DRACOSRC_PKG_WORK="${DRACOSRC_PKG_SRC_DIR}/work"
DRACOSRC_PKG="${DRACOSRC_PKG_WORK}/output"
DRACOSRC_FAIL="FAILED (work/log for more info)"
DRACOSRC_PKG_LOG="${DRACOSRC_PKG_WORK}/log"
if [ "${DRACOSRC_PROBE_ARCH}" = "i486" ]; then
DRACOSRC_ARCH=i486
elif [ "${DRACOSRC_PROBE_ARCH}" = "i586" ]; then
DRACOSRC_ARCH=i486
elif [ "${DRACOSRC_PROBE_ARCH}" = "i686" ]; then
DRACOSRC_ARCH=i486
elif [ "${DRACOSRC_PROBE_ARCH}" = "x86_64" ]; then
DRACOSRC_ARCH=x86_64
fi
if [ ! "${DRACOSRC_ARCH}" ]; then
echo
echo "=> CPU not supported"
echo
exit 1
else
echo "=> Building for ${DRACOSRC_ARCH}"
fi
if [ "${DRACOSRC_ARCH}" = "i486" ]; then
DRACOSRC_FLAGS="-O2 -pipe -march=i486 -mtune=i686"
elif [ "${DRACOSRC_ARCH}" = "x86_64" ]; then
DRACOSRC_FLAGS="-O2 -fPIC"
fi
DRACOSRC_PKG_DIFF_DIR=diff
DRACOSRC_PKG_BUILD_SCRIPT=Build
DRACOSRC_PKG_PATCH_SCRIPT=Patch
DRACOSRC_PKG_PRECONF_SCRIPT=PreConf
DRACOSRC_PKG_CUSTOM_SCRIPT=Custom
DRACOSRC_PKG_MAKE_SCRIPT=Make
DRACOSRC_PKG_EXTRA_SCRIPT=Extra
DRACOSRC_PKG_INSTALL_SCRIPT=Install
if [ ! -f ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_BUILD_SCRIPT} ]; then
echo
echo "=> Build file not found"
echo
exit 1
fi
echo -n "=> Executing Build file ... "
${RUN} ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_BUILD_SCRIPT} || exit 1
echo "OK"
DRACOSRC_PKG_BUILD=${DRACOSRC_TAG}${DRACOSRC_PKG_BUILD}
echo "=> ${DRACOSRC_PKG_NAME} ${DRACOSRC_PKG_VERSION} ${DRACOSRC_PKG_BUILD}"
if [ "${OPT}" = "deinstall" ]; then
${RUN} ${REMOVEPKG} ${DRACOSRC_PKG_NAME}
exit 1
fi
if [ -d ${DRACOSRC_PKG_WORK} ]; then
echo -n "=> Removing work directory ... "
rm -rf ${DRACOSRC_PKG_WORK}
echo "OK"
else
mkdir -p ${DRACOSRC_PKG_WORK}
fi
if [ "${OPT}" = "check" ]; then
if [ ! -f "${DRACOSRC_LOG}/${DRACOSRC_PKG_NAME}-${DRACOSRC_PKG_VERSION}-${DRACOSRC_ARCH}-${DRACOSRC_PKG_BUILD}" ]; then
echo "PACKAGE ${DRACOSRC_PKG_NAME} IS OUT OF SYNC, PLEASE REVIEW!"
fi
if [ ! -f "$DRACOSRC_PACKAGES/$DRACOSRC_PKG_NAME-$DRACOSRC_PKG_VERSION-$DRACOSRC_ARCH-$DRACOSRC_PKG_BUILD.$DRACOSRC_ZIP" ]; then
echo "PACKAGE $DRACOSRC_PKG_NAME DOES NOT EXISTS, PLEASE BUILD!"
fi
exit 1
fi
if [ ! -d ${DRACOSRC_PKG} ]; then
mkdir -p ${DRACOSRC_PKG}
fi
echo "* ${DRACOSRC_PKG_NAME} ${DRACOSRC_PKG_VERSION}-${DRACOSRC_PKG_BUILD} build started : "$(date)"" >> $DRACOSRC_PKG_LOG
if [ "${OPT}" != "fetch" ]; then
if [ -f ${DRACOSRC_PKG_SRC_DIR}/Override ]; then
echo -n "=> Running override ... "
${RUN} ${DRACOSRC_PKG_SRC_DIR}/Override 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
fi
if [ -f ${DRACOSRC_PKG_SRC_DIR}/framework.tar.gz ]; then
echo -n "=> Extracting framework ... "
( cd $DRACOSRC_PKG ; ${EXPLODEPKG} ${DRACOSRC_PKG_SRC_DIR}/framework.tar.gz 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; } )
echo "OK"
fi
fi
if [ ! "${DRACOSRC_NOSOURCE}" ]; then
if [ "${DRACOSRC_PKG_ALT_NAME}" ]; then
DRACOSRC_PKG_DWN=${DRACOSRC_PKG_ALT_NAME}
else
DRACOSRC_PKG_DWN="${DRACOSRC_PKG_NAME}-"
fi
if [ "${DRACOSRC_PKG_ALT_VERSION}" ]; then
DRACOSRC_PKG_DWN_VERSION=${DRACOSRC_PKG_ALT_VERSION}
else
DRACOSRC_PKG_DWN_VERSION=${DRACOSRC_PKG_VERSION}
fi
DRACOSRC_PKG_SRC_FILE=${DRACOSRC_PKG_DWN}${DRACOSRC_PKG_DWN_VERSION}.tar.xz
if [ ! -f ${DRACOSRC_CACHE}/${DRACOSRC_PKG_SRC_FILE} ]; then
echo -n "=> Source not available. "
exit 1
fi
EXTRACT="${TAR} xfJ"
echo -n "=> Extracting source ... "
${EXTRACT} ${DRACOSRC_CACHE}/${DRACOSRC_PKG_SRC_FILE} -C ${DRACOSRC_PKG_WORK} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
if [ "${DRACOSRC_PKG_ALT_PKG_SRC}" ]; then
DRACOSRC_PKG_SRC=${DRACOSRC_PKG_WORK}/${DRACOSRC_PKG_ALT_PKG_SRC}
else
DRACOSRC_PKG_SRC=${DRACOSRC_PKG_WORK}/${DRACOSRC_PKG_DWN}${DRACOSRC_PKG_DWN_VERSION}
fi
cd ${DRACOSRC_PKG_SRC} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
if [ -f ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_PATCH_SCRIPT} ]; then
echo -n "=> Executing Patch file ... "
${RUN} ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_PATCH_SCRIPT} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
fi
if [ "${DRACOSRC_PKG_ALT_DIFF_PATH}" ]; then
DRACOSRC_PKG_DIFF_PATH=${DRACOSRC_PKG_ALT_DIFF_PATH}
else
DRACOSRC_PKG_DIFF_PATH=${DRACOSRC_PKG_SRC_DIR}
fi
if [ -a $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR} ]; then
echo -n "=> Patching ... "
if [ -a $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/2 ]; then
for i in `ls $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/2`; do
${PATCH} -p2 -l < $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/2/$i 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
done
fi
if [ -a $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/1 ]; then
for i in `ls $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/1`; do
${PATCH} -p1 -l < $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/1/$i 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
done
fi
if [ -a $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/0 ]; then
for i in `ls $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/0`; do
${PATCH} -p0 -l < $DRACOSRC_PKG_DIFF_PATH/${DRACOSRC_PKG_DIFF_DIR}/0/$i 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
done
fi
echo "OK"
fi
if [ -f ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_PRECONF_SCRIPT} ]; then
echo -n "=> Executing PreConf file ... "
${RUN} ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_PRECONF_SCRIPT} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
fi
chown -R root:root .
find . \
\( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
-exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
-exec chmod 644 {} \;
if [ -f ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_CUSTOM_SCRIPT} ]; then
echo -n "=> Executing Custom file ... "
${RUN} ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_CUSTOM_SCRIPT} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
else
if [ "${DRACOSRC_PKG_USE_AUTOCONF}" ]; then
echo -n "=> Running autoconf ... "
${AUTOCONF} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
fi
echo -n "=> Configuring source ... "
CFLAGS="${DRACOSRC_FLAGS}" CXXFLAGS="${DRACOSRC_FLAGS}" ./configure ${DRACOSRC_PKG_CONFIGURE} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
if [ -f ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_MAKE_SCRIPT} ]; then
echo -n "=> Executing Make file ... "
${RUN} ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_MAKE_SCRIPT} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
else
echo -n "=> Compiling, please wait (tail -f work/log for more info) ... "
make -j4 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
echo -n "=> Installing ... "
make install DESTDIR=${DRACOSRC_PKG} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
fi
fi
fi
if [ -f ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_EXTRA_SCRIPT} ]; then
echo -n "=> Executing Extra file ... "
${RUN} ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_EXTRA_SCRIPT} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
echo "OK"
fi
if [ ! $DRACOSRC_NOSTRIP ]; then
echo -n "=> Stripping ... "
( cd ${DRACOSRC_PKG} ;
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
echo "OK"
fi
if [ -a $DRACOSRC_PKG/usr/info ]; then
( cd $DRACOSRC_PKG/usr/info ;
if [ -a dir ]; then
if [ ! "$DRACOSRC_PKG_NAME" = "texinfo" ]; then
rm dir
fi
fi
gzip -9 *
if [ -a dir.gz ]; then
gunzip dir.gz
fi
)
fi
if [ ! "$DRACOSRC_NOMANGZ" ]; then
if [ -a $DRACOSRC_PKG/usr/man ]; then
( cd $DRACOSRC_PKG/usr/man ;
for manpagedir in $(find . -type d -name "man*") ; do
( cd $manpagedir ;
for eachpage in $( find . -type l -maxdepth 1) ; do
ln -s $( readlink $eachpage ).gz $eachpage.gz
rm $eachpage
done
gzip -9 *.*
)
done
)
fi
fi
if [ -a $DRACOSRC_PKG/lib/modules ]; then
find $DRACOSRC_PKG/lib/modules -type f -name "*.ko" -exec gzip -9f {} \;
fi
( cd $DRACOSRC_PKG;
for svn in $(find . -type d -name ".svn" -maxdepth 50) ; do
rm -rf $svn
done
find . -type f -name "*~" -exec rm {} \;
)
mkdir -p $DRACOSRC_PKG/usr/doc/$DRACOSRC_PKG_NAME-$DRACOSRC_PKG_VERSION
( cd ${DRACOSRC_PKG_SRC} ; cp -a REL* COPY* AUTH* READ* Change* LIC* $DRACOSRC_PKG/usr/doc/$DRACOSRC_PKG_NAME-$DRACOSRC_PKG_VERSION/ 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} )
mkdir -p $DRACOSRC_PKG/install
cat >$DRACOSRC_PKG/install/slack-desc <<EOF
$DRACOSRC_PKG_NAME: ${DRACOSRC_PKG_NAME}
$DRACOSRC_PKG_NAME:
$DRACOSRC_PKG_NAME: ${DRACOSRC_PKG_DESC}
$DRACOSRC_PKG_NAME:
$DRACOSRC_PKG_NAME:
$DRACOSRC_PKG_NAME:
$DRACOSRC_PKG_NAME:
$DRACOSRC_PKG_NAME:
$DRACOSRC_PKG_NAME:
$DRACOSRC_PKG_NAME:
$DRACOSRC_PKG_NAME:
EOF
if [ -f ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_INSTALL_SCRIPT} ]; then
cat ${DRACOSRC_PKG_SRC_DIR}/${DRACOSRC_PKG_INSTALL_SCRIPT} > $DRACOSRC_PKG/install/doinst.sh || exit 1
fi
if [ "${DRACOSRC_NOPKG}" ]; then
exit 1
fi
if [ "${DRACOSRC_PKG_CAT}" ]; then
DRACOSRC_PACKAGES=${DRACOSRC_PACKAGES}/${DRACOSRC_PKG_CAT}
if [ ! -d $DRACOSRC_PACKAGES ]; then
mkdir -p $DRACOSRC_PACKAGES
fi
fi
DRACOSRC_PKG_TGZ=${DRACOSRC_PACKAGES}/${DRACOSRC_PKG_NAME}-${DRACOSRC_PKG_VERSION}-${DRACOSRC_ARCH}-${DRACOSRC_PKG_BUILD}.${DRACOSRC_ZIP}
( cd $DRACOSRC_PKG ;
echo -n "=> Creating package ... "
${MAKEPKG} -l y -c n ${DRACOSRC_PKG_TGZ} 2>>${DRACOSRC_PKG_LOG} 1>>${DRACOSRC_PKG_LOG} || { echo ${DRACOSRC_FAIL}; exit 1; }
#tree > $DRACOSRC_PKG_TGZ.manifest
echo "OK"
)
echo "* Build ended: "$(date)"" >> $DRACOSRC_PKG_LOG
#cat $DRACOSRC_PKG_LOG > $DRACOSRC_PKG_TGZ.build
#( cd $DRACOSRC_PACKAGES;
# DRACOSRC_PKGFILE=$DRACOSRC_PKG_NAME-$DRACOSRC_PKG_VERSION-$DRACOSRC_ARCH-$DRACOSRC_PKG_BUILD.$DRACOSRC_ZIP
# md5sum $DRACOSRC_PKGFILE > $DRACOSRC_PKGFILE.md5
# sha1sum $DRACOSRC_PKGFILE > $DRACOSRC_PKGFILE.sha1
# xz $DRACOSRC_PKGFILE.manifest
# xz $DRACOSRC_PKGFILE.build
#)
echo "=> Build done."
if [ "$1" == "install" ]; then
if [ -f $DRACOSRC_PKG_TGZ ]; then
${UPGRADEPKG} --install-new --reinstall $DRACOSRC_PKG_TGZ
fi
fi