Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 419 - (hide annotations) (download) (as text)
Mon Jan 22 00:24:14 2007 UTC (17 years, 3 months ago) by niro
File MIME type: application/x-sh
File size: 26082 byte(s)
variable mage.rc

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

Properties

Name Value
svn:executable *