Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *