Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *