Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 351 - (hide annotations) (download) (as text)
Wed Mar 22 17:45:49 2006 UTC (18 years, 1 month ago) by niro
Original Path: trunk/mage/usr/lib/mage/smage2.sh
File MIME type: application/x-sh
File size: 23207 byte(s)
- added colors defines
- addded multlib support
- added lib64 support via mlibdir
- removed old commented cruft

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

Properties

Name Value
svn:executable *