Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 413 - (hide annotations) (download) (as text)
Fri Jan 19 23:15:04 2007 UTC (17 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 26034 byte(s)
show lineno and script name if a script dies

1 niro 24 #!/bin/bash
2    
3     # compiles/installs .smage2 source install scripts
4     # needs pkgbuild_dir (mage)
5    
6     # SMAGE2
7 niro 413 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.50 2007-01-19 23:15:04 niro Exp $
8 niro 24
9     #01.10.2004
10     # added ccache support
11     # added distcc support
12    
13     ## setup ##
14     PKGSUFFIX="mpk"
15 niro 403 SRCPKGSUFFIX="mpks"
16 niro 24 SMAGENAME="$1"
17     SMAGESUFFIX="smage2"
18     MLIBDIR=/usr/lib/mage
19 niro 186 SMAGEVERSION="$( < ${MLIBDIR}/version)"
20 niro 24
21 niro 351 ## only for tests -> normally in /etc/rc.d/init.d/functions
22     COLRED="\033[1;6m\033[31m"
23     COLGREEN="\033[1;6m\033[32m"
24     COLYELLOW="\033[1;6m\033[33m"
25     COLBLUE="\033[1;6m\033[34m"
26     COLMAGENTA="\033[1;6m\033[35m"
27     COLWHITE="\033[1;6m\033[37m"
28     COLGRAY="\033[0;6m\033[37m"
29     COLBOLD="\033[1m"
30     COLDEFAULT="\033[0m"
31    
32     if [[ ${NOCOLORS} = true ]]
33     then
34     COLRED=""
35     COLGREEN=""
36     COLYELLOW=""
37     COLBLUE=""
38     COLMAGENTA=""
39     COLWHITE=""
40     COLGRAY=""
41     COLBOLD=""
42     COLDEFAULT=""
43     fi
44    
45 niro 169 # export default C locale
46     export LC_ALL=C
47    
48 niro 24 source /etc/mage.rc
49    
50 niro 347 # set PKGDIR and BUILDDIR and BINDIR to MROOT
51     if [[ -n ${MROOT} ]]
52     then
53     export PKGDIR=${MROOT}/${PKGDIR}
54     export BUILDDIR=${MROOT}/${BUILDDIR}
55     export BINDIR=${MROOT}/${BINDIR}
56     fi
57    
58 niro 306 showversion()
59     {
60 niro 24 echo -en "Magellan Source Install v${SMAGEVERSION} "
61     echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
62     }
63    
64 niro 306 die()
65     {
66 niro 24 xtitleclean
67 niro 413 echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
68 niro 24 echo "SMAGE failed: $@"
69     exit 1
70     }
71    
72 niro 306 xtitle()
73     {
74     if [[ ${TERM} = xterm ]]
75 niro 24 then
76     echo -ne "\033]0;[sMage: $@]\007"
77     fi
78     return 0
79     }
80    
81 niro 306 xtitleclean()
82     {
83     if [[ ${TERM} = xterm ]]
84 niro 24 then
85     echo -ne "\033]0;\007"
86     fi
87     return 0
88     }
89    
90 niro 306 syncsmage2()
91     {
92 niro 24 xtitle "Updating smage2-script tree ..."
93     local i
94     for i in ${SMAGE2RSYNC}
95     do
96 niro 386 rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR}
97 niro 306 if [[ $? = 0 ]]
98 niro 24 then
99     break
100     else
101     continue
102     fi
103     done
104 niro 306
105     # clean up backup files (foo~)
106 niro 24 find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';'
107 niro 306
108 niro 24 xtitleclean
109     }
110    
111 niro 59 # $1 filename
112 niro 306 get_db_md5_sum()
113     {
114 niro 59 local DB_FILE
115     local MD5_FILE
116     local i
117    
118     DB_ENTRY="$(basename $1)"
119     MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})"
120    
121     i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)"
122    
123     echo "${i}"
124     }
125    
126 niro 306 download_sources()
127     {
128 niro 59
129 niro 61 [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0
130 niro 59
131     local EOA=${#SRC_URI[*]}
132 niro 66 local my_SRC_URI
133     local my_SRC_URI_DEST
134     local my_SRC_URI_MIRROR
135     local my_SOURCEDIR
136 niro 59 local DB_MD5_SUM_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
137     local FETCHING
138     local i mirror
139    
140 niro 306
141     # install SRCDIR/PNAME if not exist
142 niro 59 [ ! -d ${SOURCEDIR}/${PNAME} ] && install -d ${SOURCEDIR}/${PNAME}
143    
144     # check if FETCHING is needed
145 niro 66 ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} &> /dev/null )
146 niro 306 if [[ $? = 0 ]]
147 niro 59 then
148     # md5's ok, not fetching needed
149     FETCHING=false
150     else
151     FETCHING=true
152     fi
153 niro 306
154 niro 59 for ((i=0; i < EOA; i++))
155     do
156 niro 66 # url to file
157     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
158 niro 59
159 niro 66 # subdir in sources dir; the my_SRCI_URI file goes to there
160     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
161    
162     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
163     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
164     then
165     my_SOURCEDIR="${SOURCEDIR}/${PNAME}/${my_SRC_URI_DEST}"
166     else
167     my_SOURCEDIR="${SOURCEDIR}/${PNAME}"
168     fi
169    
170 niro 59 # if an mirrored file than replace first the mirror uri
171 niro 66 if [ -n "$(echo ${my_SRC_URI} | grep 'mirror://')" ]
172 niro 59 then
173     for mirror in ${MIRRORS}
174     do
175 niro 66 my_SRC_URI_MIRROR="$(echo ${my_SRC_URI} | sed "s|mirror:/|${mirror}/sources|g")"
176 niro 59
177 niro 306 if [[ ${FETCHING} = true ]]
178 niro 59 then
179 niro 66 echo "==> fetching ${my_SRC_URI_MIRROR}"
180 niro 59 wget \
181     --passive-ftp \
182     --tries 3 \
183     --continue \
184     --progress bar \
185 niro 66 --directory-prefix="${my_SOURCEDIR}" \
186     "${my_SRC_URI_MIRROR}"
187 niro 306 if [[ $? = 0 ]]
188 niro 59 then
189     break
190     else
191     continue
192     fi
193     fi
194     done
195     else
196 niro 306 if [[ ${FETCHING} = true ]]
197 niro 59 then
198 niro 66 echo "==> fetching ${my_SRC_URI}"
199 niro 59 wget \
200     --passive-ftp \
201     --tries 3 \
202     --continue \
203     --progress bar \
204 niro 66 --directory-prefix="${my_SOURCEDIR}" \
205     "${my_SRC_URI}"
206 niro 59 fi
207     fi
208 niro 306
209 niro 66 # unset them to be shure
210     unset my_SRC_URI
211     unset my_SRC_URI_DEST
212     unset my_SRC_URI_MIRROR
213     unset my_SOURCEDIR
214 niro 59 done
215    
216     # recheck md5 sums
217     echo
218     echo ">== Checking MD5 sums:"
219 niro 63 ( cd ${SOURCEDIR}/${PNAME}; md5sum --check ${DB_MD5_SUM_FILE} ) || die "md5 failed"
220 niro 59 echo
221    
222     # not needed anymore
223     unset SRC_URI
224     }
225    
226 niro 24 # dummy function, used if that not exist in smage file
227 niro 306 src_prepare()
228     {
229 niro 24 echo "no src_prepare defined"
230     sleep 2
231     return 0
232     }
233    
234     # dummy function, used if that not exist in smage file
235 niro 306 src_compile()
236     {
237 niro 24 echo "no src_compile defined"
238     sleep 2
239     return 0
240     }
241    
242     # dummy function, used if that not exist in smage file
243 niro 306 src_install()
244     {
245 niro 24 echo "no src_install defined"
246     sleep 2
247     return 0
248     }
249    
250 niro 351 mlibdir()
251     {
252     local libdir=lib
253     [[ ${ARCH} = x86_64 ]] && libdir=lib64
254    
255     echo "${libdir}"
256     }
257    
258 niro 306 mconfigure()
259     {
260 niro 24 if [ -x ./configure ]
261     then
262 niro 306 ./configure \
263     --prefix=/usr \
264     --host=${CHOST} \
265     --mandir=/usr/share/man \
266     --infodir=/usr/share/info \
267     --datadir=/usr/share \
268     --sysconfdir=/etc \
269     --localstatedir=/var/lib \
270 niro 351 --libdir=/usr/$(mlibdir) \
271 niro 306 "$@" || die "mconfigure failed"
272 niro 24 else
273     echo "configure is not an executable ..."
274     exit 1
275     fi
276     }
277    
278 niro 306 minstall()
279     {
280     if [ -f ./[mM]akefile -o -f ./GNUmakefile ]
281     then
282 niro 24 make prefix=${BINDIR}/usr \
283     datadir=${BINDIR}/usr/share \
284     infodir=${BINDIR}/usr/share/info \
285     localstatedir=${BINDIR}/var/lib \
286     mandir=${BINDIR}/usr/share/man \
287     sysconfdir=${BINDIR}/etc \
288 niro 351 libdir=${BINDIR}/usr/$(mlibdir) \
289 niro 24 "$@" install || die "minstall failed"
290     else
291     die "no Makefile found"
292     fi
293     }
294    
295 niro 306 mmake()
296     {
297 niro 24 make ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
298     }
299    
300 niro 306 munpack()
301     {
302 niro 24 local SRCFILE
303     local IFTAR
304     local DEST
305    
306     SRCFILE=$1
307 niro 306
308 niro 24 if [ -z "$2" ]
309     then
310     DEST=${BUILDDIR}
311     else
312     DEST=$2
313     fi
314 niro 306
315 niro 411 [[ ! -d ${DEST} ]] && install -d ${DEST}
316    
317 niro 24 case "${SRCFILE##*.}" in
318     bz2)
319     IFTAR="$(basename $SRCFILE .bz2)"
320     IFTAR="${IFTAR##*.}"
321 niro 306 if [[ ${IFTAR} = tar ]]
322 niro 24 then
323     tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
324     fi
325     ;;
326     gz)
327     IFTAR="$(basename $SRCFILE .gz)"
328     IFTAR="${IFTAR##*.}"
329 niro 306 if [[ ${IFTAR} = tar ]]
330 niro 24 then
331     tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
332     fi
333     ;;
334     tbz2)
335     tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
336     ;;
337     tgz)
338     tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
339     ;;
340     *)
341     die "munpack failed"
342     ;;
343     esac
344     }
345    
346 niro 306 mpatch()
347     {
348 niro 24 local PATCHOPTS
349     local PATCHFILE
350    
351     PATCHOPTS=$1
352     PATCHFILE=$2
353    
354 niro 384 echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}"
355 niro 24 patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE}
356     }
357    
358    
359 niro 306 minstalldocs()
360     {
361 niro 24 local docfiles
362     docfiles="$@"
363 niro 306
364 niro 24 if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ]
365     then
366     install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs."
367     fi
368 niro 306
369 niro 24 for i in ${docfiles}
370     do
371     cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs."
372     install -m 0644 ${SRCDIR}/${i}.gz \
373     ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs."
374     done
375     }
376    
377 niro 306 mstriplibs()
378     {
379 niro 79 local stripdir="$@"
380    
381     [ -z "${stripdir}" ] && stripdir=${BINDIR}
382     find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
383     }
384    
385 niro 306 mstripbins()
386     {
387 niro 79 local stripdir="$@"
388    
389     [ -z "${stripdir}" ] && stripdir=${BINDIR}
390     find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
391     }
392    
393 niro 306 sminclude()
394     {
395 niro 172 local i
396    
397 niro 183 if [[ -n "$@" ]]
398 niro 172 then
399     for i in $@
400     do
401 niro 175 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
402 niro 172 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
403     done
404 niro 177 echo
405 niro 172 fi
406     }
407    
408 niro 306 setup_distcc_environment()
409     {
410 niro 24 if [ -x /usr/bin/distcc ]
411     then
412     echo "Using DistCC for compilation ..."
413 niro 351 export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH"
414 niro 24
415     export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed"
416    
417 niro 306 # creating distcc tempdir
418 niro 24 install -o distcc -g daemon -d ${DISTCC_DIR}
419     chmod 1777 ${DISTCC_DIR}
420     fi
421     }
422    
423 niro 306 setup_ccache_environment()
424     {
425 niro 24 if [ -x /usr/bin/ccache ]
426     then
427     echo "Using CCache for compilation ..."
428 niro 351 export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
429 niro 24 fi
430     }
431    
432 niro 193
433     # fixes given dependencies to match a MAGE_TARGET
434 niro 198 # fix_mage_deps -target s/depend # <-- note -target !
435 niro 306 fix_mage_deps()
436     {
437 niro 193 local target="$1"
438     local depend="$2"
439     local NDEPEND
440     local sym dep cat pver pname
441    
442     # deps and provides are special
443     # they must be fixed to match the target
444    
445     # run this only if target and depend is not empty
446     if [ -n "${target}" ] && [ -n "${depend}" ]
447     then
448     # fix DEPEND
449     while read sym dep
450     do
451     cat="$(dirname ${dep})"
452 niro 199 # change if not virtual
453 niro 200 if [[ ${cat} = virtual ]]
454 niro 199 then
455 niro 200 pname="$(basename ${dep})"
456     else
457 niro 199 # fix pver to target-pver
458     # to get pname-target-pver
459 niro 193
460 niro 199 # doing it backwards !
461     pver="${dep##*-}"
462 niro 200 # full pver
463     pname="$(basename ${dep/-${pver}/})${target}-${pver}"
464 niro 199 fi
465 niro 193
466     # do not add empty lines
467     if [ -z "${NDEPEND}" ]
468     then
469 niro 200 NDEPEND="${sym} ${cat}/${pname}"
470 niro 193 else
471     NDEPEND="${NDEPEND}
472 niro 201 ${sym} ${cat}/${pname}"
473 niro 193 fi
474    
475     unset cat pname pver
476     done << EOF
477     ${depend}
478     EOF
479     # set NDEPEND to DEPEND
480     depend="${NDEPEND}"
481     fi
482    
483     echo "${depend}"
484     }
485    
486 niro 192 # build_mage_script(): helper functions for regen_mage_tree()
487 niro 191 # generates an mage file with given information in smage file
488     # needs at least:
489     # PNAME name of pkg
490     # PVER version
491     # PBUILD revision
492     # PCATEGORIE categorie of the pkg
493     # STATE state of pkg stable|unstable|old
494     # DESCRIPTION va short description (opt)
495     # HOMEPAGE homepage (opt)
496     # DEPEND runtime dependencies (opt)
497     # SDEPEND add. needed deps to build the pkg (opt)
498     # PROVIDE provides a virtual (opt)
499     #
500     # special tags:
501     # PKGTYPE type of pkg
502     # INHERITS which functions get included
503     # SPECIAL_FUNCTIONS special functions wich should also be added
504     # warning: they get killed before the build starts !
505     #
506     # MAGE_TREE_DEST target destination of the generated tree
507     # REGEN_MAGE_TREE set to 'true' to enable this
508 niro 193 #
509 niro 195 # gets called with build_mage_script target
510 niro 192 build_mage_script()
511 niro 191 {
512     local magefile
513     local dest
514 niro 193 local target
515 niro 191 local sym
516     local depname
517    
518     # if MAGE_TREE_DEST not set use BUILDDIR
519     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
520    
521     # determinate which suffix this mage file should get, if any
522 niro 195 [ -n "$1" ] && target="-$1"
523 niro 191
524     # name of magefile
525 niro 193 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
526 niro 191
527     # destination to magefile
528 niro 193 dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}"
529 niro 191
530     # show what we are doing
531     echo "Generating Mage file:"
532     echo " ${dest}"
533    
534     install -d "$(dirname ${dest})"
535     # now build the mage file
536     > ${dest}
537    
538     # header
539 niro 413 echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.50 2007-01-19 23:15:04 niro Exp $' >> ${dest}
540 niro 191 echo >> ${dest}
541    
542     # pgkname and state
543 niro 193 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
544 niro 191 echo "STATE=\"${STATE}\"" >> ${dest}
545     echo >> ${dest}
546    
547     # description and homepage
548     echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
549     echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
550     echo >> ${dest}
551    
552 niro 196 # special tags and vars
553 niro 191 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
554 niro 214
555     # echo MAGE_TARGETS ## note -target is needed !
556     echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
557     echo >> ${dest}
558    
559 niro 197 # add special vars
560     if [ -n "${SPECIAL_VARS}" ]
561 niro 191 then
562     local i
563 niro 197 for i in ${SPECIAL_VARS}
564 niro 191 do
565 niro 197 # being tricky here :)
566     echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
567 niro 191 done
568     echo >> ${dest}
569     fi
570 niro 214
571 niro 197 # add at least all includes
572     if [ -n "${INHERITS}" ]
573 niro 196 then
574 niro 197 echo -n "minclude" >> ${dest}
575 niro 196 local i
576 niro 197 for i in ${INHERITS}
577 niro 196 do
578 niro 197 echo -n " ${i}" >> ${dest}
579 niro 196 done
580     echo >> ${dest}
581     fi
582 niro 197 echo >> ${dest}
583 niro 196
584 niro 191 # deps and provides
585 niro 193 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
586 niro 196 echo >> ${dest}
587 niro 193 echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
588 niro 196 echo >> ${dest}
589 niro 191 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
590     echo >> ${dest}
591    
592     # add special functions
593     if [ -n "${SPECIAL_FUNCTIONS}" ]
594     then
595     local i
596     for i in ${SPECIAL_FUNCTIONS}
597     do
598     # add to mage (quotes needed !)
599     typeset -f "${i}" >> ${dest}
600 niro 214 echo >> ${dest}
601 niro 191 # unset to be safe (quotes needed !)
602 niro 192 #unset "${i}" <-- later to get every target built
603 niro 191 done
604 niro 196 echo >> ${dest}
605 niro 191 fi
606    
607     # pre|post-install|removes
608     typeset -f preinstall >> ${dest}
609     echo >> ${dest}
610     typeset -f postinstall >> ${dest}
611     echo >> ${dest}
612     typeset -f preremove >> ${dest}
613     echo >> ${dest}
614     typeset -f postremove >> ${dest}
615     echo >> ${dest}
616     }
617    
618     regen_mage_tree()
619     {
620     local i
621    
622     # build them only if requested
623     if [[ ${REGEN_MAGE_TREE} = true ]]
624     then
625 niro 195 # run it without targets
626     if [ -z "${MAGE_TARGETS}" ]
627     then
628 niro 191 echo
629 niro 195 build_mage_script
630 niro 191 echo
631 niro 195 else
632    
633     # build for each target an mage file
634     # run it with several targets
635     for i in ${MAGE_TARGETS}
636     do
637     echo
638     build_mage_script "${i}"
639     echo
640     done
641     fi
642 niro 191 fi
643    
644     # now unset all uneeded vars to be safe
645 niro 192 # unset PKGNAME <-- don't do that; smage needs this var
646     # unset to be safe (quotes needed !)
647     for i in ${SPECIAL_FUNCTIONS}
648     do
649     unset "${i}"
650     done
651     unset SPECIAL_FUNCTIONS
652 niro 194 for i in ${SPECIAL_VARS}
653     do
654     unset "${i}"
655     done
656     unset SPECIAL_VARS
657 niro 191 unset STATE
658     unset DESCRIPTION
659     unset HOMEPAGE
660     unset PKGTYPE
661     unset INHERITS
662     unset DEPEND
663     unset SDEPEND
664     unset PROVIDE
665     unset preinstall
666     unset postinstall
667     unset preremove
668     unset postremove
669     }
670    
671 niro 253 export_inherits()
672     {
673     local include="$1"
674     shift
675    
676     while [ "$1" ]
677     do
678     local functions="$1"
679    
680     # sanity checks
681     [ -z "${include}" ] && die "export_inherits(): \$include not given."
682     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
683    
684     eval "${functions}() { ${include}_${functions} ; }"
685    
686     # debug
687     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
688    
689     shift
690     done
691     }
692    
693 niro 255 generate_package_md5sum()
694     {
695     local dest
696     local pcat
697     local pname
698     local pver
699     local pbuild
700     local parch
701     local target
702     local pkgname
703    
704     # very basic getops
705     for i in $*
706     do
707     case $1 in
708     --pcat|-c) shift; pcat="$1" ;;
709     --pname|-n) shift; pname="$1" ;;
710     --pver|-v) shift; pver="$1" ;;
711     --pbuild|-b) shift; pbuild="$1" ;;
712     --parch|a) shift; parch="$1" ;;
713     --target|t) shift; target="$1" ;;
714     esac
715     shift
716     done
717    
718     # sanity checks; abort if not given
719     [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
720     [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
721     [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
722     [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
723     [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
724    
725     # check needed global vars
726     [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
727     [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
728    
729     # fix target as it may be empty !
730     [ -n "${target}" ] && target="-${target}"
731    
732     # build pkgname
733     pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
734    
735     # build pkg-md5-sum only if requested
736     if [[ ${REGEN_MAGE_TREE} = true ]]
737     then
738     echo -n "Generating a md5sum for ${pkgname}.${PKGSUFFIX} ... "
739    
740     # abort if not exist
741     if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
742     then
743     echo "! exists"
744     return 0
745     fi
746    
747     # if MAGE_TREE_DEST not set use BUILDDIR
748     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
749    
750     # setup md5 dir
751     dest="${MAGE_TREE_DEST}/${pcat}/${pname}/md5"
752     install -d ${dest}
753    
754     # gen md5sum
755     ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
756 niro 256 > ${dest}/${pkgname}.md5
757 niro 255 echo "done"
758     fi
759     }
760    
761 niro 403 source_pkg_build()
762     {
763     if [[ ${PKGTYPE} = virtual ]]
764     then
765     echo "Virtual package detected; src-pkg-tarball not necessary ..."
766     return 0
767     fi
768    
769     if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
770     then
771     echo "No SRC_URI defined; src-pkg-tarball not necessary ..."
772     return 0
773     fi
774    
775 niro 406 [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your mage.rc correctly."
776    
777 niro 403 echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}"
778 niro 412
779     # include the smage2 file
780     cp ${SMAGENAME} ${SOURCEDIR}/${PNAME}
781    
782 niro 403 ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; )
783 niro 406 [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR}
784     mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX}
785 niro 403
786     echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}"
787     }
788    
789    
790 niro 59 # print out our version
791     showversion
792     echo
793    
794 niro 24 if [ -z "$1" ]
795     then
796     echo "No .smage2 file given. Exiting."
797     echo
798     exit 1
799     fi
800    
801 niro 192 # updating smage2-scripts
802 niro 306 if [[ $1 = update ]]
803 niro 24 then
804 niro 59 if [ ! -d ${SOURCEDIR} ]
805     then
806     install -d ${SOURCEDIR}
807     fi
808     syncsmage2
809     exit 0
810     fi
811    
812 niro 192 # creates md5sums for smages to given dir
813 niro 306 if [[ $1 = calcmd5 ]]
814 niro 59 then
815     if [ $# -ge 3 ]
816     then
817     SMAGENAME="$2"
818     MD5DIR="$3"
819     source ${SMAGENAME} || die "download source failed"
820    
821 niro 66 # overridable sourcedir; must be declared after source of the smage2
822     CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
823    
824 niro 59 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
825    
826     # end of array
827     EOA=${#SRC_URI[*]}
828    
829     [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
830    
831     # clear md5sum file
832     MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
833     echo -n > ${MY_MD5_FILE}
834    
835     for ((i=0; i < EOA; i++))
836     do
837 niro 66 # url to file
838     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
839    
840     # subdir in sources dir; the my_SRCI_URI file goes to there
841     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
842    
843     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
844     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
845     then
846     MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
847     else
848     MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
849     fi
850    
851 niro 59 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
852     then
853     echo "calculating $(basename ${MY_SRC_FILE}) ..."
854     ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
855     else
856     echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
857     fi
858 niro 66
859     # unset them to be shure
860     unset my_SRC_URI
861     unset my_SRC_URI_DEST
862     unset my_SRC_URI_MIRROR
863     unset my_SOURCEDIR
864 niro 59 done
865 niro 306
866 niro 59 echo
867     echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
868     echo
869     else
870     echo "Usage: Calculating MD5 Sums:"
871     echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR"
872     echo
873     echo
874     echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
875     echo
876     exit 1
877     fi
878 niro 306
879 niro 59 exit 0
880     fi
881    
882 niro 192 # download sources
883 niro 59 if [ "$1" == "download" -a -n "$2" ]
884     then
885 niro 24 if [ ! -d ${SMAGESCRIPTSDIR} ]
886     then
887     install -d ${SMAGESCRIPTSDIR}
888     fi
889 niro 59
890     # get smage
891     SMAGENAME="$2"
892     MD5DIR="$(dirname ${SMAGENAME})/md5"
893     source ${SMAGENAME} || die "download source failed"
894    
895     download_sources
896 niro 24 exit 0
897     fi
898    
899 niro 202 # regen-mage-tree
900     if [ "$1" == "only-regen-tree" -a -n "$2" ]
901     then
902     # set correct SMAGENAME
903     SMAGENAME="$2"
904     MD5DIR="$(dirname ${SMAGENAME})/md5"
905     source ${SMAGENAME} || die "regen: smage2 not found"
906    
907     regen_mage_tree
908 niro 255
909     # build md5sum for existing packages
910     generate_package_md5sum \
911     --pcat "${PCATEGORIE}" \
912     --pname "${PNAME}" \
913     --pver "${PVER}" \
914     --pbuild "${PBUILD}" \
915     --parch "${ARCH}" \
916     --target "${target}"
917    
918 niro 202 exit 0
919     fi
920    
921 niro 412 if [ "$1" == "--create-src-tarball" -a -n "$2" ]
922 niro 403 then
923     # set correct SMAGENAME
924     SMAGENAME="$2"
925     MD5DIR="$(dirname ${SMAGENAME})/md5"
926    
927 niro 412 echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}"
928 niro 403
929     source ${SMAGENAME} || die "regen: smage2 not found"
930    
931     if [[ -d ${SOURCEDIR}/${PNAME} ]]
932     then
933     echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
934     rm -rf ${SOURCEDIR}/${PKGNAME}
935     fi
936    
937     download_sources
938     source_pkg_build ${SMAGENAME}
939     exit 0
940     fi
941    
942 niro 406 if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ]
943 niro 403 then
944 niro 412 SRCPKGTARBALL="${2}"
945 niro 403 USE_SRC_PKG_TARBALL=true
946    
947 niro 412 # abort if given file is not a source pkg
948     [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file."
949    
950     # set correct SMAGENAME; use the one that the src_pkg provide
951     # /path/to/SOURCEDIR/PNAME/SMAGENAME
952     SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}"
953    
954 niro 403 echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}"
955    
956     [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR}
957    
958     # unpack srctarball
959     [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting."
960    
961     tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}"
962 niro 412
963     [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}"
964 niro 403 fi
965    
966    
967 niro 306 [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
968     [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] &&
969     die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting."
970     [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your mage.rc correctly."
971     [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your mage.rc correctly."
972     [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your mage.rc correctly."
973     [ -z "${BINDIR}" ] && die "no BINDIR variable found in /etc/mage.rc"
974     [ -z "${CHOST}" ] && die "no CHOST variable found in /etc/mage.rc"
975     [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in /etc/mage.rc"
976     [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in /etc/mage.rc"
977 niro 24
978     source ${SMAGENAME} || die "source failed"
979 niro 255 PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}"
980 niro 59 MD5DIR="$(dirname ${SMAGENAME})/md5"
981 niro 24
982     xtitle "Compiling ${PKGNAME}"
983 niro 59 echo "Compiling ${PKGNAME}"
984    
985 niro 191 # auto regen mage tree if requested
986     regen_mage_tree
987    
988 niro 403 if [[ ${CREATE_SRC_PKG_TARBALL} = true ]]
989     then
990     if [[ -d ${SOURCEDIR}/${PNAME} ]]
991     then
992     echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
993 niro 408 rm -rf ${SOURCEDIR}/${PNAME}
994 niro 403 fi
995     fi
996    
997 niro 192 # download sources
998 niro 403 [[ ${USE_SRC_PKG_TARBALL} != true ]] && download_sources
999 niro 59
1000 niro 192 # fixes some issues with these functions
1001 niro 24 export -f src_prepare || die "src_prepare export failed"
1002     export -f src_compile || die "src_compile export failed"
1003     export -f src_install || die "src_install export failed"
1004    
1005 niro 192 # fixes some compile issues
1006 niro 24 export CHOST="${CHOST}" || die "CHOST export failed"
1007     export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
1008     export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
1009     export BINDIR="${BINDIR}" || die "BINDIR export failed"
1010     export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
1011    
1012    
1013 niro 192 # setup distcc
1014 niro 351 # setup for distcc goes *before* ccache, so ccache comes before distcc in path
1015 niro 306 [[ ${SMAGE_USE_DISTCC} = true ]] && setup_distcc_environment
1016 niro 24
1017 niro 192 # setup ccache
1018 niro 306 [[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment
1019 niro 24
1020     # small sleep to show our settings
1021     sleep 1
1022    
1023 niro 192 # cleans up build if a previously one exists
1024 niro 24 if [ -d ${BUILDDIR} ]
1025     then
1026     rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
1027     fi
1028     install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
1029    
1030 niro 192 # cleans up srcdir if a previously unpacked one exists
1031 niro 24 if [ -d ${SRCDIR} ]
1032     then
1033     rm -rf ${SRCDIR}
1034     fi
1035    
1036 niro 192 # cleans up bindir if a previous build exists or creates a new one
1037 niro 24 if [ -d ${BINDIR} ]
1038     then
1039     rm -rf ${BINDIR}
1040     fi
1041     install -d ${BINDIR} || die "couldn't create \$BINDIR."
1042    
1043 niro 192 # cleans up package temp dir if a previous build exists
1044 niro 24 if [ -d ${BUILDDIR}/${PKGNAME} ]
1045     then
1046     rm -rf ${BUILDDIR}/${PKGNAME}
1047     fi
1048    
1049 niro 192 # cleans up timestamp if one exists
1050 niro 24 if [ -f /var/tmp/timestamp ]
1051     then
1052     mage rmstamp
1053     fi
1054    
1055     src_prepare || die "src_prepare failed"
1056     src_compile || die "src_compile failed"
1057     src_install || die "src_install failed"
1058    
1059    
1060 niro 192 # compressing doc, info & man files
1061 niro 24 echo -e "Compressing man-pages ..."
1062     if [ -d ${BUILDDIR}/builded/usr/share/man ]
1063     then
1064     ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man
1065     fi
1066    
1067     echo -e "Compressing info-pages ..."
1068     if [ -d ${BUILDDIR}/builded/usr/share/info ]
1069     then
1070     ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info
1071     fi
1072    
1073 niro 79 # stripping all bins and libs
1074     case ${NOSTRIP} in
1075     true|TRUE|yes|y)
1076     echo -e "NOSTRIP=true detected; Package will not be stripped ..."
1077     ;;
1078     *)
1079     echo -e "Stripping binaries ..."
1080     mstripbins ${BINDIR}
1081     echo -e "Stripping libraries ..."
1082     mstriplibs ${BINDIR}
1083     ;;
1084     esac
1085    
1086 niro 192 # the new buildpkg command
1087 niro 24 case ${NOPKGBUILD} in
1088     true|TRUE|yes|y)
1089     echo -e "NOPGKBUILD=true detected; Package will not be build ..."
1090     ;;
1091 niro 192 *)
1092 niro 306 # build several targets
1093 niro 192 if [ -n "${MAGE_TARGETS}" ]
1094     then
1095     for target in ${MAGE_TARGETS}
1096     do
1097     # check if an special target_pkgbuild exists
1098     if typeset -f ${target}_pkgbuild > /dev/null
1099     then
1100     # run it
1101     ${target}_pkgbuild
1102     fi
1103     # now create the target package
1104     ${MLIBDIR}/pkgbuild_dir.sh \
1105 niro 255 "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \
1106 niro 192 ${BINDIR} || die "target: ${target} package-build failed"
1107 niro 255
1108     # build pkg-md5-sum if requested
1109     generate_package_md5sum \
1110     --pcat "${PCATEGORIE}" \
1111     --pname "${PNAME}" \
1112     --pver "${PVER}" \
1113     --pbuild "${PBUILD}" \
1114     --parch "${ARCH}" \
1115     --target "${target}"
1116    
1117     echo -e "\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n"
1118 niro 192 done
1119     else
1120     ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1121 niro 255
1122     # build pkg-md5-sum if requested
1123     generate_package_md5sum \
1124     --pcat "${PCATEGORIE}" \
1125     --pname "${PNAME}" \
1126     --pver "${PVER}" \
1127     --pbuild "${PBUILD}" \
1128     --parch "${ARCH}"
1129    
1130 niro 192 echo -e "\nPackage ${PKGNAME} successfully builded.\n"
1131     fi
1132 niro 403
1133     # build src-pkg-tarball if requested
1134     [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME}
1135 niro 24 ;;
1136     esac
1137    
1138 niro 192 # for sure
1139 niro 24 unset NOPKGBUILD
1140 niro 85 unset NOSTRIP
1141 niro 351
1142 niro 24 xtitleclean

Properties

Name Value
svn:executable *