Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 941 - (hide annotations) (download) (as text)
Fri Nov 20 19:41:27 2009 UTC (14 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 31812 byte(s)
-fixed compile logging
1 niro 24 #!/bin/bash
2    
3     # compiles/installs .smage2 source install scripts
4     # needs pkgbuild_dir (mage)
5    
6     # SMAGE2
7 niro 635 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.62 2007-11-28 10:47:50 niro Exp $
8 niro 24
9     #01.10.2004
10     # added ccache support
11     # added distcc support
12    
13 niro 419 # set default user mage.rc
14     : ${MAGERC="/etc/mage.rc"}
15    
16 niro 24 ## setup ##
17     PKGSUFFIX="mpk"
18 niro 403 SRCPKGSUFFIX="mpks"
19 niro 24 SMAGENAME="$1"
20     SMAGESUFFIX="smage2"
21     MLIBDIR=/usr/lib/mage
22 niro 186 SMAGEVERSION="$( < ${MLIBDIR}/version)"
23 niro 24
24 niro 351 ## only for tests -> normally in /etc/rc.d/init.d/functions
25     COLRED="\033[1;6m\033[31m"
26     COLGREEN="\033[1;6m\033[32m"
27     COLYELLOW="\033[1;6m\033[33m"
28     COLBLUE="\033[1;6m\033[34m"
29     COLMAGENTA="\033[1;6m\033[35m"
30     COLWHITE="\033[1;6m\033[37m"
31     COLGRAY="\033[0;6m\033[37m"
32     COLBOLD="\033[1m"
33     COLDEFAULT="\033[0m"
34    
35     if [[ ${NOCOLORS} = true ]]
36     then
37     COLRED=""
38     COLGREEN=""
39     COLYELLOW=""
40     COLBLUE=""
41     COLMAGENTA=""
42     COLWHITE=""
43     COLGRAY=""
44     COLBOLD=""
45     COLDEFAULT=""
46     fi
47    
48 niro 169 # export default C locale
49     export LC_ALL=C
50    
51 niro 439 source /etc/mage.rc.global
52 niro 419 source ${MAGERC}
53 niro 24
54 niro 347 # set PKGDIR and BUILDDIR and BINDIR to MROOT
55     if [[ -n ${MROOT} ]]
56     then
57     export PKGDIR=${MROOT}/${PKGDIR}
58     export BUILDDIR=${MROOT}/${BUILDDIR}
59     export BINDIR=${MROOT}/${BINDIR}
60     fi
61    
62 niro 306 showversion()
63     {
64 niro 24 echo -en "Magellan Source Install v${SMAGEVERSION} "
65     echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
66     }
67    
68 niro 306 die()
69     {
70 niro 24 xtitleclean
71 niro 413 echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
72 niro 24 echo "SMAGE failed: $@"
73     exit 1
74     }
75    
76 niro 941 die_pipestatus()
77     {
78     local pos="$1"
79     local comment="$2"
80    
81     [ ${PIPESTATUS[${pos}]} -gt 0 ] && die "${comment}"
82     }
83    
84 niro 306 xtitle()
85     {
86     if [[ ${TERM} = xterm ]]
87 niro 24 then
88     echo -ne "\033]0;[sMage: $@]\007"
89     fi
90     return 0
91     }
92    
93 niro 306 xtitleclean()
94     {
95     if [[ ${TERM} = xterm ]]
96 niro 24 then
97     echo -ne "\033]0;\007"
98     fi
99     return 0
100     }
101    
102 niro 306 syncsmage2()
103     {
104 niro 24 xtitle "Updating smage2-script tree ..."
105     local i
106     for i in ${SMAGE2RSYNC}
107     do
108 niro 386 rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR}
109 niro 306 if [[ $? = 0 ]]
110 niro 24 then
111     break
112     else
113     continue
114     fi
115     done
116 niro 306
117     # clean up backup files (foo~)
118 niro 24 find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';'
119 niro 306
120 niro 24 xtitleclean
121     }
122    
123 niro 59 # $1 filename
124 niro 306 get_db_md5_sum()
125     {
126 niro 59 local DB_FILE
127     local MD5_FILE
128     local i
129    
130     DB_ENTRY="$(basename $1)"
131     MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})"
132    
133     i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)"
134    
135     echo "${i}"
136     }
137    
138 niro 306 download_sources()
139     {
140 niro 59
141 niro 61 [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0
142 niro 59
143     local EOA=${#SRC_URI[*]}
144 niro 66 local my_SRC_URI
145     local my_SRC_URI_DEST
146     local my_SRC_URI_MIRROR
147     local my_SOURCEDIR
148 niro 59 local DB_MD5_SUM_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
149     local FETCHING
150     local i mirror
151    
152 niro 306
153     # install SRCDIR/PNAME if not exist
154 niro 59 [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME}
155    
156     # check if FETCHING is needed
157 niro 66 ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} &> /dev/null )
158 niro 306 if [[ $? = 0 ]]
159 niro 59 then
160 niro 439 # md5's ok, no fetching needed
161 niro 59 FETCHING=false
162     else
163     FETCHING=true
164     fi
165 niro 306
166 niro 59 for ((i=0; i < EOA; i++))
167     do
168 niro 66 # url to file
169     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
170 niro 59
171 niro 66 # subdir in sources dir; the my_SRCI_URI file goes to there
172     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
173    
174     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
175     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
176     then
177     my_SOURCEDIR="${SOURCEDIR}/${PNAME}/${my_SRC_URI_DEST}"
178     else
179     my_SOURCEDIR="${SOURCEDIR}/${PNAME}"
180     fi
181    
182 niro 885 # create the SOURCEDIR
183     install -d ${my_SOURCEDIR}
184    
185 niro 59 # if an mirrored file than replace first the mirror uri
186 niro 439 if [[ -n $(echo ${my_SRC_URI} | grep 'mirror://') ]]
187 niro 59 then
188     for mirror in ${MIRRORS}
189     do
190 niro 66 my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|mirror:/|${mirror}/sources|g")"
191 niro 59
192 niro 306 if [[ ${FETCHING} = true ]]
193 niro 59 then
194 niro 439 echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}"
195 niro 59 wget \
196     --passive-ftp \
197     --tries 3 \
198     --continue \
199     --progress bar \
200 niro 883 --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \
201 niro 66 "${my_SRC_URI_MIRROR}"
202 niro 306 if [[ $? = 0 ]]
203 niro 59 then
204     break
205     else
206     continue
207     fi
208     fi
209     done
210 niro 439 elif [[ -n $(echo ${my_SRC_URI} | grep 'sourceforge://') ]]
211     then
212     for mirror in ${SOURCEFORGE_MIRRORS}
213     do
214     my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|sourceforge:/|${mirror}|g")"
215    
216     if [[ ${FETCHING} = true ]]
217     then
218     echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}"
219     wget \
220     --passive-ftp \
221     --tries 3 \
222     --continue \
223     --progress bar \
224 niro 883 --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \
225 niro 439 "${my_SRC_URI_MIRROR}"
226     if [[ $? = 0 ]]
227     then
228     break
229     else
230     continue
231     fi
232     fi
233     done
234     elif [[ -n $(echo ${my_SRC_URI} | grep 'gnu://') ]]
235     then
236     for mirror in ${GNU_MIRRORS}
237     do
238     my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|gnu:/|${mirror}|g")"
239    
240     if [[ ${FETCHING} = true ]]
241     then
242     echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}"
243     wget \
244     --passive-ftp \
245     --tries 3 \
246     --continue \
247     --progress bar \
248 niro 883 --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \
249 niro 439 "${my_SRC_URI_MIRROR}"
250     if [[ $? = 0 ]]
251     then
252     break
253     else
254     continue
255     fi
256     fi
257     done
258 niro 459 elif [[ -n $(echo ${my_SRC_URI} | grep 'kde://') ]]
259     then
260     for mirror in ${KDE_MIRRORS}
261     do
262     my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|kde:/|${mirror}|g")"
263    
264     if [[ ${FETCHING} = true ]]
265     then
266     echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}"
267     wget \
268     --passive-ftp \
269     --tries 3 \
270     --continue \
271     --progress bar \
272 niro 883 --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \
273 niro 459 "${my_SRC_URI_MIRROR}"
274     if [[ $? = 0 ]]
275     then
276     break
277     else
278     continue
279     fi
280     fi
281     done
282     elif [[ -n $(echo ${my_SRC_URI} | grep 'gnome://') ]]
283     then
284     for mirror in ${GNOME_MIRRORS}
285     do
286     my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|gnome:/|${mirror}|g")"
287    
288     if [[ ${FETCHING} = true ]]
289     then
290     echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI_MIRROR}${COLDEFAULT}"
291     wget \
292     --passive-ftp \
293     --tries 3 \
294     --continue \
295     --progress bar \
296 niro 883 --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI_MIRROR})" \
297 niro 459 "${my_SRC_URI_MIRROR}"
298     if [[ $? = 0 ]]
299     then
300     break
301     else
302     continue
303     fi
304     fi
305     done
306 niro 59 else
307 niro 306 if [[ ${FETCHING} = true ]]
308 niro 59 then
309 niro 439 echo -e "${COLBLUE}==>${COLGREEN} fetching ${my_SRC_URI}${COLDEFAULT}"
310 niro 59 wget \
311     --passive-ftp \
312     --tries 3 \
313     --continue \
314     --progress bar \
315 niro 883 --output-document="${my_SOURCEDIR}/$(basename ${my_SRC_URI})" \
316 niro 66 "${my_SRC_URI}"
317 niro 59 fi
318     fi
319 niro 306
320 niro 66 # unset them to be shure
321     unset my_SRC_URI
322     unset my_SRC_URI_DEST
323     unset my_SRC_URI_MIRROR
324     unset my_SOURCEDIR
325 niro 59 done
326    
327     # recheck md5 sums
328     echo
329 niro 439 echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}"
330 niro 63 ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} ) || die "md5 failed"
331 niro 59 echo
332    
333     # not needed anymore
334     unset SRC_URI
335     }
336    
337 niro 24 # dummy function, used if that not exist in smage file
338 niro 306 src_prepare()
339     {
340 niro 24 echo "no src_prepare defined"
341     sleep 2
342     return 0
343     }
344    
345     # dummy function, used if that not exist in smage file
346 niro 306 src_compile()
347     {
348 niro 24 echo "no src_compile defined"
349     sleep 2
350     return 0
351     }
352    
353     # dummy function, used if that not exist in smage file
354 niro 306 src_install()
355     {
356 niro 24 echo "no src_install defined"
357     sleep 2
358     return 0
359     }
360    
361 niro 351 mlibdir()
362     {
363     local libdir=lib
364     [[ ${ARCH} = x86_64 ]] && libdir=lib64
365    
366     echo "${libdir}"
367     }
368    
369 niro 306 mconfigure()
370     {
371 niro 24 if [ -x ./configure ]
372     then
373 niro 306 ./configure \
374     --prefix=/usr \
375     --host=${CHOST} \
376 niro 833 --build=${CHOST} \
377 niro 306 --mandir=/usr/share/man \
378     --infodir=/usr/share/info \
379     --datadir=/usr/share \
380     --sysconfdir=/etc \
381     --localstatedir=/var/lib \
382 niro 351 --libdir=/usr/$(mlibdir) \
383 niro 306 "$@" || die "mconfigure failed"
384 niro 24 else
385     echo "configure is not an executable ..."
386     exit 1
387     fi
388     }
389    
390 niro 306 minstall()
391     {
392     if [ -f ./[mM]akefile -o -f ./GNUmakefile ]
393     then
394 niro 24 make prefix=${BINDIR}/usr \
395     datadir=${BINDIR}/usr/share \
396     infodir=${BINDIR}/usr/share/info \
397     localstatedir=${BINDIR}/var/lib \
398     mandir=${BINDIR}/usr/share/man \
399     sysconfdir=${BINDIR}/etc \
400 niro 351 libdir=${BINDIR}/usr/$(mlibdir) \
401 niro 24 "$@" install || die "minstall failed"
402     else
403     die "no Makefile found"
404     fi
405     }
406    
407 niro 306 mmake()
408     {
409 niro 24 make ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
410     }
411    
412 niro 306 munpack()
413     {
414 niro 24 local SRCFILE
415     local IFTAR
416     local DEST
417    
418     SRCFILE=$1
419 niro 306
420 niro 597 if [[ -z $2 ]]
421 niro 24 then
422     DEST=${BUILDDIR}
423     else
424     DEST=$2
425     fi
426 niro 306
427 niro 411 [[ ! -d ${DEST} ]] && install -d ${DEST}
428    
429 niro 24 case "${SRCFILE##*.}" in
430     bz2)
431     IFTAR="$(basename $SRCFILE .bz2)"
432     IFTAR="${IFTAR##*.}"
433 niro 306 if [[ ${IFTAR} = tar ]]
434 niro 24 then
435 niro 597 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.bz2 unpack failed."
436     else
437     pushd ${DEST} > /dev/null
438     bzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .bz2) || die ".bz2 unpack failed."
439     popd > /dev/null
440 niro 24 fi
441     ;;
442     gz)
443     IFTAR="$(basename $SRCFILE .gz)"
444     IFTAR="${IFTAR##*.}"
445 niro 306 if [[ ${IFTAR} = tar ]]
446 niro 24 then
447 niro 597 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.gz unpack failed."
448     else
449     pushd ${DEST} > /dev/null
450     zcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .gz) || die ".gz unpack failed."
451     popd > /dev/null
452 niro 24 fi
453     ;;
454 niro 600 tbz2|mpks|mpk)
455 niro 597 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed."
456 niro 24 ;;
457     tgz)
458 niro 597 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tgz unpack failed."
459 niro 24 ;;
460 niro 597 rar)
461     unrar x ${SOURCEDIR}/${PNAME}/${SRCFILE} ${DEST} || die ".rar unpack failed."
462     ;;
463 niro 600 zip|xpi)
464 niro 597 unzip ${SOURCEDIR}/${PNAME}/${SRCFILE} -d ${DEST} || die ".zip unpack failed."
465     ;;
466     rpm)
467 niro 635 pushd ${DEST} > /dev/null
468 niro 597 rpm2targz ${SOURCEDIR}/${PNAME}/${SRCFILE} || die "rpm2targz: .rpm unpack failed."
469 niro 602 tar --no-same-owner -xvzf ${SRCFILE/.rpm/.tar.gz} || die "tar: .rpm unpack failed."
470 niro 635 if [[ -f ${DEST}/${SRCFILE/.rpm/.tar.gz} ]]
471 niro 602 then
472 niro 635 rm ${DEST}/${SRCFILE/.rpm/.tar.gz}
473 niro 602 fi
474 niro 597 ;;
475 niro 24 *)
476     die "munpack failed"
477     ;;
478     esac
479     }
480    
481 niro 306 mpatch()
482     {
483 niro 24 local PATCHOPTS
484     local PATCHFILE
485 niro 447 local i
486 niro 24
487     PATCHOPTS=$1
488     PATCHFILE=$2
489    
490 niro 447 if [[ -z $2 ]]
491     then
492     PATCHFILE=$1
493    
494     ## patch level auto-detection, get patch level
495     for ((i=0; i < 10; i++))
496     do
497     patch --dry-run -Np${i} -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} > /dev/null
498     if [[ $? = 0 ]]
499     then
500     PATCHOPTS="-Np${i}"
501     break
502     fi
503     done
504     fi
505    
506 niro 384 echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}"
507 niro 24 patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE}
508     }
509    
510 niro 497 mlibtoolize()
511     {
512     local opts="$@"
513     [[ -z ${opts} ]] && opts="--copy --force"
514 niro 24
515 niro 497 libtoolize ${opts} || die "running: mlibtoolize ${opts}"
516     }
517    
518 niro 306 minstalldocs()
519     {
520 niro 24 local docfiles
521     docfiles="$@"
522 niro 306
523 niro 24 if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ]
524     then
525     install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs."
526     fi
527 niro 306
528 niro 24 for i in ${docfiles}
529     do
530     cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs."
531     install -m 0644 ${SRCDIR}/${i}.gz \
532     ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs."
533     done
534     }
535    
536 niro 306 mstriplibs()
537     {
538 niro 79 local stripdir="$@"
539    
540     [ -z "${stripdir}" ] && stripdir=${BINDIR}
541     find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
542     }
543    
544 niro 306 mstripbins()
545     {
546 niro 79 local stripdir="$@"
547    
548     [ -z "${stripdir}" ] && stripdir=${BINDIR}
549     find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
550     }
551    
552 niro 306 sminclude()
553     {
554 niro 172 local i
555    
556 niro 183 if [[ -n "$@" ]]
557 niro 172 then
558     for i in $@
559     do
560 niro 175 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
561 niro 172 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
562     done
563 niro 177 echo
564 niro 172 fi
565     }
566    
567 niro 306 setup_distcc_environment()
568     {
569 niro 24 if [ -x /usr/bin/distcc ]
570     then
571 niro 441 echo -e "${COLBLUE}---${COLGREEN} Using DistCC for compilation ...${COLDEFAULT}"
572 niro 351 export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH"
573 niro 24
574     export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed"
575    
576 niro 306 # creating distcc tempdir
577 niro 24 install -o distcc -g daemon -d ${DISTCC_DIR}
578     chmod 1777 ${DISTCC_DIR}
579     fi
580     }
581    
582 niro 306 setup_ccache_environment()
583     {
584 niro 24 if [ -x /usr/bin/ccache ]
585     then
586 niro 441 echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}"
587 niro 351 export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
588 niro 24 fi
589     }
590    
591 niro 193
592     # fixes given dependencies to match a MAGE_TARGET
593 niro 198 # fix_mage_deps -target s/depend # <-- note -target !
594 niro 306 fix_mage_deps()
595     {
596 niro 193 local target="$1"
597     local depend="$2"
598     local NDEPEND
599     local sym dep cat pver pname
600    
601     # deps and provides are special
602     # they must be fixed to match the target
603    
604     # run this only if target and depend is not empty
605     if [ -n "${target}" ] && [ -n "${depend}" ]
606     then
607     # fix DEPEND
608     while read sym dep
609     do
610 niro 427 # ignore empty lines
611     [[ -z ${dep} ]] && continue
612    
613 niro 193 cat="$(dirname ${dep})"
614 niro 199 # change if not virtual
615 niro 200 if [[ ${cat} = virtual ]]
616 niro 199 then
617 niro 200 pname="$(basename ${dep})"
618     else
619 niro 199 # fix pver to target-pver
620     # to get pname-target-pver
621 niro 193
622 niro 199 # doing it backwards !
623     pver="${dep##*-}"
624 niro 200 # full pver
625     pname="$(basename ${dep/-${pver}/})${target}-${pver}"
626 niro 199 fi
627 niro 193
628     # do not add empty lines
629     if [ -z "${NDEPEND}" ]
630     then
631 niro 200 NDEPEND="${sym} ${cat}/${pname}"
632 niro 193 else
633     NDEPEND="${NDEPEND}
634 niro 201 ${sym} ${cat}/${pname}"
635 niro 193 fi
636    
637     unset cat pname pver
638     done << EOF
639     ${depend}
640     EOF
641     # set NDEPEND to DEPEND
642     depend="${NDEPEND}"
643     fi
644    
645     echo "${depend}"
646     }
647    
648 niro 192 # build_mage_script(): helper functions for regen_mage_tree()
649 niro 191 # generates an mage file with given information in smage file
650     # needs at least:
651     # PNAME name of pkg
652     # PVER version
653     # PBUILD revision
654     # PCATEGORIE categorie of the pkg
655     # STATE state of pkg stable|unstable|old
656     # DESCRIPTION va short description (opt)
657     # HOMEPAGE homepage (opt)
658     # DEPEND runtime dependencies (opt)
659     # SDEPEND add. needed deps to build the pkg (opt)
660     # PROVIDE provides a virtual (opt)
661     #
662     # special tags:
663     # PKGTYPE type of pkg
664     # INHERITS which functions get included
665 niro 832 # SPECIAL_FUNCTIONS special functions which should also be added
666 niro 191 # warning: they get killed before the build starts !
667     #
668     # MAGE_TREE_DEST target destination of the generated tree
669     # REGEN_MAGE_TREE set to 'true' to enable this
670 niro 193 #
671 niro 195 # gets called with build_mage_script target
672 niro 192 build_mage_script()
673 niro 191 {
674     local magefile
675     local dest
676 niro 193 local target
677 niro 191 local sym
678     local depname
679    
680     # if MAGE_TREE_DEST not set use BUILDDIR
681     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
682    
683     # determinate which suffix this mage file should get, if any
684 niro 195 [ -n "$1" ] && target="-$1"
685 niro 191
686     # name of magefile
687 niro 193 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
688 niro 191
689     # destination to magefile
690 niro 193 dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}"
691 niro 191
692     # show what we are doing
693 niro 439 echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
694     echo "${dest}"
695 niro 191
696     install -d "$(dirname ${dest})"
697     # now build the mage file
698     > ${dest}
699    
700     # header
701 niro 635 echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.62 2007-11-28 10:47:50 niro Exp $' >> ${dest}
702 niro 191 echo >> ${dest}
703    
704     # pgkname and state
705 niro 193 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
706 niro 191 echo "STATE=\"${STATE}\"" >> ${dest}
707     echo >> ${dest}
708    
709     # description and homepage
710     echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
711     echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
712     echo >> ${dest}
713    
714 niro 196 # special tags and vars
715 niro 191 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
716 niro 214
717     # echo MAGE_TARGETS ## note -target is needed !
718     echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
719     echo >> ${dest}
720    
721 niro 197 # add special vars
722     if [ -n "${SPECIAL_VARS}" ]
723 niro 191 then
724     local i
725 niro 197 for i in ${SPECIAL_VARS}
726 niro 191 do
727 niro 197 # being tricky here :)
728     echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
729 niro 191 done
730     echo >> ${dest}
731     fi
732 niro 214
733 niro 197 # add at least all includes
734     if [ -n "${INHERITS}" ]
735 niro 196 then
736 niro 197 echo -n "minclude" >> ${dest}
737 niro 196 local i
738 niro 197 for i in ${INHERITS}
739 niro 196 do
740 niro 197 echo -n " ${i}" >> ${dest}
741 niro 196 done
742     echo >> ${dest}
743     fi
744 niro 197 echo >> ${dest}
745 niro 196
746 niro 191 # deps and provides
747 niro 193 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
748 niro 196 echo >> ${dest}
749 niro 193 echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
750 niro 196 echo >> ${dest}
751 niro 191 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
752     echo >> ${dest}
753    
754     # add special functions
755     if [ -n "${SPECIAL_FUNCTIONS}" ]
756     then
757     local i
758     for i in ${SPECIAL_FUNCTIONS}
759     do
760     # add to mage (quotes needed !)
761     typeset -f "${i}" >> ${dest}
762 niro 214 echo >> ${dest}
763 niro 191 # unset to be safe (quotes needed !)
764 niro 192 #unset "${i}" <-- later to get every target built
765 niro 191 done
766 niro 196 echo >> ${dest}
767 niro 191 fi
768    
769     # pre|post-install|removes
770     typeset -f preinstall >> ${dest}
771     echo >> ${dest}
772     typeset -f postinstall >> ${dest}
773     echo >> ${dest}
774     typeset -f preremove >> ${dest}
775     echo >> ${dest}
776     typeset -f postremove >> ${dest}
777     echo >> ${dest}
778     }
779    
780     regen_mage_tree()
781     {
782     local i
783    
784     # build them only if requested
785     if [[ ${REGEN_MAGE_TREE} = true ]]
786     then
787 niro 195 # run it without targets
788     if [ -z "${MAGE_TARGETS}" ]
789     then
790 niro 191 echo
791 niro 195 build_mage_script
792 niro 191 echo
793 niro 195 else
794    
795     # build for each target an mage file
796     # run it with several targets
797     for i in ${MAGE_TARGETS}
798     do
799     echo
800     build_mage_script "${i}"
801     echo
802     done
803     fi
804 niro 191 fi
805    
806     # now unset all uneeded vars to be safe
807 niro 192 # unset PKGNAME <-- don't do that; smage needs this var
808     # unset to be safe (quotes needed !)
809 niro 477 # for i in ${SPECIAL_FUNCTIONS}
810     # do
811     # unset "${i}"
812     # done
813 niro 192 unset SPECIAL_FUNCTIONS
814 niro 477 # for i in ${SPECIAL_VARS}
815     # do
816     # unset "${i}"
817     # done
818 niro 194 unset SPECIAL_VARS
819 niro 191 unset STATE
820     unset DESCRIPTION
821     unset HOMEPAGE
822     unset PKGTYPE
823     unset INHERITS
824     unset DEPEND
825     unset SDEPEND
826     unset PROVIDE
827     unset preinstall
828     unset postinstall
829     unset preremove
830     unset postremove
831     }
832    
833 niro 253 export_inherits()
834     {
835     local include="$1"
836     shift
837    
838     while [ "$1" ]
839     do
840     local functions="$1"
841    
842     # sanity checks
843     [ -z "${include}" ] && die "export_inherits(): \$include not given."
844     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
845    
846     eval "${functions}() { ${include}_${functions} ; }"
847    
848     # debug
849     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
850    
851     shift
852     done
853     }
854    
855 niro 255 generate_package_md5sum()
856     {
857     local dest
858     local pcat
859     local pname
860     local pver
861     local pbuild
862     local parch
863     local target
864     local pkgname
865    
866     # very basic getops
867     for i in $*
868     do
869     case $1 in
870     --pcat|-c) shift; pcat="$1" ;;
871     --pname|-n) shift; pname="$1" ;;
872     --pver|-v) shift; pver="$1" ;;
873     --pbuild|-b) shift; pbuild="$1" ;;
874     --parch|a) shift; parch="$1" ;;
875     --target|t) shift; target="$1" ;;
876     esac
877     shift
878     done
879    
880     # sanity checks; abort if not given
881     [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
882     [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
883     [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
884     [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
885     [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
886    
887     # check needed global vars
888     [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
889     [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
890    
891     # fix target as it may be empty !
892     [ -n "${target}" ] && target="-${target}"
893    
894 niro 890
895 niro 255 # build pkgname
896     pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
897    
898     # build pkg-md5-sum only if requested
899     if [[ ${REGEN_MAGE_TREE} = true ]]
900     then
901 niro 439 echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}"
902 niro 255
903     # abort if not exist
904     if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
905     then
906 niro 439 echo -e "${COLRED}! exists${COLDEFAULT}"
907 niro 255 return 0
908     fi
909    
910     # if MAGE_TREE_DEST not set use BUILDDIR
911     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
912    
913     # setup md5 dir
914 niro 891 dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"
915 niro 255 install -d ${dest}
916    
917     # gen md5sum
918     ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
919 niro 256 > ${dest}/${pkgname}.md5
920 niro 439 echo -e "${COLGREEN}done${COLDEFAULT}"
921 niro 255 fi
922     }
923    
924 niro 403 source_pkg_build()
925     {
926     if [[ ${PKGTYPE} = virtual ]]
927     then
928     echo "Virtual package detected; src-pkg-tarball not necessary ..."
929     return 0
930     fi
931    
932     if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
933     then
934     echo "No SRC_URI defined; src-pkg-tarball not necessary ..."
935     return 0
936     fi
937    
938 niro 419 [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly."
939 niro 406
940 niro 403 echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}"
941 niro 412
942     # include the smage2 file
943     cp ${SMAGENAME} ${SOURCEDIR}/${PNAME}
944    
945 niro 403 ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; )
946 niro 406 [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR}
947     mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX}
948 niro 403
949     echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}"
950     }
951    
952 niro 859 step_by_step()
953     {
954     if [[ ${STEP_BY_STEP} = true ]]
955     then
956     echo "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}"
957     echo "Press [enter] to continue"
958     read
959     fi
960     }
961 niro 403
962 niro 859
963 niro 59 # print out our version
964     showversion
965     echo
966    
967 niro 24 if [ -z "$1" ]
968     then
969     echo "No .smage2 file given. Exiting."
970     echo
971     exit 1
972     fi
973    
974 niro 192 # updating smage2-scripts
975 niro 306 if [[ $1 = update ]]
976 niro 24 then
977 niro 59 if [ ! -d ${SOURCEDIR} ]
978     then
979     install -d ${SOURCEDIR}
980     fi
981     syncsmage2
982     exit 0
983     fi
984    
985 niro 192 # creates md5sums for smages to given dir
986 niro 306 if [[ $1 = calcmd5 ]]
987 niro 59 then
988     if [ $# -ge 3 ]
989     then
990     SMAGENAME="$2"
991     MD5DIR="$3"
992     source ${SMAGENAME} || die "download source failed"
993    
994 niro 66 # overridable sourcedir; must be declared after source of the smage2
995     CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
996    
997 niro 59 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
998    
999     # end of array
1000     EOA=${#SRC_URI[*]}
1001    
1002     [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
1003    
1004     # clear md5sum file
1005     MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
1006     echo -n > ${MY_MD5_FILE}
1007    
1008     for ((i=0; i < EOA; i++))
1009     do
1010 niro 66 # url to file
1011     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
1012    
1013     # subdir in sources dir; the my_SRCI_URI file goes to there
1014     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
1015    
1016     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
1017     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
1018     then
1019     MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
1020     else
1021     MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
1022     fi
1023    
1024 niro 59 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
1025     then
1026     echo "calculating $(basename ${MY_SRC_FILE}) ..."
1027     ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
1028     else
1029     echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
1030     fi
1031 niro 66
1032     # unset them to be shure
1033     unset my_SRC_URI
1034     unset my_SRC_URI_DEST
1035     unset my_SRC_URI_MIRROR
1036     unset my_SOURCEDIR
1037 niro 59 done
1038 niro 306
1039 niro 59 echo
1040     echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
1041     echo
1042     else
1043     echo "Usage: Calculating MD5 Sums:"
1044     echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR"
1045     echo
1046     echo
1047     echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
1048     echo
1049     exit 1
1050     fi
1051 niro 306
1052 niro 59 exit 0
1053     fi
1054    
1055 niro 192 # download sources
1056 niro 59 if [ "$1" == "download" -a -n "$2" ]
1057     then
1058 niro 24 if [ ! -d ${SMAGESCRIPTSDIR} ]
1059     then
1060     install -d ${SMAGESCRIPTSDIR}
1061     fi
1062 niro 59
1063     # get smage
1064     SMAGENAME="$2"
1065     MD5DIR="$(dirname ${SMAGENAME})/md5"
1066     source ${SMAGENAME} || die "download source failed"
1067    
1068     download_sources
1069 niro 24 exit 0
1070     fi
1071    
1072 niro 202 # regen-mage-tree
1073     if [ "$1" == "only-regen-tree" -a -n "$2" ]
1074     then
1075     # set correct SMAGENAME
1076     SMAGENAME="$2"
1077     MD5DIR="$(dirname ${SMAGENAME})/md5"
1078     source ${SMAGENAME} || die "regen: smage2 not found"
1079    
1080     regen_mage_tree
1081 niro 255
1082 niro 890 # build several targets
1083     if [ -n "${MAGE_TARGETS}" ]
1084     then
1085     for target in ${MAGE_TARGETS}
1086     do
1087     # build md5sum for existing packages
1088     generate_package_md5sum \
1089     --pcat "${PCATEGORIE}" \
1090     --pname "${PNAME}" \
1091     --pver "${PVER}" \
1092     --pbuild "${PBUILD}" \
1093     --parch "${ARCH}" \
1094     --target "${target}"
1095     done
1096     else
1097     # build md5sum for existing packages
1098     generate_package_md5sum \
1099     --pcat "${PCATEGORIE}" \
1100     --pname "${PNAME}" \
1101     --pver "${PVER}" \
1102     --pbuild "${PBUILD}" \
1103     --parch "${ARCH}" \
1104     --target "${target}"
1105     fi
1106 niro 255
1107 niro 202 exit 0
1108     fi
1109    
1110 niro 412 if [ "$1" == "--create-src-tarball" -a -n "$2" ]
1111 niro 403 then
1112     # set correct SMAGENAME
1113     SMAGENAME="$2"
1114     MD5DIR="$(dirname ${SMAGENAME})/md5"
1115    
1116 niro 412 echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}"
1117 niro 403
1118     source ${SMAGENAME} || die "regen: smage2 not found"
1119    
1120     if [[ -d ${SOURCEDIR}/${PNAME} ]]
1121     then
1122     echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1123     rm -rf ${SOURCEDIR}/${PKGNAME}
1124     fi
1125    
1126     download_sources
1127     source_pkg_build ${SMAGENAME}
1128     exit 0
1129     fi
1130    
1131 niro 406 if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ]
1132 niro 403 then
1133 niro 412 SRCPKGTARBALL="${2}"
1134 niro 403 USE_SRC_PKG_TARBALL=true
1135    
1136 niro 412 # abort if given file is not a source pkg
1137     [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file."
1138    
1139     # set correct SMAGENAME; use the one that the src_pkg provide
1140     # /path/to/SOURCEDIR/PNAME/SMAGENAME
1141     SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}"
1142    
1143 niro 403 echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}"
1144    
1145     [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR}
1146    
1147     # unpack srctarball
1148     [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting."
1149    
1150     tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}"
1151 niro 412
1152     [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}"
1153 niro 403 fi
1154    
1155    
1156 niro 306 [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
1157     [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] &&
1158     die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting."
1159 niro 419 [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your ${MAGERC} correctly."
1160     [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your ${MAGERC} correctly."
1161     [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your ${MAGERC} correctly."
1162     [ -z "${BINDIR}" ] && die "no BINDIR variable found in ${MAGERC}"
1163     [ -z "${CHOST}" ] && die "no CHOST variable found in ${MAGERC}"
1164     [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in ${MAGERC}"
1165     [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in ${MAGERC}"
1166 niro 24
1167     source ${SMAGENAME} || die "source failed"
1168 niro 255 PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}"
1169 niro 59 MD5DIR="$(dirname ${SMAGENAME})/md5"
1170 niro 941 SMAGE_LOG_CMD="tee -a /var/log/smage/${PKGNAME}.log"
1171 niro 24
1172     xtitle "Compiling ${PKGNAME}"
1173 niro 439 echo -e "${COLGREEN}Compiling ${PKGNAME}${COLDEFAULT}"
1174 niro 59
1175 niro 191 # auto regen mage tree if requested
1176     regen_mage_tree
1177    
1178 niro 403 if [[ ${CREATE_SRC_PKG_TARBALL} = true ]]
1179     then
1180     if [[ -d ${SOURCEDIR}/${PNAME} ]]
1181     then
1182 niro 441 echo -e "${COLBLUE}===${COLGREEN} deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1183 niro 408 rm -rf ${SOURCEDIR}/${PNAME}
1184 niro 403 fi
1185     fi
1186    
1187 niro 192 # download sources
1188 niro 403 [[ ${USE_SRC_PKG_TARBALL} != true ]] && download_sources
1189 niro 59
1190 niro 192 # fixes some issues with these functions
1191 niro 24 export -f src_prepare || die "src_prepare export failed"
1192     export -f src_compile || die "src_compile export failed"
1193     export -f src_install || die "src_install export failed"
1194    
1195 niro 192 # fixes some compile issues
1196 niro 24 export CHOST="${CHOST}" || die "CHOST export failed"
1197     export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
1198     export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
1199     export BINDIR="${BINDIR}" || die "BINDIR export failed"
1200     export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
1201    
1202    
1203 niro 192 # setup distcc
1204 niro 351 # setup for distcc goes *before* ccache, so ccache comes before distcc in path
1205 niro 306 [[ ${SMAGE_USE_DISTCC} = true ]] && setup_distcc_environment
1206 niro 24
1207 niro 192 # setup ccache
1208 niro 306 [[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment
1209 niro 24
1210     # small sleep to show our settings
1211     sleep 1
1212    
1213 niro 192 # cleans up build if a previously one exists
1214 niro 24 if [ -d ${BUILDDIR} ]
1215     then
1216     rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
1217     fi
1218     install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
1219    
1220 niro 192 # cleans up srcdir if a previously unpacked one exists
1221 niro 24 if [ -d ${SRCDIR} ]
1222     then
1223     rm -rf ${SRCDIR}
1224     fi
1225    
1226 niro 192 # cleans up bindir if a previous build exists or creates a new one
1227 niro 24 if [ -d ${BINDIR} ]
1228     then
1229     rm -rf ${BINDIR}
1230     fi
1231     install -d ${BINDIR} || die "couldn't create \$BINDIR."
1232    
1233 niro 192 # cleans up package temp dir if a previous build exists
1234 niro 24 if [ -d ${BUILDDIR}/${PKGNAME} ]
1235     then
1236     rm -rf ${BUILDDIR}/${PKGNAME}
1237     fi
1238    
1239 niro 192 # cleans up timestamp if one exists
1240 niro 24 if [ -f /var/tmp/timestamp ]
1241     then
1242     mage rmstamp
1243     fi
1244    
1245 niro 875 # setup build loggins
1246     [[ ! -d /var/log/smage ]] && install -d /var/log/smage
1247     echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log
1248    
1249 niro 941 src_prepare | ${SMAGE_LOG_CMD}
1250     die_pipestatus 0 "src_prepare failed"
1251 niro 859 step_by_step $_
1252 niro 941
1253     src_compile | ${SMAGE_LOG_CMD}
1254     die_pipestatus 0 "src_compile failed"
1255 niro 859 step_by_step $_
1256 niro 941
1257     src_install | ${SMAGE_LOG_CMD}
1258     die_pipestatus 0 "src_install failed"
1259 niro 859 step_by_step $_
1260 niro 24
1261    
1262 niro 192 # compressing doc, info & man files
1263 niro 24 if [ -d ${BUILDDIR}/builded/usr/share/man ]
1264     then
1265 niro 439 echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}"
1266 niro 24 ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man
1267     fi
1268    
1269     if [ -d ${BUILDDIR}/builded/usr/share/info ]
1270     then
1271 niro 439 echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}"
1272 niro 24 ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info
1273     fi
1274    
1275 niro 79 # stripping all bins and libs
1276     case ${NOSTRIP} in
1277     true|TRUE|yes|y)
1278     echo -e "NOSTRIP=true detected; Package will not be stripped ..."
1279     ;;
1280     *)
1281 niro 439 echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}"
1282 niro 79 mstripbins ${BINDIR}
1283 niro 439 echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}"
1284 niro 79 mstriplibs ${BINDIR}
1285     ;;
1286     esac
1287    
1288 niro 192 # the new buildpkg command
1289 niro 24 case ${NOPKGBUILD} in
1290     true|TRUE|yes|y)
1291     echo -e "NOPGKBUILD=true detected; Package will not be build ..."
1292     ;;
1293 niro 192 *)
1294 niro 306 # build several targets
1295 niro 192 if [ -n "${MAGE_TARGETS}" ]
1296     then
1297     for target in ${MAGE_TARGETS}
1298     do
1299     # check if an special target_pkgbuild exists
1300     if typeset -f ${target}_pkgbuild > /dev/null
1301     then
1302     # run it
1303     ${target}_pkgbuild
1304     fi
1305     # now create the target package
1306     ${MLIBDIR}/pkgbuild_dir.sh \
1307 niro 255 "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \
1308 niro 192 ${BINDIR} || die "target: ${target} package-build failed"
1309 niro 255
1310     # build pkg-md5-sum if requested
1311     generate_package_md5sum \
1312     --pcat "${PCATEGORIE}" \
1313     --pname "${PNAME}" \
1314     --pver "${PVER}" \
1315     --pbuild "${PBUILD}" \
1316     --parch "${ARCH}" \
1317     --target "${target}"
1318    
1319 niro 439 echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1320 niro 192 done
1321     else
1322     ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1323 niro 255
1324     # build pkg-md5-sum if requested
1325     generate_package_md5sum \
1326     --pcat "${PCATEGORIE}" \
1327     --pname "${PNAME}" \
1328     --pver "${PVER}" \
1329     --pbuild "${PBUILD}" \
1330     --parch "${ARCH}"
1331    
1332 niro 439 echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}"
1333 niro 192 fi
1334 niro 403
1335     # build src-pkg-tarball if requested
1336     [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME}
1337 niro 24 ;;
1338     esac
1339    
1340 niro 875 if [[ ${SMAGE_BUILD_LOGGING} != false ]]
1341     then
1342     bzip2 -9f /var/log/smage/${PKGNAME}.log
1343     else
1344     [[ -f /var/log/smage/${PKGNAME}.log ]] && rm /var/log/smage/${PKGNAME}.log
1345     fi
1346    
1347 niro 192 # for sure
1348 niro 24 unset NOPKGBUILD
1349 niro 85 unset NOSTRIP
1350 niro 351
1351 niro 24 xtitleclean

Properties

Name Value
svn:executable *