Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *