Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *