Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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