Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1085 - (hide annotations) (download) (as text)
Mon Jun 28 18:15:44 2010 UTC (13 years, 10 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/smage2.sh
File MIME type: application/x-sh
File size: 39376 byte(s)
-added WGET_FETCH_OPTIONS variable to mage.rc.global to be more busybox friendly
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     if [ $# -ge 3 ]
1174     then
1175     SMAGENAME="$2"
1176     MD5DIR="$3"
1177     source ${SMAGENAME} || die "download source failed"
1178    
1179 niro 66 # overridable sourcedir; must be declared after source of the smage2
1180     CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
1181    
1182 niro 59 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
1183    
1184     # end of array
1185     EOA=${#SRC_URI[*]}
1186    
1187     [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
1188    
1189     # clear md5sum file
1190     MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
1191     echo -n > ${MY_MD5_FILE}
1192    
1193     for ((i=0; i < EOA; i++))
1194     do
1195 niro 66 # url to file
1196     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
1197    
1198     # subdir in sources dir; the my_SRCI_URI file goes to there
1199     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
1200    
1201     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
1202     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
1203     then
1204     MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
1205     else
1206     MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
1207     fi
1208    
1209 niro 59 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
1210     then
1211     echo "calculating $(basename ${MY_SRC_FILE}) ..."
1212     ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
1213     else
1214     echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
1215     fi
1216 niro 66
1217     # unset them to be shure
1218     unset my_SRC_URI
1219     unset my_SRC_URI_DEST
1220     unset my_SRC_URI_MIRROR
1221     unset my_SOURCEDIR
1222 niro 59 done
1223 niro 306
1224 niro 59 echo
1225     echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
1226     echo
1227     else
1228     echo "Usage: Calculating MD5 Sums:"
1229     echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR"
1230     echo
1231     echo
1232     echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
1233     echo
1234     exit 1
1235     fi
1236 niro 306
1237 niro 59 exit 0
1238     fi
1239    
1240 niro 192 # download sources
1241 niro 59 if [ "$1" == "download" -a -n "$2" ]
1242     then
1243 niro 24 if [ ! -d ${SMAGESCRIPTSDIR} ]
1244     then
1245     install -d ${SMAGESCRIPTSDIR}
1246     fi
1247 niro 59
1248     # get smage
1249     SMAGENAME="$2"
1250     MD5DIR="$(dirname ${SMAGENAME})/md5"
1251     source ${SMAGENAME} || die "download source failed"
1252    
1253     download_sources
1254 niro 24 exit 0
1255     fi
1256    
1257 niro 202 # regen-mage-tree
1258     if [ "$1" == "only-regen-tree" -a -n "$2" ]
1259     then
1260     # set correct SMAGENAME
1261     SMAGENAME="$2"
1262     MD5DIR="$(dirname ${SMAGENAME})/md5"
1263     source ${SMAGENAME} || die "regen: smage2 not found"
1264    
1265     regen_mage_tree
1266 niro 255
1267 niro 890 # build several targets
1268 niro 943 if [[ -n ${MAGE_TARGETS} ]]
1269 niro 890 then
1270     for target in ${MAGE_TARGETS}
1271     do
1272     # build md5sum for existing packages
1273     generate_package_md5sum \
1274     --pcat "${PCATEGORIE}" \
1275     --pname "${PNAME}" \
1276     --pver "${PVER}" \
1277     --pbuild "${PBUILD}" \
1278     --parch "${ARCH}" \
1279     --target "${target}"
1280     done
1281 niro 943
1282     # build several subpackages
1283     elif [[ -n ${SPLIT_PACKAGES} ]]
1284     then
1285     split_save_variables
1286 niro 964 for subpackage in ${SPLIT_PACKAGES}
1287 niro 943 do
1288     # get the right variables for the split
1289     export PNAME="${subpackage}"
1290     split_info_${subpackage}
1291     # build md5sum for existing packages
1292     generate_package_md5sum \
1293     --pcat "${PCATEGORIE}" \
1294     --pname "${PNAME}" \
1295     --pver "${PVER}" \
1296     --pbuild "${PBUILD}" \
1297     --parch "${ARCH}"
1298 niro 951 # restore smage environment
1299     split_restore_variables
1300 niro 943 done
1301 niro 951 # unset all saved smage variables
1302     split_unset_variables
1303 niro 943
1304 niro 890 else
1305     # build md5sum for existing packages
1306     generate_package_md5sum \
1307     --pcat "${PCATEGORIE}" \
1308     --pname "${PNAME}" \
1309     --pver "${PVER}" \
1310     --pbuild "${PBUILD}" \
1311 niro 943 --parch "${ARCH}"
1312 niro 890 fi
1313 niro 255
1314 niro 202 exit 0
1315     fi
1316    
1317 niro 412 if [ "$1" == "--create-src-tarball" -a -n "$2" ]
1318 niro 403 then
1319     # set correct SMAGENAME
1320     SMAGENAME="$2"
1321     MD5DIR="$(dirname ${SMAGENAME})/md5"
1322    
1323 niro 412 echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}"
1324 niro 403
1325     source ${SMAGENAME} || die "regen: smage2 not found"
1326    
1327     if [[ -d ${SOURCEDIR}/${PNAME} ]]
1328     then
1329     echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1330     rm -rf ${SOURCEDIR}/${PKGNAME}
1331     fi
1332    
1333     download_sources
1334     source_pkg_build ${SMAGENAME}
1335     exit 0
1336     fi
1337    
1338 niro 406 if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ]
1339 niro 403 then
1340 niro 412 SRCPKGTARBALL="${2}"
1341 niro 403 USE_SRC_PKG_TARBALL=true
1342    
1343 niro 412 # abort if given file is not a source pkg
1344     [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file."
1345    
1346     # set correct SMAGENAME; use the one that the src_pkg provide
1347     # /path/to/SOURCEDIR/PNAME/SMAGENAME
1348     SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}"
1349    
1350 niro 403 echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}"
1351    
1352     [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR}
1353    
1354     # unpack srctarball
1355     [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting."
1356    
1357     tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}"
1358 niro 412
1359     [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}"
1360 niro 403 fi
1361    
1362    
1363 niro 306 [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
1364     [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] &&
1365     die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting."
1366 niro 419 [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your ${MAGERC} correctly."
1367     [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your ${MAGERC} correctly."
1368     [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your ${MAGERC} correctly."
1369     [ -z "${BINDIR}" ] && die "no BINDIR variable found in ${MAGERC}"
1370     [ -z "${CHOST}" ] && die "no CHOST variable found in ${MAGERC}"
1371     [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in ${MAGERC}"
1372     [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in ${MAGERC}"
1373 niro 24
1374     source ${SMAGENAME} || die "source failed"
1375 niro 255 PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}"
1376 niro 59 MD5DIR="$(dirname ${SMAGENAME})/md5"
1377 niro 941 SMAGE_LOG_CMD="tee -a /var/log/smage/${PKGNAME}.log"
1378 niro 24
1379     xtitle "Compiling ${PKGNAME}"
1380 niro 439 echo -e "${COLGREEN}Compiling ${PKGNAME}${COLDEFAULT}"
1381 niro 59
1382 niro 191 # auto regen mage tree if requested
1383     regen_mage_tree
1384    
1385 niro 403 if [[ ${CREATE_SRC_PKG_TARBALL} = true ]]
1386     then
1387     if [[ -d ${SOURCEDIR}/${PNAME} ]]
1388     then
1389 niro 441 echo -e "${COLBLUE}===${COLGREEN} deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1390 niro 408 rm -rf ${SOURCEDIR}/${PNAME}
1391 niro 403 fi
1392     fi
1393    
1394 niro 192 # download sources
1395 niro 403 [[ ${USE_SRC_PKG_TARBALL} != true ]] && download_sources
1396 niro 59
1397 niro 192 # fixes some issues with these functions
1398 niro 24 export -f src_prepare || die "src_prepare export failed"
1399     export -f src_compile || die "src_compile export failed"
1400     export -f src_install || die "src_install export failed"
1401    
1402 niro 192 # fixes some compile issues
1403 niro 24 export CHOST="${CHOST}" || die "CHOST export failed"
1404     export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
1405     export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
1406     export BINDIR="${BINDIR}" || die "BINDIR export failed"
1407     export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
1408    
1409    
1410 niro 192 # setup distcc
1411 niro 351 # setup for distcc goes *before* ccache, so ccache comes before distcc in path
1412 niro 306 [[ ${SMAGE_USE_DISTCC} = true ]] && setup_distcc_environment
1413 niro 24
1414 niro 192 # setup ccache
1415 niro 306 [[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment
1416 niro 24
1417     # small sleep to show our settings
1418     sleep 1
1419    
1420 niro 192 # cleans up build if a previously one exists
1421 niro 24 if [ -d ${BUILDDIR} ]
1422     then
1423     rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
1424     fi
1425     install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
1426    
1427 niro 192 # cleans up srcdir if a previously unpacked one exists
1428 niro 24 if [ -d ${SRCDIR} ]
1429     then
1430     rm -rf ${SRCDIR}
1431     fi
1432    
1433 niro 192 # cleans up bindir if a previous build exists or creates a new one
1434 niro 24 if [ -d ${BINDIR} ]
1435     then
1436     rm -rf ${BINDIR}
1437     fi
1438     install -d ${BINDIR} || die "couldn't create \$BINDIR."
1439    
1440 niro 192 # cleans up package temp dir if a previous build exists
1441 niro 24 if [ -d ${BUILDDIR}/${PKGNAME} ]
1442     then
1443     rm -rf ${BUILDDIR}/${PKGNAME}
1444     fi
1445    
1446 niro 192 # cleans up timestamp if one exists
1447 niro 24 if [ -f /var/tmp/timestamp ]
1448     then
1449     mage rmstamp
1450     fi
1451    
1452 niro 875 # setup build loggins
1453     [[ ! -d /var/log/smage ]] && install -d /var/log/smage
1454     echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log
1455    
1456 niro 941 src_prepare | ${SMAGE_LOG_CMD}
1457     die_pipestatus 0 "src_prepare failed"
1458 niro 859 step_by_step $_
1459 niro 941
1460     src_compile | ${SMAGE_LOG_CMD}
1461     die_pipestatus 0 "src_compile failed"
1462 niro 859 step_by_step $_
1463 niro 941
1464 niro 943 # build several subpackages
1465     if [[ -n ${SPLIT_PACKAGES} ]]
1466     then
1467 niro 945 # save bindir & pname
1468     split_save_variables
1469 niro 943 export SAVED_BINDIR="${BINDIR}"
1470     for subpackage in ${SPLIT_PACKAGES}
1471     do
1472     if typeset -f src_install_${subpackage} > /dev/null
1473     then
1474     # export subpackage bindir
1475     export BINDIR="${SAVED_BINDIR}_${subpackage}"
1476 niro 945 # export PNAME, several internal function and include
1477     # rely on this variable
1478     export PNAME="${subpackage}"
1479    
1480     echo
1481     echo -en "${COLBLUE}*** ${COLDEFAULT}"
1482     echo -en " Running ${COLGREEN}split src_install()${COLDEFAULT}"
1483     echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}"
1484     echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..."
1485    
1486 niro 943 src_install_${subpackage} | ${SMAGE_LOG_CMD}
1487     die_pipestatus 0 "src_install_${subpackage} failed"
1488     step_by_step $_
1489     fi
1490     done
1491 niro 945 # restore bindir & pname
1492     split_restore_variables
1493 niro 951 # unset all saved smage variables
1494     split_unset_variables
1495 niro 943 else
1496     src_install | ${SMAGE_LOG_CMD}
1497     die_pipestatus 0 "src_install failed"
1498     step_by_step $_
1499     fi
1500 niro 24
1501 niro 192 # compressing doc, info & man files
1502 niro 943 if [[ -n ${SPLIT_PACKAGES} ]]
1503 niro 24 then
1504 niro 964 for subpackage in ${SPLIT_PACKAGES}
1505 niro 943 do
1506     mcompressdocs ${BINDIR}_${subpackage}
1507     done
1508     else
1509     mcompressdocs ${BINDIR}
1510 niro 24 fi
1511    
1512    
1513 niro 79 # stripping all bins and libs
1514     case ${NOSTRIP} in
1515     true|TRUE|yes|y)
1516     echo -e "NOSTRIP=true detected; Package will not be stripped ..."
1517     ;;
1518     *)
1519 niro 943 if [[ -n ${SPLIT_PACKAGES} ]]
1520     then
1521 niro 964 for subpackage in ${SPLIT_PACKAGES}
1522 niro 943 do
1523 niro 1082 echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}"
1524 niro 943 mstripbins ${BINDIR}_${subpackage}
1525 niro 1082 echo -e "${COLBLUE}===${COLGREEN} stripping libraries for '${subpackage}' ...${COLDEFAULT}"
1526 niro 943 mstriplibs ${BINDIR}_${subpackage}
1527     done
1528     else
1529     echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}"
1530     mstripbins ${BINDIR}
1531     echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}"
1532     mstriplibs ${BINDIR}
1533     fi
1534 niro 79 ;;
1535     esac
1536    
1537 niro 192 # the new buildpkg command
1538 niro 24 case ${NOPKGBUILD} in
1539     true|TRUE|yes|y)
1540     echo -e "NOPGKBUILD=true detected; Package will not be build ..."
1541     ;;
1542 niro 192 *)
1543 niro 306 # build several targets
1544 niro 943 if [[ -n ${MAGE_TARGETS} ]]
1545 niro 192 then
1546     for target in ${MAGE_TARGETS}
1547     do
1548     # check if an special target_pkgbuild exists
1549     if typeset -f ${target}_pkgbuild > /dev/null
1550     then
1551     # run it
1552     ${target}_pkgbuild
1553     fi
1554     # now create the target package
1555     ${MLIBDIR}/pkgbuild_dir.sh \
1556 niro 255 "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \
1557 niro 192 ${BINDIR} || die "target: ${target} package-build failed"
1558 niro 255
1559     # build pkg-md5-sum if requested
1560     generate_package_md5sum \
1561     --pcat "${PCATEGORIE}" \
1562     --pname "${PNAME}" \
1563     --pver "${PVER}" \
1564     --pbuild "${PBUILD}" \
1565     --parch "${ARCH}" \
1566     --target "${target}"
1567    
1568 niro 439 echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1569 niro 192 done
1570 niro 943
1571     # build several subpackages
1572     elif [[ -n ${SPLIT_PACKAGES} ]]
1573     then
1574     split_save_variables
1575     for subpackage in ${SPLIT_PACKAGES}
1576     do
1577     # get the right variables for the split
1578     export PNAME="${subpackage}"
1579     split_info_${PNAME}
1580    
1581 niro 947 # jump to next one if NOPKGBUILD is set in split_info
1582     case ${NOPKGBUILD} in
1583     true|TRUE|yes|y) continue ;;
1584     esac
1585    
1586 niro 943 # check if an special subpackage_pkgbuild exists
1587     if typeset -f ${PNAME}_pkgbuild > /dev/null
1588     then
1589     # run it
1590     ${PNAME}_pkgbuild
1591     fi
1592     # now create the target package
1593     ${MLIBDIR}/pkgbuild_dir.sh \
1594     "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \
1595     "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed"
1596    
1597     # build pkg-md5-sum if requested
1598     generate_package_md5sum \
1599     --pcat "${PCATEGORIE}" \
1600     --pname "${PNAME}" \
1601     --pver "${PVER}" \
1602     --pbuild "${PBUILD}" \
1603     --parch "${ARCH}"
1604    
1605     echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1606 niro 951
1607     # restore smage environment
1608     split_restore_variables
1609 niro 943 done
1610 niro 951 # unset all saved smage variables
1611     split_unset_variables
1612 niro 943
1613 niro 192 else
1614     ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1615 niro 255
1616     # build pkg-md5-sum if requested
1617     generate_package_md5sum \
1618     --pcat "${PCATEGORIE}" \
1619     --pname "${PNAME}" \
1620     --pver "${PVER}" \
1621     --pbuild "${PBUILD}" \
1622     --parch "${ARCH}"
1623    
1624 niro 439 echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}"
1625 niro 192 fi
1626 niro 403
1627     # build src-pkg-tarball if requested
1628     [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME}
1629 niro 24 ;;
1630     esac
1631    
1632 niro 875 if [[ ${SMAGE_BUILD_LOGGING} != false ]]
1633     then
1634     bzip2 -9f /var/log/smage/${PKGNAME}.log
1635     else
1636     [[ -f /var/log/smage/${PKGNAME}.log ]] && rm /var/log/smage/${PKGNAME}.log
1637     fi
1638    
1639 niro 192 # for sure
1640 niro 24 unset NOPKGBUILD
1641 niro 85 unset NOSTRIP
1642 niro 351
1643 niro 24 xtitleclean

Properties

Name Value
svn:executable *