Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 347 - (hide annotations) (download) (as text)
Sat Mar 4 23:29:45 2006 UTC (18 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 23605 byte(s)
fixed srcinstall with MROOT enabled

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

Properties

Name Value
svn:executable *