Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1648 - (show annotations) (download) (as text)
Fri Jan 13 20:51:18 2012 UTC (12 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 27894 byte(s)
-honor license information
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 # LICENSE license information of the pkg (opt)
631 # DEPEND runtime dependencies (opt)
632 # SDEPEND adds needed deps to build the pkg (opt)
633 # PROVIDE provides a virtual (opt)
634 #
635 # special tags:
636 # PKGTYPE type of pkg
637 # INHERITS which functions get included
638 # SPECIAL_FUNCTIONS special functions which should also be added
639 # warning: they get killed before the build starts !
640 # SPLIT_PACKAGES names of all subpackages which are splitted from parent
641 # SPLIT_PACKAGE_BASE base package name for splitpackages
642 # (only in the resulting magefile}
643 #
644 # MAGE_TREE_DEST target destination of the generated tree
645 # REGEN_MAGE_TREE set to 'true' to enable this
646 #
647 # gets called with build_mage_script target
648 build_mage_script()
649 {
650 local magefile
651 local dest
652 local target
653 local split_pkg_base
654 local sym
655 local depname
656
657 # if MAGE_TREE_DEST not set use BUILDDIR
658 : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
659
660 # determinate which suffix this mage file should get, if any
661 [[ $1 = --target ]] && shift && target="-$1"
662
663 # mark package as splitpackage
664 [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
665
666 # name of magefile
667 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
668
669 # destination to magefile
670 dest="${MAGE_TREE_DEST}/${PCAT}/${PNAME}${target}/${magefile}"
671
672 # show what we are doing
673 echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
674 echo "${dest}"
675
676 install -d "$(dirname ${dest})"
677 # now build the mage file
678 > ${dest}
679
680 # pgkname and state
681 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
682 echo "STATE=\"${STATE}\"" >> ${dest}
683
684 # description and homepage
685 echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
686 echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
687
688 # license information
689 echo "LICENSE=\"${LICENSE}\"" >> ${dest}
690
691 # special tags and vars
692 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
693
694 # echo MAGE_TARGETS ## note -target is needed !
695 echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
696
697 # split package base
698 echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
699
700 # add special vars
701 if [ -n "${SPECIAL_VARS}" ]
702 then
703 local i
704 for i in ${SPECIAL_VARS}
705 do
706 # being tricky here :)
707 echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
708 done
709 fi
710
711 # add at least all includes
712 if [ -n "${INHERITS}" ]
713 then
714 echo -n "minclude" >> ${dest}
715 local i
716 for i in ${INHERITS}
717 do
718 echo -n " ${i}" >> ${dest}
719 done
720 # a CRLF is needed here!
721 echo >> ${dest}
722 fi
723
724 # deps and provides
725 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
726 echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
727 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
728
729 # add special functions
730 if [ -n "${SPECIAL_FUNCTIONS}" ]
731 then
732 local i
733 for i in ${SPECIAL_FUNCTIONS}
734 do
735 # add to mage (quotes needed !)
736 typeset -f "${i}" >> ${dest}
737 # unset to be safe (quotes needed !)
738 #unset "${i}" <-- later to get every target built
739 done
740 fi
741
742 # pre|post-install|removes
743 typeset -f preinstall >> ${dest}
744 typeset -f postinstall >> ${dest}
745 typeset -f preremove >> ${dest}
746 typeset -f postremove >> ${dest}
747 }
748
749 regen_mage_tree()
750 {
751 local subpackage
752
753 # build them only if requested
754 if mqueryfeature regentree
755 then
756 # run it without targets
757 if [[ -n ${MAGE_TARGETS} ]]
758 then
759 # build for each target a mage file
760 # run it with several targets
761 echo
762 for subpackage in ${MAGE_TARGETS}
763 do
764 build_mage_script --target "${subpackage}"
765 done
766 echo
767
768 # run it for splitpackages
769 elif [[ -n ${SPLIT_PACKAGES} ]]
770 then
771 local split_pkg_base="${PNAME}"
772 # save smage environment
773 split_save_variables
774 # build for each subpackage a mage file
775 # run it with several targets
776 echo
777 for subpackage in ${SPLIT_PACKAGES}
778 do
779 # get the right variables for the split
780 export PNAME="${subpackage}"
781 split_info_${subpackage}
782 # get the preinstall etc
783 split_export_inherits ${subpackage}
784 build_mage_script --split-pkg-base "${split_pkg_base}"
785 # delete split preinstall etc
786 split_delete_inherits ${subpackage}
787 # restore smage environment
788 split_restore_variables
789 done
790 echo
791 # unset all saved smage variables
792 split_unset_variables
793
794 else
795 echo
796 build_mage_script
797 echo
798 fi
799 fi
800
801 # now unset all uneeded vars to be safe
802 # unset PKGNAME <-- don't do that; smage needs this var
803 # unset to be safe (quotes needed !)
804 # for i in ${SPECIAL_FUNCTIONS}
805 # do
806 # unset "${i}"
807 # done
808 unset SPECIAL_FUNCTIONS
809 # for i in ${SPECIAL_VARS}
810 # do
811 # unset "${i}"
812 # done
813 unset SPECIAL_VARS
814 unset STATE
815 unset DESCRIPTION
816 unset HOMEPAGE
817 # unset PKGTYPE <-- don't do that either; smage needs this var
818 unset INHERITS
819 unset DEPEND
820 unset SDEPEND
821 unset PROVIDE
822 unset preinstall
823 unset postinstall
824 unset preremove
825 unset postremove
826 }
827
828 split_save_variables()
829 {
830 export SAVED_PNAME="${PNAME}"
831 export SAVED_PVER="${PVER}"
832 export SAVED_PBUILD="${PBUILD}"
833 export SAVED_PCAT="${PCAT}"
834 export SAVED_DESCRIPTION="${DESCRIPTION}"
835 export SAVED_HOMEPAGE="${HOMEPAGE}"
836 export SAVED_SPECIAL_VARS="${SPECIAL_VARS}"
837 export SAVED_STATE="${STATE}"
838 export SAVED_PKGTYPE="${PKGTYPE}"
839 export SAVED_INHERITS="${INHERITS}"
840 export SAVED_DEPEND="${DEPEND}"
841 export SAVED_SDEPEND="${SDEPEND}"
842 export SAVED_PROVIDE="${PROVIDE}"
843 export SAVED_PKGTYPE="${PKGTYPE}"
844
845 # special handling needed for mage features
846 # pkgbuild
847 mqueryfeature "pkgbuild" && export SAVED_FEATURE_PKGBUILD="pkgbuild"
848 mqueryfeature "!pkgbuild" && export SAVED_FEATURE_PKGBUILD="!pkgbuild"
849 # strip
850 mqueryfeature "strip" && export SAVED_FEATURE_STRIP="strip"
851 mqueryfeature "!strip" && export SAVED_FEATURE_STRIP="!strip"
852 # libtool
853 mqueryfeature "libtool" && export SAVED_FEATURE_LIBTOOL="libtool"
854 mqueryfeature "!libtool" && export SAVED_FEATURE_LIBTOOL="!libtool"
855 # compressdoc
856 mqueryfeature "compressdoc" && export SAVED_FEATURE_COMPRESSDOC="compressdoc"
857 mqueryfeature "!compressdoc" && export SAVED_FEATURE_COMPRESSDOC="!compressdoc"
858
859 # bindir too
860 export SAVED_BINDIR="${BINDIR}"
861
862 # export the SPLIT_PACKAGE_BASE
863 export SPLIT_PACKAGE_BASE="${SAVED_PNAME}"
864
865 # functions
866 if [[ ! -z $(typeset -f preinstall) ]]
867 then
868 # rename the old one
869 local saved_preinstall
870 saved_preinstall=SAVED_$(typeset -f preinstall)
871 eval "${saved_preinstall}"
872 export -f SAVED_preinstall
873 fi
874
875 if [[ ! -z $(typeset -f postinstall) ]]
876 then
877 # rename the old one
878 local saved_postinstall
879 saved_postinstall=SAVED_$(typeset -f postinstall)
880 eval "${saved_postinstall}"
881 export -f SAVED_postinstall
882 fi
883
884 if [[ ! -z $(typeset -f preremove) ]]
885 then
886 # rename the old one
887 local saved_preremove
888 saved_preremove=SAVED_$(typeset -f preremove)
889 eval "${saved_preremove}"
890 export -f SAVED_preremove
891 fi
892
893 if [[ ! -z $(typeset -f postremove) ]]
894 then
895 # rename the old one
896 local saved_postremove
897 saved_postremove=SAVED_$(typeset -f postremove)
898 eval "${saved_postremove}"
899 export -f SAVED_postremove
900 fi
901 }
902
903 split_restore_variables()
904 {
905 export PNAME="${SAVED_PNAME}"
906 export PVER="${SAVED_PVER}"
907 export PBUILD="${SAVED_PBUILD}"
908 export PCAT="${SAVED_PCAT}"
909 export DESCRIPTION="${SAVED_DESCRIPTION}"
910 export HOMEPAGE="${SAVED_HOMEPAGE}"
911 export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"
912 export STATE="${SAVED_STATE}"
913 export PKGTYPE="${SAVED_PKGTYPE}"
914 export INHERITS="${SAVED_INHERITS}"
915 export DEPEND="${SAVED_DEPEND}"
916 export SDEPEND="${SAVED_SDEPEND}"
917 export PROVIDE="${SAVED_PROVIDE}"
918 export PKGTYPE="${SAVED_PKGTYPE}"
919
920 # special handling needed for mage features
921 # pkgbuild
922 FVERBOSE=off msetfeature "${SAVED_FEATURE_PKGBUILD}"
923 # strip
924 FVERBOSE=off msetfeature "${SAVED_FEATURE_STRIP}"
925 # libtool
926 FVERBOSE=off msetfeature "${SAVED_FEATURE_LIBTOOL}"
927 # compressdoc
928 FVERBOSE=off msetfeature "${SAVED_FEATURE_COMPRESSDOC}"
929
930 # bindir too
931 export BINDIR="${SAVED_BINDIR}"
932
933 # functions
934 if [[ ! -z $(typeset -f SAVED_preinstall) ]]
935 then
936 # rename the old one
937 local saved_preinstall
938 saved_preinstall=$(typeset -f SAVED_preinstall)
939 eval "${saved_preinstall/SAVED_/}"
940 export -f preinstall
941 fi
942
943 if [[ ! -z $(typeset -f SAVED_postinstall) ]]
944 then
945 # rename the old one
946 local saved_postinstall
947 saved_postinstall=$(typeset -f SAVED_postinstall)
948 eval "${saved_postinstall/SAVED_/}"
949 export -f postinstall
950 fi
951
952 if [[ ! -z $(typeset -f SAVED_preremove) ]]
953 then
954 # rename the old one
955 local saved_preremove
956 saved_preremove=$(typeset -f SAVED_preremove)
957 eval "${saved_preremove/SAVED_/}"
958 export -f preremove
959 fi
960
961 if [[ ! -z $(typeset -f SAVED_postremove) ]]
962 then
963 # rename the old one
964 local saved_postremove
965 saved_postremove=$(typeset -f SAVED_postremove)
966 eval "${saved_postremove/SAVED_/}"
967 export -f postremove
968 fi
969 }
970
971 split_unset_variables()
972 {
973 # unset saved vars; not needed anymore
974 unset SAVED_PNAME
975 unset SAVED_PVER
976 unset SAVED_PBUILD
977 unset SAVED_PCAT
978 unset SAVED_DESCRIPTION
979 unset SAVED_HOMEPAGE
980 unset SAVED_SPECIAL_VARS
981 unset SAVED_STATE
982 unset SAVED_PKGTYPE
983 unset SAVED_INHERITS
984 unset SAVED_DEPEND
985 unset SAVED_SDEPEND
986 unset SAVED_PROVIDE
987 unset SAVED_BINDIR
988 unset SAVED_PKGTYPE
989 unset SAVED_FEATURE_PKGBUILD
990 unset SAVED_FEATURE_STRIP
991 unset SAVED_FEATURE_LIBTOOL
992 unset SAVED_FEATURE_COMPRESSDOC
993 unset SPLIT_PACKAGE_BASE
994 unset -f SAVED_preinstall
995 unset -f SAVED_postinstall
996 unset -f SAVED_preremove
997 unset -f SAVED_postremove
998 }
999
1000 split_export_inherits()
1001 {
1002 local subpackage="$1"
1003 local func
1004 local newfunc
1005
1006 for func in preinstall postinstall preremove postremove
1007 do
1008 if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
1009 then
1010 newfunc=$(typeset -f ${func}_${subpackage})
1011 newfunc="${newfunc/_${subpackage} (/ (}"
1012 eval "${newfunc}"
1013 fi
1014 done
1015 }
1016
1017 split_delete_inherits()
1018 {
1019 local subpackage="$1"
1020 local func
1021
1022 for func in preinstall postinstall preremove postremove
1023 do
1024 if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
1025 then
1026 unset -f ${func}
1027 fi
1028 done
1029 }
1030
1031 export_inherits()
1032 {
1033 local include="$1"
1034 shift
1035
1036 while [ "$1" ]
1037 do
1038 local functions="$1"
1039
1040 # sanity checks
1041 [ -z "${include}" ] && die "export_inherits(): \$include not given."
1042 [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
1043
1044 eval "${functions}() { ${include}_${functions} ; }"
1045
1046 # debug
1047 [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
1048
1049 shift
1050 done
1051 }
1052
1053 generate_package_md5sum()
1054 {
1055 local dest
1056 local pcat
1057 local pname
1058 local pver
1059 local pbuild
1060 local parch
1061 local target
1062 local pkgname
1063
1064 # very basic getops
1065 for i in $*
1066 do
1067 case $1 in
1068 --pcat|-c) shift; pcat="$1" ;;
1069 --pname|-n) shift; pname="$1" ;;
1070 --pver|-v) shift; pver="$1" ;;
1071 --pbuild|-b) shift; pbuild="$1" ;;
1072 --parch|a) shift; parch="$1" ;;
1073 --target|t) shift; target="$1" ;;
1074 esac
1075 shift
1076 done
1077
1078 # sanity checks; abort if not given
1079 [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
1080 [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
1081 [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
1082 [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
1083 [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
1084
1085 # check needed global vars
1086 [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
1087 [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
1088
1089 # fix target as it may be empty !
1090 [ -n "${target}" ] && target="-${target}"
1091
1092 # build pkgname
1093 pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
1094
1095 # build pkg-md5-sum only if requested
1096 if mqueryfeature regentree
1097 then
1098 echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}"
1099
1100 # abort if not exist
1101 if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
1102 then
1103 echo -e "${COLRED}! exists${COLDEFAULT}"
1104 return 0
1105 fi
1106
1107 # if MAGE_TREE_DEST not set use BUILDDIR
1108 : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
1109
1110 # setup md5 dir
1111 dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"
1112 install -d ${dest}
1113
1114 # gen md5sum
1115 ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
1116 > ${dest}/${pkgname}.md5
1117 echo -e "${COLGREEN}done${COLDEFAULT}"
1118 fi
1119 }
1120
1121 source_pkg_build()
1122 {
1123 if [[ ${PKGTYPE} = virtual ]]
1124 then
1125 echo "Virtual package detected; src-pkg-tarball not necessary ..."
1126 return 0
1127 fi
1128
1129 if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
1130 then
1131 echo "No SRC_URI defined; src-pkg-tarball not necessary ..."
1132 return 0
1133 fi
1134
1135 [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly."
1136
1137 echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}"
1138
1139 # include the smage2 file
1140 cp ${SMAGENAME} ${SOURCEDIR}/${PNAME}
1141
1142 ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; )
1143 [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR}
1144 mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX}
1145
1146 echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}"
1147 }
1148
1149 step_by_step()
1150 {
1151 if mqueryfeature stepbystep
1152 then
1153 echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}"
1154 echo "Press [enter] to continue"
1155 read
1156 fi
1157 }
1158
1159 resume_stamp()
1160 {
1161 local step="$1"
1162 [[ ! -d ${BUILDDIR}/.stamps ]] && install -d ${BUILDDIR}/.stamps
1163 touch ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step}
1164 }
1165
1166 run_resume()
1167 {
1168 local step="$1"
1169
1170 if mqueryfeature "resume" && [[ -f ${BUILDDIR}/.stamps/smage-${PKGNAME}-${step} ]]
1171 then
1172 echo -e "${COLMAGENTA}${step} already processed; doing nothing${COLDEFAULT}"
1173 return 0
1174 else
1175 return 1
1176 fi
1177 }