Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *