Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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