Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *