Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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