Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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