Magellan Linux

Contents of /branches/mage-next/src/smage2.functions.sh.in

Parent Directory Parent Directory | Revision Log Revision Log


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