Magellan Linux

Contents of /trunk/mage/usr/lib/mage/smage2.functions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1641 - (show annotations) (download) (as text)
Fri Jan 13 18:31:48 2012 UTC (12 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 27765 byte(s)
-deprecate PCATEGORIE in favor of PCAT and warn the packages about it
1 #!/bin/bash
2 # smage2 releated functions
3 # $Id$
4
5 # sources the smage file and uses state from distribution file if exist
6 # may helpful for repository support later on
7 smagesource()
8 {
9 local file="$1"
10 local mystate
11 local mycodename
12
13 source ${file}
14
15 # if PCAT was not set and PCATEGORIE was found
16 # inform the user and use PCATEGORIE as PCAT
17 if [[ -z ${PCAT} ]]
18 then
19 if [[ -n ${PCATEGORIE} ]]
20 then
21 PCAT="${PCATEGORIE}"
22 # print a warning
23 echo -e "${COLYELLOW}Warning: 'PCATEGORIE' is deprecated and gets removed in the future.${COLDEFAULT}"
24 echo -e "${COLYELLOW} Please modify this smage2 script to use the 'PCAT' variable.${COLDEFAULT}"
25 echo
26 else
27 die "Neither PCAT nor PCATEGORIE are defined!"
28 fi
29 fi
30
31 [[ -n ${STATE} ]] && mystate="${STATE}"
32
33 # do not overide if local state was broken or disabled!
34 case ${STATE} in
35 broken) return ;;
36 disabled) return ;;
37 esac
38
39 if [ -f ${SMAGESCRIPTSDIR}/distribution ]
40 then
41 source ${SMAGESCRIPTSDIR}/distribution
42 [[ -n ${STATE} ]] && mystate="${STATE}"
43 fi
44 # now switch state and export it
45 STATE="${mystate}"
46 }
47
48 showversion()
49 {
50 echo -en "Magellan Source Install v${SMAGEVERSION} "
51 echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
52 }
53
54 die()
55 {
56 xtitleclean
57 echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
58 echo "SMAGE failed: $@"
59 exit 1
60 }
61
62 die_pipestatus()
63 {
64 # the status change if we do any parameter declarations!!
65 # dont do this anymore, keep this in mind!
66 #
67 # local pos="$1"
68 # local comment="$2"
69 #
70 # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}"
71 #
72 [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2"
73 }
74
75 xtitle()
76 {
77 if [[ ${TERM} = xterm ]]
78 then
79 echo -ne "\033]0;[sMage: $@]\007"
80 fi
81 return 0
82 }
83
84 xtitleclean()
85 {
86 if [[ ${TERM} = xterm ]]
87 then
88 echo -ne "\033]0;\007"
89 fi
90 return 0
91 }
92
93 syncsmage2()
94 {
95 xtitle "Updating smage2-script tree ..."
96 local i
97 for i in ${SMAGE2RSYNC}
98 do
99 rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR}
100 if [[ $? = 0 ]]
101 then
102 break
103 else
104 continue
105 fi
106 done
107
108 # clean up backup files (foo~)
109 find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';'
110
111 xtitleclean
112 }
113
114 # $1 filename
115 get_db_md5_sum()
116 {
117 local DB_FILE
118 local MD5_FILE
119 local i
120
121 DB_ENTRY="$(basename $1)"
122 MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})"
123
124 i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)"
125
126 echo "${i}"
127 }
128
129 download_sources()
130 {
131 [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0
132
133 local count=${#SRC_URI[*]}
134 local uri
135 local subdir
136 local outputdir
137 local db_md5_file="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
138 local fetching
139 local i
140
141 # check if FETCHING is needed
142 if mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5
143 then
144 # md5's ok, no fetching needed
145 fetching=false
146 else
147 fetching=true
148 fi
149
150 if [[ ${fetching} = true ]]
151 then
152 for ((i=0; i < count; i++))
153 do
154 # url to file
155 uri="${SRC_URI[${i}]%%' '*}"
156
157 # subdir in sources dir; the my_SRCI_URI file goes to there
158 subdir="${SRC_URI[${i}]##*' '}"
159
160 # if $subdir is not equal with $uri then an other dir is used
161 if [[ ${uri} != ${subdir} ]]
162 then
163 outputdir="${SOURCEDIR}/${PNAME}/${subdir}"
164 else
165 outputdir="${SOURCEDIR}/${PNAME}"
166 fi
167
168 echo -e "${COLBLUE}==>${COLGREEN} fetching ${uri}${COLDEFAULT}"
169 # always use verbose mode for source downloads
170 FVERBOSE=off msetfeature "verbose"
171 # do not die here, mchecksum catches download errors
172 mdownload --uri "${uri}" --dir "${outputdir}"
173
174 # unset them to be sure
175 unset uri
176 unset subdir
177 unset outputdir
178 done
179
180 # recheck md5 sums after download
181 echo
182 echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}"
183 mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 || die "md5 failed"
184 echo
185 else
186 echo -e "${COLBLUE}===${COLGREEN} All sources already fetched, nothing to do${COLDEFAULT}"
187 fi
188
189 # not needed anymore
190 unset SRC_URI
191 }
192
193 # dummy function, used if that does not exist in smage file
194 src_prepare()
195 {
196 echo "no src_prepare defined; doing nothing ..."
197 return 0
198 }
199
200 # dummy function, used if that does not exist in smage file
201 src_compile()
202 {
203 echo "no src_compile defined; doing nothing ..."
204 return 0
205 }
206
207 # dummy function, used if that does not exist in smage file
208 src_check()
209 {
210 echo "no src_check defined; doing nothing ..."
211 return 0
212 }
213
214 # dummy function, used if that does not exist in smage file
215 src_install()
216 {
217 echo "no src_install defined; doing nothing ..."
218 return 0
219 }
220
221 mlibdir()
222 {
223 local libdir=lib
224 [[ ${ARCH} = x86_64 ]] && libdir=lib64
225
226 echo "${libdir}"
227 }
228
229 mconfigure()
230 {
231 local myopts
232 if [[ ! -z ${CTARGET} ]]
233 then
234 myopts+=" --target=${CTARGET}"
235 fi
236
237 if [ -x ./configure ]
238 then
239 # if requested disable-static
240 if [[ ! -z $(./configure --help | grep -- '--.*able-static') ]]
241 then
242 if mqueryfeature '!static'
243 then
244 myopts+=" --disable-static"
245 else
246 myopts+=" --enable-static"
247 fi
248 fi
249
250 # always enable shared by default
251 if [[ ! -z $(./configure --help | grep -- '--.*able-shared') ]]
252 then
253 myopts+=" --enable-shared"
254 fi
255
256 ./configure \
257 --prefix=/usr \
258 --host=${CHOST} \
259 --build=${CHOST} \
260 --mandir=/usr/share/man \
261 --infodir=/usr/share/info \
262 --datadir=/usr/share \
263 --sysconfdir=/etc \
264 --localstatedir=/var/lib \
265 --libdir=/usr/$(mlibdir) \
266 ${myopts} \
267 "$@" || die "mconfigure failed"
268 else
269 echo "configure is not an executable ..."
270 exit 1
271 fi
272 }
273
274 minstall()
275 {
276 if [ -f ./[mM]akefile -o -f ./GNUmakefile ]
277 then
278 make prefix=${BINDIR}/usr \
279 datadir=${BINDIR}/usr/share \
280 infodir=${BINDIR}/usr/share/info \
281 localstatedir=${BINDIR}/var/lib \
282 mandir=${BINDIR}/usr/share/man \
283 sysconfdir=${BINDIR}/etc \
284 libdir=${BINDIR}/usr/$(mlibdir) \
285 "$@" install || die "minstall failed"
286 else
287 die "no Makefile found"
288 fi
289 }
290
291 mmake()
292 {
293 make ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
294 }
295
296 munpack()
297 {
298 local SRCFILE
299 local IFTAR
300 local DEST
301
302 SRCFILE=$1
303
304 if [[ -z $2 ]]
305 then
306 DEST=${BUILDDIR}
307 else
308 DEST=$2
309 fi
310
311 [[ ! -d ${DEST} ]] && install -d ${DEST}
312
313 case "${SRCFILE##*.}" in
314 bz2)
315 IFTAR="$(basename $SRCFILE .bz2)"
316 IFTAR="${IFTAR##*.}"
317 if [[ ${IFTAR} = tar ]]
318 then
319 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.bz2 unpack failed."
320 else
321 pushd ${DEST} > /dev/null
322 bzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .bz2) || die ".bz2 unpack failed."
323 popd > /dev/null
324 fi
325 ;;
326 gz)
327 IFTAR="$(basename $SRCFILE .gz)"
328 IFTAR="${IFTAR##*.}"
329 if [[ ${IFTAR} = tar ]]
330 then
331 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.gz unpack failed."
332 else
333 pushd ${DEST} > /dev/null
334 zcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .gz) || die ".gz unpack failed."
335 popd > /dev/null
336 fi
337 ;;
338 xz)
339 IFTAR="$(basename $SRCFILE .xz)"
340 IFTAR="${IFTAR##*.}"
341 if [[ ${IFTAR} = tar ]]
342 then
343 tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.xz unpack failed."
344 else
345 pushd ${DEST} > /dev/null
346 xzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .xz) || die ".xz unpack failed."
347 popd > /dev/null
348 fi
349 ;;
350 tbz2|mpks|mpk)
351 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed."
352 ;;
353 tgz)
354 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tgz unpack failed."
355 ;;
356 txz|mpkzs|mpkz)
357 tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".txz unpack failed."
358 ;;
359 rar)
360 unrar x ${SOURCEDIR}/${PNAME}/${SRCFILE} ${DEST} || die ".rar unpack failed."
361 ;;
362 zip|xpi|jar)
363 unzip ${SOURCEDIR}/${PNAME}/${SRCFILE} -d ${DEST} || die ".zip unpack failed."
364 ;;
365 rpm)
366 pushd ${DEST} > /dev/null
367 rpm2targz ${SOURCEDIR}/${PNAME}/${SRCFILE} || die "rpm2targz: .rpm unpack failed."
368 tar --no-same-owner -xvzf ${SRCFILE/.rpm/.tar.gz} || die "tar: .rpm unpack failed."
369 if [[ -f ${DEST}/${SRCFILE/.rpm/.tar.gz} ]]
370 then
371 rm ${DEST}/${SRCFILE/.rpm/.tar.gz}
372 fi
373 ;;
374 *)
375 die "munpack failed"
376 ;;
377 esac
378 }
379
380 mpatch()
381 {
382 local PATCHOPTS
383 local PATCHFILE
384 local i
385
386 PATCHOPTS=$1
387 PATCHFILE=$2
388
389 if [[ -z $2 ]]
390 then
391 PATCHFILE=$1
392
393 ## patch level auto-detection, get patch level
394 for ((i=0; i < 10; i++))
395 do
396 patch --dry-run -Np${i} -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} > /dev/null
397 if [[ $? = 0 ]]
398 then
399 PATCHOPTS="-Np${i}"
400 break
401 fi
402 done
403 fi
404
405 echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}"
406 patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE}
407 }
408
409 mlibtoolize()
410 {
411 local opts="$@"
412 [[ -z ${opts} ]] && opts="--verbose --install --force"
413
414 libtoolize ${opts} || die "running: mlibtoolize ${opts}"
415 }
416
417 mautoreconf()
418 {
419 local opts="$@"
420 [[ -z ${opts} ]] && opts="--verbose --install --force"
421
422 autoreconf ${opts} || die "running: mautoreconf ${opts}"
423 }
424
425 minstalldocs()
426 {
427 local docfiles
428 local doc
429 docfiles="$@"
430
431 if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ]
432 then
433 install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs."
434 fi
435
436 for doc in ${docfiles}
437 do
438 if [ -f ${doc} ]
439 then
440 if mqueryfeature "compressdoc"
441 then
442 cat ${doc} | gzip -9c > ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/$(basename ${doc}).gz || die "gzipping +installing ${doc}."
443 chmod 0644 ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/$(basename ${doc}).gz || die "fixing permissions of ${doc}."
444 else
445 install -m 0644 ${doc} ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "installing ${doc}."
446 fi
447 fi
448 done
449 }
450
451 mstriplibs()
452 {
453 local stripdir="$@"
454
455 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
456 [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug"
457 find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null
458 }
459
460 mstripbins()
461 {
462 local stripdir="$@"
463
464 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
465 [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug"
466 find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null
467 }
468
469 mstripstatic()
470 {
471 local stripdir="$@"
472
473 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
474 [[ -z ${STRIP_STATIC_LIB} ]] && STRIP_STATIC_LIB="--strip-debug"
475 find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "ar archive" | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_STATIC_LIB} 2> /dev/null
476 }
477
478 mstriplibtoolarchive()
479 {
480 local stripdir="$@"
481
482 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
483 find ${stripdir} ! -type d -name \*.la | xargs --no-run-if-empty file | grep "libtool library" | cut -f 1 -d : | xargs --no-run-if-empty rm -f -- 2> /dev/null
484 }
485
486 mpurgetargets()
487 {
488 local stripdir="$@"
489 local target
490
491 [[ -z ${stripdir} ]] && stripdir=${BINDIR}
492 # nothing to do in this case
493 [[ -z ${PURGE_TARGETS[*]} ]] && return
494
495 for target in ${PURGE_TARGETS[*]}
496 do
497 # check if target is a regex pattern without any slashes
498 if [[ ${target} = ${target//\/} ]]
499 then
500 find ${BINDIR} -type f -name "${target}" | xargs --no-run-if-empty rm -f -- 2> /dev/null
501 else
502 rm -f -- ${target} 2> /dev/null
503 fi
504 done
505 }
506
507 mcompressdocs()
508 {
509 local bindir="$@"
510
511 if [ -d ${bindir}/usr/share/man ]
512 then
513 echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}"
514 ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man
515 fi
516
517 if [ -d ${bindir}/usr/share/info ]
518 then
519 echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}"
520 ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info
521 fi
522 }
523
524 sminclude()
525 {
526 local i
527
528 if [[ -n "$@" ]]
529 then
530 for i in $@
531 do
532 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
533 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
534 done
535 echo
536 fi
537 }
538
539 setup_distcc_environment()
540 {
541 if [ -x /usr/bin/distcc ]
542 then
543 echo -e "${COLBLUE}---${COLGREEN} Using DistCC for compilation ...${COLDEFAULT}"
544 export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH"
545
546 export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed"
547
548 # creating distcc tempdir
549 install -o distcc -g daemon -d ${DISTCC_DIR}
550 chmod 1777 ${DISTCC_DIR}
551 fi
552 }
553
554 setup_ccache_environment()
555 {
556 if [ -x /usr/bin/ccache ]
557 then
558 echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}"
559 export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
560 fi
561 }
562
563 # fixes given dependencies to match a MAGE_TARGET
564 # fix_mage_deps -target s/depend # <-- note -target !
565 fix_mage_deps()
566 {
567 local target="$1"
568 local depend="$2"
569 local NDEPEND
570 local sym dep cat pver pname
571
572 # deps and provides are special
573 # they must be fixed to match the target
574
575 # run this only if target and depend is not empty
576 if [ -n "${target}" ] && [ -n "${depend}" ]
577 then
578 # fix DEPEND
579 while read sym dep
580 do
581 # ignore empty lines
582 [[ -z ${dep} ]] && continue
583
584 cat="$(dirname ${dep})"
585 # change if not virtual
586 if [[ ${cat} = virtual ]]
587 then
588 pname="$(basename ${dep})"
589 else
590 # fix pver to target-pver
591 # to get pname-target-pver
592
593 # doing it backwards !
594 pver="${dep##*-}"
595 # full pver
596 pname="$(basename ${dep/-${pver}/})${target}-${pver}"
597 fi
598
599 # do not add empty lines
600 if [ -z "${NDEPEND}" ]
601 then
602 NDEPEND="${sym} ${cat}/${pname}"
603 else
604 NDEPEND="${NDEPEND}
605 ${sym} ${cat}/${pname}"
606 fi
607
608 unset cat pname pver
609 done << EOF
610 ${depend}
611 EOF
612 # set NDEPEND to DEPEND
613 depend="${NDEPEND}"
614 fi
615
616 echo "${depend}"
617 }
618
619 # build_mage_script(): helper functions for regen_mage_tree()
620 # generates an mage file with given information in smage file
621 # needs at least:
622 # PNAME name of pkg
623 # PVER version
624 # PBUILD revision
625 # PCAT category of the pkg
626 # PCATEGORIE category of the pkg (deprecated, use PCAT!)
627 # STATE state of pkg stable|unstable|old
628 # DESCRIPTION a short description (opt)
629 # HOMEPAGE homepage (opt)
630 # DEPEND runtime dependencies (opt)
631 # SDEPEND adds needed deps to build the pkg (opt)
632 # PROVIDE provides a virtual (opt)
633 #
634 # special tags:
635 # PKGTYPE type of pkg
636 # INHERITS which functions get included
637 # SPECIAL_FUNCTIONS special functions which should also be added
638 # warning: they get killed before the build starts !
639 # SPLIT_PACKAGES names of all subpackages which are splitted from parent
640 # SPLIT_PACKAGE_BASE base package name for splitpackages
641 # (only in the resulting magefile}
642 #
643 # MAGE_TREE_DEST target destination of the generated tree
644 # REGEN_MAGE_TREE set to 'true' to enable this
645 #
646 # gets called with build_mage_script target
647 build_mage_script()
648 {
649 local magefile
650 local dest
651 local target
652 local split_pkg_base
653 local sym
654 local depname
655
656 # if MAGE_TREE_DEST not set use BUILDDIR
657 : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
658
659 # determinate which suffix this mage file should get, if any
660 [[ $1 = --target ]] && shift && target="-$1"
661
662 # mark package as splitpackage
663 [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
664
665 # name of magefile
666 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
667
668 # destination to magefile
669 dest="${MAGE_TREE_DEST}/${PCAT}/${PNAME}${target}/${magefile}"
670
671 # show what we are doing
672 echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
673 echo "${dest}"
674
675 install -d "$(dirname ${dest})"
676 # now build the mage file
677 > ${dest}
678
679 # pgkname and state
680 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
681 echo "STATE=\"${STATE}\"" >> ${dest}
682
683 # description and homepage
684 echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
685 echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
686
687 # special tags and vars
688 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
689
690 # echo MAGE_TARGETS ## note -target is needed !
691 echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
692
693 # split package base
694 echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
695
696 # add special vars
697 if [ -n "${SPECIAL_VARS}" ]
698 then
699 local i
700 for i in ${SPECIAL_VARS}
701 do
702 # being tricky here :)
703 echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
704 done
705 fi
706
707 # add at least all includes
708 if [ -n "${INHERITS}" ]
709 then
710 echo -n "minclude" >> ${dest}
711 local i
712 for i in ${INHERITS}
713 do
714 echo -n " ${i}" >> ${dest}
715 done
716 # a CRLF is needed here!
717 echo >> ${dest}
718 fi
719
720 # deps and provides
721 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
722 echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
723 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
724
725 # add special functions
726 if [ -n "${SPECIAL_FUNCTIONS}" ]
727 then
728 local i
729 for i in ${SPECIAL_FUNCTIONS}
730 do
731 # add to mage (quotes needed !)
732 typeset -f "${i}" >> ${dest}
733 # unset to be safe (quotes needed !)
734 #unset "${i}" <-- later to get every target built
735 done
736 fi
737
738 # pre|post-install|removes
739 typeset -f preinstall >> ${dest}
740 typeset -f postinstall >> ${dest}
741 typeset -f preremove >> ${dest}
742 typeset -f postremove >> ${dest}
743 }
744
745 regen_mage_tree()
746 {
747 local subpackage
748
749 # build them only if requested
750 if mqueryfeature regentree
751 then
752 # run it without targets
753 if [[ -n ${MAGE_TARGETS} ]]
754 then
755 # build for each target a mage file
756 # run it with several targets
757 echo
758 for subpackage in ${MAGE_TARGETS}
759 do
760 build_mage_script --target "${subpackage}"
761 done
762 echo
763
764 # run it for splitpackages
765 elif [[ -n ${SPLIT_PACKAGES} ]]
766 then
767 local split_pkg_base="${PNAME}"
768 # save smage environment
769 split_save_variables
770 # build for each subpackage a mage file
771 # run it with several targets
772 echo
773 for subpackage in ${SPLIT_PACKAGES}
774 do
775 # get the right variables for the split
776 export PNAME="${subpackage}"
777 split_info_${subpackage}
778 # get the preinstall etc
779 split_export_inherits ${subpackage}
780 build_mage_script --split-pkg-base "${split_pkg_base}"
781 # delete split preinstall etc
782 split_delete_inherits ${subpackage}
783 # restore smage environment
784 split_restore_variables
785 done
786 echo
787 # unset all saved smage variables
788 split_unset_variables
789
790 else
791 echo
792 build_mage_script
793 echo
794 fi
795 fi
796
797 # now unset all uneeded vars to be safe
798 # unset PKGNAME <-- don't do that; smage needs this var
799 # unset to be safe (quotes needed !)
800 # for i in ${SPECIAL_FUNCTIONS}
801 # do
802 # unset "${i}"
803 # done
804 unset SPECIAL_FUNCTIONS
805 # for i in ${SPECIAL_VARS}
806 # do
807 # unset "${i}"
808 # done
809 unset SPECIAL_VARS
810 unset STATE
811 unset DESCRIPTION
812 unset HOMEPAGE
813 # unset PKGTYPE <-- don't do that either; smage needs this var
814 unset INHERITS
815 unset DEPEND
816 unset SDEPEND
817 unset PROVIDE
818 unset preinstall
819 unset postinstall
820 unset preremove
821 unset postremove
822 }
823
824 split_save_variables()
825 {
826 export SAVED_PNAME="${PNAME}"
827 export SAVED_PVER="${PVER}"
828 export SAVED_PBUILD="${PBUILD}"
829 export SAVED_PCAT="${PCAT}"
830 export SAVED_DESCRIPTION="${DESCRIPTION}"
831 export SAVED_HOMEPAGE="${HOMEPAGE}"
832 export SAVED_SPECIAL_VARS="${SPECIAL_VARS}"
833 export SAVED_STATE="${STATE}"
834 export SAVED_PKGTYPE="${PKGTYPE}"
835 export SAVED_INHERITS="${INHERITS}"
836 export SAVED_DEPEND="${DEPEND}"
837 export SAVED_SDEPEND="${SDEPEND}"
838 export SAVED_PROVIDE="${PROVIDE}"
839 export SAVED_PKGTYPE="${PKGTYPE}"
840
841 # special handling needed for mage features
842 # pkgbuild
843 mqueryfeature "pkgbuild" && export SAVED_FEATURE_PKGBUILD="pkgbuild"
844 mqueryfeature "!pkgbuild" && export SAVED_FEATURE_PKGBUILD="!pkgbuild"
845 # strip
846 mqueryfeature "strip" && export SAVED_FEATURE_STRIP="strip"
847 mqueryfeature "!strip" && export SAVED_FEATURE_STRIP="!strip"
848 # libtool
849 mqueryfeature "libtool" && export SAVED_FEATURE_LIBTOOL="libtool"
850 mqueryfeature "!libtool" && export SAVED_FEATURE_LIBTOOL="!libtool"
851 # compressdoc
852 mqueryfeature "compressdoc" && export SAVED_FEATURE_COMPRESSDOC="compressdoc"
853 mqueryfeature "!compressdoc" && export SAVED_FEATURE_COMPRESSDOC="!compressdoc"
854
855 # bindir too
856 export SAVED_BINDIR="${BINDIR}"
857
858 # export the SPLIT_PACKAGE_BASE
859 export SPLIT_PACKAGE_BASE="${SAVED_PNAME}"
860
861 # functions
862 if [[ ! -z $(typeset -f preinstall) ]]
863 then
864 # rename the old one
865 local saved_preinstall
866 saved_preinstall=SAVED_$(typeset -f preinstall)
867 eval "${saved_preinstall}"
868 export -f SAVED_preinstall
869 fi
870
871 if [[ ! -z $(typeset -f postinstall) ]]
872 then
873 # rename the old one
874 local saved_postinstall
875 saved_postinstall=SAVED_$(typeset -f postinstall)
876 eval "${saved_postinstall}"
877 export -f SAVED_postinstall
878 fi
879
880 if [[ ! -z $(typeset -f preremove) ]]
881 then
882 # rename the old one
883 local saved_preremove
884 saved_preremove=SAVED_$(typeset -f preremove)
885 eval "${saved_preremove}"
886 export -f SAVED_preremove
887 fi
888
889 if [[ ! -z $(typeset -f postremove) ]]
890 then
891 # rename the old one
892 local saved_postremove
893 saved_postremove=SAVED_$(typeset -f postremove)
894 eval "${saved_postremove}"
895 export -f SAVED_postremove
896 fi
897 }
898
899 split_restore_variables()
900 {
901 export PNAME="${SAVED_PNAME}"
902 export PVER="${SAVED_PVER}"
903 export PBUILD="${SAVED_PBUILD}"
904 export PCAT="${SAVED_PCAT}"
905 export DESCRIPTION="${SAVED_DESCRIPTION}"
906 export HOMEPAGE="${SAVED_HOMEPAGE}"
907 export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"
908 export STATE="${SAVED_STATE}"
909 export PKGTYPE="${SAVED_PKGTYPE}"
910 export INHERITS="${SAVED_INHERITS}"
911 export DEPEND="${SAVED_DEPEND}"
912 export SDEPEND="${SAVED_SDEPEND}"
913 export PROVIDE="${SAVED_PROVIDE}"
914 export PKGTYPE="${SAVED_PKGTYPE}"
915
916 # special handling needed for mage features
917 # pkgbuild
918 FVERBOSE=off msetfeature "${SAVED_FEATURE_PKGBUILD}"
919 # strip
920 FVERBOSE=off msetfeature "${SAVED_FEATURE_STRIP}"
921 # libtool
922 FVERBOSE=off msetfeature "${SAVED_FEATURE_LIBTOOL}"
923 # compressdoc
924 FVERBOSE=off msetfeature "${SAVED_FEATURE_COMPRESSDOC}"
925
926 # bindir too
927 export BINDIR="${SAVED_BINDIR}"
928
929 # functions
930 if [[ ! -z $(typeset -f SAVED_preinstall) ]]
931 then
932 # rename the old one
933 local saved_preinstall
934 saved_preinstall=$(typeset -f SAVED_preinstall)
935 eval "${saved_preinstall/SAVED_/}"
936 export -f preinstall
937 fi
938
939 if [[ ! -z $(typeset -f SAVED_postinstall) ]]
940 then
941 # rename the old one
942 local saved_postinstall
943 saved_postinstall=$(typeset -f SAVED_postinstall)
944 eval "${saved_postinstall/SAVED_/}"
945 export -f postinstall
946 fi
947
948 if [[ ! -z $(typeset -f SAVED_preremove) ]]
949 then
950 # rename the old one
951 local saved_preremove
952 saved_preremove=$(typeset -f SAVED_preremove)
953 eval "${saved_preremove/SAVED_/}"
954 export -f preremove
955 fi
956
957 if [[ ! -z $(typeset -f SAVED_postremove) ]]
958 then
959 # rename the old one
960 local saved_postremove
961 saved_postremove=$(typeset -f SAVED_postremove)
962 eval "${saved_postremove/SAVED_/}"
963 export -f postremove
964 fi
965 }
966
967 split_unset_variables()
968 {
969 # unset saved vars; not needed anymore
970 unset SAVED_PNAME
971 unset SAVED_PVER
972 unset SAVED_PBUILD
973 unset SAVED_PCAT
974 unset SAVED_DESCRIPTION
975 unset SAVED_HOMEPAGE
976 unset SAVED_SPECIAL_VARS
977 unset SAVED_STATE
978 unset SAVED_PKGTYPE
979 unset SAVED_INHERITS
980 unset SAVED_DEPEND
981 unset SAVED_SDEPEND
982 unset SAVED_PROVIDE
983 unset SAVED_BINDIR
984 unset SAVED_PKGTYPE
985 unset SAVED_FEATURE_PKGBUILD
986 unset SAVED_FEATURE_STRIP
987 unset SAVED_FEATURE_LIBTOOL
988 unset SAVED_FEATURE_COMPRESSDOC
989 unset SPLIT_PACKAGE_BASE
990 unset -f SAVED_preinstall
991 unset -f SAVED_postinstall
992 unset -f SAVED_preremove
993 unset -f SAVED_postremove
994 }
995
996 split_export_inherits()
997 {
998 local subpackage="$1"
999 local func
1000 local newfunc
1001
1002 for func in preinstall postinstall preremove postremove
1003 do
1004 if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
1005 then
1006 newfunc=$(typeset -f ${func}_${subpackage})
1007 newfunc="${newfunc/_${subpackage} (/ (}"
1008 eval "${newfunc}"
1009 fi
1010 done
1011 }
1012
1013 split_delete_inherits()
1014 {
1015 local subpackage="$1"
1016 local func
1017
1018 for func in preinstall postinstall preremove postremove
1019 do
1020 if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
1021 then
1022 unset -f ${func}
1023 fi
1024 done
1025 }
1026
1027 export_inherits()
1028 {
1029 local include="$1"
1030 shift
1031
1032 while [ "$1" ]
1033 do
1034 local functions="$1"
1035
1036 # sanity checks
1037 [ -z "${include}" ] && die "export_inherits(): \$include not given."
1038 [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
1039
1040 eval "${functions}() { ${include}_${functions} ; }"
1041
1042 # debug
1043 [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
1044
1045 shift
1046 done
1047 }
1048
1049 generate_package_md5sum()
1050 {
1051 local dest
1052 local pcat
1053 local pname
1054 local pver
1055 local pbuild
1056 local parch
1057 local target
1058 local pkgname
1059
1060 # very basic getops
1061 for i in $*
1062 do
1063 case $1 in
1064 --pcat|-c) shift; pcat="$1" ;;
1065 --pname|-n) shift; pname="$1" ;;
1066 --pver|-v) shift; pver="$1" ;;
1067 --pbuild|-b) shift; pbuild="$1" ;;
1068 --parch|a) shift; parch="$1" ;;
1069 --target|t) shift; target="$1" ;;
1070 esac
1071 shift
1072 done
1073
1074 # sanity checks; abort if not given
1075 [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
1076 [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
1077 [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
1078 [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
1079 [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
1080
1081 # check needed global vars
1082 [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
1083 [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
1084
1085 # fix target as it may be empty !
1086 [ -n "${target}" ] && target="-${target}"
1087
1088 # build pkgname
1089 pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
1090
1091 # build pkg-md5-sum only if requested
1092 if mqueryfeature regentree
1093 then
1094 echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}"
1095
1096 # abort if not exist
1097 if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
1098 then
1099 echo -e "${COLRED}! exists${COLDEFAULT}"
1100 return 0
1101 fi
1102
1103 # if MAGE_TREE_DEST not set use BUILDDIR
1104 : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
1105
1106 # setup md5 dir
1107 dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"
1108 install -d ${dest}
1109
1110 # gen md5sum
1111 ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
1112 > ${dest}/${pkgname}.md5
1113 echo -e "${COLGREEN}done${COLDEFAULT}"
1114 fi
1115 }
1116
1117 source_pkg_build()
1118 {
1119 if [[ ${PKGTYPE} = virtual ]]
1120 then
1121 echo "Virtual package detected; src-pkg-tarball not necessary ..."
1122 return 0
1123 fi
1124
1125 if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
1126 then
1127 echo "No SRC_URI defined; src-pkg-tarball not necessary ..."
1128 return 0
1129 fi
1130
1131 [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly."
1132
1133 echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}"
1134
1135 # include the smage2 file
1136 cp ${SMAGENAME} ${SOURCEDIR}/${PNAME}
1137
1138 ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; )
1139 [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR}
1140 mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX}
1141
1142 echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}"
1143 }
1144
1145 step_by_step()
1146 {
1147 if mqueryfeature stepbystep
1148 then
1149 echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}"
1150 echo "Press [enter] to continue"
1151 read
1152 fi
1153 }
1154
1155 resume_stamp()
1156 {
1157 local step="$1"
1158 [[ ! -d ${BUILDDIR}/.stamps ]] && install -d ${BUILDDIR}/.stamps
1159 touch ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step}
1160 }
1161
1162 run_resume()
1163 {
1164 local step="$1"
1165
1166 if mqueryfeature "resume" && [[ -f ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step} ]]
1167 then
1168 echo -e "${COLMAGENTA}${step} already processed; doing nothing${COLDEFAULT}"
1169 return 0
1170 else
1171 return 1
1172 fi
1173 }