Annotation of /trunk/mage/usr/lib/mage/smage2.sh
Parent Directory | Revision Log
Revision 477 -
(hide annotations)
(download)
(as text)
Mon Apr 23 16:41:44 2007 UTC (17 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 29277 byte(s)
Mon Apr 23 16:41:44 2007 UTC (17 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 29277 byte(s)
-only unset SPECIAL_VARS itself not the containing variables. Same goes for SPECIAL_FUNCTIONS
1 | niro | 24 | #!/bin/bash |
2 | |||
3 | # compiles/installs .smage2 source install scripts | ||
4 | # needs pkgbuild_dir (mage) | ||
5 | |||
6 | # SMAGE2 | ||
7 | niro | 477 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.57 2007-04-23 16:41:44 niro Exp $ |
8 | niro | 24 | |
9 | #01.10.2004 | ||
10 | # added ccache support | ||
11 | # added distcc support | ||
12 | |||
13 | niro | 419 | # set default user mage.rc |
14 | : ${MAGERC="/etc/mage.rc"} | ||
15 | |||
16 | niro | 24 | ## setup ## |
17 | PKGSUFFIX="mpk" | ||
18 | niro | 403 | SRCPKGSUFFIX="mpks" |
19 | niro | 24 | SMAGENAME="$1" |
20 | SMAGESUFFIX="smage2" | ||
21 | MLIBDIR=/usr/lib/mage | ||
22 | niro | 186 | SMAGEVERSION="$( < ${MLIBDIR}/version)" |
23 | niro | 24 | |
24 | niro | 351 | ## only for tests -> normally in /etc/rc.d/init.d/functions |
25 | COLRED="\033[1;6m\033[31m" | ||
26 | COLGREEN="\033[1;6m\033[32m" | ||
27 | COLYELLOW="\033[1;6m\033[33m" | ||
28 | COLBLUE="\033[1;6m\033[34m" | ||
29 | COLMAGENTA="\033[1;6m\033[35m" | ||
30 | COLWHITE="\033[1;6m\033[37m" | ||
31 | COLGRAY="\033[0;6m\033[37m" | ||
32 | COLBOLD="\033[1m" | ||
33 | COLDEFAULT="\033[0m" | ||
34 | |||
35 | if [[ ${NOCOLORS} = true ]] | ||
36 | then | ||
37 | COLRED="" | ||
38 | COLGREEN="" | ||
39 | COLYELLOW="" | ||
40 | COLBLUE="" | ||
41 | COLMAGENTA="" | ||
42 | COLWHITE="" | ||
43 | COLGRAY="" | ||
44 | COLBOLD="" | ||
45 | COLDEFAULT="" | ||
46 | fi | ||
47 | |||
48 | niro | 169 | # export default C locale |
49 | export LC_ALL=C | ||
50 | |||
51 | niro | 439 | source /etc/mage.rc.global |
52 | niro | 419 | source ${MAGERC} |
53 | niro | 24 | |
54 | niro | 347 | # set PKGDIR and BUILDDIR and BINDIR to MROOT |
55 | if [[ -n ${MROOT} ]] | ||
56 | then | ||
57 | export PKGDIR=${MROOT}/${PKGDIR} | ||
58 | export BUILDDIR=${MROOT}/${BUILDDIR} | ||
59 | export BINDIR=${MROOT}/${BINDIR} | ||
60 | fi | ||
61 | |||
62 | niro | 306 | showversion() |
63 | { | ||
64 | niro | 24 | echo -en "Magellan Source Install v${SMAGEVERSION} " |
65 | echo -e "-- Niels Rogalla (niro@magellan-linux.de)" | ||
66 | } | ||
67 | |||
68 | niro | 306 | die() |
69 | { | ||
70 | niro | 24 | xtitleclean |
71 | niro | 413 | echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT} |
72 | niro | 24 | echo "SMAGE failed: $@" |
73 | exit 1 | ||
74 | } | ||
75 | |||
76 | niro | 306 | xtitle() |
77 | { | ||
78 | if [[ ${TERM} = xterm ]] | ||
79 | niro | 24 | then |
80 | echo -ne "\033]0;[sMage: $@]\007" | ||
81 | fi | ||
82 | return 0 | ||
83 | } | ||
84 | |||
85 | niro | 306 | xtitleclean() |
86 | { | ||
87 | if [[ ${TERM} = xterm ]] | ||
88 | niro | 24 | then |
89 | echo -ne "\033]0;\007" | ||
90 | fi | ||
91 | return 0 | ||
92 | } | ||
93 | |||
94 | niro | 306 | syncsmage2() |
95 | { | ||
96 | niro | 24 | xtitle "Updating smage2-script tree ..." |
97 | local i | ||
98 | for i in ${SMAGE2RSYNC} | ||
99 | do | ||
100 | niro | 386 | rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR} |
101 | niro | 306 | if [[ $? = 0 ]] |
102 | niro | 24 | then |
103 | break | ||
104 | else | ||
105 | continue | ||
106 | fi | ||
107 | done | ||
108 | niro | 306 | |
109 | # clean up backup files (foo~) | ||
110 | niro | 24 | find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';' |
111 | niro | 306 | |
112 | niro | 24 | xtitleclean |
113 | } | ||
114 | |||
115 | niro | 59 | # $1 filename |
116 | niro | 306 | get_db_md5_sum() |
117 | { | ||
118 | niro | 59 | local DB_FILE |
119 | local MD5_FILE | ||
120 | local i | ||
121 | |||
122 | DB_ENTRY="$(basename $1)" | ||
123 | MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})" | ||
124 | |||
125 | i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)" | ||
126 | |||
127 | echo "${i}" | ||
128 | } | ||
129 | |||
130 | niro | 306 | download_sources() |
131 | { | ||
132 | niro | 59 | |
133 | niro | 61 | [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0 |
134 | niro | 59 | |
135 | local EOA=${#SRC_URI[*]} | ||
136 | niro | 66 | local my_SRC_URI |
137 | local my_SRC_URI_DEST | ||
138 | local my_SRC_URI_MIRROR | ||
139 | local my_SOURCEDIR | ||
140 | niro | 59 | local DB_MD5_SUM_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" |
141 | local FETCHING | ||
142 | local i mirror | ||
143 | |||
144 | niro | 306 | |
145 | # install SRCDIR/PNAME if not exist | ||
146 | niro | 59 | [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME} |
147 | |||
148 | # check if FETCHING is needed | ||
149 | niro | 66 | ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} &> /dev/null ) |
150 | niro | 306 | if [[ $? = 0 ]] |
151 | niro | 59 | then |
152 | niro | 439 | # md5's ok, no fetching needed |
153 | niro | 59 | FETCHING=false |
154 | else | ||
155 | FETCHING=true | ||
156 | fi | ||
157 | niro | 306 | |
158 | niro | 59 | for ((i=0; i < EOA; i++)) |
159 | do | ||
160 | niro | 66 | # url to file |
161 | my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" | ||
162 | niro | 59 | |
163 | niro | 66 | # subdir in sources dir; the my_SRCI_URI file goes to there |
164 | my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" | ||
165 | |||
166 | # if my_src_uri_dest is not equal my_src_uri; than an other dir is used | ||
167 | if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] | ||
168 | then | ||
169 | my_SOURCEDIR="${SOURCEDIR}/${PNAME}/${my_SRC_URI_DEST}" | ||
170 | else | ||
171 | my_SOURCEDIR="${SOURCEDIR}/${PNAME}" | ||
172 | fi | ||
173 | |||
174 | niro | 59 | # if an mirrored file than replace first the mirror uri |
175 | niro | 439 | if [[ -n $(echo ${my_SRC_URI} | grep 'mirror://') ]] |
176 | niro | 59 | then |
177 | for mirror in ${MIRRORS} | ||
178 | do | ||
179 | niro | 66 | my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|mirror:/|${mirror}/sources|g")" |
180 | niro | 59 | |
181 | niro | 306 | if [[ ${FETCHING} = true ]] |
182 | niro | 59 | then |
183 | niro | 439 | echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" |
184 | niro | 59 | wget \ |
185 | --passive-ftp \ | ||
186 | --tries 3 \ | ||
187 | --continue \ | ||
188 | --progress bar \ | ||
189 | niro | 66 | --directory-prefix="${my_SOURCEDIR}" \ |
190 | "${my_SRC_URI_MIRROR}" | ||
191 | niro | 306 | if [[ $? = 0 ]] |
192 | niro | 59 | then |
193 | break | ||
194 | else | ||
195 | continue | ||
196 | fi | ||
197 | fi | ||
198 | done | ||
199 | niro | 439 | elif [[ -n $(echo ${my_SRC_URI} | grep 'sourceforge://') ]] |
200 | then | ||
201 | for mirror in ${SOURCEFORGE_MIRRORS} | ||
202 | do | ||
203 | my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|sourceforge:/|${mirror}|g")" | ||
204 | |||
205 | if [[ ${FETCHING} = true ]] | ||
206 | then | ||
207 | echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" | ||
208 | wget \ | ||
209 | --passive-ftp \ | ||
210 | --tries 3 \ | ||
211 | --continue \ | ||
212 | --progress bar \ | ||
213 | --directory-prefix="${my_SOURCEDIR}" \ | ||
214 | "${my_SRC_URI_MIRROR}" | ||
215 | if [[ $? = 0 ]] | ||
216 | then | ||
217 | break | ||
218 | else | ||
219 | continue | ||
220 | fi | ||
221 | fi | ||
222 | done | ||
223 | elif [[ -n $(echo ${my_SRC_URI} | grep 'gnu://') ]] | ||
224 | then | ||
225 | for mirror in ${GNU_MIRRORS} | ||
226 | do | ||
227 | my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|gnu:/|${mirror}|g")" | ||
228 | |||
229 | if [[ ${FETCHING} = true ]] | ||
230 | then | ||
231 | echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" | ||
232 | wget \ | ||
233 | --passive-ftp \ | ||
234 | --tries 3 \ | ||
235 | --continue \ | ||
236 | --progress bar \ | ||
237 | --directory-prefix="${my_SOURCEDIR}" \ | ||
238 | "${my_SRC_URI_MIRROR}" | ||
239 | if [[ $? = 0 ]] | ||
240 | then | ||
241 | break | ||
242 | else | ||
243 | continue | ||
244 | fi | ||
245 | fi | ||
246 | done | ||
247 | niro | 459 | elif [[ -n $(echo ${my_SRC_URI} | grep 'kde://') ]] |
248 | then | ||
249 | for mirror in ${KDE_MIRRORS} | ||
250 | do | ||
251 | my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|kde:/|${mirror}|g")" | ||
252 | |||
253 | if [[ ${FETCHING} = true ]] | ||
254 | then | ||
255 | echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" | ||
256 | wget \ | ||
257 | --passive-ftp \ | ||
258 | --tries 3 \ | ||
259 | --continue \ | ||
260 | --progress bar \ | ||
261 | --directory-prefix="${my_SOURCEDIR}" \ | ||
262 | "${my_SRC_URI_MIRROR}" | ||
263 | if [[ $? = 0 ]] | ||
264 | then | ||
265 | break | ||
266 | else | ||
267 | continue | ||
268 | fi | ||
269 | fi | ||
270 | done | ||
271 | elif [[ -n $(echo ${my_SRC_URI} | grep 'gnome://') ]] | ||
272 | then | ||
273 | for mirror in ${GNOME_MIRRORS} | ||
274 | do | ||
275 | my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|gnome:/|${mirror}|g")" | ||
276 | |||
277 | if [[ ${FETCHING} = true ]] | ||
278 | then | ||
279 | echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}" | ||
280 | wget \ | ||
281 | --passive-ftp \ | ||
282 | --tries 3 \ | ||
283 | --continue \ | ||
284 | --progress bar \ | ||
285 | --directory-prefix="${my_SOURCEDIR}" \ | ||
286 | "${my_SRC_URI_MIRROR}" | ||
287 | if [[ $? = 0 ]] | ||
288 | then | ||
289 | break | ||
290 | else | ||
291 | continue | ||
292 | fi | ||
293 | fi | ||
294 | done | ||
295 | niro | 59 | else |
296 | niro | 306 | if [[ ${FETCHING} = true ]] |
297 | niro | 59 | then |
298 | niro | 439 | echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI}${COLDEFAULT}" |
299 | niro | 59 | wget \ |
300 | --passive-ftp \ | ||
301 | --tries 3 \ | ||
302 | --continue \ | ||
303 | --progress bar \ | ||
304 | niro | 66 | --directory-prefix="${my_SOURCEDIR}" \ |
305 | "${my_SRC_URI}" | ||
306 | niro | 59 | fi |
307 | fi | ||
308 | niro | 306 | |
309 | niro | 66 | # unset them to be shure |
310 | unset my_SRC_URI | ||
311 | unset my_SRC_URI_DEST | ||
312 | unset my_SRC_URI_MIRROR | ||
313 | unset my_SOURCEDIR | ||
314 | niro | 59 | done |
315 | |||
316 | # recheck md5 sums | ||
317 | echo | ||
318 | niro | 439 | echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}" |
319 | niro | 63 | ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} ) || die "md5 failed" |
320 | niro | 59 | echo |
321 | |||
322 | # not needed anymore | ||
323 | unset SRC_URI | ||
324 | } | ||
325 | |||
326 | niro | 24 | # dummy function, used if that not exist in smage file |
327 | niro | 306 | src_prepare() |
328 | { | ||
329 | niro | 24 | echo "no src_prepare defined" |
330 | sleep 2 | ||
331 | return 0 | ||
332 | } | ||
333 | |||
334 | # dummy function, used if that not exist in smage file | ||
335 | niro | 306 | src_compile() |
336 | { | ||
337 | niro | 24 | echo "no src_compile defined" |
338 | sleep 2 | ||
339 | return 0 | ||
340 | } | ||
341 | |||
342 | # dummy function, used if that not exist in smage file | ||
343 | niro | 306 | src_install() |
344 | { | ||
345 | niro | 24 | echo "no src_install defined" |
346 | sleep 2 | ||
347 | return 0 | ||
348 | } | ||
349 | |||
350 | niro | 351 | mlibdir() |
351 | { | ||
352 | local libdir=lib | ||
353 | [[ ${ARCH} = x86_64 ]] && libdir=lib64 | ||
354 | |||
355 | echo "${libdir}" | ||
356 | } | ||
357 | |||
358 | niro | 306 | mconfigure() |
359 | { | ||
360 | niro | 24 | if [ -x ./configure ] |
361 | then | ||
362 | niro | 306 | ./configure \ |
363 | --prefix=/usr \ | ||
364 | --host=${CHOST} \ | ||
365 | --mandir=/usr/share/man \ | ||
366 | --infodir=/usr/share/info \ | ||
367 | --datadir=/usr/share \ | ||
368 | --sysconfdir=/etc \ | ||
369 | --localstatedir=/var/lib \ | ||
370 | niro | 351 | --libdir=/usr/$(mlibdir) \ |
371 | niro | 306 | "$@" || die "mconfigure failed" |
372 | niro | 24 | else |
373 | echo "configure is not an executable ..." | ||
374 | exit 1 | ||
375 | fi | ||
376 | } | ||
377 | |||
378 | niro | 306 | minstall() |
379 | { | ||
380 | if [ -f ./[mM]akefile -o -f ./GNUmakefile ] | ||
381 | then | ||
382 | niro | 24 | make prefix=${BINDIR}/usr \ |
383 | datadir=${BINDIR}/usr/share \ | ||
384 | infodir=${BINDIR}/usr/share/info \ | ||
385 | localstatedir=${BINDIR}/var/lib \ | ||
386 | mandir=${BINDIR}/usr/share/man \ | ||
387 | sysconfdir=${BINDIR}/etc \ | ||
388 | niro | 351 | libdir=${BINDIR}/usr/$(mlibdir) \ |
389 | niro | 24 | "$@" install || die "minstall failed" |
390 | else | ||
391 | die "no Makefile found" | ||
392 | fi | ||
393 | } | ||
394 | |||
395 | niro | 306 | mmake() |
396 | { | ||
397 | niro | 24 | make ${MAKEOPTS} ${EXTRA_EMAKE} "$@" |
398 | } | ||
399 | |||
400 | niro | 306 | munpack() |
401 | { | ||
402 | niro | 24 | local SRCFILE |
403 | local IFTAR | ||
404 | local DEST | ||
405 | |||
406 | SRCFILE=$1 | ||
407 | niro | 306 | |
408 | niro | 24 | if [ -z "$2" ] |
409 | then | ||
410 | DEST=${BUILDDIR} | ||
411 | else | ||
412 | DEST=$2 | ||
413 | fi | ||
414 | niro | 306 | |
415 | niro | 411 | [[ ! -d ${DEST} ]] && install -d ${DEST} |
416 | |||
417 | niro | 24 | case "${SRCFILE##*.}" in |
418 | bz2) | ||
419 | IFTAR="$(basename $SRCFILE .bz2)" | ||
420 | IFTAR="${IFTAR##*.}" | ||
421 | niro | 306 | if [[ ${IFTAR} = tar ]] |
422 | niro | 24 | then |
423 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} | ||
424 | fi | ||
425 | ;; | ||
426 | gz) | ||
427 | IFTAR="$(basename $SRCFILE .gz)" | ||
428 | IFTAR="${IFTAR##*.}" | ||
429 | niro | 306 | if [[ ${IFTAR} = tar ]] |
430 | niro | 24 | then |
431 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} | ||
432 | fi | ||
433 | ;; | ||
434 | tbz2) | ||
435 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} | ||
436 | ;; | ||
437 | tgz) | ||
438 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} | ||
439 | ;; | ||
440 | *) | ||
441 | die "munpack failed" | ||
442 | ;; | ||
443 | esac | ||
444 | } | ||
445 | |||
446 | niro | 306 | mpatch() |
447 | { | ||
448 | niro | 24 | local PATCHOPTS |
449 | local PATCHFILE | ||
450 | niro | 447 | local i |
451 | niro | 24 | |
452 | PATCHOPTS=$1 | ||
453 | PATCHFILE=$2 | ||
454 | |||
455 | niro | 447 | if [[ -z $2 ]] |
456 | then | ||
457 | PATCHFILE=$1 | ||
458 | |||
459 | ## patch level auto-detection, get patch level | ||
460 | for ((i=0; i < 10; i++)) | ||
461 | do | ||
462 | patch --dry-run -Np${i} -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} > /dev/null | ||
463 | if [[ $? = 0 ]] | ||
464 | then | ||
465 | PATCHOPTS="-Np${i}" | ||
466 | break | ||
467 | fi | ||
468 | done | ||
469 | fi | ||
470 | |||
471 | niro | 384 | echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}" |
472 | niro | 24 | patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} |
473 | } | ||
474 | |||
475 | |||
476 | niro | 306 | minstalldocs() |
477 | { | ||
478 | niro | 24 | local docfiles |
479 | docfiles="$@" | ||
480 | niro | 306 | |
481 | niro | 24 | if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ] |
482 | then | ||
483 | install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs." | ||
484 | fi | ||
485 | niro | 306 | |
486 | niro | 24 | for i in ${docfiles} |
487 | do | ||
488 | cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs." | ||
489 | install -m 0644 ${SRCDIR}/${i}.gz \ | ||
490 | ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs." | ||
491 | done | ||
492 | } | ||
493 | |||
494 | niro | 306 | mstriplibs() |
495 | { | ||
496 | niro | 79 | local stripdir="$@" |
497 | |||
498 | [ -z "${stripdir}" ] && stripdir=${BINDIR} | ||
499 | find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null | ||
500 | } | ||
501 | |||
502 | niro | 306 | mstripbins() |
503 | { | ||
504 | niro | 79 | local stripdir="$@" |
505 | |||
506 | [ -z "${stripdir}" ] && stripdir=${BINDIR} | ||
507 | find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null | ||
508 | } | ||
509 | |||
510 | niro | 306 | sminclude() |
511 | { | ||
512 | niro | 172 | local i |
513 | |||
514 | niro | 183 | if [[ -n "$@" ]] |
515 | niro | 172 | then |
516 | for i in $@ | ||
517 | do | ||
518 | niro | 175 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
519 | niro | 172 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
520 | done | ||
521 | niro | 177 | echo |
522 | niro | 172 | fi |
523 | } | ||
524 | |||
525 | niro | 306 | setup_distcc_environment() |
526 | { | ||
527 | niro | 24 | if [ -x /usr/bin/distcc ] |
528 | then | ||
529 | niro | 441 | echo -e "${COLBLUE}---${COLGREEN} Using DistCC for compilation ...${COLDEFAULT}" |
530 | niro | 351 | export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH" |
531 | niro | 24 | |
532 | export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed" | ||
533 | |||
534 | niro | 306 | # creating distcc tempdir |
535 | niro | 24 | install -o distcc -g daemon -d ${DISTCC_DIR} |
536 | chmod 1777 ${DISTCC_DIR} | ||
537 | fi | ||
538 | } | ||
539 | |||
540 | niro | 306 | setup_ccache_environment() |
541 | { | ||
542 | niro | 24 | if [ -x /usr/bin/ccache ] |
543 | then | ||
544 | niro | 441 | echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}" |
545 | niro | 351 | export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH" |
546 | niro | 24 | fi |
547 | } | ||
548 | |||
549 | niro | 193 | |
550 | # fixes given dependencies to match a MAGE_TARGET | ||
551 | niro | 198 | # fix_mage_deps -target s/depend # <-- note -target ! |
552 | niro | 306 | fix_mage_deps() |
553 | { | ||
554 | niro | 193 | local target="$1" |
555 | local depend="$2" | ||
556 | local NDEPEND | ||
557 | local sym dep cat pver pname | ||
558 | |||
559 | # deps and provides are special | ||
560 | # they must be fixed to match the target | ||
561 | |||
562 | # run this only if target and depend is not empty | ||
563 | if [ -n "${target}" ] && [ -n "${depend}" ] | ||
564 | then | ||
565 | # fix DEPEND | ||
566 | while read sym dep | ||
567 | do | ||
568 | niro | 427 | # ignore empty lines |
569 | [[ -z ${dep} ]] && continue | ||
570 | |||
571 | niro | 193 | cat="$(dirname ${dep})" |
572 | niro | 199 | # change if not virtual |
573 | niro | 200 | if [[ ${cat} = virtual ]] |
574 | niro | 199 | then |
575 | niro | 200 | pname="$(basename ${dep})" |
576 | else | ||
577 | niro | 199 | # fix pver to target-pver |
578 | # to get pname-target-pver | ||
579 | niro | 193 | |
580 | niro | 199 | # doing it backwards ! |
581 | pver="${dep##*-}" | ||
582 | niro | 200 | # full pver |
583 | pname="$(basename ${dep/-${pver}/})${target}-${pver}" | ||
584 | niro | 199 | fi |
585 | niro | 193 | |
586 | # do not add empty lines | ||
587 | if [ -z "${NDEPEND}" ] | ||
588 | then | ||
589 | niro | 200 | NDEPEND="${sym} ${cat}/${pname}" |
590 | niro | 193 | else |
591 | NDEPEND="${NDEPEND} | ||
592 | niro | 201 | ${sym} ${cat}/${pname}" |
593 | niro | 193 | fi |
594 | |||
595 | unset cat pname pver | ||
596 | done << EOF | ||
597 | ${depend} | ||
598 | EOF | ||
599 | # set NDEPEND to DEPEND | ||
600 | depend="${NDEPEND}" | ||
601 | fi | ||
602 | |||
603 | echo "${depend}" | ||
604 | } | ||
605 | |||
606 | niro | 192 | # build_mage_script(): helper functions for regen_mage_tree() |
607 | niro | 191 | # generates an mage file with given information in smage file |
608 | # needs at least: | ||
609 | # PNAME name of pkg | ||
610 | # PVER version | ||
611 | # PBUILD revision | ||
612 | # PCATEGORIE categorie of the pkg | ||
613 | # STATE state of pkg stable|unstable|old | ||
614 | # DESCRIPTION va short description (opt) | ||
615 | # HOMEPAGE homepage (opt) | ||
616 | # DEPEND runtime dependencies (opt) | ||
617 | # SDEPEND add. needed deps to build the pkg (opt) | ||
618 | # PROVIDE provides a virtual (opt) | ||
619 | # | ||
620 | # special tags: | ||
621 | # PKGTYPE type of pkg | ||
622 | # INHERITS which functions get included | ||
623 | # SPECIAL_FUNCTIONS special functions wich should also be added | ||
624 | # warning: they get killed before the build starts ! | ||
625 | # | ||
626 | # MAGE_TREE_DEST target destination of the generated tree | ||
627 | # REGEN_MAGE_TREE set to 'true' to enable this | ||
628 | niro | 193 | # |
629 | niro | 195 | # gets called with build_mage_script target |
630 | niro | 192 | build_mage_script() |
631 | niro | 191 | { |
632 | local magefile | ||
633 | local dest | ||
634 | niro | 193 | local target |
635 | niro | 191 | local sym |
636 | local depname | ||
637 | |||
638 | # if MAGE_TREE_DEST not set use BUILDDIR | ||
639 | : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} | ||
640 | |||
641 | # determinate which suffix this mage file should get, if any | ||
642 | niro | 195 | [ -n "$1" ] && target="-$1" |
643 | niro | 191 | |
644 | # name of magefile | ||
645 | niro | 193 | magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" |
646 | niro | 191 | |
647 | # destination to magefile | ||
648 | niro | 193 | dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}" |
649 | niro | 191 | |
650 | # show what we are doing | ||
651 | niro | 439 | echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}" |
652 | echo "${dest}" | ||
653 | niro | 191 | |
654 | install -d "$(dirname ${dest})" | ||
655 | # now build the mage file | ||
656 | > ${dest} | ||
657 | |||
658 | # header | ||
659 | niro | 477 | echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.57 2007-04-23 16:41:44 niro Exp $' >> ${dest} |
660 | niro | 191 | echo >> ${dest} |
661 | |||
662 | # pgkname and state | ||
663 | niro | 193 | echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} |
664 | niro | 191 | echo "STATE=\"${STATE}\"" >> ${dest} |
665 | echo >> ${dest} | ||
666 | |||
667 | # description and homepage | ||
668 | echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest} | ||
669 | echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} | ||
670 | echo >> ${dest} | ||
671 | |||
672 | niro | 196 | # special tags and vars |
673 | niro | 191 | echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest} |
674 | niro | 214 | |
675 | # echo MAGE_TARGETS ## note -target is needed ! | ||
676 | echo "MAGE_TARGETS=\"${target}\"" >> ${dest} | ||
677 | echo >> ${dest} | ||
678 | |||
679 | niro | 197 | # add special vars |
680 | if [ -n "${SPECIAL_VARS}" ] | ||
681 | niro | 191 | then |
682 | local i | ||
683 | niro | 197 | for i in ${SPECIAL_VARS} |
684 | niro | 191 | do |
685 | niro | 197 | # being tricky here :) |
686 | echo "${i}=\"$(eval echo \$${i})\"" >> ${dest} | ||
687 | niro | 191 | done |
688 | echo >> ${dest} | ||
689 | fi | ||
690 | niro | 214 | |
691 | niro | 197 | # add at least all includes |
692 | if [ -n "${INHERITS}" ] | ||
693 | niro | 196 | then |
694 | niro | 197 | echo -n "minclude" >> ${dest} |
695 | niro | 196 | local i |
696 | niro | 197 | for i in ${INHERITS} |
697 | niro | 196 | do |
698 | niro | 197 | echo -n " ${i}" >> ${dest} |
699 | niro | 196 | done |
700 | echo >> ${dest} | ||
701 | fi | ||
702 | niro | 197 | echo >> ${dest} |
703 | niro | 196 | |
704 | niro | 191 | # deps and provides |
705 | niro | 193 | echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest} |
706 | niro | 196 | echo >> ${dest} |
707 | niro | 193 | echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest} |
708 | niro | 196 | echo >> ${dest} |
709 | niro | 191 | echo "PROVIDE=\"${PROVIDE}\"" >> ${dest} |
710 | echo >> ${dest} | ||
711 | |||
712 | # add special functions | ||
713 | if [ -n "${SPECIAL_FUNCTIONS}" ] | ||
714 | then | ||
715 | local i | ||
716 | for i in ${SPECIAL_FUNCTIONS} | ||
717 | do | ||
718 | # add to mage (quotes needed !) | ||
719 | typeset -f "${i}" >> ${dest} | ||
720 | niro | 214 | echo >> ${dest} |
721 | niro | 191 | # unset to be safe (quotes needed !) |
722 | niro | 192 | #unset "${i}" <-- later to get every target built |
723 | niro | 191 | done |
724 | niro | 196 | echo >> ${dest} |
725 | niro | 191 | fi |
726 | |||
727 | # pre|post-install|removes | ||
728 | typeset -f preinstall >> ${dest} | ||
729 | echo >> ${dest} | ||
730 | typeset -f postinstall >> ${dest} | ||
731 | echo >> ${dest} | ||
732 | typeset -f preremove >> ${dest} | ||
733 | echo >> ${dest} | ||
734 | typeset -f postremove >> ${dest} | ||
735 | echo >> ${dest} | ||
736 | } | ||
737 | |||
738 | regen_mage_tree() | ||
739 | { | ||
740 | local i | ||
741 | |||
742 | # build them only if requested | ||
743 | if [[ ${REGEN_MAGE_TREE} = true ]] | ||
744 | then | ||
745 | niro | 195 | # run it without targets |
746 | if [ -z "${MAGE_TARGETS}" ] | ||
747 | then | ||
748 | niro | 191 | echo |
749 | niro | 195 | build_mage_script |
750 | niro | 191 | echo |
751 | niro | 195 | else |
752 | |||
753 | # build for each target an mage file | ||
754 | # run it with several targets | ||
755 | for i in ${MAGE_TARGETS} | ||
756 | do | ||
757 | echo | ||
758 | build_mage_script "${i}" | ||
759 | echo | ||
760 | done | ||
761 | fi | ||
762 | niro | 191 | fi |
763 | |||
764 | # now unset all uneeded vars to be safe | ||
765 | niro | 192 | # unset PKGNAME <-- don't do that; smage needs this var |
766 | # unset to be safe (quotes needed !) | ||
767 | niro | 477 | # for i in ${SPECIAL_FUNCTIONS} |
768 | # do | ||
769 | # unset "${i}" | ||
770 | # done | ||
771 | niro | 192 | unset SPECIAL_FUNCTIONS |
772 | niro | 477 | # for i in ${SPECIAL_VARS} |
773 | # do | ||
774 | # unset "${i}" | ||
775 | # done | ||
776 | niro | 194 | unset SPECIAL_VARS |
777 | niro | 191 | unset STATE |
778 | unset DESCRIPTION | ||
779 | unset HOMEPAGE | ||
780 | unset PKGTYPE | ||
781 | unset INHERITS | ||
782 | unset DEPEND | ||
783 | unset SDEPEND | ||
784 | unset PROVIDE | ||
785 | unset preinstall | ||
786 | unset postinstall | ||
787 | unset preremove | ||
788 | unset postremove | ||
789 | } | ||
790 | |||
791 | niro | 253 | export_inherits() |
792 | { | ||
793 | local include="$1" | ||
794 | shift | ||
795 | |||
796 | while [ "$1" ] | ||
797 | do | ||
798 | local functions="$1" | ||
799 | |||
800 | # sanity checks | ||
801 | [ -z "${include}" ] && die "export_inherits(): \$include not given." | ||
802 | [ -z "${functions}" ] && die "export_inherits(): \$functions not given." | ||
803 | |||
804 | eval "${functions}() { ${include}_${functions} ; }" | ||
805 | |||
806 | # debug | ||
807 | [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}" | ||
808 | |||
809 | shift | ||
810 | done | ||
811 | } | ||
812 | |||
813 | niro | 255 | generate_package_md5sum() |
814 | { | ||
815 | local dest | ||
816 | local pcat | ||
817 | local pname | ||
818 | local pver | ||
819 | local pbuild | ||
820 | local parch | ||
821 | local target | ||
822 | local pkgname | ||
823 | |||
824 | # very basic getops | ||
825 | for i in $* | ||
826 | do | ||
827 | case $1 in | ||
828 | --pcat|-c) shift; pcat="$1" ;; | ||
829 | --pname|-n) shift; pname="$1" ;; | ||
830 | --pver|-v) shift; pver="$1" ;; | ||
831 | --pbuild|-b) shift; pbuild="$1" ;; | ||
832 | --parch|a) shift; parch="$1" ;; | ||
833 | --target|t) shift; target="$1" ;; | ||
834 | esac | ||
835 | shift | ||
836 | done | ||
837 | |||
838 | # sanity checks; abort if not given | ||
839 | [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given." | ||
840 | [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given." | ||
841 | [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given." | ||
842 | [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given." | ||
843 | [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given." | ||
844 | |||
845 | # check needed global vars | ||
846 | [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set." | ||
847 | [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set." | ||
848 | |||
849 | # fix target as it may be empty ! | ||
850 | [ -n "${target}" ] && target="-${target}" | ||
851 | |||
852 | # build pkgname | ||
853 | pkgname="${pname}${target}-${pver}-${parch}-${pbuild}" | ||
854 | |||
855 | # build pkg-md5-sum only if requested | ||
856 | if [[ ${REGEN_MAGE_TREE} = true ]] | ||
857 | then | ||
858 | niro | 439 | echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}" |
859 | niro | 255 | |
860 | # abort if not exist | ||
861 | if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ] | ||
862 | then | ||
863 | niro | 439 | echo -e "${COLRED}! exists${COLDEFAULT}" |
864 | niro | 255 | return 0 |
865 | fi | ||
866 | |||
867 | # if MAGE_TREE_DEST not set use BUILDDIR | ||
868 | : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} | ||
869 | |||
870 | # setup md5 dir | ||
871 | dest="${MAGE_TREE_DEST}/${pcat}/${pname}/md5" | ||
872 | install -d ${dest} | ||
873 | |||
874 | # gen md5sum | ||
875 | ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \ | ||
876 | niro | 256 | > ${dest}/${pkgname}.md5 |
877 | niro | 439 | echo -e "${COLGREEN}done${COLDEFAULT}" |
878 | niro | 255 | fi |
879 | } | ||
880 | |||
881 | niro | 403 | source_pkg_build() |
882 | { | ||
883 | if [[ ${PKGTYPE} = virtual ]] | ||
884 | then | ||
885 | echo "Virtual package detected; src-pkg-tarball not necessary ..." | ||
886 | return 0 | ||
887 | fi | ||
888 | |||
889 | if [[ ! -d ${SOURCEDIR}/${PNAME} ]] | ||
890 | then | ||
891 | echo "No SRC_URI defined; src-pkg-tarball not necessary ..." | ||
892 | return 0 | ||
893 | fi | ||
894 | |||
895 | niro | 419 | [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly." |
896 | niro | 406 | |
897 | niro | 403 | echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}" |
898 | niro | 412 | |
899 | # include the smage2 file | ||
900 | cp ${SMAGENAME} ${SOURCEDIR}/${PNAME} | ||
901 | |||
902 | niro | 403 | ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; ) |
903 | niro | 406 | [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR} |
904 | mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} | ||
905 | niro | 403 | |
906 | echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}" | ||
907 | } | ||
908 | |||
909 | |||
910 | niro | 59 | # print out our version |
911 | showversion | ||
912 | echo | ||
913 | |||
914 | niro | 24 | if [ -z "$1" ] |
915 | then | ||
916 | echo "No .smage2 file given. Exiting." | ||
917 | echo | ||
918 | exit 1 | ||
919 | fi | ||
920 | |||
921 | niro | 192 | # updating smage2-scripts |
922 | niro | 306 | if [[ $1 = update ]] |
923 | niro | 24 | then |
924 | niro | 59 | if [ ! -d ${SOURCEDIR} ] |
925 | then | ||
926 | install -d ${SOURCEDIR} | ||
927 | fi | ||
928 | syncsmage2 | ||
929 | exit 0 | ||
930 | fi | ||
931 | |||
932 | niro | 192 | # creates md5sums for smages to given dir |
933 | niro | 306 | if [[ $1 = calcmd5 ]] |
934 | niro | 59 | then |
935 | if [ $# -ge 3 ] | ||
936 | then | ||
937 | SMAGENAME="$2" | ||
938 | MD5DIR="$3" | ||
939 | source ${SMAGENAME} || die "download source failed" | ||
940 | |||
941 | niro | 66 | # overridable sourcedir; must be declared after source of the smage2 |
942 | CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}" | ||
943 | |||
944 | niro | 59 | [ -z "${SRC_URI}" ] && die "Nothing declared to calculate." |
945 | |||
946 | # end of array | ||
947 | EOA=${#SRC_URI[*]} | ||
948 | |||
949 | [ ! -d ${MD5DIR} ] && install -d ${MD5DIR} | ||
950 | |||
951 | # clear md5sum file | ||
952 | MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" | ||
953 | echo -n > ${MY_MD5_FILE} | ||
954 | |||
955 | for ((i=0; i < EOA; i++)) | ||
956 | do | ||
957 | niro | 66 | # url to file |
958 | my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" | ||
959 | |||
960 | # subdir in sources dir; the my_SRCI_URI file goes to there | ||
961 | my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" | ||
962 | |||
963 | # if my_src_uri_dest is not equal my_src_uri; than an other dir is used | ||
964 | if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] | ||
965 | then | ||
966 | MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})" | ||
967 | else | ||
968 | MY_SRC_FILE="$(basename ${SRC_URI[${i}]})" | ||
969 | fi | ||
970 | |||
971 | niro | 59 | if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ] |
972 | then | ||
973 | echo "calculating $(basename ${MY_SRC_FILE}) ..." | ||
974 | ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE} | ||
975 | else | ||
976 | echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}." | ||
977 | fi | ||
978 | niro | 66 | |
979 | # unset them to be shure | ||
980 | unset my_SRC_URI | ||
981 | unset my_SRC_URI_DEST | ||
982 | unset my_SRC_URI_MIRROR | ||
983 | unset my_SOURCEDIR | ||
984 | niro | 59 | done |
985 | niro | 306 | |
986 | niro | 59 | echo |
987 | echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done." | ||
988 | echo | ||
989 | else | ||
990 | echo "Usage: Calculating MD5 Sums:" | ||
991 | echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR" | ||
992 | echo | ||
993 | echo | ||
994 | echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs." | ||
995 | echo | ||
996 | exit 1 | ||
997 | fi | ||
998 | niro | 306 | |
999 | niro | 59 | exit 0 |
1000 | fi | ||
1001 | |||
1002 | niro | 192 | # download sources |
1003 | niro | 59 | if [ "$1" == "download" -a -n "$2" ] |
1004 | then | ||
1005 | niro | 24 | if [ ! -d ${SMAGESCRIPTSDIR} ] |
1006 | then | ||
1007 | install -d ${SMAGESCRIPTSDIR} | ||
1008 | fi | ||
1009 | niro | 59 | |
1010 | # get smage | ||
1011 | SMAGENAME="$2" | ||
1012 | MD5DIR="$(dirname ${SMAGENAME})/md5" | ||
1013 | source ${SMAGENAME} || die "download source failed" | ||
1014 | |||
1015 | download_sources | ||
1016 | niro | 24 | exit 0 |
1017 | fi | ||
1018 | |||
1019 | niro | 202 | # regen-mage-tree |
1020 | if [ "$1" == "only-regen-tree" -a -n "$2" ] | ||
1021 | then | ||
1022 | # set correct SMAGENAME | ||
1023 | SMAGENAME="$2" | ||
1024 | MD5DIR="$(dirname ${SMAGENAME})/md5" | ||
1025 | source ${SMAGENAME} || die "regen: smage2 not found" | ||
1026 | |||
1027 | regen_mage_tree | ||
1028 | niro | 255 | |
1029 | # build md5sum for existing packages | ||
1030 | generate_package_md5sum \ | ||
1031 | --pcat "${PCATEGORIE}" \ | ||
1032 | --pname "${PNAME}" \ | ||
1033 | --pver "${PVER}" \ | ||
1034 | --pbuild "${PBUILD}" \ | ||
1035 | --parch "${ARCH}" \ | ||
1036 | --target "${target}" | ||
1037 | |||
1038 | niro | 202 | exit 0 |
1039 | fi | ||
1040 | |||
1041 | niro | 412 | if [ "$1" == "--create-src-tarball" -a -n "$2" ] |
1042 | niro | 403 | then |
1043 | # set correct SMAGENAME | ||
1044 | SMAGENAME="$2" | ||
1045 | MD5DIR="$(dirname ${SMAGENAME})/md5" | ||
1046 | |||
1047 | niro | 412 | echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}" |
1048 | niro | 403 | |
1049 | source ${SMAGENAME} || die "regen: smage2 not found" | ||
1050 | |||
1051 | if [[ -d ${SOURCEDIR}/${PNAME} ]] | ||
1052 | then | ||
1053 | echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}" | ||
1054 | rm -rf ${SOURCEDIR}/${PKGNAME} | ||
1055 | fi | ||
1056 | |||
1057 | download_sources | ||
1058 | source_pkg_build ${SMAGENAME} | ||
1059 | exit 0 | ||
1060 | fi | ||
1061 | |||
1062 | niro | 406 | if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ] |
1063 | niro | 403 | then |
1064 | niro | 412 | SRCPKGTARBALL="${2}" |
1065 | niro | 403 | USE_SRC_PKG_TARBALL=true |
1066 | |||
1067 | niro | 412 | # abort if given file is not a source pkg |
1068 | [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file." | ||
1069 | |||
1070 | # set correct SMAGENAME; use the one that the src_pkg provide | ||
1071 | # /path/to/SOURCEDIR/PNAME/SMAGENAME | ||
1072 | SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}" | ||
1073 | |||
1074 | niro | 403 | echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}" |
1075 | |||
1076 | [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR} | ||
1077 | |||
1078 | # unpack srctarball | ||
1079 | [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting." | ||
1080 | |||
1081 | tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}" | ||
1082 | niro | 412 | |
1083 | [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}" | ||
1084 | niro | 403 | fi |
1085 | |||
1086 | |||
1087 | niro | 306 | [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." |
1088 | [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] && | ||
1089 | die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting." | ||
1090 | niro | 419 | [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your ${MAGERC} correctly." |
1091 | [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your ${MAGERC} correctly." | ||
1092 | [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your ${MAGERC} correctly." | ||
1093 | [ -z "${BINDIR}" ] && die "no BINDIR variable found in ${MAGERC}" | ||
1094 | [ -z "${CHOST}" ] && die "no CHOST variable found in ${MAGERC}" | ||
1095 | [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in ${MAGERC}" | ||
1096 | [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in ${MAGERC}" | ||
1097 | niro | 24 | |
1098 | source ${SMAGENAME} || die "source failed" | ||
1099 | niro | 255 | PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}" |
1100 | niro | 59 | MD5DIR="$(dirname ${SMAGENAME})/md5" |
1101 | niro | 24 | |
1102 | xtitle "Compiling ${PKGNAME}" | ||
1103 | niro | 439 | echo -e "${COLGREEN}Compiling ${PKGNAME}${COLDEFAULT}" |
1104 | niro | 59 | |
1105 | niro | 191 | # auto regen mage tree if requested |
1106 | regen_mage_tree | ||
1107 | |||
1108 | niro | 403 | if [[ ${CREATE_SRC_PKG_TARBALL} = true ]] |
1109 | then | ||
1110 | if [[ -d ${SOURCEDIR}/${PNAME} ]] | ||
1111 | then | ||
1112 | niro | 441 | echo -e "${COLBLUE}===${COLGREEN} deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}" |
1113 | niro | 408 | rm -rf ${SOURCEDIR}/${PNAME} |
1114 | niro | 403 | fi |
1115 | fi | ||
1116 | |||
1117 | niro | 192 | # download sources |
1118 | niro | 403 | [[ ${USE_SRC_PKG_TARBALL} != true ]] && download_sources |
1119 | niro | 59 | |
1120 | niro | 192 | # fixes some issues with these functions |
1121 | niro | 24 | export -f src_prepare || die "src_prepare export failed" |
1122 | export -f src_compile || die "src_compile export failed" | ||
1123 | export -f src_install || die "src_install export failed" | ||
1124 | |||
1125 | niro | 192 | # fixes some compile issues |
1126 | niro | 24 | export CHOST="${CHOST}" || die "CHOST export failed" |
1127 | export CFLAGS="${CFLAGS}" || die "CFLAGS export failed" | ||
1128 | export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" | ||
1129 | export BINDIR="${BINDIR}" || die "BINDIR export failed" | ||
1130 | export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed" | ||
1131 | |||
1132 | |||
1133 | niro | 192 | # setup distcc |
1134 | niro | 351 | # setup for distcc goes *before* ccache, so ccache comes before distcc in path |
1135 | niro | 306 | [[ ${SMAGE_USE_DISTCC} = true ]] && setup_distcc_environment |
1136 | niro | 24 | |
1137 | niro | 192 | # setup ccache |
1138 | niro | 306 | [[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment |
1139 | niro | 24 | |
1140 | # small sleep to show our settings | ||
1141 | sleep 1 | ||
1142 | |||
1143 | niro | 192 | # cleans up build if a previously one exists |
1144 | niro | 24 | if [ -d ${BUILDDIR} ] |
1145 | then | ||
1146 | rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." | ||
1147 | fi | ||
1148 | install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." | ||
1149 | |||
1150 | niro | 192 | # cleans up srcdir if a previously unpacked one exists |
1151 | niro | 24 | if [ -d ${SRCDIR} ] |
1152 | then | ||
1153 | rm -rf ${SRCDIR} | ||
1154 | fi | ||
1155 | |||
1156 | niro | 192 | # cleans up bindir if a previous build exists or creates a new one |
1157 | niro | 24 | if [ -d ${BINDIR} ] |
1158 | then | ||
1159 | rm -rf ${BINDIR} | ||
1160 | fi | ||
1161 | install -d ${BINDIR} || die "couldn't create \$BINDIR." | ||
1162 | |||
1163 | niro | 192 | # cleans up package temp dir if a previous build exists |
1164 | niro | 24 | if [ -d ${BUILDDIR}/${PKGNAME} ] |
1165 | then | ||
1166 | rm -rf ${BUILDDIR}/${PKGNAME} | ||
1167 | fi | ||
1168 | |||
1169 | niro | 192 | # cleans up timestamp if one exists |
1170 | niro | 24 | if [ -f /var/tmp/timestamp ] |
1171 | then | ||
1172 | mage rmstamp | ||
1173 | fi | ||
1174 | |||
1175 | src_prepare || die "src_prepare failed" | ||
1176 | src_compile || die "src_compile failed" | ||
1177 | src_install || die "src_install failed" | ||
1178 | |||
1179 | |||
1180 | niro | 192 | # compressing doc, info & man files |
1181 | niro | 24 | if [ -d ${BUILDDIR}/builded/usr/share/man ] |
1182 | then | ||
1183 | niro | 439 | echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}" |
1184 | niro | 24 | ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man |
1185 | fi | ||
1186 | |||
1187 | if [ -d ${BUILDDIR}/builded/usr/share/info ] | ||
1188 | then | ||
1189 | niro | 439 | echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}" |
1190 | niro | 24 | ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info |
1191 | fi | ||
1192 | |||
1193 | niro | 79 | # stripping all bins and libs |
1194 | case ${NOSTRIP} in | ||
1195 | true|TRUE|yes|y) | ||
1196 | echo -e "NOSTRIP=true detected; Package will not be stripped ..." | ||
1197 | ;; | ||
1198 | *) | ||
1199 | niro | 439 | echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" |
1200 | niro | 79 | mstripbins ${BINDIR} |
1201 | niro | 439 | echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}" |
1202 | niro | 79 | mstriplibs ${BINDIR} |
1203 | ;; | ||
1204 | esac | ||
1205 | |||
1206 | niro | 192 | # the new buildpkg command |
1207 | niro | 24 | case ${NOPKGBUILD} in |
1208 | true|TRUE|yes|y) | ||
1209 | echo -e "NOPGKBUILD=true detected; Package will not be build ..." | ||
1210 | ;; | ||
1211 | niro | 192 | *) |
1212 | niro | 306 | # build several targets |
1213 | niro | 192 | if [ -n "${MAGE_TARGETS}" ] |
1214 | then | ||
1215 | for target in ${MAGE_TARGETS} | ||
1216 | do | ||
1217 | # check if an special target_pkgbuild exists | ||
1218 | if typeset -f ${target}_pkgbuild > /dev/null | ||
1219 | then | ||
1220 | # run it | ||
1221 | ${target}_pkgbuild | ||
1222 | fi | ||
1223 | # now create the target package | ||
1224 | ${MLIBDIR}/pkgbuild_dir.sh \ | ||
1225 | niro | 255 | "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \ |
1226 | niro | 192 | ${BINDIR} || die "target: ${target} package-build failed" |
1227 | niro | 255 | |
1228 | # build pkg-md5-sum if requested | ||
1229 | generate_package_md5sum \ | ||
1230 | --pcat "${PCATEGORIE}" \ | ||
1231 | --pname "${PNAME}" \ | ||
1232 | --pver "${PVER}" \ | ||
1233 | --pbuild "${PBUILD}" \ | ||
1234 | --parch "${ARCH}" \ | ||
1235 | --target "${target}" | ||
1236 | |||
1237 | niro | 439 | echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" |
1238 | niro | 192 | done |
1239 | else | ||
1240 | ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" | ||
1241 | niro | 255 | |
1242 | # build pkg-md5-sum if requested | ||
1243 | generate_package_md5sum \ | ||
1244 | --pcat "${PCATEGORIE}" \ | ||
1245 | --pname "${PNAME}" \ | ||
1246 | --pver "${PVER}" \ | ||
1247 | --pbuild "${PBUILD}" \ | ||
1248 | --parch "${ARCH}" | ||
1249 | |||
1250 | niro | 439 | echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}" |
1251 | niro | 192 | fi |
1252 | niro | 403 | |
1253 | # build src-pkg-tarball if requested | ||
1254 | [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME} | ||
1255 | niro | 24 | ;; |
1256 | esac | ||
1257 | |||
1258 | niro | 192 | # for sure |
1259 | niro | 24 | unset NOPKGBUILD |
1260 | niro | 85 | unset NOSTRIP |
1261 | niro | 351 | |
1262 | niro | 24 | xtitleclean |
Properties
Name | Value |
---|---|
svn:executable | * |