Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 199 - (hide annotations) (download) (as text)
Sun Aug 21 21:23:48 2005 UTC (18 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 20451 byte(s)
fixed fix_dep logic in regen-mage-tree

1 niro 24 #!/bin/bash
2    
3     # compiles/installs .smage2 source install scripts
4     # needs pkgbuild_dir (mage)
5    
6     # SMAGE2
7 niro 199 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.30 2005-08-21 21:23:48 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     if [[ ${cat} != virtual ]]
430     then
431     # fix pver to target-pver
432     # to get pname-target-pver
433 niro 193
434 niro 199 # doing it backwards !
435     pver="${dep##*-}"
436     pname=$(basename ${dep/-${pver}/})
437     fi
438 niro 193
439     # do not add empty lines
440     if [ -z "${NDEPEND}" ]
441     then
442 niro 198 NDEPEND="${sym} ${cat}/${pname}${target}-${pver}"
443 niro 193 else
444     NDEPEND="${NDEPEND}
445 niro 198 ${sym} ${cat}/${pname}${target}-${pver}"
446 niro 193 fi
447    
448     unset cat pname pver
449     done << EOF
450     ${depend}
451     EOF
452     # set NDEPEND to DEPEND
453     depend="${NDEPEND}"
454     fi
455    
456     echo "${depend}"
457     }
458    
459 niro 192 # build_mage_script(): helper functions for regen_mage_tree()
460 niro 191 # generates an mage file with given information in smage file
461     # needs at least:
462     # PNAME name of pkg
463     # PVER version
464     # PBUILD revision
465     # PCATEGORIE categorie of the pkg
466     # STATE state of pkg stable|unstable|old
467     # DESCRIPTION va short description (opt)
468     # HOMEPAGE homepage (opt)
469     # DEPEND runtime dependencies (opt)
470     # SDEPEND add. needed deps to build the pkg (opt)
471     # PROVIDE provides a virtual (opt)
472     #
473     # special tags:
474     # PKGTYPE type of pkg
475     # INHERITS which functions get included
476     # SPECIAL_FUNCTIONS special functions wich should also be added
477     # warning: they get killed before the build starts !
478     #
479     # MAGE_TREE_DEST target destination of the generated tree
480     # REGEN_MAGE_TREE set to 'true' to enable this
481 niro 193 #
482 niro 195 # gets called with build_mage_script target
483 niro 192 build_mage_script()
484 niro 191 {
485     local magefile
486     local dest
487 niro 193 local target
488 niro 191 local sym
489     local depname
490    
491     # if MAGE_TREE_DEST not set use BUILDDIR
492     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
493    
494     # determinate which suffix this mage file should get, if any
495 niro 195 [ -n "$1" ] && target="-$1"
496 niro 191
497     # name of magefile
498 niro 193 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
499 niro 191
500     # destination to magefile
501 niro 193 dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}"
502 niro 191
503     # show what we are doing
504     echo "Generating Mage file:"
505     echo " ${dest}"
506    
507     install -d "$(dirname ${dest})"
508     # now build the mage file
509     > ${dest}
510    
511     # header
512 niro 199 echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.30 2005-08-21 21:23:48 niro Exp $' >> ${dest}
513 niro 191 echo >> ${dest}
514    
515     # pgkname and state
516 niro 193 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
517 niro 191 echo "STATE=\"${STATE}\"" >> ${dest}
518     echo >> ${dest}
519    
520     # description and homepage
521     echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
522     echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
523     echo >> ${dest}
524    
525 niro 196 # special tags and vars
526 niro 191 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
527 niro 197 # add special vars
528     if [ -n "${SPECIAL_VARS}" ]
529 niro 191 then
530     local i
531 niro 197 for i in ${SPECIAL_VARS}
532 niro 191 do
533 niro 197 # being tricky here :)
534     echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
535 niro 191 done
536     echo >> ${dest}
537     fi
538 niro 197 # add at least all includes
539     if [ -n "${INHERITS}" ]
540 niro 196 then
541 niro 197 echo -n "minclude" >> ${dest}
542 niro 196 local i
543 niro 197 for i in ${INHERITS}
544 niro 196 do
545 niro 197 echo -n " ${i}" >> ${dest}
546 niro 196 done
547     echo >> ${dest}
548     fi
549 niro 197 echo >> ${dest}
550 niro 196
551 niro 191 # deps and provides
552 niro 193 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
553 niro 196 echo >> ${dest}
554 niro 193 echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
555 niro 196 echo >> ${dest}
556 niro 191 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
557     echo >> ${dest}
558    
559     # add special functions
560     if [ -n "${SPECIAL_FUNCTIONS}" ]
561     then
562     local i
563     for i in ${SPECIAL_FUNCTIONS}
564     do
565     # add to mage (quotes needed !)
566     typeset -f "${i}" >> ${dest}
567     # unset to be safe (quotes needed !)
568 niro 192 #unset "${i}" <-- later to get every target built
569 niro 191 done
570 niro 196 echo >> ${dest}
571 niro 191 fi
572    
573     # pre|post-install|removes
574     typeset -f preinstall >> ${dest}
575     echo >> ${dest}
576     typeset -f postinstall >> ${dest}
577     echo >> ${dest}
578     typeset -f preremove >> ${dest}
579     echo >> ${dest}
580     typeset -f postremove >> ${dest}
581     echo >> ${dest}
582     }
583    
584     regen_mage_tree()
585     {
586     local i
587    
588     # build them only if requested
589     if [[ ${REGEN_MAGE_TREE} = true ]]
590     then
591 niro 195 # run it without targets
592     if [ -z "${MAGE_TARGETS}" ]
593     then
594 niro 191 echo
595 niro 195 build_mage_script
596 niro 191 echo
597 niro 195 else
598    
599     # build for each target an mage file
600     # run it with several targets
601     for i in ${MAGE_TARGETS}
602     do
603     echo
604     build_mage_script "${i}"
605     echo
606     done
607     fi
608 niro 191 fi
609    
610     # now unset all uneeded vars to be safe
611 niro 192 # unset PKGNAME <-- don't do that; smage needs this var
612     # unset to be safe (quotes needed !)
613     for i in ${SPECIAL_FUNCTIONS}
614     do
615     unset "${i}"
616     done
617     unset SPECIAL_FUNCTIONS
618 niro 194 for i in ${SPECIAL_VARS}
619     do
620     unset "${i}"
621     done
622     unset SPECIAL_VARS
623 niro 191 unset STATE
624     unset DESCRIPTION
625     unset HOMEPAGE
626     unset PKGTYPE
627     unset INHERITS
628     unset DEPEND
629     unset SDEPEND
630     unset PROVIDE
631     unset preinstall
632     unset postinstall
633     unset preremove
634     unset postremove
635     }
636    
637 niro 59 # print out our version
638     showversion
639     echo
640    
641 niro 24 if [ -z "$1" ]
642     then
643     echo "No .smage2 file given. Exiting."
644     echo
645     exit 1
646     fi
647    
648 niro 192 # updating smage2-scripts
649 niro 24 if [ "$1" == "update" ]
650     then
651 niro 59 if [ ! -d ${SOURCEDIR} ]
652     then
653     install -d ${SOURCEDIR}
654     fi
655     syncsmage2
656     exit 0
657     fi
658    
659 niro 192 # creates md5sums for smages to given dir
660 niro 59 if [ "$1" == "calcmd5" ]
661     then
662     if [ $# -ge 3 ]
663     then
664     SMAGENAME="$2"
665     MD5DIR="$3"
666     source ${SMAGENAME} || die "download source failed"
667    
668 niro 66 # overridable sourcedir; must be declared after source of the smage2
669     CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
670    
671 niro 59 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
672    
673     # end of array
674     EOA=${#SRC_URI[*]}
675    
676     [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
677    
678     # clear md5sum file
679     MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
680     echo -n > ${MY_MD5_FILE}
681    
682     for ((i=0; i < EOA; i++))
683     do
684 niro 66 # url to file
685     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
686    
687     # subdir in sources dir; the my_SRCI_URI file goes to there
688     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
689    
690     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
691     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
692     then
693     MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
694     else
695     MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
696     fi
697    
698 niro 59 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
699     then
700     echo "calculating $(basename ${MY_SRC_FILE}) ..."
701     ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
702     else
703     echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
704     fi
705 niro 66
706     # unset them to be shure
707     unset my_SRC_URI
708     unset my_SRC_URI_DEST
709     unset my_SRC_URI_MIRROR
710     unset my_SOURCEDIR
711 niro 59 done
712    
713     echo
714     echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
715     echo
716     else
717     echo "Usage: Calculating MD5 Sums:"
718     echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR"
719     echo
720     echo
721     echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
722     echo
723     exit 1
724     fi
725    
726     exit 0
727     fi
728    
729 niro 192 # download sources
730 niro 59 if [ "$1" == "download" -a -n "$2" ]
731     then
732 niro 24 if [ ! -d ${SMAGESCRIPTSDIR} ]
733     then
734     install -d ${SMAGESCRIPTSDIR}
735     fi
736 niro 59
737     # get smage
738     SMAGENAME="$2"
739     MD5DIR="$(dirname ${SMAGENAME})/md5"
740     source ${SMAGENAME} || die "download source failed"
741    
742     download_sources
743 niro 24 exit 0
744     fi
745    
746     if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ]
747     then
748     die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
749     fi
750    
751     if [ -z "`basename ${SMAGENAME}|grep .${SMAGESUFFIX}`" ]
752     then
753     die "File '`basename ${SMAGENAME}`' is not a sMage v${SMAGEVERSION} file. Aborting."
754     fi
755    
756     if [ -z "${SOURCEDIR}" ]
757     then
758     die "\$SOURCEDIR not found. Please setup your mage.rc correctly."
759     fi
760    
761     if [ -z "${SMAGESCRIPTSDIR}" ]
762     then
763     die "\$SMAGESCRIPTSDIR not found. Please setup your mage.rc correctly."
764     fi
765    
766     if [ -z "${SMAGE2RSYNC}" ]
767     then
768     echo "\$SMAGE2RSYNC not found. Please setup your mage.rc correctly."
769     exit 1
770     fi
771    
772     if [ -z "${BINDIR}" ]
773     then
774     die "no BINDIR variable found in /etc/mage.rc"
775     fi
776    
777     if [ -z "${CHOST}" ]
778     then
779     die "no CHOST variable found in /etc/mage.rc"
780     fi
781    
782     if [ -z "${CFLAGS}" ]
783     then
784     die "no CFLAGS variable found in /etc/mage.rc"
785     fi
786    
787     if [ -z "${CXXFLAGS}" ]
788     then
789     die "no CXXFLAGS variable found in /etc/mage.rc"
790     fi
791    
792    
793     source ${SMAGENAME} || die "source failed"
794     PKGNAME="${PNAME}-${PVER}-${CHOST%%-*}-${PBUILD}"
795 niro 59 MD5DIR="$(dirname ${SMAGENAME})/md5"
796 niro 24
797     xtitle "Compiling ${PKGNAME}"
798 niro 59 echo "Compiling ${PKGNAME}"
799    
800 niro 191 # auto regen mage tree if requested
801     regen_mage_tree
802    
803 niro 192 # download sources
804 niro 59 download_sources
805    
806 niro 192 # fixes some issues with these functions
807 niro 24 export -f src_prepare || die "src_prepare export failed"
808     export -f src_compile || die "src_compile export failed"
809     export -f src_install || die "src_install export failed"
810    
811 niro 192 # fixes some compile issues
812 niro 24 export CHOST="${CHOST}" || die "CHOST export failed"
813     export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
814     export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
815     export BINDIR="${BINDIR}" || die "BINDIR export failed"
816     export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
817    
818    
819 niro 192 # setup distcc
820     # distcc mus be setup *before* ccache, as ccache need to be before distcc in path
821 niro 24 if [ "${SMAGE_USE_DISTCC}" == "true" ]
822     then
823     setup_distcc_environment
824     fi
825    
826 niro 192 # setup ccache
827 niro 24 if [ "${SMAGE_USE_CCACHE}" == "true" ]
828     then
829     setup_ccache_environment
830     fi
831    
832    
833     # small sleep to show our settings
834     sleep 1
835    
836     #debug
837     #echo "CC=${CC}"
838     #echo "CXX=${CXX}"
839     #echo "DISTCC_DIR=${DISTCC_DIR}"
840     #echo "PATH: ${PATH}"
841     #echo "--------------------------------------"
842     #env
843     #echo "--------------------------------------"
844     #read
845     #debug end
846    
847 niro 192 # cleans up build if a previously one exists
848 niro 24 if [ -d ${BUILDDIR} ]
849     then
850     rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
851     fi
852     install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
853    
854 niro 192 # cleans up srcdir if a previously unpacked one exists
855 niro 24 if [ -d ${SRCDIR} ]
856     then
857     rm -rf ${SRCDIR}
858     fi
859    
860 niro 192 # cleans up bindir if a previous build exists or creates a new one
861 niro 24 if [ -d ${BINDIR} ]
862     then
863     rm -rf ${BINDIR}
864     fi
865     install -d ${BINDIR} || die "couldn't create \$BINDIR."
866    
867 niro 192 # cleans up package temp dir if a previous build exists
868 niro 24 if [ -d ${BUILDDIR}/${PKGNAME} ]
869     then
870     rm -rf ${BUILDDIR}/${PKGNAME}
871     fi
872    
873 niro 192 # cleans up timestamp if one exists
874 niro 24 if [ -f /var/tmp/timestamp ]
875     then
876     mage rmstamp
877     fi
878    
879     src_prepare || die "src_prepare failed"
880     src_compile || die "src_compile failed"
881     src_install || die "src_install failed"
882    
883    
884 niro 192 # compressing doc, info & man files
885 niro 24 echo -e "Compressing man-pages ..."
886     if [ -d ${BUILDDIR}/builded/usr/share/man ]
887     then
888     ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man
889     fi
890    
891     echo -e "Compressing info-pages ..."
892     if [ -d ${BUILDDIR}/builded/usr/share/info ]
893     then
894     ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info
895     fi
896    
897 niro 79 # stripping all bins and libs
898     case ${NOSTRIP} in
899     true|TRUE|yes|y)
900     echo -e "NOSTRIP=true detected; Package will not be stripped ..."
901     ;;
902     *)
903     echo -e "Stripping binaries ..."
904     mstripbins ${BINDIR}
905     echo -e "Stripping libraries ..."
906     mstriplibs ${BINDIR}
907     ;;
908     esac
909    
910 niro 192 # the new buildpkg command
911 niro 24 case ${NOPKGBUILD} in
912     true|TRUE|yes|y)
913     echo -e "NOPGKBUILD=true detected; Package will not be build ..."
914     ;;
915 niro 192 *)
916     # build serveral targets
917     if [ -n "${MAGE_TARGETS}" ]
918     then
919     for target in ${MAGE_TARGETS}
920     do
921     # check if an special target_pkgbuild exists
922     if typeset -f ${target}_pkgbuild > /dev/null
923     then
924     # run it
925     ${target}_pkgbuild
926     fi
927     # now create the target package
928     ${MLIBDIR}/pkgbuild_dir.sh \
929     "${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD}" \
930     ${BINDIR} || die "target: ${target} package-build failed"
931     echo -e "\nPackage ${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD} successfully builded.\n"
932     done
933     else
934     ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
935     echo -e "\nPackage ${PKGNAME} successfully builded.\n"
936     fi
937 niro 24 ;;
938     esac
939    
940 niro 192 # for sure
941 niro 24 unset NOPKGBUILD
942 niro 85 unset NOSTRIP
943 niro 24
944     xtitleclean
945     #echo -e "\nPackage ${PKGNAME} successfully builded.\n"

Properties

Name Value
svn:executable *