Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 441 - (hide annotations) (download) (as text)
Mon Mar 19 19:21:40 2007 UTC (17 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 27865 byte(s)
some colour tweaks

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

Properties

Name Value
svn:executable *