Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 256 - (hide annotations) (download) (as text)
Mon Oct 3 21:02:31 2005 UTC (18 years, 7 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/smage2.sh
File MIME type: application/x-sh
File size: 23576 byte(s)
fixed a typo

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

Properties

Name Value
svn:executable *