Contents of /branches/mage-0_3_7-r6/mage/usr/lib/mage/smage2.sh
Parent Directory | Revision Log
Revision 398 -
(show annotations)
(download)
(as text)
Mon Nov 20 12:48:17 2006 UTC (17 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 20899 byte(s)
Mon Nov 20 12:48:17 2006 UTC (17 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 20899 byte(s)
fixed missing includes
1 | #!/bin/bash |
2 | |
3 | # compiles/installs .smage2 source install scripts |
4 | # needs pkgbuild_dir (mage) |
5 | |
6 | # SMAGE2 |
7 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.36.2.1 2006-11-20 12:48:17 niro Exp $ |
8 | |
9 | #01.10.2004 |
10 | # added ccache support |
11 | # added distcc support |
12 | |
13 | ## setup ## |
14 | PKGSUFFIX="mpk" |
15 | SMAGENAME="$1" |
16 | SMAGESUFFIX="smage2" |
17 | #SOURCEDIR="/bootstrap/sources" |
18 | #SMAGESCRIPTSDIR="/bootstrap/smage2-install-scripts" |
19 | #SMAGE2RSYNC="rsync://192.168.0.2/smage2-scripts" |
20 | MLIBDIR=/usr/lib/mage |
21 | SMAGEVERSION="$( < ${MLIBDIR}/version)" |
22 | |
23 | # export default C locale |
24 | export LC_ALL=C |
25 | |
26 | source /etc/mage.rc |
27 | source ${MLIBDIR}/mage3.functions.sh |
28 | |
29 | showversion() { |
30 | echo -en "Magellan Source Install v${SMAGEVERSION} " |
31 | echo -e "-- Niels Rogalla (niro@magellan-linux.de)" |
32 | } |
33 | |
34 | die() { |
35 | xtitleclean |
36 | echo "SMAGE failed: $@" |
37 | exit 1 |
38 | } |
39 | |
40 | xtitle() { |
41 | if [ ${TERM} == "xterm" ] |
42 | then |
43 | echo -ne "\033]0;[sMage: $@]\007" |
44 | fi |
45 | return 0 |
46 | } |
47 | |
48 | xtitleclean() { |
49 | if [ ${TERM} == "xterm" ] |
50 | then |
51 | echo -ne "\033]0;\007" |
52 | fi |
53 | return 0 |
54 | } |
55 | |
56 | syncsmage2() { |
57 | xtitle "Updating smage2-script tree ..." |
58 | local i |
59 | for i in ${SMAGE2RSYNC} |
60 | do |
61 | rsync \ |
62 | --recursive \ |
63 | --links \ |
64 | --perms \ |
65 | --times \ |
66 | --devices \ |
67 | --timeout=600 \ |
68 | --verbose \ |
69 | --compress \ |
70 | --progress \ |
71 | --stats \ |
72 | --delete \ |
73 | --delete-after \ |
74 | ${i} ${SMAGESCRIPTSDIR} |
75 | |
76 | if [ "$?" == "0" ] |
77 | then |
78 | break |
79 | else |
80 | continue |
81 | fi |
82 | |
83 | done |
84 | |
85 | #clean up backup files (foo~) |
86 | find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';' |
87 | |
88 | xtitleclean |
89 | } |
90 | |
91 | # $1 filename |
92 | get_db_md5_sum() { |
93 | local DB_FILE |
94 | local MD5_FILE |
95 | local i |
96 | |
97 | DB_ENTRY="$(basename $1)" |
98 | MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})" |
99 | |
100 | i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)" |
101 | |
102 | echo "${i}" |
103 | } |
104 | |
105 | download_sources() { |
106 | |
107 | [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0 |
108 | |
109 | local EOA=${#SRC_URI[*]} |
110 | local my_SRC_URI |
111 | local my_SRC_URI_DEST |
112 | local my_SRC_URI_MIRROR |
113 | local my_SOURCEDIR |
114 | local DB_MD5_SUM_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" |
115 | local FETCHING |
116 | local i mirror |
117 | |
118 | |
119 | #install SRCDIR/PNAME if not exist |
120 | [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME} |
121 | |
122 | # check if FETCHING is needed |
123 | ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} &> /dev/null ) |
124 | if [[ $? == 0 ]] |
125 | then |
126 | # md5's ok, not fetching needed |
127 | FETCHING=false |
128 | else |
129 | FETCHING=true |
130 | fi |
131 | |
132 | for ((i=0; i < EOA; i++)) |
133 | do |
134 | # url to file |
135 | my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" |
136 | |
137 | # subdir in sources dir; the my_SRCI_URI file goes to there |
138 | my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" |
139 | |
140 | # if my_src_uri_dest is not equal my_src_uri; than an other dir is used |
141 | if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] |
142 | then |
143 | my_SOURCEDIR="${SOURCEDIR}/${PNAME}/${my_SRC_URI_DEST}" |
144 | else |
145 | my_SOURCEDIR="${SOURCEDIR}/${PNAME}" |
146 | fi |
147 | |
148 | # if an mirrored file than replace first the mirror uri |
149 | if [ -n "$(echo ${my_SRC_URI} | grep 'mirror://')" ] |
150 | then |
151 | for mirror in ${MIRRORS} |
152 | do |
153 | my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|mirror:/|${mirror}/sources|g")" |
154 | |
155 | #echo "DEBUG: ${MY_SRC_URI}" |
156 | if [[ ${FETCHING} == true ]] |
157 | then |
158 | echo "==> fetching ${my_SRC_URI_MIRROR}" |
159 | wget \ |
160 | --passive-ftp \ |
161 | --tries 3 \ |
162 | --continue \ |
163 | --progress bar \ |
164 | --directory-prefix="${my_SOURCEDIR}" \ |
165 | "${my_SRC_URI_MIRROR}" |
166 | if [ "$?" == "0" ] |
167 | then |
168 | break |
169 | else |
170 | continue |
171 | fi |
172 | fi |
173 | done |
174 | else |
175 | #echo "DEBUG: ${SRC_URI[${i}]}" |
176 | if [[ ${FETCHING} == true ]] |
177 | then |
178 | echo "==> fetching ${my_SRC_URI}" |
179 | wget \ |
180 | --passive-ftp \ |
181 | --tries 3 \ |
182 | --continue \ |
183 | --progress bar \ |
184 | --directory-prefix="${my_SOURCEDIR}" \ |
185 | "${my_SRC_URI}" |
186 | # only needed to run through a list of mirrors |
187 | # if [ "$?" == "0" ] |
188 | # then |
189 | # break |
190 | # else |
191 | # continue |
192 | # fi |
193 | fi |
194 | fi |
195 | |
196 | # unset them to be shure |
197 | unset my_SRC_URI |
198 | unset my_SRC_URI_DEST |
199 | unset my_SRC_URI_MIRROR |
200 | unset my_SOURCEDIR |
201 | done |
202 | |
203 | # recheck md5 sums |
204 | echo |
205 | echo ">== Checking MD5 sums:" |
206 | ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} ) || die "md5 failed" |
207 | echo |
208 | |
209 | # not needed anymore |
210 | unset SRC_URI |
211 | } |
212 | |
213 | # dummy function, used if that not exist in smage file |
214 | src_prepare() { |
215 | echo "no src_prepare defined" |
216 | sleep 2 |
217 | return 0 |
218 | } |
219 | |
220 | # dummy function, used if that not exist in smage file |
221 | src_compile() { |
222 | echo "no src_compile defined" |
223 | sleep 2 |
224 | return 0 |
225 | } |
226 | |
227 | # dummy function, used if that not exist in smage file |
228 | src_install() { |
229 | echo "no src_install defined" |
230 | sleep 2 |
231 | return 0 |
232 | } |
233 | |
234 | mconfigure() { |
235 | if [ -x ./configure ] |
236 | then |
237 | ./configure \ |
238 | --prefix=/usr \ |
239 | --host=${CHOST} \ |
240 | --mandir=/usr/share/man \ |
241 | --infodir=/usr/share/info \ |
242 | --datadir=/usr/share \ |
243 | --sysconfdir=/etc \ |
244 | --localstatedir=/var/lib \ |
245 | "$@" || die "mconfigure failed" |
246 | else |
247 | echo "configure is not an executable ..." |
248 | exit 1 |
249 | fi |
250 | } |
251 | |
252 | minstall() { |
253 | if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then |
254 | make prefix=${BINDIR}/usr \ |
255 | datadir=${BINDIR}/usr/share \ |
256 | infodir=${BINDIR}/usr/share/info \ |
257 | localstatedir=${BINDIR}/var/lib \ |
258 | mandir=${BINDIR}/usr/share/man \ |
259 | sysconfdir=${BINDIR}/etc \ |
260 | "$@" install || die "minstall failed" |
261 | else |
262 | die "no Makefile found" |
263 | fi |
264 | } |
265 | |
266 | mmake() { |
267 | make ${MAKEOPTS} ${EXTRA_EMAKE} "$@" |
268 | } |
269 | |
270 | munpack() { |
271 | local SRCFILE |
272 | local IFTAR |
273 | local DEST |
274 | |
275 | SRCFILE=$1 |
276 | |
277 | if [ -z "$2" ] |
278 | then |
279 | DEST=${BUILDDIR} |
280 | else |
281 | DEST=$2 |
282 | fi |
283 | |
284 | case "${SRCFILE##*.}" in |
285 | bz2) |
286 | IFTAR="$(basename $SRCFILE .bz2)" |
287 | IFTAR="${IFTAR##*.}" |
288 | if [ "${IFTAR}" == "tar" ] |
289 | then |
290 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} |
291 | fi |
292 | ;; |
293 | gz) |
294 | IFTAR="$(basename $SRCFILE .gz)" |
295 | IFTAR="${IFTAR##*.}" |
296 | if [ "${IFTAR}" == "tar" ] |
297 | then |
298 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} |
299 | fi |
300 | ;; |
301 | tbz2) |
302 | tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} |
303 | ;; |
304 | tgz) |
305 | tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} |
306 | ;; |
307 | *) |
308 | die "munpack failed" |
309 | ;; |
310 | esac |
311 | } |
312 | |
313 | mpatch() { |
314 | local PATCHOPTS |
315 | local PATCHFILE |
316 | |
317 | PATCHOPTS=$1 |
318 | PATCHFILE=$2 |
319 | |
320 | patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} |
321 | } |
322 | |
323 | |
324 | minstalldocs() { |
325 | local docfiles |
326 | |
327 | docfiles="$@" |
328 | |
329 | if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ] |
330 | then |
331 | install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs." |
332 | fi |
333 | |
334 | for i in ${docfiles} |
335 | do |
336 | cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs." |
337 | install -m 0644 ${SRCDIR}/${i}.gz \ |
338 | ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs." |
339 | done |
340 | } |
341 | |
342 | mstriplibs() { |
343 | local stripdir="$@" |
344 | |
345 | [ -z "${stripdir}" ] && stripdir=${BINDIR} |
346 | find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
347 | } |
348 | |
349 | mstripbins() { |
350 | local stripdir="$@" |
351 | |
352 | [ -z "${stripdir}" ] && stripdir=${BINDIR} |
353 | find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
354 | } |
355 | |
356 | sminclude() { |
357 | local i |
358 | |
359 | if [[ -n "$@" ]] |
360 | then |
361 | for i in $@ |
362 | do |
363 | echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
364 | source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
365 | done |
366 | echo |
367 | fi |
368 | } |
369 | |
370 | setup_distcc_environment(){ |
371 | if [ -x /usr/bin/distcc ] |
372 | then |
373 | echo "Using DistCC for compilation ..." |
374 | export PATH=/usr/lib/distcc/bin:${PATH} || die "distcc: could not export new $PATH" |
375 | |
376 | #export distcc as compiler |
377 | # export CC="distcc" |
378 | # export CXX=distcc |
379 | |
380 | export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed" |
381 | |
382 | |
383 | #ccache + distcc together |
384 | if [ "${SMAGE_USE_CCACHE}" == "true" ] |
385 | then |
386 | if [ -x /usr/bin/ccache ] |
387 | then |
388 | echo "Preparing DistCC to work together with CCache ..." |
389 | #export CCACHE_PREFIX="distcc" || die "distcc: could not set ccach_prefix" |
390 | # export CC="ccache distcc" |
391 | # export CXX="ccache distcc" |
392 | fi |
393 | fi |
394 | |
395 | #creating distcc tempdir |
396 | install -o distcc -g daemon -d ${DISTCC_DIR} |
397 | chmod 1777 ${DISTCC_DIR} |
398 | fi |
399 | } |
400 | |
401 | setup_ccache_environment(){ |
402 | if [ -x /usr/bin/ccache ] |
403 | then |
404 | echo "Using CCache for compilation ..." |
405 | export PATH=/usr/lib/ccache/bin:${PATH} || die "ccache: could not export new $PATH" |
406 | #unset CC CXX |
407 | fi |
408 | } |
409 | |
410 | |
411 | # fixes given dependencies to match a MAGE_TARGET |
412 | # fix_mage_deps -target s/depend # <-- note -target ! |
413 | fix_mage_deps() { |
414 | local target="$1" |
415 | local depend="$2" |
416 | local NDEPEND |
417 | local sym dep cat pver pname |
418 | |
419 | # deps and provides are special |
420 | # they must be fixed to match the target |
421 | |
422 | # run this only if target and depend is not empty |
423 | if [ -n "${target}" ] && [ -n "${depend}" ] |
424 | then |
425 | # fix DEPEND |
426 | while read sym dep |
427 | do |
428 | cat="$(dirname ${dep})" |
429 | # change if not virtual |
430 | if [[ ${cat} = virtual ]] |
431 | then |
432 | pname="$(basename ${dep})" |
433 | else |
434 | # fix pver to target-pver |
435 | # to get pname-target-pver |
436 | |
437 | # doing it backwards ! |
438 | pver="${dep##*-}" |
439 | # full pver |
440 | pname="$(basename ${dep/-${pver}/})${target}-${pver}" |
441 | fi |
442 | |
443 | # do not add empty lines |
444 | if [ -z "${NDEPEND}" ] |
445 | then |
446 | NDEPEND="${sym} ${cat}/${pname}" |
447 | else |
448 | NDEPEND="${NDEPEND} |
449 | ${sym} ${cat}/${pname}" |
450 | fi |
451 | |
452 | unset cat pname pver |
453 | done << EOF |
454 | ${depend} |
455 | EOF |
456 | # set NDEPEND to DEPEND |
457 | depend="${NDEPEND}" |
458 | fi |
459 | |
460 | echo "${depend}" |
461 | } |
462 | |
463 | # build_mage_script(): helper functions for regen_mage_tree() |
464 | # generates an mage file with given information in smage file |
465 | # needs at least: |
466 | # PNAME name of pkg |
467 | # PVER version |
468 | # PBUILD revision |
469 | # PCATEGORIE categorie of the pkg |
470 | # STATE state of pkg stable|unstable|old |
471 | # DESCRIPTION va short description (opt) |
472 | # HOMEPAGE homepage (opt) |
473 | # DEPEND runtime dependencies (opt) |
474 | # SDEPEND add. needed deps to build the pkg (opt) |
475 | # PROVIDE provides a virtual (opt) |
476 | # |
477 | # special tags: |
478 | # PKGTYPE type of pkg |
479 | # INHERITS which functions get included |
480 | # SPECIAL_FUNCTIONS special functions wich should also be added |
481 | # warning: they get killed before the build starts ! |
482 | # |
483 | # MAGE_TREE_DEST target destination of the generated tree |
484 | # REGEN_MAGE_TREE set to 'true' to enable this |
485 | # |
486 | # gets called with build_mage_script target |
487 | build_mage_script() |
488 | { |
489 | local magefile |
490 | local dest |
491 | local target |
492 | local sym |
493 | local depname |
494 | |
495 | # if MAGE_TREE_DEST not set use BUILDDIR |
496 | : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} |
497 | |
498 | # determinate which suffix this mage file should get, if any |
499 | [ -n "$1" ] && target="-$1" |
500 | |
501 | # name of magefile |
502 | magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" |
503 | |
504 | # destination to magefile |
505 | dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}" |
506 | |
507 | # show what we are doing |
508 | echo "Generating Mage file:" |
509 | echo " ${dest}" |
510 | |
511 | install -d "$(dirname ${dest})" |
512 | # now build the mage file |
513 | > ${dest} |
514 | |
515 | # header |
516 | echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.36.2.1 2006-11-20 12:48:17 niro Exp $' >> ${dest} |
517 | echo >> ${dest} |
518 | |
519 | # pgkname and state |
520 | echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} |
521 | echo "STATE=\"${STATE}\"" >> ${dest} |
522 | echo >> ${dest} |
523 | |
524 | # description and homepage |
525 | echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest} |
526 | echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} |
527 | echo >> ${dest} |
528 | |
529 | # special tags and vars |
530 | echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest} |
531 | |
532 | # echo MAGE_TARGETS ## note -target is needed ! |
533 | echo "MAGE_TARGETS=\"${target}\"" >> ${dest} |
534 | echo >> ${dest} |
535 | |
536 | # add special vars |
537 | if [ -n "${SPECIAL_VARS}" ] |
538 | then |
539 | local i |
540 | for i in ${SPECIAL_VARS} |
541 | do |
542 | # being tricky here :) |
543 | echo "${i}=\"$(eval echo \$${i})\"" >> ${dest} |
544 | done |
545 | echo >> ${dest} |
546 | fi |
547 | |
548 | # add at least all includes |
549 | if [ -n "${INHERITS}" ] |
550 | then |
551 | echo -n "minclude" >> ${dest} |
552 | local i |
553 | for i in ${INHERITS} |
554 | do |
555 | echo -n " ${i}" >> ${dest} |
556 | done |
557 | echo >> ${dest} |
558 | fi |
559 | echo >> ${dest} |
560 | |
561 | # deps and provides |
562 | echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest} |
563 | echo >> ${dest} |
564 | echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest} |
565 | echo >> ${dest} |
566 | echo "PROVIDE=\"${PROVIDE}\"" >> ${dest} |
567 | echo >> ${dest} |
568 | |
569 | # add special functions |
570 | if [ -n "${SPECIAL_FUNCTIONS}" ] |
571 | then |
572 | local i |
573 | for i in ${SPECIAL_FUNCTIONS} |
574 | do |
575 | # add to mage (quotes needed !) |
576 | typeset -f "${i}" >> ${dest} |
577 | echo >> ${dest} |
578 | # unset to be safe (quotes needed !) |
579 | #unset "${i}" <-- later to get every target built |
580 | done |
581 | echo >> ${dest} |
582 | fi |
583 | |
584 | # pre|post-install|removes |
585 | typeset -f preinstall >> ${dest} |
586 | echo >> ${dest} |
587 | typeset -f postinstall >> ${dest} |
588 | echo >> ${dest} |
589 | typeset -f preremove >> ${dest} |
590 | echo >> ${dest} |
591 | typeset -f postremove >> ${dest} |
592 | echo >> ${dest} |
593 | } |
594 | |
595 | regen_mage_tree() |
596 | { |
597 | local i |
598 | |
599 | # build them only if requested |
600 | if [[ ${REGEN_MAGE_TREE} = true ]] |
601 | then |
602 | # run it without targets |
603 | if [ -z "${MAGE_TARGETS}" ] |
604 | then |
605 | echo |
606 | build_mage_script |
607 | echo |
608 | else |
609 | |
610 | # build for each target an mage file |
611 | # run it with several targets |
612 | for i in ${MAGE_TARGETS} |
613 | do |
614 | echo |
615 | build_mage_script "${i}" |
616 | echo |
617 | done |
618 | fi |
619 | fi |
620 | |
621 | # now unset all uneeded vars to be safe |
622 | # unset PKGNAME <-- don't do that; smage needs this var |
623 | # unset to be safe (quotes needed !) |
624 | for i in ${SPECIAL_FUNCTIONS} |
625 | do |
626 | unset "${i}" |
627 | done |
628 | unset SPECIAL_FUNCTIONS |
629 | for i in ${SPECIAL_VARS} |
630 | do |
631 | unset "${i}" |
632 | done |
633 | unset SPECIAL_VARS |
634 | unset STATE |
635 | unset DESCRIPTION |
636 | unset HOMEPAGE |
637 | unset PKGTYPE |
638 | unset INHERITS |
639 | unset DEPEND |
640 | unset SDEPEND |
641 | unset PROVIDE |
642 | unset preinstall |
643 | unset postinstall |
644 | unset preremove |
645 | unset postremove |
646 | } |
647 | |
648 | # print out our version |
649 | showversion |
650 | echo |
651 | |
652 | if [ -z "$1" ] |
653 | then |
654 | echo "No .smage2 file given. Exiting." |
655 | echo |
656 | exit 1 |
657 | fi |
658 | |
659 | # updating smage2-scripts |
660 | if [ "$1" == "update" ] |
661 | then |
662 | if [ ! -d ${SOURCEDIR} ] |
663 | then |
664 | install -d ${SOURCEDIR} |
665 | fi |
666 | syncsmage2 |
667 | exit 0 |
668 | fi |
669 | |
670 | # creates md5sums for smages to given dir |
671 | if [ "$1" == "calcmd5" ] |
672 | then |
673 | if [ $# -ge 3 ] |
674 | then |
675 | SMAGENAME="$2" |
676 | MD5DIR="$3" |
677 | source ${SMAGENAME} || die "download source failed" |
678 | |
679 | # overridable sourcedir; must be declared after source of the smage2 |
680 | CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}" |
681 | |
682 | [ -z "${SRC_URI}" ] && die "Nothing declared to calculate." |
683 | |
684 | # end of array |
685 | EOA=${#SRC_URI[*]} |
686 | |
687 | [ ! -d ${MD5DIR} ] && install -d ${MD5DIR} |
688 | |
689 | # clear md5sum file |
690 | MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5" |
691 | echo -n > ${MY_MD5_FILE} |
692 | |
693 | for ((i=0; i < EOA; i++)) |
694 | do |
695 | # url to file |
696 | my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)" |
697 | |
698 | # subdir in sources dir; the my_SRCI_URI file goes to there |
699 | my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)" |
700 | |
701 | # if my_src_uri_dest is not equal my_src_uri; than an other dir is used |
702 | if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]] |
703 | then |
704 | MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})" |
705 | else |
706 | MY_SRC_FILE="$(basename ${SRC_URI[${i}]})" |
707 | fi |
708 | |
709 | if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ] |
710 | then |
711 | echo "calculating $(basename ${MY_SRC_FILE}) ..." |
712 | ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE} |
713 | else |
714 | echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}." |
715 | fi |
716 | |
717 | # unset them to be shure |
718 | unset my_SRC_URI |
719 | unset my_SRC_URI_DEST |
720 | unset my_SRC_URI_MIRROR |
721 | unset my_SOURCEDIR |
722 | done |
723 | |
724 | echo |
725 | echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done." |
726 | echo |
727 | else |
728 | echo "Usage: Calculating MD5 Sums:" |
729 | echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR" |
730 | echo |
731 | echo |
732 | echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs." |
733 | echo |
734 | exit 1 |
735 | fi |
736 | |
737 | exit 0 |
738 | fi |
739 | |
740 | # download sources |
741 | if [ "$1" == "download" -a -n "$2" ] |
742 | then |
743 | if [ ! -d ${SMAGESCRIPTSDIR} ] |
744 | then |
745 | install -d ${SMAGESCRIPTSDIR} |
746 | fi |
747 | |
748 | # get smage |
749 | SMAGENAME="$2" |
750 | MD5DIR="$(dirname ${SMAGENAME})/md5" |
751 | source ${SMAGENAME} || die "download source failed" |
752 | |
753 | download_sources |
754 | exit 0 |
755 | fi |
756 | |
757 | # regen-mage-tree |
758 | if [ "$1" == "only-regen-tree" -a -n "$2" ] |
759 | then |
760 | # set correct SMAGENAME |
761 | SMAGENAME="$2" |
762 | MD5DIR="$(dirname ${SMAGENAME})/md5" |
763 | source ${SMAGENAME} || die "regen: smage2 not found" |
764 | |
765 | regen_mage_tree |
766 | exit 0 |
767 | fi |
768 | |
769 | if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] |
770 | then |
771 | die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting." |
772 | fi |
773 | |
774 | if [ -z "`basename ${SMAGENAME}|grep .${SMAGESUFFIX}`" ] |
775 | then |
776 | die "File '`basename ${SMAGENAME}`' is not a sMage v${SMAGEVERSION} file. Aborting." |
777 | fi |
778 | |
779 | if [ -z "${SOURCEDIR}" ] |
780 | then |
781 | die "\$SOURCEDIR not found. Please setup your mage.rc correctly." |
782 | fi |
783 | |
784 | if [ -z "${SMAGESCRIPTSDIR}" ] |
785 | then |
786 | die "\$SMAGESCRIPTSDIR not found. Please setup your mage.rc correctly." |
787 | fi |
788 | |
789 | if [ -z "${SMAGE2RSYNC}" ] |
790 | then |
791 | echo "\$SMAGE2RSYNC not found. Please setup your mage.rc correctly." |
792 | exit 1 |
793 | fi |
794 | |
795 | if [ -z "${BINDIR}" ] |
796 | then |
797 | die "no BINDIR variable found in /etc/mage.rc" |
798 | fi |
799 | |
800 | if [ -z "${CHOST}" ] |
801 | then |
802 | die "no CHOST variable found in /etc/mage.rc" |
803 | fi |
804 | |
805 | if [ -z "${CFLAGS}" ] |
806 | then |
807 | die "no CFLAGS variable found in /etc/mage.rc" |
808 | fi |
809 | |
810 | if [ -z "${CXXFLAGS}" ] |
811 | then |
812 | die "no CXXFLAGS variable found in /etc/mage.rc" |
813 | fi |
814 | |
815 | |
816 | source ${SMAGENAME} || die "source failed" |
817 | PKGNAME="${PNAME}-${PVER}-${CHOST%%-*}-${PBUILD}" |
818 | MD5DIR="$(dirname ${SMAGENAME})/md5" |
819 | |
820 | xtitle "Compiling ${PKGNAME}" |
821 | echo "Compiling ${PKGNAME}" |
822 | |
823 | # auto regen mage tree if requested |
824 | regen_mage_tree |
825 | |
826 | # download sources |
827 | download_sources |
828 | |
829 | # fixes some issues with these functions |
830 | export -f src_prepare || die "src_prepare export failed" |
831 | export -f src_compile || die "src_compile export failed" |
832 | export -f src_install || die "src_install export failed" |
833 | |
834 | # fixes some compile issues |
835 | export CHOST="${CHOST}" || die "CHOST export failed" |
836 | export CFLAGS="${CFLAGS}" || die "CFLAGS export failed" |
837 | export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" |
838 | export BINDIR="${BINDIR}" || die "BINDIR export failed" |
839 | export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed" |
840 | |
841 | |
842 | # setup distcc |
843 | # distcc mus be setup *before* ccache, as ccache need to be before distcc in path |
844 | if [ "${SMAGE_USE_DISTCC}" == "true" ] |
845 | then |
846 | setup_distcc_environment |
847 | fi |
848 | |
849 | # setup ccache |
850 | if [ "${SMAGE_USE_CCACHE}" == "true" ] |
851 | then |
852 | setup_ccache_environment |
853 | fi |
854 | |
855 | |
856 | # small sleep to show our settings |
857 | sleep 1 |
858 | |
859 | #debug |
860 | #echo "CC=${CC}" |
861 | #echo "CXX=${CXX}" |
862 | #echo "DISTCC_DIR=${DISTCC_DIR}" |
863 | #echo "PATH: ${PATH}" |
864 | #echo "--------------------------------------" |
865 | #env |
866 | #echo "--------------------------------------" |
867 | #read |
868 | #debug end |
869 | |
870 | # cleans up build if a previously one exists |
871 | if [ -d ${BUILDDIR} ] |
872 | then |
873 | rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." |
874 | fi |
875 | install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." |
876 | |
877 | # cleans up srcdir if a previously unpacked one exists |
878 | if [ -d ${SRCDIR} ] |
879 | then |
880 | rm -rf ${SRCDIR} |
881 | fi |
882 | |
883 | # cleans up bindir if a previous build exists or creates a new one |
884 | if [ -d ${BINDIR} ] |
885 | then |
886 | rm -rf ${BINDIR} |
887 | fi |
888 | install -d ${BINDIR} || die "couldn't create \$BINDIR." |
889 | |
890 | # cleans up package temp dir if a previous build exists |
891 | if [ -d ${BUILDDIR}/${PKGNAME} ] |
892 | then |
893 | rm -rf ${BUILDDIR}/${PKGNAME} |
894 | fi |
895 | |
896 | # cleans up timestamp if one exists |
897 | if [ -f /var/tmp/timestamp ] |
898 | then |
899 | mage rmstamp |
900 | fi |
901 | |
902 | src_prepare || die "src_prepare failed" |
903 | src_compile || die "src_compile failed" |
904 | src_install || die "src_install failed" |
905 | |
906 | |
907 | # compressing doc, info & man files |
908 | echo -e "Compressing man-pages ..." |
909 | if [ -d ${BUILDDIR}/builded/usr/share/man ] |
910 | then |
911 | ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man |
912 | fi |
913 | |
914 | echo -e "Compressing info-pages ..." |
915 | if [ -d ${BUILDDIR}/builded/usr/share/info ] |
916 | then |
917 | ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info |
918 | fi |
919 | |
920 | # stripping all bins and libs |
921 | case ${NOSTRIP} in |
922 | true|TRUE|yes|y) |
923 | echo -e "NOSTRIP=true detected; Package will not be stripped ..." |
924 | ;; |
925 | *) |
926 | echo -e "Stripping binaries ..." |
927 | mstripbins ${BINDIR} |
928 | echo -e "Stripping libraries ..." |
929 | mstriplibs ${BINDIR} |
930 | ;; |
931 | esac |
932 | |
933 | # the new buildpkg command |
934 | case ${NOPKGBUILD} in |
935 | true|TRUE|yes|y) |
936 | echo -e "NOPGKBUILD=true detected; Package will not be build ..." |
937 | ;; |
938 | *) |
939 | # build serveral targets |
940 | if [ -n "${MAGE_TARGETS}" ] |
941 | then |
942 | for target in ${MAGE_TARGETS} |
943 | do |
944 | # check if an special target_pkgbuild exists |
945 | if typeset -f ${target}_pkgbuild > /dev/null |
946 | then |
947 | # run it |
948 | ${target}_pkgbuild |
949 | fi |
950 | # now create the target package |
951 | ${MLIBDIR}/pkgbuild_dir.sh \ |
952 | "${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD}" \ |
953 | ${BINDIR} || die "target: ${target} package-build failed" |
954 | echo -e "\nPackage ${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD} successfully builded.\n" |
955 | done |
956 | else |
957 | ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" |
958 | echo -e "\nPackage ${PKGNAME} successfully builded.\n" |
959 | fi |
960 | ;; |
961 | esac |
962 | |
963 | # for sure |
964 | unset NOPKGBUILD |
965 | unset NOSTRIP |
966 | |
967 | xtitleclean |
968 | #echo -e "\nPackage ${PKGNAME} successfully builded.\n" |
Properties
Name | Value |
---|---|
svn:executable | * |