Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *