Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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