Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *