Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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