Magellan Linux

Annotation of /branches/mage-next/src/smage2.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1591 - (hide annotations) (download) (as text)
Thu Dec 29 15:15:05 2011 UTC (12 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/smage2.sh
File MIME type: application/x-sh
File size: 41121 byte(s)
-more informative messages in default src_* functions
1 niro 24 #!/bin/bash
2 niro 1571 # $Id$
3 niro 24
4     # compiles/installs .smage2 source install scripts
5     # needs pkgbuild_dir (mage)
6    
7 niro 1571 # TODO: record dynlib, gz | xz database
8 niro 24
9    
10 niro 419 # set default user mage.rc
11     : ${MAGERC="/etc/mage.rc"}
12    
13 niro 169 # export default C locale
14     export LC_ALL=C
15    
16 niro 439 source /etc/mage.rc.global
17 niro 419 source ${MAGERC}
18 niro 1273 source ${MLIBDIR}/mage4.functions.sh
19 niro 24
20 niro 1589 ## setup ##
21     SMAGENAME="$1"
22     SMAGEVERSION="$(< ${MLIBDIR}/version)"
23    
24 niro 347 # set PKGDIR and BUILDDIR and BINDIR to MROOT
25     if [[ -n ${MROOT} ]]
26     then
27     export PKGDIR=${MROOT}/${PKGDIR}
28     export BUILDDIR=${MROOT}/${BUILDDIR}
29     export BINDIR=${MROOT}/${BINDIR}
30     fi
31    
32 niro 1346 # sources the smage file and uses state from distribution file if exist
33     # may helpful for repository support later on
34     smagesource()
35     {
36     local file="$1"
37     local mystate
38     local mycodename
39    
40     source ${file}
41    
42     [[ -n ${STATE} ]] && mystate="${STATE}"
43 niro 1349
44     # do not overide if local state was broken or disabled!
45     case ${STATE} in
46     broken) return ;;
47     disabled) return ;;
48     esac
49    
50 niro 1346 if [ -f ${SMAGESCRIPTSDIR}/distribution ]
51     then
52     source ${SMAGESCRIPTSDIR}/distribution
53     [[ -n ${STATE} ]] && mystate="${STATE}"
54     fi
55     # now switch state and export it
56     STATE="${mystate}"
57     }
58    
59 niro 306 showversion()
60     {
61 niro 24 echo -en "Magellan Source Install v${SMAGEVERSION} "
62     echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
63     }
64    
65 niro 306 die()
66     {
67 niro 24 xtitleclean
68 niro 413 echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
69 niro 24 echo "SMAGE failed: $@"
70     exit 1
71     }
72    
73 niro 941 die_pipestatus()
74     {
75 niro 943 # the status change if we do any parameter declarations!!
76     # dont do this anymore, keep this in mind!
77     #
78     # local pos="$1"
79     # local comment="$2"
80     #
81     # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}"
82     #
83     [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2"
84 niro 941 }
85    
86 niro 306 xtitle()
87     {
88     if [[ ${TERM} = xterm ]]
89 niro 24 then
90     echo -ne "\033]0;[sMage: $@]\007"
91     fi
92     return 0
93     }
94    
95 niro 306 xtitleclean()
96     {
97     if [[ ${TERM} = xterm ]]
98 niro 24 then
99     echo -ne "\033]0;\007"
100     fi
101     return 0
102     }
103    
104 niro 306 syncsmage2()
105     {
106 niro 24 xtitle "Updating smage2-script tree ..."
107     local i
108     for i in ${SMAGE2RSYNC}
109     do
110 niro 386 rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR}
111 niro 306 if [[ $? = 0 ]]
112 niro 24 then
113     break
114     else
115     continue
116     fi
117     done
118 niro 306
119     # clean up backup files (foo~)
120 niro 24 find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';'
121 niro 306
122 niro 24 xtitleclean
123     }
124    
125 niro 59 # $1 filename
126 niro 306 get_db_md5_sum()
127     {
128 niro 59 local DB_FILE
129     local MD5_FILE
130     local i
131    
132     DB_ENTRY="$(basename $1)"
133     MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})"
134    
135     i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)"
136    
137     echo "${i}"
138     }
139    
140 niro 306 download_sources()
141     {
142 niro 61 [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0
143 niro 59
144 niro 1580 local count=${#SRC_URI[*]}
145     local uri
146     local subdir
147     local outputdir
148     local db_md5_file="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
149     local fetching
150     local i
151 niro 59
152     # check if FETCHING is needed
153 niro 1580 if mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5
154 niro 59 then
155 niro 439 # md5's ok, no fetching needed
156 niro 1580 fetching=false
157 niro 59 else
158 niro 1580 fetching=true
159 niro 59 fi
160 niro 306
161 niro 1580 if [[ ${fetching} = true ]]
162     then
163     for ((i=0; i < count; i++))
164     do
165     # url to file
166     uri="${SRC_URI[${i}]%%' '*}"
167 niro 59
168 niro 1580 # subdir in sources dir; the my_SRCI_URI file goes to there
169     subdir="${SRC_URI[${i}]##*' '}"
170 niro 66
171 niro 1580 # if $subdir is not equal with $uri then an other dir is used
172     if [[ ${uri} != ${subdir} ]]
173 niro 59 then
174 niro 1580 outputdir="${SOURCEDIR}/${PNAME}/${subdir}"
175     else
176     outputdir="${SOURCEDIR}/${PNAME}"
177 niro 59 fi
178 niro 306
179 niro 1580 echo -e "${COLBLUE}==>${COLGREEN} fetching ${uri}${COLDEFAULT}"
180     mdownload --uri "${uri}" --dir "${outputdir}" || die "Could not download '${uri}'"
181 niro 59
182 niro 1580 # unset them to be sure
183     unset uri
184     unset subdir
185     unset outputdir
186     done
187 niro 59
188 niro 1580 # recheck md5 sums after download
189     echo
190     echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}"
191     mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 || die "md5 failed"
192     echo
193     else
194     echo -e "${COLBLUE}===${COLGREEN} All sources already fetched, nothing to do${COLDEFAULT}"
195     fi
196    
197 niro 59 # not needed anymore
198     unset SRC_URI
199     }
200    
201 niro 1573 # dummy function, used if that does not exist in smage file
202 niro 306 src_prepare()
203     {
204 niro 1591 + echo "no src_prepare defined; doing nothing ..."
205 niro 24 return 0
206     }
207    
208 niro 1573 # dummy function, used if that does not exist in smage file
209 niro 1577 src_compile()
210 niro 1575 {
211 niro 1591 echo "no src_compile defined; doing nothing ..."
212 niro 1575 return 0
213     }
214    
215     # dummy function, used if that does not exist in smage file
216 niro 1577 src_check()
217 niro 306 {
218 niro 1591 echo "no src_check defined; doing nothing ..."
219 niro 24 return 0
220     }
221    
222 niro 1573 # dummy function, used if that does not exist in smage file
223 niro 306 src_install()
224     {
225 niro 1591 echo "no src_install defined; doing nothing ..."
226 niro 24 return 0
227     }
228    
229 niro 351 mlibdir()
230     {
231     local libdir=lib
232     [[ ${ARCH} = x86_64 ]] && libdir=lib64
233    
234     echo "${libdir}"
235     }
236    
237 niro 306 mconfigure()
238     {
239 niro 24 if [ -x ./configure ]
240     then
241 niro 306 ./configure \
242     --prefix=/usr \
243     --host=${CHOST} \
244 niro 833 --build=${CHOST} \
245 niro 306 --mandir=/usr/share/man \
246     --infodir=/usr/share/info \
247     --datadir=/usr/share \
248     --sysconfdir=/etc \
249     --localstatedir=/var/lib \
250 niro 351 --libdir=/usr/$(mlibdir) \
251 niro 306 "$@" || die "mconfigure failed"
252 niro 24 else
253     echo "configure is not an executable ..."
254     exit 1
255     fi
256     }
257    
258 niro 306 minstall()
259     {
260     if [ -f ./[mM]akefile -o -f ./GNUmakefile ]
261     then
262 niro 24 make prefix=${BINDIR}/usr \
263     datadir=${BINDIR}/usr/share \
264     infodir=${BINDIR}/usr/share/info \
265     localstatedir=${BINDIR}/var/lib \
266     mandir=${BINDIR}/usr/share/man \
267     sysconfdir=${BINDIR}/etc \
268 niro 351 libdir=${BINDIR}/usr/$(mlibdir) \
269 niro 24 "$@" install || die "minstall failed"
270     else
271     die "no Makefile found"
272     fi
273     }
274    
275 niro 306 mmake()
276     {
277 niro 24 make ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
278     }
279    
280 niro 306 munpack()
281     {
282 niro 24 local SRCFILE
283     local IFTAR
284     local DEST
285    
286     SRCFILE=$1
287 niro 306
288 niro 597 if [[ -z $2 ]]
289 niro 24 then
290     DEST=${BUILDDIR}
291     else
292     DEST=$2
293     fi
294 niro 306
295 niro 411 [[ ! -d ${DEST} ]] && install -d ${DEST}
296    
297 niro 24 case "${SRCFILE##*.}" in
298     bz2)
299     IFTAR="$(basename $SRCFILE .bz2)"
300     IFTAR="${IFTAR##*.}"
301 niro 306 if [[ ${IFTAR} = tar ]]
302 niro 24 then
303 niro 597 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.bz2 unpack failed."
304     else
305     pushd ${DEST} > /dev/null
306     bzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .bz2) || die ".bz2 unpack failed."
307     popd > /dev/null
308 niro 24 fi
309     ;;
310     gz)
311     IFTAR="$(basename $SRCFILE .gz)"
312     IFTAR="${IFTAR##*.}"
313 niro 306 if [[ ${IFTAR} = tar ]]
314 niro 24 then
315 niro 597 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.gz unpack failed."
316     else
317     pushd ${DEST} > /dev/null
318     zcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .gz) || die ".gz unpack failed."
319     popd > /dev/null
320 niro 24 fi
321     ;;
322 niro 1351 xz)
323     IFTAR="$(basename $SRCFILE .xz)"
324     IFTAR="${IFTAR##*.}"
325     if [[ ${IFTAR} = tar ]]
326     then
327     tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.xz unpack failed."
328     else
329     pushd ${DEST} > /dev/null
330     xzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .xz) || die ".xz unpack failed."
331     popd > /dev/null
332     fi
333     ;;
334 niro 600 tbz2|mpks|mpk)
335 niro 597 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed."
336 niro 24 ;;
337     tgz)
338 niro 597 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tgz unpack failed."
339 niro 24 ;;
340 niro 1351 txz|mpkzs|mpkz)
341     tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".txz unpack failed."
342     ;;
343 niro 597 rar)
344     unrar x ${SOURCEDIR}/${PNAME}/${SRCFILE} ${DEST} || die ".rar unpack failed."
345     ;;
346 niro 600 zip|xpi)
347 niro 597 unzip ${SOURCEDIR}/${PNAME}/${SRCFILE} -d ${DEST} || die ".zip unpack failed."
348     ;;
349     rpm)
350 niro 635 pushd ${DEST} > /dev/null
351 niro 597 rpm2targz ${SOURCEDIR}/${PNAME}/${SRCFILE} || die "rpm2targz: .rpm unpack failed."
352 niro 602 tar --no-same-owner -xvzf ${SRCFILE/.rpm/.tar.gz} || die "tar: .rpm unpack failed."
353 niro 635 if [[ -f ${DEST}/${SRCFILE/.rpm/.tar.gz} ]]
354 niro 602 then
355 niro 635 rm ${DEST}/${SRCFILE/.rpm/.tar.gz}
356 niro 602 fi
357 niro 597 ;;
358 niro 24 *)
359     die "munpack failed"
360     ;;
361     esac
362     }
363    
364 niro 306 mpatch()
365     {
366 niro 24 local PATCHOPTS
367     local PATCHFILE
368 niro 447 local i
369 niro 24
370     PATCHOPTS=$1
371     PATCHFILE=$2
372    
373 niro 447 if [[ -z $2 ]]
374     then
375     PATCHFILE=$1
376    
377     ## patch level auto-detection, get patch level
378     for ((i=0; i < 10; i++))
379     do
380     patch --dry-run -Np${i} -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} > /dev/null
381     if [[ $? = 0 ]]
382     then
383     PATCHOPTS="-Np${i}"
384     break
385     fi
386     done
387     fi
388    
389 niro 384 echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}"
390 niro 24 patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE}
391     }
392    
393 niro 497 mlibtoolize()
394     {
395     local opts="$@"
396 niro 1435 [[ -z ${opts} ]] && opts="--verbose --install --force"
397 niro 24
398 niro 497 libtoolize ${opts} || die "running: mlibtoolize ${opts}"
399     }
400    
401 niro 1291 mautoreconf()
402     {
403     local opts="$@"
404     [[ -z ${opts} ]] && opts="--verbose --install --force"
405    
406     autoreconf ${opts} || die "running: mautoreconf ${opts}"
407     }
408    
409 niro 306 minstalldocs()
410     {
411 niro 24 local docfiles
412 niro 1581 local doc
413 niro 24 docfiles="$@"
414 niro 306
415 niro 24 if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ]
416     then
417     install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs."
418     fi
419 niro 306
420 niro 1581 for doc in ${docfiles}
421 niro 24 do
422 niro 1581 if [ -f ${doc} ]
423 niro 953 then
424 niro 1584 if mqueryfeature "compressdoc"
425 niro 1581 then
426     cat ${doc} | gzip -9c > ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/${doc}.gz || die "gzipping +installing ${doc}."
427     chmod 0644 ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/${doc}.gz || die "fixing permissions of ${doc}."
428     else
429     install -m 0644 ${SRCDIR}/${i} ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "installing ${doc}."
430     fi
431 niro 953 fi
432 niro 24 done
433     }
434    
435 niro 306 mstriplibs()
436     {
437 niro 79 local stripdir="$@"
438    
439 niro 1578 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
440     [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug"
441     find ${stripdir} ! -type d | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null
442 niro 79 }
443    
444 niro 306 mstripbins()
445     {
446 niro 79 local stripdir="$@"
447    
448 niro 1578 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
449     [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug"
450     find ${stripdir} ! -type d | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null
451 niro 79 }
452    
453 niro 1543 mstripstatic()
454     {
455     local stripdir="$@"
456    
457 niro 1578 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
458     [[ -z ${STRIP_STATIC_LIB} ]] && STRIP_STATIC_LIB="--strip-debug"
459     find ${stripdir} ! -type d | xargs file | grep "ar archive" | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_STATIC_LIB} 2> /dev/null
460 niro 1543 }
461    
462 niro 1580 mstriplibtoolarchive()
463     {
464     local stripdir="$@"
465    
466     [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
467     find ${stripdir} ! -type d -name \*.la | xargs file | grep "libtool library" | cut -f 1 -d : | xargs --no-run-if-empty rm -f -- 2> /dev/null
468     }
469    
470     mpurgetargets()
471     {
472     local stripdir="$@"
473     local target
474    
475     [[ -z ${stripdir} ]] && stripdir=${BINDIR}
476     # nothing to do in this case
477     [[ -z ${PURGE_TARGETS[*]} ]] && return
478    
479     for target in ${PURGE_TARGETS[*]}
480     do
481     # check if target is a regex pattern without any slashes
482     if [[ ${target} = ${target//\/} ]]
483     then
484     find ${BINDIR} -type f -name "${target}" | xargs --no-run-if-empty rm -f -- 2> /dev/null
485     else
486     rm -f -- ${target} 2> /dev/null
487     fi
488     done
489     }
490    
491 niro 943 mcompressdocs()
492     {
493     local bindir="$@"
494    
495     if [ -d ${bindir}/usr/share/man ]
496     then
497     echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}"
498     ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man
499     fi
500    
501     if [ -d ${bindir}/usr/share/info ]
502     then
503     echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}"
504     ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info
505     fi
506     }
507    
508 niro 306 sminclude()
509     {
510 niro 172 local i
511    
512 niro 183 if [[ -n "$@" ]]
513 niro 172 then
514     for i in $@
515     do
516 niro 175 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
517 niro 172 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
518     done
519 niro 177 echo
520 niro 172 fi
521     }
522    
523 niro 306 setup_distcc_environment()
524     {
525 niro 24 if [ -x /usr/bin/distcc ]
526     then
527 niro 441 echo -e "${COLBLUE}---${COLGREEN} Using DistCC for compilation ...${COLDEFAULT}"
528 niro 351 export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH"
529 niro 24
530     export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed"
531    
532 niro 306 # creating distcc tempdir
533 niro 24 install -o distcc -g daemon -d ${DISTCC_DIR}
534     chmod 1777 ${DISTCC_DIR}
535     fi
536     }
537    
538 niro 306 setup_ccache_environment()
539     {
540 niro 24 if [ -x /usr/bin/ccache ]
541     then
542 niro 441 echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}"
543 niro 351 export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
544 niro 24 fi
545     }
546    
547 niro 193 # fixes given dependencies to match a MAGE_TARGET
548 niro 198 # fix_mage_deps -target s/depend # <-- note -target !
549 niro 306 fix_mage_deps()
550     {
551 niro 193 local target="$1"
552     local depend="$2"
553     local NDEPEND
554     local sym dep cat pver pname
555    
556     # deps and provides are special
557     # they must be fixed to match the target
558    
559     # run this only if target and depend is not empty
560     if [ -n "${target}" ] && [ -n "${depend}" ]
561     then
562     # fix DEPEND
563     while read sym dep
564     do
565 niro 427 # ignore empty lines
566     [[ -z ${dep} ]] && continue
567    
568 niro 193 cat="$(dirname ${dep})"
569 niro 199 # change if not virtual
570 niro 200 if [[ ${cat} = virtual ]]
571 niro 199 then
572 niro 200 pname="$(basename ${dep})"
573     else
574 niro 199 # fix pver to target-pver
575     # to get pname-target-pver
576 niro 193
577 niro 199 # doing it backwards !
578     pver="${dep##*-}"
579 niro 200 # full pver
580     pname="$(basename ${dep/-${pver}/})${target}-${pver}"
581 niro 199 fi
582 niro 193
583     # do not add empty lines
584     if [ -z "${NDEPEND}" ]
585     then
586 niro 200 NDEPEND="${sym} ${cat}/${pname}"
587 niro 193 else
588     NDEPEND="${NDEPEND}
589 niro 201 ${sym} ${cat}/${pname}"
590 niro 193 fi
591    
592     unset cat pname pver
593     done << EOF
594     ${depend}
595     EOF
596     # set NDEPEND to DEPEND
597     depend="${NDEPEND}"
598     fi
599    
600     echo "${depend}"
601     }
602    
603 niro 192 # build_mage_script(): helper functions for regen_mage_tree()
604 niro 191 # generates an mage file with given information in smage file
605     # needs at least:
606     # PNAME name of pkg
607     # PVER version
608     # PBUILD revision
609     # PCATEGORIE categorie of the pkg
610     # STATE state of pkg stable|unstable|old
611     # DESCRIPTION va short description (opt)
612     # HOMEPAGE homepage (opt)
613     # DEPEND runtime dependencies (opt)
614     # SDEPEND add. needed deps to build the pkg (opt)
615     # PROVIDE provides a virtual (opt)
616     #
617     # special tags:
618     # PKGTYPE type of pkg
619     # INHERITS which functions get included
620 niro 832 # SPECIAL_FUNCTIONS special functions which should also be added
621 niro 191 # warning: they get killed before the build starts !
622 niro 943 # SPLIT_PACKAGES names of all subpackages which are splitted from parent
623     # SPLIT_PACKAGE_BASE base package name for splitpackages
624     # (only in the resulting magefile}
625 niro 191 #
626     # MAGE_TREE_DEST target destination of the generated tree
627     # REGEN_MAGE_TREE set to 'true' to enable this
628 niro 193 #
629 niro 195 # gets called with build_mage_script target
630 niro 192 build_mage_script()
631 niro 191 {
632     local magefile
633     local dest
634 niro 193 local target
635 niro 943 local split_pkg_base
636 niro 191 local sym
637     local depname
638    
639     # if MAGE_TREE_DEST not set use BUILDDIR
640     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
641    
642     # determinate which suffix this mage file should get, if any
643 niro 943 [[ $1 = --target ]] && shift && target="-$1"
644 niro 191
645 niro 943 # mark package as splitpackage
646     [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
647    
648 niro 191 # name of magefile
649 niro 193 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
650 niro 191
651     # destination to magefile
652 niro 193 dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}"
653 niro 191
654     # show what we are doing
655 niro 439 echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
656     echo "${dest}"
657 niro 191
658     install -d "$(dirname ${dest})"
659     # now build the mage file
660     > ${dest}
661    
662     # pgkname and state
663 niro 193 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
664 niro 191 echo "STATE=\"${STATE}\"" >> ${dest}
665    
666     # description and homepage
667     echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
668     echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
669    
670 niro 196 # special tags and vars
671 niro 191 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
672 niro 214
673     # echo MAGE_TARGETS ## note -target is needed !
674     echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
675    
676 niro 943 # split package base
677     echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
678    
679 niro 197 # add special vars
680     if [ -n "${SPECIAL_VARS}" ]
681 niro 191 then
682     local i
683 niro 197 for i in ${SPECIAL_VARS}
684 niro 191 do
685 niro 197 # being tricky here :)
686     echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
687 niro 191 done
688     fi
689 niro 214
690 niro 197 # add at least all includes
691     if [ -n "${INHERITS}" ]
692 niro 196 then
693 niro 197 echo -n "minclude" >> ${dest}
694 niro 196 local i
695 niro 197 for i in ${INHERITS}
696 niro 196 do
697 niro 197 echo -n " ${i}" >> ${dest}
698 niro 196 done
699 niro 1351 # a CRLF is needed here!
700     echo >> ${dest}
701 niro 196 fi
702    
703 niro 191 # deps and provides
704 niro 193 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
705     echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
706 niro 191 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
707    
708     # add special functions
709     if [ -n "${SPECIAL_FUNCTIONS}" ]
710     then
711     local i
712     for i in ${SPECIAL_FUNCTIONS}
713     do
714     # add to mage (quotes needed !)
715     typeset -f "${i}" >> ${dest}
716     # unset to be safe (quotes needed !)
717 niro 192 #unset "${i}" <-- later to get every target built
718 niro 191 done
719     fi
720    
721     # pre|post-install|removes
722     typeset -f preinstall >> ${dest}
723     typeset -f postinstall >> ${dest}
724     typeset -f preremove >> ${dest}
725     typeset -f postremove >> ${dest}
726     }
727    
728     regen_mage_tree()
729     {
730 niro 1436 local subpackage
731 niro 191
732     # build them only if requested
733 niro 1584 if mqueryfeature regentree
734 niro 191 then
735 niro 195 # run it without targets
736 niro 943 if [[ -n ${MAGE_TARGETS} ]]
737 niro 195 then
738 niro 943 # build for each target a mage file
739     # run it with several targets
740 niro 191 echo
741 niro 1436 for subpackage in ${MAGE_TARGETS}
742 niro 943 do
743 niro 1436 build_mage_script --target "${subpackage}"
744 niro 943 done
745 niro 191 echo
746 niro 195
747 niro 943 # run it for splitpackages
748     elif [[ -n ${SPLIT_PACKAGES} ]]
749     then
750     local split_pkg_base="${PNAME}"
751     # save smage environment
752     split_save_variables
753     # build for each subpackage a mage file
754 niro 195 # run it with several targets
755 niro 943 echo
756 niro 1436 for subpackage in ${SPLIT_PACKAGES}
757 niro 195 do
758 niro 943 # get the right variables for the split
759 niro 1436 export PNAME="${subpackage}"
760     split_info_${subpackage}
761     # get the preinstall etc
762     split_export_inherits ${subpackage}
763 niro 943 build_mage_script --split-pkg-base "${split_pkg_base}"
764 niro 1436 # delete split preinstall etc
765     split_delete_inherits ${subpackage}
766 niro 951 # restore smage environment
767     split_restore_variables
768 niro 195 done
769 niro 943 echo
770 niro 951 # unset all saved smage variables
771     split_unset_variables
772 niro 943
773     else
774     echo
775     build_mage_script
776     echo
777 niro 195 fi
778 niro 191 fi
779    
780     # now unset all uneeded vars to be safe
781 niro 192 # unset PKGNAME <-- don't do that; smage needs this var
782     # unset to be safe (quotes needed !)
783 niro 477 # for i in ${SPECIAL_FUNCTIONS}
784     # do
785     # unset "${i}"
786     # done
787 niro 192 unset SPECIAL_FUNCTIONS
788 niro 477 # for i in ${SPECIAL_VARS}
789     # do
790     # unset "${i}"
791     # done
792 niro 194 unset SPECIAL_VARS
793 niro 191 unset STATE
794     unset DESCRIPTION
795     unset HOMEPAGE
796     unset PKGTYPE
797     unset INHERITS
798     unset DEPEND
799     unset SDEPEND
800     unset PROVIDE
801     unset preinstall
802     unset postinstall
803     unset preremove
804     unset postremove
805     }
806    
807 niro 943 split_save_variables()
808     {
809     export SAVED_PNAME="${PNAME}"
810     export SAVED_PVER="${PVER}"
811     export SAVED_PBUILD="${PBUILD}"
812     export SAVED_PCATEGORIE="${PCATEGORIE}"
813     export SAVED_DESCRIPTION="${DESCRIPTION}"
814     export SAVED_HOMEPAGE="${HOMEPAGE}"
815     export SAVED_SPECIAL_VARS="${SPECIAL_VARS}"
816     export SAVED_STATE="${STATE}"
817     export SAVED_PKGTYPE="${PKGTYPE}"
818     export SAVED_INHERITS="${INHERITS}"
819     export SAVED_DEPEND="${DEPEND}"
820     export SAVED_SDEPEND="${SDEPEND}"
821     export SAVED_PROVIDE="${PROVIDE}"
822 niro 1582 export SAVED_PKGTYPE="${PKGTYPE}"
823 niro 943
824 niro 1584 # special handling needed for mage features
825     # pkgbuild
826     mqueryfeature "pkgbuild" && export SAVED_FEATURE_PKGBUILD="pkgbuild"
827     mqueryfeature "!pkgbuild" && export SAVED_FEATURE_PKGBUILD="!pkgbuild"
828     # strip
829     mqueryfeature "strip" && export SAVED_FEATURE_STRIP="strip"
830     mqueryfeature "!strip" && export SAVED_FEATURE_STRIP="!strip"
831     # libtool
832     mqueryfeature "libtool" && export SAVED_FEATURE_LIBTOOL="libtool"
833     mqueryfeature "!libtool" && export SAVED_FEATURE_LIBTOOL="!libtool"
834     # compressdoc
835     mqueryfeature "compressdoc" && export SAVED_FEATURE_COMPRESSDOC="compressdoc"
836     mqueryfeature "!compressdoc" && export SAVED_FEATURE_COMPRESSDOC="!compressdoc"
837    
838 niro 945 # bindir too
839     export SAVED_BINDIR="${BINDIR}"
840    
841     # export the SPLIT_PACKAGE_BASE
842     export SPLIT_PACKAGE_BASE="${SAVED_PNAME}"
843    
844 niro 943 # functions
845     if [[ ! -z $(typeset -f preinstall) ]]
846     then
847     # rename the old one
848     local saved_preinstall
849     saved_preinstall=SAVED_$(typeset -f preinstall)
850     eval "${saved_preinstall}"
851     export -f SAVED_preinstall
852     fi
853    
854     if [[ ! -z $(typeset -f postinstall) ]]
855     then
856     # rename the old one
857     local saved_postinstall
858     saved_postinstall=SAVED_$(typeset -f postinstall)
859     eval "${saved_postinstall}"
860     export -f SAVED_postinstall
861     fi
862    
863     if [[ ! -z $(typeset -f preremove) ]]
864     then
865     # rename the old one
866     local saved_preremove
867     saved_preremove=SAVED_$(typeset -f preremove)
868     eval "${saved_preremove}"
869     export -f SAVED_preremove
870     fi
871    
872     if [[ ! -z $(typeset -f postremove) ]]
873     then
874     # rename the old one
875     local saved_postremove
876     saved_postremove=SAVED_$(typeset -f postremove)
877     eval "${saved_postremove}"
878     export -f SAVED_postremove
879     fi
880     }
881    
882     split_restore_variables()
883     {
884     export PNAME="${SAVED_PNAME}"
885     export PVER="${SAVED_PVER}"
886     export PBUILD="${SAVED_PBUILD}"
887     export PCATEGORIE="${SAVED_PCATEGORIE}"
888     export DESCRIPTION="${SAVED_DESCRIPTION}"
889     export HOMEPAGE="${SAVED_HOMEPAGE}"
890     export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"
891     export STATE="${SAVED_STATE}"
892     export PKGTYPE="${SAVED_PKGTYPE}"
893     export INHERITS="${SAVED_INHERITS}"
894     export DEPEND="${SAVED_DEPEND}"
895     export SDEPEND="${SAVED_SDEPEND}"
896     export PROVIDE="${SAVED_PROVIDE}"
897 niro 1582 export PKGTYPE="${SAVED_PKGTYPE}"
898 niro 943
899 niro 1584 # special handling needed for mage features
900     # pkgbuild
901     msetfeature "${SAVED_FEATURE_PKGBUILD}"
902     # strip
903     msetfeature "${SAVED_FEATURE_STRIP}"
904     # libtool
905     msetfeature "${SAVED_FEATURE_LIBTOOL}"
906     # compressdoc
907     msetfeature "${SAVED_FEATURE_COMPRESSDOC}"
908    
909 niro 945 # bindir too
910     export BINDIR="${SAVED_BINDIR}"
911    
912 niro 943 # functions
913     if [[ ! -z $(typeset -f SAVED_preinstall) ]]
914     then
915     # rename the old one
916     local saved_preinstall
917     saved_preinstall=$(typeset -f SAVED_preinstall)
918     eval "${saved_preinstall/SAVED_/}"
919     export -f preinstall
920     fi
921    
922     if [[ ! -z $(typeset -f SAVED_postinstall) ]]
923     then
924     # rename the old one
925     local saved_postinstall
926     saved_postinstall=$(typeset -f SAVED_postinstall)
927     eval "${saved_postinstall/SAVED_/}"
928     export -f postinstall
929     fi
930    
931     if [[ ! -z $(typeset -f SAVED_preremove) ]]
932     then
933     # rename the old one
934     local saved_preremove
935     saved_preremove=$(typeset -f SAVED_preremove)
936     eval "${saved_preremove/SAVED_/}"
937     export -f preremove
938     fi
939    
940     if [[ ! -z $(typeset -f SAVED_postremove) ]]
941     then
942     # rename the old one
943     local saved_postremove
944     saved_postremove=$(typeset -f SAVED_postremove)
945     eval "${saved_postremove/SAVED_/}"
946     export -f postremove
947     fi
948 niro 951 }
949 niro 943
950 niro 951 split_unset_variables()
951     {
952 niro 943 # unset saved vars; not needed anymore
953     unset SAVED_PNAME
954     unset SAVED_PVER
955     unset SAVED_PBUILD
956     unset SAVED_PCATEGORIE
957     unset SAVED_DESCRIPTION
958     unset SAVED_HOMEPAGE
959     unset SAVED_SPECIAL_VARS
960     unset SAVED_STATE
961     unset SAVED_PKGTYPE
962     unset SAVED_INHERITS
963     unset SAVED_DEPEND
964     unset SAVED_SDEPEND
965     unset SAVED_PROVIDE
966 niro 945 unset SAVED_BINDIR
967 niro 1582 unset SAVED_PKGTYPE
968 niro 1584 unset SAVED_FEATURE_PKGBUILD
969     unset SAVED_FEATURE_STRIP
970     unset SAVED_FEATURE_LIBTOOL
971     unset SAVED_FEATURE_COMPRESSDOC
972 niro 945 unset SPLIT_PACKAGE_BASE
973 niro 943 unset -f SAVED_preinstall
974     unset -f SAVED_postinstall
975     unset -f SAVED_preremove
976     unset -f SAVED_postremove
977     }
978    
979 niro 1436 split_export_inherits()
980     {
981     local subpackage="$1"
982     local func
983     local newfunc
984    
985     for func in preinstall postinstall preremove postremove
986     do
987     if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
988     then
989     newfunc=$(typeset -f ${func}_${subpackage})
990     newfunc="${newfunc/_${subpackage} (/ (}"
991     eval "${newfunc}"
992     fi
993     done
994     }
995    
996     split_delete_inherits()
997     {
998     local subpackage="$1"
999     local func
1000    
1001     for func in preinstall postinstall preremove postremove
1002     do
1003     if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
1004     then
1005     unset -f ${func}
1006     fi
1007     done
1008     }
1009    
1010 niro 253 export_inherits()
1011     {
1012     local include="$1"
1013     shift
1014    
1015     while [ "$1" ]
1016     do
1017     local functions="$1"
1018    
1019     # sanity checks
1020     [ -z "${include}" ] && die "export_inherits(): \$include not given."
1021     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
1022    
1023     eval "${functions}() { ${include}_${functions} ; }"
1024    
1025     # debug
1026     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
1027    
1028     shift
1029     done
1030     }
1031    
1032 niro 255 generate_package_md5sum()
1033     {
1034     local dest
1035     local pcat
1036     local pname
1037     local pver
1038     local pbuild
1039     local parch
1040     local target
1041     local pkgname
1042    
1043     # very basic getops
1044     for i in $*
1045     do
1046     case $1 in
1047     --pcat|-c) shift; pcat="$1" ;;
1048     --pname|-n) shift; pname="$1" ;;
1049     --pver|-v) shift; pver="$1" ;;
1050     --pbuild|-b) shift; pbuild="$1" ;;
1051     --parch|a) shift; parch="$1" ;;
1052     --target|t) shift; target="$1" ;;
1053     esac
1054     shift
1055     done
1056    
1057     # sanity checks; abort if not given
1058     [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
1059     [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
1060     [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
1061     [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
1062     [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
1063    
1064     # check needed global vars
1065     [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
1066     [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
1067    
1068     # fix target as it may be empty !
1069     [ -n "${target}" ] && target="-${target}"
1070    
1071     # build pkgname
1072     pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
1073    
1074     # build pkg-md5-sum only if requested
1075 niro 1584 if mqueryfeature regentree
1076 niro 255 then
1077 niro 439 echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}"
1078 niro 255
1079     # abort if not exist
1080     if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
1081     then
1082 niro 439 echo -e "${COLRED}! exists${COLDEFAULT}"
1083 niro 255 return 0
1084     fi
1085    
1086     # if MAGE_TREE_DEST not set use BUILDDIR
1087     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
1088    
1089     # setup md5 dir
1090 niro 891 dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"
1091 niro 255 install -d ${dest}
1092    
1093     # gen md5sum
1094     ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
1095 niro 256 > ${dest}/${pkgname}.md5
1096 niro 439 echo -e "${COLGREEN}done${COLDEFAULT}"
1097 niro 255 fi
1098     }
1099    
1100 niro 403 source_pkg_build()
1101     {
1102     if [[ ${PKGTYPE} = virtual ]]
1103     then
1104     echo "Virtual package detected; src-pkg-tarball not necessary ..."
1105     return 0
1106     fi
1107    
1108     if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
1109     then
1110     echo "No SRC_URI defined; src-pkg-tarball not necessary ..."
1111     return 0
1112     fi
1113    
1114 niro 419 [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly."
1115 niro 406
1116 niro 403 echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}"
1117 niro 412
1118     # include the smage2 file
1119     cp ${SMAGENAME} ${SOURCEDIR}/${PNAME}
1120    
1121 niro 403 ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; )
1122 niro 406 [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR}
1123     mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX}
1124 niro 403
1125     echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}"
1126     }
1127    
1128 niro 859 step_by_step()
1129     {
1130 niro 1584 if mqueryfeature stepbystep
1131 niro 859 then
1132 niro 945 echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}"
1133 niro 859 echo "Press [enter] to continue"
1134     read
1135     fi
1136     }
1137 niro 403
1138 niro 859
1139 niro 59 # print out our version
1140     showversion
1141     echo
1142    
1143 niro 24 if [ -z "$1" ]
1144     then
1145     echo "No .smage2 file given. Exiting."
1146     echo
1147     exit 1
1148     fi
1149    
1150 niro 1584 # load supported mage features
1151     load_mage_features
1152    
1153 niro 192 # updating smage2-scripts
1154 niro 306 if [[ $1 = update ]]
1155 niro 24 then
1156 niro 59 if [ ! -d ${SOURCEDIR} ]
1157     then
1158     install -d ${SOURCEDIR}
1159     fi
1160     syncsmage2
1161     exit 0
1162     fi
1163    
1164 niro 192 # creates md5sums for smages to given dir
1165 niro 306 if [[ $1 = calcmd5 ]]
1166 niro 59 then
1167 niro 1207 if [ $# -ge 2 ]
1168 niro 59 then
1169     SMAGENAME="$2"
1170     MD5DIR="$3"
1171 niro 1207 [[ -z ${MD5DIR} ]] && MD5DIR="$(dirname ${SMAGENAME})/md5"
1172    
1173 niro 1346 smagesource ${SMAGENAME} || die "download source failed"
1174 niro 59
1175 niro 66 # overridable sourcedir; must be declared after source of the smage2
1176     CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
1177    
1178 niro 59 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
1179    
1180     # end of array
1181     EOA=${#SRC_URI[*]}
1182    
1183     [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
1184    
1185     # clear md5sum file
1186     MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
1187     echo -n > ${MY_MD5_FILE}
1188    
1189     for ((i=0; i < EOA; i++))
1190     do
1191 niro 66 # url to file
1192     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
1193    
1194     # subdir in sources dir; the my_SRCI_URI file goes to there
1195     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
1196    
1197     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
1198     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
1199     then
1200     MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
1201     else
1202     MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
1203     fi
1204    
1205 niro 59 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
1206     then
1207     echo "calculating $(basename ${MY_SRC_FILE}) ..."
1208     ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
1209     else
1210     echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
1211     fi
1212 niro 66
1213     # unset them to be shure
1214     unset my_SRC_URI
1215     unset my_SRC_URI_DEST
1216     unset my_SRC_URI_MIRROR
1217     unset my_SOURCEDIR
1218 niro 59 done
1219 niro 306
1220 niro 59 echo
1221     echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
1222     echo
1223     else
1224     echo "Usage: Calculating MD5 Sums:"
1225 niro 1207 echo " $(basename $0) calcmd5 /path/to/SMAGENAME [/path/to/MD5DIR]"
1226 niro 59 echo
1227     echo
1228     echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
1229     echo
1230     exit 1
1231     fi
1232 niro 306
1233 niro 59 exit 0
1234     fi
1235    
1236 niro 192 # download sources
1237 niro 59 if [ "$1" == "download" -a -n "$2" ]
1238     then
1239 niro 24 if [ ! -d ${SMAGESCRIPTSDIR} ]
1240     then
1241     install -d ${SMAGESCRIPTSDIR}
1242     fi
1243 niro 59
1244     # get smage
1245     SMAGENAME="$2"
1246     MD5DIR="$(dirname ${SMAGENAME})/md5"
1247 niro 1346 smagesource ${SMAGENAME} || die "download source failed"
1248 niro 59
1249     download_sources
1250 niro 24 exit 0
1251     fi
1252    
1253 niro 202 # regen-mage-tree
1254     if [ "$1" == "only-regen-tree" -a -n "$2" ]
1255     then
1256     # set correct SMAGENAME
1257     SMAGENAME="$2"
1258     MD5DIR="$(dirname ${SMAGENAME})/md5"
1259 niro 1346 smagesource ${SMAGENAME} || die "regen: smage2 not found"
1260 niro 202
1261     regen_mage_tree
1262 niro 255
1263 niro 890 # build several targets
1264 niro 943 if [[ -n ${MAGE_TARGETS} ]]
1265 niro 890 then
1266     for target in ${MAGE_TARGETS}
1267     do
1268     # build md5sum for existing packages
1269     generate_package_md5sum \
1270     --pcat "${PCATEGORIE}" \
1271     --pname "${PNAME}" \
1272     --pver "${PVER}" \
1273     --pbuild "${PBUILD}" \
1274     --parch "${ARCH}" \
1275     --target "${target}"
1276     done
1277 niro 943
1278     # build several subpackages
1279     elif [[ -n ${SPLIT_PACKAGES} ]]
1280     then
1281     split_save_variables
1282 niro 964 for subpackage in ${SPLIT_PACKAGES}
1283 niro 943 do
1284     # get the right variables for the split
1285     export PNAME="${subpackage}"
1286     split_info_${subpackage}
1287     # build md5sum for existing packages
1288     generate_package_md5sum \
1289     --pcat "${PCATEGORIE}" \
1290     --pname "${PNAME}" \
1291     --pver "${PVER}" \
1292     --pbuild "${PBUILD}" \
1293     --parch "${ARCH}"
1294 niro 951 # restore smage environment
1295     split_restore_variables
1296 niro 943 done
1297 niro 951 # unset all saved smage variables
1298     split_unset_variables
1299 niro 943
1300 niro 890 else
1301     # build md5sum for existing packages
1302     generate_package_md5sum \
1303     --pcat "${PCATEGORIE}" \
1304     --pname "${PNAME}" \
1305     --pver "${PVER}" \
1306     --pbuild "${PBUILD}" \
1307 niro 943 --parch "${ARCH}"
1308 niro 890 fi
1309 niro 255
1310 niro 202 exit 0
1311     fi
1312    
1313 niro 412 if [ "$1" == "--create-src-tarball" -a -n "$2" ]
1314 niro 403 then
1315     # set correct SMAGENAME
1316     SMAGENAME="$2"
1317     MD5DIR="$(dirname ${SMAGENAME})/md5"
1318    
1319 niro 412 echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}"
1320 niro 403
1321 niro 1346 smagesource ${SMAGENAME} || die "regen: smage2 not found"
1322 niro 403
1323     if [[ -d ${SOURCEDIR}/${PNAME} ]]
1324     then
1325     echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1326     rm -rf ${SOURCEDIR}/${PKGNAME}
1327     fi
1328    
1329     download_sources
1330     source_pkg_build ${SMAGENAME}
1331     exit 0
1332     fi
1333    
1334 niro 406 if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ]
1335 niro 403 then
1336 niro 412 SRCPKGTARBALL="${2}"
1337 niro 1584 msetfeature "srcpkgtarball"
1338 niro 403
1339 niro 412 # abort if given file is not a source pkg
1340     [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file."
1341    
1342     # set correct SMAGENAME; use the one that the src_pkg provide
1343     # /path/to/SOURCEDIR/PNAME/SMAGENAME
1344     SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}"
1345    
1346 niro 403 echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}"
1347    
1348     [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR}
1349    
1350     # unpack srctarball
1351     [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting."
1352    
1353     tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}"
1354 niro 412
1355     [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}"
1356 niro 403 fi
1357    
1358    
1359 niro 306 [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
1360     [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] &&
1361     die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting."
1362 niro 419 [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your ${MAGERC} correctly."
1363     [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your ${MAGERC} correctly."
1364     [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your ${MAGERC} correctly."
1365     [ -z "${BINDIR}" ] && die "no BINDIR variable found in ${MAGERC}"
1366     [ -z "${CHOST}" ] && die "no CHOST variable found in ${MAGERC}"
1367     [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in ${MAGERC}"
1368     [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in ${MAGERC}"
1369 niro 24
1370 niro 1346 smagesource ${SMAGENAME} || die "source failed"
1371 niro 255 PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}"
1372 niro 59 MD5DIR="$(dirname ${SMAGENAME})/md5"
1373 niro 941 SMAGE_LOG_CMD="tee -a /var/log/smage/${PKGNAME}.log"
1374 niro 24
1375     xtitle "Compiling ${PKGNAME}"
1376 niro 439 echo -e "${COLGREEN}Compiling ${PKGNAME}${COLDEFAULT}"
1377 niro 59
1378 niro 191 # auto regen mage tree if requested
1379     regen_mage_tree
1380    
1381 niro 1584 if mqueryfeature "srcpkg"
1382 niro 403 then
1383     if [[ -d ${SOURCEDIR}/${PNAME} ]]
1384     then
1385 niro 441 echo -e "${COLBLUE}===${COLGREEN} deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1386 niro 408 rm -rf ${SOURCEDIR}/${PNAME}
1387 niro 403 fi
1388     fi
1389    
1390 niro 192 # download sources
1391 niro 1584 mqueryfeature "srcpkgtarball" || download_sources
1392 niro 59
1393 niro 192 # fixes some issues with these functions
1394 niro 24 export -f src_prepare || die "src_prepare export failed"
1395     export -f src_compile || die "src_compile export failed"
1396 niro 1575 export -f src_check || die "src_check export failed"
1397 niro 24 export -f src_install || die "src_install export failed"
1398    
1399 niro 192 # fixes some compile issues
1400 niro 24 export CHOST="${CHOST}" || die "CHOST export failed"
1401     export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
1402     export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
1403     export BINDIR="${BINDIR}" || die "BINDIR export failed"
1404     export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
1405    
1406 niro 192 # setup distcc
1407 niro 351 # setup for distcc goes *before* ccache, so ccache comes before distcc in path
1408 niro 1584 mqueryfeature "distcc" && setup_distcc_environment
1409 niro 24
1410 niro 192 # setup ccache
1411 niro 1584 mqueryfeature "ccache" && setup_ccache_environment
1412 niro 24
1413 niro 1573 # clean up builddir if a previously one exist
1414 niro 24 if [ -d ${BUILDDIR} ]
1415     then
1416     rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
1417     fi
1418     install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
1419    
1420 niro 1573 # clean up srcdir if a previously unpacked one exist
1421 niro 24 if [ -d ${SRCDIR} ]
1422     then
1423     rm -rf ${SRCDIR}
1424     fi
1425    
1426 niro 1573 # clean up bindir if a previous build exist or create a new one
1427 niro 24 if [ -d ${BINDIR} ]
1428     then
1429     rm -rf ${BINDIR}
1430     fi
1431     install -d ${BINDIR} || die "couldn't create \$BINDIR."
1432    
1433 niro 1579 # clean up package temp dir if a previous build exist
1434 niro 24 if [ -d ${BUILDDIR}/${PKGNAME} ]
1435     then
1436     rm -rf ${BUILDDIR}/${PKGNAME}
1437     fi
1438    
1439 niro 1573 # setup build logging
1440 niro 875 [[ ! -d /var/log/smage ]] && install -d /var/log/smage
1441     echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log
1442    
1443 niro 941 src_prepare | ${SMAGE_LOG_CMD}
1444     die_pipestatus 0 "src_prepare failed"
1445 niro 859 step_by_step $_
1446 niro 941
1447     src_compile | ${SMAGE_LOG_CMD}
1448     die_pipestatus 0 "src_compile failed"
1449 niro 859 step_by_step $_
1450 niro 941
1451 niro 1575 # only run checks if requested
1452 niro 1584 if mqueryfeature "!check"
1453 niro 1575 then
1454 niro 1584 echo "!check detected; src_check() will not be run!" | ${SMAGE_LOG_CMD}
1455 niro 1575 step_by_step src_check
1456     else
1457     src_check | ${SMAGE_LOG_CMD}
1458     die_pipestatus 0 "src_check failed"
1459     step_by_step $_
1460     fi
1461    
1462 niro 943 # build several subpackages
1463     if [[ -n ${SPLIT_PACKAGES} ]]
1464     then
1465 niro 945 # save bindir & pname
1466     split_save_variables
1467 niro 943 export SAVED_BINDIR="${BINDIR}"
1468     for subpackage in ${SPLIT_PACKAGES}
1469     do
1470     if typeset -f src_install_${subpackage} > /dev/null
1471     then
1472     # export subpackage bindir
1473     export BINDIR="${SAVED_BINDIR}_${subpackage}"
1474 niro 945 # export PNAME, several internal function and include
1475     # rely on this variable
1476     export PNAME="${subpackage}"
1477    
1478     echo
1479     echo -en "${COLBLUE}*** ${COLDEFAULT}"
1480     echo -en " Running ${COLGREEN}split src_install()${COLDEFAULT}"
1481     echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}"
1482     echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..."
1483    
1484 niro 943 src_install_${subpackage} | ${SMAGE_LOG_CMD}
1485     die_pipestatus 0 "src_install_${subpackage} failed"
1486     step_by_step $_
1487     fi
1488     done
1489 niro 945 # restore bindir & pname
1490     split_restore_variables
1491 niro 951 # unset all saved smage variables
1492     split_unset_variables
1493 niro 943 else
1494     src_install | ${SMAGE_LOG_CMD}
1495     die_pipestatus 0 "src_install failed"
1496     step_by_step $_
1497     fi
1498 niro 24
1499 niro 1584 if mqueryfeature "!compressdoc"
1500 niro 24 then
1501 niro 1584 echo -e "!compressdoc detected; documentation will not be compressed ..."
1502 niro 943 else
1503 niro 1584 # compressing doc, info & man files
1504     if [[ -n ${SPLIT_PACKAGES} ]]
1505     then
1506     for subpackage in ${SPLIT_PACKAGES}
1507     do
1508     mcompressdocs ${BINDIR}_${subpackage}
1509     done
1510     else
1511     mcompressdocs ${BINDIR}
1512     fi
1513 niro 24 fi
1514    
1515 niro 1584 if mqueryfeature "!libtool"
1516 niro 1580 then
1517     if [[ -n ${SPLIT_PACKAGES} ]]
1518     then
1519     for subpackage in ${SPLIT_PACKAGES}
1520     do
1521     echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives for '${subpackage}' ...${COLDEFAULT}"
1522     mstriplibtoolarchive ${BINDIR}_${subpackage}
1523     done
1524     else
1525     echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives ...${COLDEFAULT}"
1526     mstriplibtoolarchive ${BINDIR}
1527     fi
1528     fi
1529 niro 24
1530 niro 1584 if mqueryfeature "purge"
1531 niro 1580 then
1532     if [[ -n ${SPLIT_PACKAGES} ]]
1533     then
1534     for subpackage in ${SPLIT_PACKAGES}
1535     do
1536     echo -e "${COLBLUE}===${COLGREEN} purging all purge targets in '${subpackage}' ...${COLDEFAULT}"
1537     mpurgetargets ${BINDIR}_${subpackage}
1538     done
1539     else
1540     echo -e "${COLBLUE}===${COLGREEN} purging all purge targets ...${COLDEFAULT}"
1541     mpurgetargets ${BINDIR}
1542     fi
1543     fi
1544    
1545 niro 79 # stripping all bins and libs
1546 niro 1584 if mqueryfeature "!strip"
1547     then
1548     echo -e "!strip detected; Package will not be stripped ..."
1549     else
1550 niro 943 if [[ -n ${SPLIT_PACKAGES} ]]
1551     then
1552 niro 964 for subpackage in ${SPLIT_PACKAGES}
1553 niro 943 do
1554 niro 1082 echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}"
1555 niro 943 mstripbins ${BINDIR}_${subpackage}
1556 niro 1543 echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries for '${subpackage}' ...${COLDEFAULT}"
1557 niro 943 mstriplibs ${BINDIR}_${subpackage}
1558 niro 1543 echo -e "${COLBLUE}===${COLGREEN} stripping static libraries for '${subpackage}' ...${COLDEFAULT}"
1559     mstripstatic ${BINDIR}_${subpackage}
1560 niro 943 done
1561     else
1562     echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}"
1563     mstripbins ${BINDIR}
1564 niro 1543 echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries ...${COLDEFAULT}"
1565 niro 943 mstriplibs ${BINDIR}
1566 niro 1543 echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}"
1567     mstripstatic ${BINDIR}
1568 niro 943 fi
1569 niro 1584 fi
1570 niro 79
1571 niro 1584 if mqueryfeature "!buildpkg"
1572     then
1573     echo -e "!buildpkg detected; Package will not be build ..."
1574     else
1575 niro 306 # build several targets
1576 niro 943 if [[ -n ${MAGE_TARGETS} ]]
1577 niro 192 then
1578     for target in ${MAGE_TARGETS}
1579     do
1580 niro 1573 # check if a special target_pkgbuild exists
1581 niro 192 if typeset -f ${target}_pkgbuild > /dev/null
1582     then
1583     # run it
1584     ${target}_pkgbuild
1585     fi
1586     # now create the target package
1587     ${MLIBDIR}/pkgbuild_dir.sh \
1588 niro 255 "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \
1589 niro 192 ${BINDIR} || die "target: ${target} package-build failed"
1590 niro 255
1591     # build pkg-md5-sum if requested
1592     generate_package_md5sum \
1593     --pcat "${PCATEGORIE}" \
1594     --pname "${PNAME}" \
1595     --pver "${PVER}" \
1596     --pbuild "${PBUILD}" \
1597     --parch "${ARCH}" \
1598     --target "${target}"
1599    
1600 niro 439 echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1601 niro 192 done
1602 niro 943
1603     # build several subpackages
1604     elif [[ -n ${SPLIT_PACKAGES} ]]
1605     then
1606     split_save_variables
1607     for subpackage in ${SPLIT_PACKAGES}
1608     do
1609     # get the right variables for the split
1610     export PNAME="${subpackage}"
1611     split_info_${PNAME}
1612    
1613 niro 1584 # jump to next one if !buildpkg is set in split_info
1614     mqueryfeature "!buildpkg" && continue
1615 niro 947
1616 niro 943 # check if an special subpackage_pkgbuild exists
1617     if typeset -f ${PNAME}_pkgbuild > /dev/null
1618     then
1619     # run it
1620     ${PNAME}_pkgbuild
1621     fi
1622     # now create the target package
1623     ${MLIBDIR}/pkgbuild_dir.sh \
1624     "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \
1625     "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed"
1626    
1627     # build pkg-md5-sum if requested
1628     generate_package_md5sum \
1629     --pcat "${PCATEGORIE}" \
1630     --pname "${PNAME}" \
1631     --pver "${PVER}" \
1632     --pbuild "${PBUILD}" \
1633     --parch "${ARCH}"
1634    
1635     echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1636 niro 951
1637     # restore smage environment
1638     split_restore_variables
1639 niro 943 done
1640 niro 951 # unset all saved smage variables
1641     split_unset_variables
1642 niro 943
1643 niro 192 else
1644     ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1645 niro 255
1646     # build pkg-md5-sum if requested
1647     generate_package_md5sum \
1648     --pcat "${PCATEGORIE}" \
1649     --pname "${PNAME}" \
1650     --pver "${PVER}" \
1651     --pbuild "${PBUILD}" \
1652     --parch "${ARCH}"
1653    
1654 niro 439 echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}"
1655 niro 192 fi
1656 niro 403
1657     # build src-pkg-tarball if requested
1658 niro 1584 mqueryfeature "srcpkg" && source_pkg_build ${SMAGENAME}
1659     fi
1660 niro 24
1661 niro 1584 if mqueryfeature "buildlog"
1662 niro 875 then
1663     bzip2 -9f /var/log/smage/${PKGNAME}.log
1664     else
1665     [[ -f /var/log/smage/${PKGNAME}.log ]] && rm /var/log/smage/${PKGNAME}.log
1666     fi
1667    
1668 niro 24 xtitleclean

Properties

Name Value
svn:executable *