Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 306 - (hide annotations) (download) (as text)
Mon Dec 26 23:16:38 2005 UTC (18 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/smage2.sh
File MIME type: application/x-sh
File size: 23423 byte(s)
- fixed header in created mage file
- style updates & typos

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

Properties

Name Value
svn:executable *