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