Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (hide annotations) (download) (as text)
Fri Jan 19 23:11:17 2007 UTC (17 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 25952 byte(s)
better support for srctarballs

1 niro 24 #!/bin/bash
2    
3     # compiles/installs .smage2 source install scripts
4     # needs pkgbuild_dir (mage)
5    
6     # SMAGE2
7 niro 412 # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.49 2007-01-19 23:11:17 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 411 [[ ! -d ${DEST} ]] && install -d ${DEST}
315    
316 niro 24 case "${SRCFILE##*.}" in
317     bz2)
318     IFTAR="$(basename $SRCFILE .bz2)"
319     IFTAR="${IFTAR##*.}"
320 niro 306 if [[ ${IFTAR} = tar ]]
321 niro 24 then
322     tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
323     fi
324     ;;
325     gz)
326     IFTAR="$(basename $SRCFILE .gz)"
327     IFTAR="${IFTAR##*.}"
328 niro 306 if [[ ${IFTAR} = tar ]]
329 niro 24 then
330     tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
331     fi
332     ;;
333     tbz2)
334     tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
335     ;;
336     tgz)
337     tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST}
338     ;;
339     *)
340     die "munpack failed"
341     ;;
342     esac
343     }
344    
345 niro 306 mpatch()
346     {
347 niro 24 local PATCHOPTS
348     local PATCHFILE
349    
350     PATCHOPTS=$1
351     PATCHFILE=$2
352    
353 niro 384 echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}"
354 niro 24 patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE}
355     }
356    
357    
358 niro 306 minstalldocs()
359     {
360 niro 24 local docfiles
361     docfiles="$@"
362 niro 306
363 niro 24 if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ]
364     then
365     install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs."
366     fi
367 niro 306
368 niro 24 for i in ${docfiles}
369     do
370     cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs."
371     install -m 0644 ${SRCDIR}/${i}.gz \
372     ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs."
373     done
374     }
375    
376 niro 306 mstriplibs()
377     {
378 niro 79 local stripdir="$@"
379    
380     [ -z "${stripdir}" ] && stripdir=${BINDIR}
381     find ${stripdir} | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
382     }
383    
384 niro 306 mstripbins()
385     {
386 niro 79 local stripdir="$@"
387    
388     [ -z "${stripdir}" ] && stripdir=${BINDIR}
389     find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
390     }
391    
392 niro 306 sminclude()
393     {
394 niro 172 local i
395    
396 niro 183 if [[ -n "$@" ]]
397 niro 172 then
398     for i in $@
399     do
400 niro 175 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
401 niro 172 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
402     done
403 niro 177 echo
404 niro 172 fi
405     }
406    
407 niro 306 setup_distcc_environment()
408     {
409 niro 24 if [ -x /usr/bin/distcc ]
410     then
411     echo "Using DistCC for compilation ..."
412 niro 351 export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH"
413 niro 24
414     export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed"
415    
416 niro 306 # creating distcc tempdir
417 niro 24 install -o distcc -g daemon -d ${DISTCC_DIR}
418     chmod 1777 ${DISTCC_DIR}
419     fi
420     }
421    
422 niro 306 setup_ccache_environment()
423     {
424 niro 24 if [ -x /usr/bin/ccache ]
425     then
426     echo "Using CCache for compilation ..."
427 niro 351 export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
428 niro 24 fi
429     }
430    
431 niro 193
432     # fixes given dependencies to match a MAGE_TARGET
433 niro 198 # fix_mage_deps -target s/depend # <-- note -target !
434 niro 306 fix_mage_deps()
435     {
436 niro 193 local target="$1"
437     local depend="$2"
438     local NDEPEND
439     local sym dep cat pver pname
440    
441     # deps and provides are special
442     # they must be fixed to match the target
443    
444     # run this only if target and depend is not empty
445     if [ -n "${target}" ] && [ -n "${depend}" ]
446     then
447     # fix DEPEND
448     while read sym dep
449     do
450     cat="$(dirname ${dep})"
451 niro 199 # change if not virtual
452 niro 200 if [[ ${cat} = virtual ]]
453 niro 199 then
454 niro 200 pname="$(basename ${dep})"
455     else
456 niro 199 # fix pver to target-pver
457     # to get pname-target-pver
458 niro 193
459 niro 199 # doing it backwards !
460     pver="${dep##*-}"
461 niro 200 # full pver
462     pname="$(basename ${dep/-${pver}/})${target}-${pver}"
463 niro 199 fi
464 niro 193
465     # do not add empty lines
466     if [ -z "${NDEPEND}" ]
467     then
468 niro 200 NDEPEND="${sym} ${cat}/${pname}"
469 niro 193 else
470     NDEPEND="${NDEPEND}
471 niro 201 ${sym} ${cat}/${pname}"
472 niro 193 fi
473    
474     unset cat pname pver
475     done << EOF
476     ${depend}
477     EOF
478     # set NDEPEND to DEPEND
479     depend="${NDEPEND}"
480     fi
481    
482     echo "${depend}"
483     }
484    
485 niro 192 # build_mage_script(): helper functions for regen_mage_tree()
486 niro 191 # generates an mage file with given information in smage file
487     # needs at least:
488     # PNAME name of pkg
489     # PVER version
490     # PBUILD revision
491     # PCATEGORIE categorie of the pkg
492     # STATE state of pkg stable|unstable|old
493     # DESCRIPTION va short description (opt)
494     # HOMEPAGE homepage (opt)
495     # DEPEND runtime dependencies (opt)
496     # SDEPEND add. needed deps to build the pkg (opt)
497     # PROVIDE provides a virtual (opt)
498     #
499     # special tags:
500     # PKGTYPE type of pkg
501     # INHERITS which functions get included
502     # SPECIAL_FUNCTIONS special functions wich should also be added
503     # warning: they get killed before the build starts !
504     #
505     # MAGE_TREE_DEST target destination of the generated tree
506     # REGEN_MAGE_TREE set to 'true' to enable this
507 niro 193 #
508 niro 195 # gets called with build_mage_script target
509 niro 192 build_mage_script()
510 niro 191 {
511     local magefile
512     local dest
513 niro 193 local target
514 niro 191 local sym
515     local depname
516    
517     # if MAGE_TREE_DEST not set use BUILDDIR
518     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
519    
520     # determinate which suffix this mage file should get, if any
521 niro 195 [ -n "$1" ] && target="-$1"
522 niro 191
523     # name of magefile
524 niro 193 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
525 niro 191
526     # destination to magefile
527 niro 193 dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}"
528 niro 191
529     # show what we are doing
530     echo "Generating Mage file:"
531     echo " ${dest}"
532    
533     install -d "$(dirname ${dest})"
534     # now build the mage file
535     > ${dest}
536    
537     # header
538 niro 412 echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.49 2007-01-19 23:11:17 niro Exp $' >> ${dest}
539 niro 191 echo >> ${dest}
540    
541     # pgkname and state
542 niro 193 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
543 niro 191 echo "STATE=\"${STATE}\"" >> ${dest}
544     echo >> ${dest}
545    
546     # description and homepage
547     echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
548     echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
549     echo >> ${dest}
550    
551 niro 196 # special tags and vars
552 niro 191 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
553 niro 214
554     # echo MAGE_TARGETS ## note -target is needed !
555     echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
556     echo >> ${dest}
557    
558 niro 197 # add special vars
559     if [ -n "${SPECIAL_VARS}" ]
560 niro 191 then
561     local i
562 niro 197 for i in ${SPECIAL_VARS}
563 niro 191 do
564 niro 197 # being tricky here :)
565     echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
566 niro 191 done
567     echo >> ${dest}
568     fi
569 niro 214
570 niro 197 # add at least all includes
571     if [ -n "${INHERITS}" ]
572 niro 196 then
573 niro 197 echo -n "minclude" >> ${dest}
574 niro 196 local i
575 niro 197 for i in ${INHERITS}
576 niro 196 do
577 niro 197 echo -n " ${i}" >> ${dest}
578 niro 196 done
579     echo >> ${dest}
580     fi
581 niro 197 echo >> ${dest}
582 niro 196
583 niro 191 # deps and provides
584 niro 193 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
585 niro 196 echo >> ${dest}
586 niro 193 echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
587 niro 196 echo >> ${dest}
588 niro 191 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
589     echo >> ${dest}
590    
591     # add special functions
592     if [ -n "${SPECIAL_FUNCTIONS}" ]
593     then
594     local i
595     for i in ${SPECIAL_FUNCTIONS}
596     do
597     # add to mage (quotes needed !)
598     typeset -f "${i}" >> ${dest}
599 niro 214 echo >> ${dest}
600 niro 191 # unset to be safe (quotes needed !)
601 niro 192 #unset "${i}" <-- later to get every target built
602 niro 191 done
603 niro 196 echo >> ${dest}
604 niro 191 fi
605    
606     # pre|post-install|removes
607     typeset -f preinstall >> ${dest}
608     echo >> ${dest}
609     typeset -f postinstall >> ${dest}
610     echo >> ${dest}
611     typeset -f preremove >> ${dest}
612     echo >> ${dest}
613     typeset -f postremove >> ${dest}
614     echo >> ${dest}
615     }
616    
617     regen_mage_tree()
618     {
619     local i
620    
621     # build them only if requested
622     if [[ ${REGEN_MAGE_TREE} = true ]]
623     then
624 niro 195 # run it without targets
625     if [ -z "${MAGE_TARGETS}" ]
626     then
627 niro 191 echo
628 niro 195 build_mage_script
629 niro 191 echo
630 niro 195 else
631    
632     # build for each target an mage file
633     # run it with several targets
634     for i in ${MAGE_TARGETS}
635     do
636     echo
637     build_mage_script "${i}"
638     echo
639     done
640     fi
641 niro 191 fi
642    
643     # now unset all uneeded vars to be safe
644 niro 192 # unset PKGNAME <-- don't do that; smage needs this var
645     # unset to be safe (quotes needed !)
646     for i in ${SPECIAL_FUNCTIONS}
647     do
648     unset "${i}"
649     done
650     unset SPECIAL_FUNCTIONS
651 niro 194 for i in ${SPECIAL_VARS}
652     do
653     unset "${i}"
654     done
655     unset SPECIAL_VARS
656 niro 191 unset STATE
657     unset DESCRIPTION
658     unset HOMEPAGE
659     unset PKGTYPE
660     unset INHERITS
661     unset DEPEND
662     unset SDEPEND
663     unset PROVIDE
664     unset preinstall
665     unset postinstall
666     unset preremove
667     unset postremove
668     }
669    
670 niro 253 export_inherits()
671     {
672     local include="$1"
673     shift
674    
675     while [ "$1" ]
676     do
677     local functions="$1"
678    
679     # sanity checks
680     [ -z "${include}" ] && die "export_inherits(): \$include not given."
681     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
682    
683     eval "${functions}() { ${include}_${functions} ; }"
684    
685     # debug
686     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
687    
688     shift
689     done
690     }
691    
692 niro 255 generate_package_md5sum()
693     {
694     local dest
695     local pcat
696     local pname
697     local pver
698     local pbuild
699     local parch
700     local target
701     local pkgname
702    
703     # very basic getops
704     for i in $*
705     do
706     case $1 in
707     --pcat|-c) shift; pcat="$1" ;;
708     --pname|-n) shift; pname="$1" ;;
709     --pver|-v) shift; pver="$1" ;;
710     --pbuild|-b) shift; pbuild="$1" ;;
711     --parch|a) shift; parch="$1" ;;
712     --target|t) shift; target="$1" ;;
713     esac
714     shift
715     done
716    
717     # sanity checks; abort if not given
718     [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
719     [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
720     [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
721     [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
722     [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
723    
724     # check needed global vars
725     [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
726     [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
727    
728     # fix target as it may be empty !
729     [ -n "${target}" ] && target="-${target}"
730    
731     # build pkgname
732     pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
733    
734     # build pkg-md5-sum only if requested
735     if [[ ${REGEN_MAGE_TREE} = true ]]
736     then
737     echo -n "Generating a md5sum for ${pkgname}.${PKGSUFFIX} ... "
738    
739     # abort if not exist
740     if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
741     then
742     echo "! exists"
743     return 0
744     fi
745    
746     # if MAGE_TREE_DEST not set use BUILDDIR
747     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
748    
749     # setup md5 dir
750     dest="${MAGE_TREE_DEST}/${pcat}/${pname}/md5"
751     install -d ${dest}
752    
753     # gen md5sum
754     ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
755 niro 256 > ${dest}/${pkgname}.md5
756 niro 255 echo "done"
757     fi
758     }
759    
760 niro 403 source_pkg_build()
761     {
762     if [[ ${PKGTYPE} = virtual ]]
763     then
764     echo "Virtual package detected; src-pkg-tarball not necessary ..."
765     return 0
766     fi
767    
768     if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
769     then
770     echo "No SRC_URI defined; src-pkg-tarball not necessary ..."
771     return 0
772     fi
773    
774 niro 406 [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your mage.rc correctly."
775    
776 niro 403 echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}"
777 niro 412
778     # include the smage2 file
779     cp ${SMAGENAME} ${SOURCEDIR}/${PNAME}
780    
781 niro 403 ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; )
782 niro 406 [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR}
783     mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX}
784 niro 403
785     echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}"
786     }
787    
788    
789 niro 59 # print out our version
790     showversion
791     echo
792    
793 niro 24 if [ -z "$1" ]
794     then
795     echo "No .smage2 file given. Exiting."
796     echo
797     exit 1
798     fi
799    
800 niro 192 # updating smage2-scripts
801 niro 306 if [[ $1 = update ]]
802 niro 24 then
803 niro 59 if [ ! -d ${SOURCEDIR} ]
804     then
805     install -d ${SOURCEDIR}
806     fi
807     syncsmage2
808     exit 0
809     fi
810    
811 niro 192 # creates md5sums for smages to given dir
812 niro 306 if [[ $1 = calcmd5 ]]
813 niro 59 then
814     if [ $# -ge 3 ]
815     then
816     SMAGENAME="$2"
817     MD5DIR="$3"
818     source ${SMAGENAME} || die "download source failed"
819    
820 niro 66 # overridable sourcedir; must be declared after source of the smage2
821     CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
822    
823 niro 59 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
824    
825     # end of array
826     EOA=${#SRC_URI[*]}
827    
828     [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
829    
830     # clear md5sum file
831     MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
832     echo -n > ${MY_MD5_FILE}
833    
834     for ((i=0; i < EOA; i++))
835     do
836 niro 66 # url to file
837     my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
838    
839     # subdir in sources dir; the my_SRCI_URI file goes to there
840     my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
841    
842     # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
843     if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
844     then
845     MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
846     else
847     MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
848     fi
849    
850 niro 59 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
851     then
852     echo "calculating $(basename ${MY_SRC_FILE}) ..."
853     ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
854     else
855     echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
856     fi
857 niro 66
858     # unset them to be shure
859     unset my_SRC_URI
860     unset my_SRC_URI_DEST
861     unset my_SRC_URI_MIRROR
862     unset my_SOURCEDIR
863 niro 59 done
864 niro 306
865 niro 59 echo
866     echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
867     echo
868     else
869     echo "Usage: Calculating MD5 Sums:"
870     echo " $(basename $0) calcmd5 /path/to/SMAGENAME /path/to/MD5DIR"
871     echo
872     echo
873     echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
874     echo
875     exit 1
876     fi
877 niro 306
878 niro 59 exit 0
879     fi
880    
881 niro 192 # download sources
882 niro 59 if [ "$1" == "download" -a -n "$2" ]
883     then
884 niro 24 if [ ! -d ${SMAGESCRIPTSDIR} ]
885     then
886     install -d ${SMAGESCRIPTSDIR}
887     fi
888 niro 59
889     # get smage
890     SMAGENAME="$2"
891     MD5DIR="$(dirname ${SMAGENAME})/md5"
892     source ${SMAGENAME} || die "download source failed"
893    
894     download_sources
895 niro 24 exit 0
896     fi
897    
898 niro 202 # regen-mage-tree
899     if [ "$1" == "only-regen-tree" -a -n "$2" ]
900     then
901     # set correct SMAGENAME
902     SMAGENAME="$2"
903     MD5DIR="$(dirname ${SMAGENAME})/md5"
904     source ${SMAGENAME} || die "regen: smage2 not found"
905    
906     regen_mage_tree
907 niro 255
908     # build md5sum for existing packages
909     generate_package_md5sum \
910     --pcat "${PCATEGORIE}" \
911     --pname "${PNAME}" \
912     --pver "${PVER}" \
913     --pbuild "${PBUILD}" \
914     --parch "${ARCH}" \
915     --target "${target}"
916    
917 niro 202 exit 0
918     fi
919    
920 niro 412 if [ "$1" == "--create-src-tarball" -a -n "$2" ]
921 niro 403 then
922     # set correct SMAGENAME
923     SMAGENAME="$2"
924     MD5DIR="$(dirname ${SMAGENAME})/md5"
925    
926 niro 412 echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}"
927 niro 403
928     source ${SMAGENAME} || die "regen: smage2 not found"
929    
930     if [[ -d ${SOURCEDIR}/${PNAME} ]]
931     then
932     echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
933     rm -rf ${SOURCEDIR}/${PKGNAME}
934     fi
935    
936     download_sources
937     source_pkg_build ${SMAGENAME}
938     exit 0
939     fi
940    
941 niro 406 if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ]
942 niro 403 then
943 niro 412 SRCPKGTARBALL="${2}"
944 niro 403 USE_SRC_PKG_TARBALL=true
945    
946 niro 412 # abort if given file is not a source pkg
947     [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file."
948    
949     # set correct SMAGENAME; use the one that the src_pkg provide
950     # /path/to/SOURCEDIR/PNAME/SMAGENAME
951     SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}"
952    
953 niro 403 echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}"
954    
955     [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR}
956    
957     # unpack srctarball
958     [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting."
959    
960     tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}"
961 niro 412
962     [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}"
963 niro 403 fi
964    
965    
966 niro 306 [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
967     [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] &&
968     die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting."
969     [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your mage.rc correctly."
970     [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your mage.rc correctly."
971     [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your mage.rc correctly."
972     [ -z "${BINDIR}" ] && die "no BINDIR variable found in /etc/mage.rc"
973     [ -z "${CHOST}" ] && die "no CHOST variable found in /etc/mage.rc"
974     [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in /etc/mage.rc"
975     [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in /etc/mage.rc"
976 niro 24
977     source ${SMAGENAME} || die "source failed"
978 niro 255 PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}"
979 niro 59 MD5DIR="$(dirname ${SMAGENAME})/md5"
980 niro 24
981     xtitle "Compiling ${PKGNAME}"
982 niro 59 echo "Compiling ${PKGNAME}"
983    
984 niro 191 # auto regen mage tree if requested
985     regen_mage_tree
986    
987 niro 403 if [[ ${CREATE_SRC_PKG_TARBALL} = true ]]
988     then
989     if [[ -d ${SOURCEDIR}/${PNAME} ]]
990     then
991     echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
992 niro 408 rm -rf ${SOURCEDIR}/${PNAME}
993 niro 403 fi
994     fi
995    
996 niro 192 # download sources
997 niro 403 [[ ${USE_SRC_PKG_TARBALL} != true ]] && download_sources
998 niro 59
999 niro 192 # fixes some issues with these functions
1000 niro 24 export -f src_prepare || die "src_prepare export failed"
1001     export -f src_compile || die "src_compile export failed"
1002     export -f src_install || die "src_install export failed"
1003    
1004 niro 192 # fixes some compile issues
1005 niro 24 export CHOST="${CHOST}" || die "CHOST export failed"
1006     export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
1007     export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
1008     export BINDIR="${BINDIR}" || die "BINDIR export failed"
1009     export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
1010    
1011    
1012 niro 192 # setup distcc
1013 niro 351 # setup for distcc goes *before* ccache, so ccache comes before distcc in path
1014 niro 306 [[ ${SMAGE_USE_DISTCC} = true ]] && setup_distcc_environment
1015 niro 24
1016 niro 192 # setup ccache
1017 niro 306 [[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment
1018 niro 24
1019     # small sleep to show our settings
1020     sleep 1
1021    
1022 niro 192 # cleans up build if a previously one exists
1023 niro 24 if [ -d ${BUILDDIR} ]
1024     then
1025     rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
1026     fi
1027     install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
1028    
1029 niro 192 # cleans up srcdir if a previously unpacked one exists
1030 niro 24 if [ -d ${SRCDIR} ]
1031     then
1032     rm -rf ${SRCDIR}
1033     fi
1034    
1035 niro 192 # cleans up bindir if a previous build exists or creates a new one
1036 niro 24 if [ -d ${BINDIR} ]
1037     then
1038     rm -rf ${BINDIR}
1039     fi
1040     install -d ${BINDIR} || die "couldn't create \$BINDIR."
1041    
1042 niro 192 # cleans up package temp dir if a previous build exists
1043 niro 24 if [ -d ${BUILDDIR}/${PKGNAME} ]
1044     then
1045     rm -rf ${BUILDDIR}/${PKGNAME}
1046     fi
1047    
1048 niro 192 # cleans up timestamp if one exists
1049 niro 24 if [ -f /var/tmp/timestamp ]
1050     then
1051     mage rmstamp
1052     fi
1053    
1054     src_prepare || die "src_prepare failed"
1055     src_compile || die "src_compile failed"
1056     src_install || die "src_install failed"
1057    
1058    
1059 niro 192 # compressing doc, info & man files
1060 niro 24 echo -e "Compressing man-pages ..."
1061     if [ -d ${BUILDDIR}/builded/usr/share/man ]
1062     then
1063     ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man
1064     fi
1065    
1066     echo -e "Compressing info-pages ..."
1067     if [ -d ${BUILDDIR}/builded/usr/share/info ]
1068     then
1069     ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info
1070     fi
1071    
1072 niro 79 # stripping all bins and libs
1073     case ${NOSTRIP} in
1074     true|TRUE|yes|y)
1075     echo -e "NOSTRIP=true detected; Package will not be stripped ..."
1076     ;;
1077     *)
1078     echo -e "Stripping binaries ..."
1079     mstripbins ${BINDIR}
1080     echo -e "Stripping libraries ..."
1081     mstriplibs ${BINDIR}
1082     ;;
1083     esac
1084    
1085 niro 192 # the new buildpkg command
1086 niro 24 case ${NOPKGBUILD} in
1087     true|TRUE|yes|y)
1088     echo -e "NOPGKBUILD=true detected; Package will not be build ..."
1089     ;;
1090 niro 192 *)
1091 niro 306 # build several targets
1092 niro 192 if [ -n "${MAGE_TARGETS}" ]
1093     then
1094     for target in ${MAGE_TARGETS}
1095     do
1096     # check if an special target_pkgbuild exists
1097     if typeset -f ${target}_pkgbuild > /dev/null
1098     then
1099     # run it
1100     ${target}_pkgbuild
1101     fi
1102     # now create the target package
1103     ${MLIBDIR}/pkgbuild_dir.sh \
1104 niro 255 "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \
1105 niro 192 ${BINDIR} || die "target: ${target} package-build failed"
1106 niro 255
1107     # build pkg-md5-sum if requested
1108     generate_package_md5sum \
1109     --pcat "${PCATEGORIE}" \
1110     --pname "${PNAME}" \
1111     --pver "${PVER}" \
1112     --pbuild "${PBUILD}" \
1113     --parch "${ARCH}" \
1114     --target "${target}"
1115    
1116     echo -e "\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n"
1117 niro 192 done
1118     else
1119     ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1120 niro 255
1121     # build pkg-md5-sum if requested
1122     generate_package_md5sum \
1123     --pcat "${PCATEGORIE}" \
1124     --pname "${PNAME}" \
1125     --pver "${PVER}" \
1126     --pbuild "${PBUILD}" \
1127     --parch "${ARCH}"
1128    
1129 niro 192 echo -e "\nPackage ${PKGNAME} successfully builded.\n"
1130     fi
1131 niro 403
1132     # build src-pkg-tarball if requested
1133     [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME}
1134 niro 24 ;;
1135     esac
1136    
1137 niro 192 # for sure
1138 niro 24 unset NOPKGBUILD
1139 niro 85 unset NOSTRIP
1140 niro 351
1141 niro 24 xtitleclean

Properties

Name Value
svn:executable *