Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *