Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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