Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 384 - (hide annotations) (download) (as text)
Mon Jul 17 20:44:44 2006 UTC (17 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 23286 byte(s)
show a message when applying patches

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

Properties

Name Value
svn:executable *