Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1582 - (show annotations) (download) (as text)
Wed Dec 28 12:04:33 2011 UTC (12 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 40213 byte(s)
-save PKGTYPE variable too when calling split_packages
1 #!/bin/bash
2 # $Id$
3
4 # compiles/installs .smage2 source install scripts
5 # needs pkgbuild_dir (mage)
6
7 # TODO: record dynlib, gz | xz database
8
9
10 # set default user mage.rc
11 : ${MAGERC="/etc/mage.rc"}
12
13 ## setup ##
14 SMAGENAME="$1"
15 SMAGEVERSION="$( < ${MLIBDIR}/version)"
16
17 # export default C locale
18 export LC_ALL=C
19
20 source /etc/mage.rc.global
21 source ${MAGERC}
22 source ${MLIBDIR}/mage4.functions.sh
23
24 # set PKGDIR and BUILDDIR and BINDIR to MROOT
25 if [[ -n ${MROOT} ]]
26 then
27 export PKGDIR=${MROOT}/${PKGDIR}
28 export BUILDDIR=${MROOT}/${BUILDDIR}
29 export BINDIR=${MROOT}/${BINDIR}
30 fi
31
32 # sources the smage file and uses state from distribution file if exist
33 # may helpful for repository support later on
34 smagesource()
35 {
36 local file="$1"
37 local mystate
38 local mycodename
39
40 source ${file}
41
42 [[ -n ${STATE} ]] && mystate="${STATE}"
43
44 # do not overide if local state was broken or disabled!
45 case ${STATE} in
46 broken) return ;;
47 disabled) return ;;
48 esac
49
50 if [ -f ${SMAGESCRIPTSDIR}/distribution ]
51 then
52 source ${SMAGESCRIPTSDIR}/distribution
53 [[ -n ${STATE} ]] && mystate="${STATE}"
54 fi
55 # now switch state and export it
56 STATE="${mystate}"
57 }
58
59 showversion()
60 {
61 echo -en "Magellan Source Install v${SMAGEVERSION} "
62 echo -e "-- Niels Rogalla (niro@magellan-linux.de)"
63 }
64
65 die()
66 {
67 xtitleclean
68 echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}
69 echo "SMAGE failed: $@"
70 exit 1
71 }
72
73 die_pipestatus()
74 {
75 # the status change if we do any parameter declarations!!
76 # dont do this anymore, keep this in mind!
77 #
78 # local pos="$1"
79 # local comment="$2"
80 #
81 # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}"
82 #
83 [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2"
84 }
85
86 xtitle()
87 {
88 if [[ ${TERM} = xterm ]]
89 then
90 echo -ne "\033]0;[sMage: $@]\007"
91 fi
92 return 0
93 }
94
95 xtitleclean()
96 {
97 if [[ ${TERM} = xterm ]]
98 then
99 echo -ne "\033]0;\007"
100 fi
101 return 0
102 }
103
104 syncsmage2()
105 {
106 xtitle "Updating smage2-script tree ..."
107 local i
108 for i in ${SMAGE2RSYNC}
109 do
110 rsync ${RSYNC_FETCH_OPTIONS} ${i} ${SMAGESCRIPTSDIR}
111 if [[ $? = 0 ]]
112 then
113 break
114 else
115 continue
116 fi
117 done
118
119 # clean up backup files (foo~)
120 find ${SMAGESCRIPTSDIR} -name *~ -exec rm '{}' ';'
121
122 xtitleclean
123 }
124
125 # $1 filename
126 get_db_md5_sum()
127 {
128 local DB_FILE
129 local MD5_FILE
130 local i
131
132 DB_ENTRY="$(basename $1)"
133 MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} ${SMAGESUFFIX})"
134
135 i="$(cat ${MD5_FILE}| grep ${DB_ENTRY} | cut -d' ' -f1)"
136
137 echo "${i}"
138 }
139
140 download_sources()
141 {
142 [ -z "${SRC_URI}" ] && echo -e "\nNothing declared to download.\n" && return 0
143
144 local count=${#SRC_URI[*]}
145 local uri
146 local subdir
147 local outputdir
148 local db_md5_file="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
149 local fetching
150 local i
151
152 # check if FETCHING is needed
153 if mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5
154 then
155 # md5's ok, no fetching needed
156 fetching=false
157 else
158 fetching=true
159 fi
160
161 if [[ ${fetching} = true ]]
162 then
163 for ((i=0; i < count; i++))
164 do
165 # url to file
166 uri="${SRC_URI[${i}]%%' '*}"
167
168 # subdir in sources dir; the my_SRCI_URI file goes to there
169 subdir="${SRC_URI[${i}]##*' '}"
170
171 # if $subdir is not equal with $uri then an other dir is used
172 if [[ ${uri} != ${subdir} ]]
173 then
174 outputdir="${SOURCEDIR}/${PNAME}/${subdir}"
175 else
176 outputdir="${SOURCEDIR}/${PNAME}"
177 fi
178
179 echo -e "${COLBLUE}==>${COLGREEN} fetching ${uri}${COLDEFAULT}"
180 mdownload --uri "${uri}" --dir "${outputdir}" || die "Could not download '${uri}'"
181
182 # unset them to be sure
183 unset uri
184 unset subdir
185 unset outputdir
186 done
187
188 # recheck md5 sums after download
189 echo
190 echo -e "${COLBLUE}===${COLGREEN} Checking MD5 sums:${COLDEFAULT}"
191 mchecksum --rundir "${SOURCEDIR}/${PNAME}" --file "${db_md5_file}" --method md5 || die "md5 failed"
192 echo
193 else
194 echo -e "${COLBLUE}===${COLGREEN} All sources already fetched, nothing to do${COLDEFAULT}"
195 fi
196
197 # not needed anymore
198 unset SRC_URI
199 }
200
201 # dummy function, used if that does not exist in smage file
202 src_prepare()
203 {
204 echo "no src_prepare defined"
205 return 0
206 }
207
208 # dummy function, used if that does not exist in smage file
209 src_compile()
210 {
211 echo "no src_compile defined"
212 return 0
213 }
214
215 # dummy function, used if that does not exist in smage file
216 src_check()
217 {
218 echo "no src_check defined"
219 return 0
220 }
221
222 # dummy function, used if that does not exist in smage file
223 src_install()
224 {
225 echo "no src_install defined"
226 return 0
227 }
228
229 mlibdir()
230 {
231 local libdir=lib
232 [[ ${ARCH} = x86_64 ]] && libdir=lib64
233
234 echo "${libdir}"
235 }
236
237 mconfigure()
238 {
239 if [ -x ./configure ]
240 then
241 ./configure \
242 --prefix=/usr \
243 --host=${CHOST} \
244 --build=${CHOST} \
245 --mandir=/usr/share/man \
246 --infodir=/usr/share/info \
247 --datadir=/usr/share \
248 --sysconfdir=/etc \
249 --localstatedir=/var/lib \
250 --libdir=/usr/$(mlibdir) \
251 "$@" || die "mconfigure failed"
252 else
253 echo "configure is not an executable ..."
254 exit 1
255 fi
256 }
257
258 minstall()
259 {
260 if [ -f ./[mM]akefile -o -f ./GNUmakefile ]
261 then
262 make prefix=${BINDIR}/usr \
263 datadir=${BINDIR}/usr/share \
264 infodir=${BINDIR}/usr/share/info \
265 localstatedir=${BINDIR}/var/lib \
266 mandir=${BINDIR}/usr/share/man \
267 sysconfdir=${BINDIR}/etc \
268 libdir=${BINDIR}/usr/$(mlibdir) \
269 "$@" install || die "minstall failed"
270 else
271 die "no Makefile found"
272 fi
273 }
274
275 mmake()
276 {
277 make ${MAKEOPTS} ${EXTRA_EMAKE} "$@"
278 }
279
280 munpack()
281 {
282 local SRCFILE
283 local IFTAR
284 local DEST
285
286 SRCFILE=$1
287
288 if [[ -z $2 ]]
289 then
290 DEST=${BUILDDIR}
291 else
292 DEST=$2
293 fi
294
295 [[ ! -d ${DEST} ]] && install -d ${DEST}
296
297 case "${SRCFILE##*.}" in
298 bz2)
299 IFTAR="$(basename $SRCFILE .bz2)"
300 IFTAR="${IFTAR##*.}"
301 if [[ ${IFTAR} = tar ]]
302 then
303 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.bz2 unpack failed."
304 else
305 pushd ${DEST} > /dev/null
306 bzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .bz2) || die ".bz2 unpack failed."
307 popd > /dev/null
308 fi
309 ;;
310 gz)
311 IFTAR="$(basename $SRCFILE .gz)"
312 IFTAR="${IFTAR##*.}"
313 if [[ ${IFTAR} = tar ]]
314 then
315 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.gz unpack failed."
316 else
317 pushd ${DEST} > /dev/null
318 zcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .gz) || die ".gz unpack failed."
319 popd > /dev/null
320 fi
321 ;;
322 xz)
323 IFTAR="$(basename $SRCFILE .xz)"
324 IFTAR="${IFTAR##*.}"
325 if [[ ${IFTAR} = tar ]]
326 then
327 tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.xz unpack failed."
328 else
329 pushd ${DEST} > /dev/null
330 xzcat ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .xz) || die ".xz unpack failed."
331 popd > /dev/null
332 fi
333 ;;
334 tbz2|mpks|mpk)
335 tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed."
336 ;;
337 tgz)
338 tar --no-same-owner -xvzf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tgz unpack failed."
339 ;;
340 txz|mpkzs|mpkz)
341 tar --no-same-owner -xvJf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".txz unpack failed."
342 ;;
343 rar)
344 unrar x ${SOURCEDIR}/${PNAME}/${SRCFILE} ${DEST} || die ".rar unpack failed."
345 ;;
346 zip|xpi)
347 unzip ${SOURCEDIR}/${PNAME}/${SRCFILE} -d ${DEST} || die ".zip unpack failed."
348 ;;
349 rpm)
350 pushd ${DEST} > /dev/null
351 rpm2targz ${SOURCEDIR}/${PNAME}/${SRCFILE} || die "rpm2targz: .rpm unpack failed."
352 tar --no-same-owner -xvzf ${SRCFILE/.rpm/.tar.gz} || die "tar: .rpm unpack failed."
353 if [[ -f ${DEST}/${SRCFILE/.rpm/.tar.gz} ]]
354 then
355 rm ${DEST}/${SRCFILE/.rpm/.tar.gz}
356 fi
357 ;;
358 *)
359 die "munpack failed"
360 ;;
361 esac
362 }
363
364 mpatch()
365 {
366 local PATCHOPTS
367 local PATCHFILE
368 local i
369
370 PATCHOPTS=$1
371 PATCHFILE=$2
372
373 if [[ -z $2 ]]
374 then
375 PATCHFILE=$1
376
377 ## patch level auto-detection, get patch level
378 for ((i=0; i < 10; i++))
379 do
380 patch --dry-run -Np${i} -i ${SOURCEDIR}/${PNAME}/${PATCHFILE} > /dev/null
381 if [[ $? = 0 ]]
382 then
383 PATCHOPTS="-Np${i}"
384 break
385 fi
386 done
387 fi
388
389 echo -e "${COLBLUE}*** ${COLGREEN}Applying patch '${PATCHFILE}'${COLDEFAULT}"
390 patch "${PATCHOPTS}" -i ${SOURCEDIR}/${PNAME}/${PATCHFILE}
391 }
392
393 mlibtoolize()
394 {
395 local opts="$@"
396 [[ -z ${opts} ]] && opts="--verbose --install --force"
397
398 libtoolize ${opts} || die "running: mlibtoolize ${opts}"
399 }
400
401 mautoreconf()
402 {
403 local opts="$@"
404 [[ -z ${opts} ]] && opts="--verbose --install --force"
405
406 autoreconf ${opts} || die "running: mautoreconf ${opts}"
407 }
408
409 minstalldocs()
410 {
411 local docfiles
412 local doc
413 docfiles="$@"
414
415 if [ ! -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} ]
416 then
417 install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs."
418 fi
419
420 for doc in ${docfiles}
421 do
422 if [ -f ${doc} ]
423 then
424 if [[ ${SMAGE_COMPRESSDOC} = true ]]
425 then
426 cat ${doc} | gzip -9c > ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/${doc}.gz || die "gzipping +installing ${doc}."
427 chmod 0644 ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/${doc}.gz || die "fixing permissions of ${doc}."
428 else
429 install -m 0644 ${SRCDIR}/${i} ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "installing ${doc}."
430 fi
431 fi
432 done
433 }
434
435 mstriplibs()
436 {
437 local stripdir="$@"
438
439 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
440 [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug"
441 find ${stripdir} ! -type d | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null
442 }
443
444 mstripbins()
445 {
446 local stripdir="$@"
447
448 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
449 [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug"
450 find ${stripdir} ! -type d | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null
451 }
452
453 mstripstatic()
454 {
455 local stripdir="$@"
456
457 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
458 [[ -z ${STRIP_STATIC_LIB} ]] && STRIP_STATIC_LIB="--strip-debug"
459 find ${stripdir} ! -type d | xargs file | grep "ar archive" | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_STATIC_LIB} 2> /dev/null
460 }
461
462 mstriplibtoolarchive()
463 {
464 local stripdir="$@"
465
466 [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
467 find ${stripdir} ! -type d -name \*.la | xargs file | grep "libtool library" | cut -f 1 -d : | xargs --no-run-if-empty rm -f -- 2> /dev/null
468 }
469
470 mpurgetargets()
471 {
472 local stripdir="$@"
473 local target
474
475 [[ -z ${stripdir} ]] && stripdir=${BINDIR}
476 # nothing to do in this case
477 [[ -z ${PURGE_TARGETS[*]} ]] && return
478
479 for target in ${PURGE_TARGETS[*]}
480 do
481 # check if target is a regex pattern without any slashes
482 if [[ ${target} = ${target//\/} ]]
483 then
484 find ${BINDIR} -type f -name "${target}" | xargs --no-run-if-empty rm -f -- 2> /dev/null
485 else
486 rm -f -- ${target} 2> /dev/null
487 fi
488 done
489 }
490
491 mcompressdocs()
492 {
493 local bindir="$@"
494
495 if [ -d ${bindir}/usr/share/man ]
496 then
497 echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}"
498 ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man
499 fi
500
501 if [ -d ${bindir}/usr/share/info ]
502 then
503 echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}"
504 ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info
505 fi
506 }
507
508 sminclude()
509 {
510 local i
511
512 if [[ -n "$@" ]]
513 then
514 for i in $@
515 do
516 echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
517 source ${SMAGESCRIPTSDIR}/include/${i}.sminc
518 done
519 echo
520 fi
521 }
522
523 setup_distcc_environment()
524 {
525 if [ -x /usr/bin/distcc ]
526 then
527 echo -e "${COLBLUE}---${COLGREEN} Using DistCC for compilation ...${COLDEFAULT}"
528 export PATH=/usr/$(mlibdir)/distcc/bin:${PATH} || die "distcc: could not export new $PATH"
529
530 export DISTCC_DIR="${DISTCC_DIR}" || die "distcc_dir export failed"
531
532 # creating distcc tempdir
533 install -o distcc -g daemon -d ${DISTCC_DIR}
534 chmod 1777 ${DISTCC_DIR}
535 fi
536 }
537
538 setup_ccache_environment()
539 {
540 if [ -x /usr/bin/ccache ]
541 then
542 echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}"
543 export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
544 fi
545 }
546
547
548 # fixes given dependencies to match a MAGE_TARGET
549 # fix_mage_deps -target s/depend # <-- note -target !
550 fix_mage_deps()
551 {
552 local target="$1"
553 local depend="$2"
554 local NDEPEND
555 local sym dep cat pver pname
556
557 # deps and provides are special
558 # they must be fixed to match the target
559
560 # run this only if target and depend is not empty
561 if [ -n "${target}" ] && [ -n "${depend}" ]
562 then
563 # fix DEPEND
564 while read sym dep
565 do
566 # ignore empty lines
567 [[ -z ${dep} ]] && continue
568
569 cat="$(dirname ${dep})"
570 # change if not virtual
571 if [[ ${cat} = virtual ]]
572 then
573 pname="$(basename ${dep})"
574 else
575 # fix pver to target-pver
576 # to get pname-target-pver
577
578 # doing it backwards !
579 pver="${dep##*-}"
580 # full pver
581 pname="$(basename ${dep/-${pver}/})${target}-${pver}"
582 fi
583
584 # do not add empty lines
585 if [ -z "${NDEPEND}" ]
586 then
587 NDEPEND="${sym} ${cat}/${pname}"
588 else
589 NDEPEND="${NDEPEND}
590 ${sym} ${cat}/${pname}"
591 fi
592
593 unset cat pname pver
594 done << EOF
595 ${depend}
596 EOF
597 # set NDEPEND to DEPEND
598 depend="${NDEPEND}"
599 fi
600
601 echo "${depend}"
602 }
603
604 # build_mage_script(): helper functions for regen_mage_tree()
605 # generates an mage file with given information in smage file
606 # needs at least:
607 # PNAME name of pkg
608 # PVER version
609 # PBUILD revision
610 # PCATEGORIE categorie of the pkg
611 # STATE state of pkg stable|unstable|old
612 # DESCRIPTION va short description (opt)
613 # HOMEPAGE homepage (opt)
614 # DEPEND runtime dependencies (opt)
615 # SDEPEND add. needed deps to build the pkg (opt)
616 # PROVIDE provides a virtual (opt)
617 #
618 # special tags:
619 # PKGTYPE type of pkg
620 # INHERITS which functions get included
621 # SPECIAL_FUNCTIONS special functions which should also be added
622 # warning: they get killed before the build starts !
623 # SPLIT_PACKAGES names of all subpackages which are splitted from parent
624 # SPLIT_PACKAGE_BASE base package name for splitpackages
625 # (only in the resulting magefile}
626 #
627 # MAGE_TREE_DEST target destination of the generated tree
628 # REGEN_MAGE_TREE set to 'true' to enable this
629 #
630 # gets called with build_mage_script target
631 build_mage_script()
632 {
633 local magefile
634 local dest
635 local target
636 local split_pkg_base
637 local sym
638 local depname
639
640 # if MAGE_TREE_DEST not set use BUILDDIR
641 : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
642
643 # determinate which suffix this mage file should get, if any
644 [[ $1 = --target ]] && shift && target="-$1"
645
646 # mark package as splitpackage
647 [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
648
649 # name of magefile
650 magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
651
652 # destination to magefile
653 dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}"
654
655 # show what we are doing
656 echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
657 echo "${dest}"
658
659 install -d "$(dirname ${dest})"
660 # now build the mage file
661 > ${dest}
662
663 # pgkname and state
664 echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
665 echo "STATE=\"${STATE}\"" >> ${dest}
666
667 # description and homepage
668 echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest}
669 echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
670
671 # special tags and vars
672 echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest}
673
674 # echo MAGE_TARGETS ## note -target is needed !
675 echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
676
677 # split package base
678 echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
679
680 # add special vars
681 if [ -n "${SPECIAL_VARS}" ]
682 then
683 local i
684 for i in ${SPECIAL_VARS}
685 do
686 # being tricky here :)
687 echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
688 done
689 fi
690
691 # add at least all includes
692 if [ -n "${INHERITS}" ]
693 then
694 echo -n "minclude" >> ${dest}
695 local i
696 for i in ${INHERITS}
697 do
698 echo -n " ${i}" >> ${dest}
699 done
700 # a CRLF is needed here!
701 echo >> ${dest}
702 fi
703
704 # deps and provides
705 echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
706 echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
707 echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
708
709 # add special functions
710 if [ -n "${SPECIAL_FUNCTIONS}" ]
711 then
712 local i
713 for i in ${SPECIAL_FUNCTIONS}
714 do
715 # add to mage (quotes needed !)
716 typeset -f "${i}" >> ${dest}
717 # unset to be safe (quotes needed !)
718 #unset "${i}" <-- later to get every target built
719 done
720 fi
721
722 # pre|post-install|removes
723 typeset -f preinstall >> ${dest}
724 typeset -f postinstall >> ${dest}
725 typeset -f preremove >> ${dest}
726 typeset -f postremove >> ${dest}
727 }
728
729 regen_mage_tree()
730 {
731 local subpackage
732
733 # build them only if requested
734 if [[ ${REGEN_MAGE_TREE} = true ]]
735 then
736 # run it without targets
737 if [[ -n ${MAGE_TARGETS} ]]
738 then
739 # build for each target a mage file
740 # run it with several targets
741 echo
742 for subpackage in ${MAGE_TARGETS}
743 do
744 build_mage_script --target "${subpackage}"
745 done
746 echo
747
748 # run it for splitpackages
749 elif [[ -n ${SPLIT_PACKAGES} ]]
750 then
751 local split_pkg_base="${PNAME}"
752 # save smage environment
753 split_save_variables
754 # build for each subpackage a mage file
755 # run it with several targets
756 echo
757 for subpackage in ${SPLIT_PACKAGES}
758 do
759 # get the right variables for the split
760 export PNAME="${subpackage}"
761 split_info_${subpackage}
762 # get the preinstall etc
763 split_export_inherits ${subpackage}
764 build_mage_script --split-pkg-base "${split_pkg_base}"
765 # delete split preinstall etc
766 split_delete_inherits ${subpackage}
767 # restore smage environment
768 split_restore_variables
769 done
770 echo
771 # unset all saved smage variables
772 split_unset_variables
773
774 else
775 echo
776 build_mage_script
777 echo
778 fi
779 fi
780
781 # now unset all uneeded vars to be safe
782 # unset PKGNAME <-- don't do that; smage needs this var
783 # unset to be safe (quotes needed !)
784 # for i in ${SPECIAL_FUNCTIONS}
785 # do
786 # unset "${i}"
787 # done
788 unset SPECIAL_FUNCTIONS
789 # for i in ${SPECIAL_VARS}
790 # do
791 # unset "${i}"
792 # done
793 unset SPECIAL_VARS
794 unset STATE
795 unset DESCRIPTION
796 unset HOMEPAGE
797 unset PKGTYPE
798 unset INHERITS
799 unset DEPEND
800 unset SDEPEND
801 unset PROVIDE
802 unset preinstall
803 unset postinstall
804 unset preremove
805 unset postremove
806 }
807
808 split_save_variables()
809 {
810 export SAVED_PNAME="${PNAME}"
811 export SAVED_PVER="${PVER}"
812 export SAVED_PBUILD="${PBUILD}"
813 export SAVED_PCATEGORIE="${PCATEGORIE}"
814 export SAVED_DESCRIPTION="${DESCRIPTION}"
815 export SAVED_HOMEPAGE="${HOMEPAGE}"
816 export SAVED_SPECIAL_VARS="${SPECIAL_VARS}"
817 export SAVED_STATE="${STATE}"
818 export SAVED_PKGTYPE="${PKGTYPE}"
819 export SAVED_INHERITS="${INHERITS}"
820 export SAVED_DEPEND="${DEPEND}"
821 export SAVED_SDEPEND="${SDEPEND}"
822 export SAVED_PROVIDE="${PROVIDE}"
823 export SAVED_NOPKGBUILD="${NOPKGBUILD}"
824 export SAVED_PKGTYPE="${PKGTYPE}"
825
826 # bindir too
827 export SAVED_BINDIR="${BINDIR}"
828
829 # export the SPLIT_PACKAGE_BASE
830 export SPLIT_PACKAGE_BASE="${SAVED_PNAME}"
831
832 # functions
833 if [[ ! -z $(typeset -f preinstall) ]]
834 then
835 # rename the old one
836 local saved_preinstall
837 saved_preinstall=SAVED_$(typeset -f preinstall)
838 eval "${saved_preinstall}"
839 export -f SAVED_preinstall
840 fi
841
842 if [[ ! -z $(typeset -f postinstall) ]]
843 then
844 # rename the old one
845 local saved_postinstall
846 saved_postinstall=SAVED_$(typeset -f postinstall)
847 eval "${saved_postinstall}"
848 export -f SAVED_postinstall
849 fi
850
851 if [[ ! -z $(typeset -f preremove) ]]
852 then
853 # rename the old one
854 local saved_preremove
855 saved_preremove=SAVED_$(typeset -f preremove)
856 eval "${saved_preremove}"
857 export -f SAVED_preremove
858 fi
859
860 if [[ ! -z $(typeset -f postremove) ]]
861 then
862 # rename the old one
863 local saved_postremove
864 saved_postremove=SAVED_$(typeset -f postremove)
865 eval "${saved_postremove}"
866 export -f SAVED_postremove
867 fi
868 }
869
870 split_restore_variables()
871 {
872 export PNAME="${SAVED_PNAME}"
873 export PVER="${SAVED_PVER}"
874 export PBUILD="${SAVED_PBUILD}"
875 export PCATEGORIE="${SAVED_PCATEGORIE}"
876 export DESCRIPTION="${SAVED_DESCRIPTION}"
877 export HOMEPAGE="${SAVED_HOMEPAGE}"
878 export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"
879 export STATE="${SAVED_STATE}"
880 export PKGTYPE="${SAVED_PKGTYPE}"
881 export INHERITS="${SAVED_INHERITS}"
882 export DEPEND="${SAVED_DEPEND}"
883 export SDEPEND="${SAVED_SDEPEND}"
884 export PROVIDE="${SAVED_PROVIDE}"
885 export NOPKGBUILD="${SAVED_NOPKGBUILD}"
886 export PKGTYPE="${SAVED_PKGTYPE}"
887
888 # bindir too
889 export BINDIR="${SAVED_BINDIR}"
890
891 # functions
892 if [[ ! -z $(typeset -f SAVED_preinstall) ]]
893 then
894 # rename the old one
895 local saved_preinstall
896 saved_preinstall=$(typeset -f SAVED_preinstall)
897 eval "${saved_preinstall/SAVED_/}"
898 export -f preinstall
899 fi
900
901 if [[ ! -z $(typeset -f SAVED_postinstall) ]]
902 then
903 # rename the old one
904 local saved_postinstall
905 saved_postinstall=$(typeset -f SAVED_postinstall)
906 eval "${saved_postinstall/SAVED_/}"
907 export -f postinstall
908 fi
909
910 if [[ ! -z $(typeset -f SAVED_preremove) ]]
911 then
912 # rename the old one
913 local saved_preremove
914 saved_preremove=$(typeset -f SAVED_preremove)
915 eval "${saved_preremove/SAVED_/}"
916 export -f preremove
917 fi
918
919 if [[ ! -z $(typeset -f SAVED_postremove) ]]
920 then
921 # rename the old one
922 local saved_postremove
923 saved_postremove=$(typeset -f SAVED_postremove)
924 eval "${saved_postremove/SAVED_/}"
925 export -f postremove
926 fi
927 }
928
929 split_unset_variables()
930 {
931 # unset saved vars; not needed anymore
932 unset SAVED_PNAME
933 unset SAVED_PVER
934 unset SAVED_PBUILD
935 unset SAVED_PCATEGORIE
936 unset SAVED_DESCRIPTION
937 unset SAVED_HOMEPAGE
938 unset SAVED_SPECIAL_VARS
939 unset SAVED_STATE
940 unset SAVED_PKGTYPE
941 unset SAVED_INHERITS
942 unset SAVED_DEPEND
943 unset SAVED_SDEPEND
944 unset SAVED_PROVIDE
945 unset SAVED_BINDIR
946 unset SAVED_NOPKGBUILD
947 unset SAVED_PKGTYPE
948 unset SPLIT_PACKAGE_BASE
949 unset -f SAVED_preinstall
950 unset -f SAVED_postinstall
951 unset -f SAVED_preremove
952 unset -f SAVED_postremove
953 }
954
955 split_export_inherits()
956 {
957 local subpackage="$1"
958 local func
959 local newfunc
960
961 for func in preinstall postinstall preremove postremove
962 do
963 if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
964 then
965 newfunc=$(typeset -f ${func}_${subpackage})
966 newfunc="${newfunc/_${subpackage} (/ (}"
967 eval "${newfunc}"
968 fi
969 done
970 }
971
972 split_delete_inherits()
973 {
974 local subpackage="$1"
975 local func
976
977 for func in preinstall postinstall preremove postremove
978 do
979 if [[ ! -z $(typeset -f ${func}_${subpackage}) ]]
980 then
981 unset -f ${func}
982 fi
983 done
984 }
985
986 export_inherits()
987 {
988 local include="$1"
989 shift
990
991 while [ "$1" ]
992 do
993 local functions="$1"
994
995 # sanity checks
996 [ -z "${include}" ] && die "export_inherits(): \$include not given."
997 [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
998
999 eval "${functions}() { ${include}_${functions} ; }"
1000
1001 # debug
1002 [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
1003
1004 shift
1005 done
1006 }
1007
1008 generate_package_md5sum()
1009 {
1010 local dest
1011 local pcat
1012 local pname
1013 local pver
1014 local pbuild
1015 local parch
1016 local target
1017 local pkgname
1018
1019 # very basic getops
1020 for i in $*
1021 do
1022 case $1 in
1023 --pcat|-c) shift; pcat="$1" ;;
1024 --pname|-n) shift; pname="$1" ;;
1025 --pver|-v) shift; pver="$1" ;;
1026 --pbuild|-b) shift; pbuild="$1" ;;
1027 --parch|a) shift; parch="$1" ;;
1028 --target|t) shift; target="$1" ;;
1029 esac
1030 shift
1031 done
1032
1033 # sanity checks; abort if not given
1034 [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
1035 [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
1036 [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
1037 [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
1038 [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
1039
1040 # check needed global vars
1041 [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
1042 [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
1043
1044 # fix target as it may be empty !
1045 [ -n "${target}" ] && target="-${target}"
1046
1047
1048 # build pkgname
1049 pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
1050
1051 # build pkg-md5-sum only if requested
1052 if [[ ${REGEN_MAGE_TREE} = true ]]
1053 then
1054 echo -ne "${COLBLUE}===${COLGREEN} generating md5's for ${pkgname}.${PKGSUFFIX} ... ${COLDEFAULT}"
1055
1056 # abort if not exist
1057 if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
1058 then
1059 echo -e "${COLRED}! exists${COLDEFAULT}"
1060 return 0
1061 fi
1062
1063 # if MAGE_TREE_DEST not set use BUILDDIR
1064 : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
1065
1066 # setup md5 dir
1067 dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"
1068 install -d ${dest}
1069
1070 # gen md5sum
1071 ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
1072 > ${dest}/${pkgname}.md5
1073 echo -e "${COLGREEN}done${COLDEFAULT}"
1074 fi
1075 }
1076
1077 source_pkg_build()
1078 {
1079 if [[ ${PKGTYPE} = virtual ]]
1080 then
1081 echo "Virtual package detected; src-pkg-tarball not necessary ..."
1082 return 0
1083 fi
1084
1085 if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
1086 then
1087 echo "No SRC_URI defined; src-pkg-tarball not necessary ..."
1088 return 0
1089 fi
1090
1091 [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly."
1092
1093 echo -e "${COLGREEN}Creating source package tarball ... ${COLDEFAULT}"
1094
1095 # include the smage2 file
1096 cp ${SMAGENAME} ${SOURCEDIR}/${PNAME}
1097
1098 ( cd ${SOURCEDIR}; tar cvjf ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${PNAME}; )
1099 [[ ! -d ${SRCPKGDIR} ]] && install -d ${SRCPKGDIR}
1100 mv ${BUILDDIR}/${PNAME}-${PVER}-${PBUILD}.tar.bz2 ${SRCPKGDIR}/${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX}
1101
1102 echo -e "${COLGREEN}Source package ${COLBLUE}${PNAME}-${PVER}-${PBUILD}.${SRCPKGSUFFIX} ${COLGREEN}successfully builded.${COLDEFAULT}"
1103 }
1104
1105 step_by_step()
1106 {
1107 if [[ ${STEP_BY_STEP} = true ]]
1108 then
1109 echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}"
1110 echo "Press [enter] to continue"
1111 read
1112 fi
1113 }
1114
1115
1116 # print out our version
1117 showversion
1118 echo
1119
1120 if [ -z "$1" ]
1121 then
1122 echo "No .smage2 file given. Exiting."
1123 echo
1124 exit 1
1125 fi
1126
1127 # updating smage2-scripts
1128 if [[ $1 = update ]]
1129 then
1130 if [ ! -d ${SOURCEDIR} ]
1131 then
1132 install -d ${SOURCEDIR}
1133 fi
1134 syncsmage2
1135 exit 0
1136 fi
1137
1138 # creates md5sums for smages to given dir
1139 if [[ $1 = calcmd5 ]]
1140 then
1141 if [ $# -ge 2 ]
1142 then
1143 SMAGENAME="$2"
1144 MD5DIR="$3"
1145 [[ -z ${MD5DIR} ]] && MD5DIR="$(dirname ${SMAGENAME})/md5"
1146
1147 smagesource ${SMAGENAME} || die "download source failed"
1148
1149 # overridable sourcedir; must be declared after source of the smage2
1150 CALC_SOURCEDIR="${CALC_SOURCEDIR:="${SOURCEDIR}/${PNAME}"}"
1151
1152 [ -z "${SRC_URI}" ] && die "Nothing declared to calculate."
1153
1154 # end of array
1155 EOA=${#SRC_URI[*]}
1156
1157 [ ! -d ${MD5DIR} ] && install -d ${MD5DIR}
1158
1159 # clear md5sum file
1160 MY_MD5_FILE="${MD5DIR}/$(basename ${SMAGENAME} .${SMAGESUFFIX}).md5"
1161 echo -n > ${MY_MD5_FILE}
1162
1163 for ((i=0; i < EOA; i++))
1164 do
1165 # url to file
1166 my_SRC_URI="$(echo ${SRC_URI[${i}]} | cut -d' ' -f1)"
1167
1168 # subdir in sources dir; the my_SRCI_URI file goes to there
1169 my_SRC_URI_DEST="$(echo ${SRC_URI[${i}]} | cut -d' ' -f2)"
1170
1171 # if my_src_uri_dest is not equal my_src_uri; than an other dir is used
1172 if [[ ${my_SRC_URI_DEST} != ${my_SRC_URI} ]]
1173 then
1174 MY_SRC_FILE="${my_SRC_URI_DEST}/$(basename ${SRC_URI[${i}]})"
1175 else
1176 MY_SRC_FILE="$(basename ${SRC_URI[${i}]})"
1177 fi
1178
1179 if [ -e "${CALC_SOURCEDIR}/${MY_SRC_FILE}" ]
1180 then
1181 echo "calculating $(basename ${MY_SRC_FILE}) ..."
1182 ( cd ${CALC_SOURCEDIR}; md5sum "${MY_SRC_FILE}" ) >> ${MY_MD5_FILE}
1183 else
1184 echo "WARNING: File '$(basename ${MY_SRC_FILE}) not found in ${CALC_SOURCEDIR}."
1185 fi
1186
1187 # unset them to be shure
1188 unset my_SRC_URI
1189 unset my_SRC_URI_DEST
1190 unset my_SRC_URI_MIRROR
1191 unset my_SOURCEDIR
1192 done
1193
1194 echo
1195 echo "Calculating of md5 sums for '$(basename ${SMAGENAME} .${SMAGESUFFIX})' done."
1196 echo
1197 else
1198 echo "Usage: Calculating MD5 Sums:"
1199 echo " $(basename $0) calcmd5 /path/to/SMAGENAME [/path/to/MD5DIR]"
1200 echo
1201 echo
1202 echo "Export the CALC_SOURCEDIR variable to override current SOURCEDIRs."
1203 echo
1204 exit 1
1205 fi
1206
1207 exit 0
1208 fi
1209
1210 # download sources
1211 if [ "$1" == "download" -a -n "$2" ]
1212 then
1213 if [ ! -d ${SMAGESCRIPTSDIR} ]
1214 then
1215 install -d ${SMAGESCRIPTSDIR}
1216 fi
1217
1218 # get smage
1219 SMAGENAME="$2"
1220 MD5DIR="$(dirname ${SMAGENAME})/md5"
1221 smagesource ${SMAGENAME} || die "download source failed"
1222
1223 download_sources
1224 exit 0
1225 fi
1226
1227 # regen-mage-tree
1228 if [ "$1" == "only-regen-tree" -a -n "$2" ]
1229 then
1230 # set correct SMAGENAME
1231 SMAGENAME="$2"
1232 MD5DIR="$(dirname ${SMAGENAME})/md5"
1233 smagesource ${SMAGENAME} || die "regen: smage2 not found"
1234
1235 regen_mage_tree
1236
1237 # build several targets
1238 if [[ -n ${MAGE_TARGETS} ]]
1239 then
1240 for target in ${MAGE_TARGETS}
1241 do
1242 # build md5sum for existing packages
1243 generate_package_md5sum \
1244 --pcat "${PCATEGORIE}" \
1245 --pname "${PNAME}" \
1246 --pver "${PVER}" \
1247 --pbuild "${PBUILD}" \
1248 --parch "${ARCH}" \
1249 --target "${target}"
1250 done
1251
1252 # build several subpackages
1253 elif [[ -n ${SPLIT_PACKAGES} ]]
1254 then
1255 split_save_variables
1256 for subpackage in ${SPLIT_PACKAGES}
1257 do
1258 # get the right variables for the split
1259 export PNAME="${subpackage}"
1260 split_info_${subpackage}
1261 # build md5sum for existing packages
1262 generate_package_md5sum \
1263 --pcat "${PCATEGORIE}" \
1264 --pname "${PNAME}" \
1265 --pver "${PVER}" \
1266 --pbuild "${PBUILD}" \
1267 --parch "${ARCH}"
1268 # restore smage environment
1269 split_restore_variables
1270 done
1271 # unset all saved smage variables
1272 split_unset_variables
1273
1274 else
1275 # build md5sum for existing packages
1276 generate_package_md5sum \
1277 --pcat "${PCATEGORIE}" \
1278 --pname "${PNAME}" \
1279 --pver "${PVER}" \
1280 --pbuild "${PBUILD}" \
1281 --parch "${ARCH}"
1282 fi
1283
1284 exit 0
1285 fi
1286
1287 if [ "$1" == "--create-src-tarball" -a -n "$2" ]
1288 then
1289 # set correct SMAGENAME
1290 SMAGENAME="$2"
1291 MD5DIR="$(dirname ${SMAGENAME})/md5"
1292
1293 echo -e "${COLGREEN}create-src-tarball called for ${COLBLUE}${SMAGENAME}${COLGREEN} ...${COLDEFAULT}"
1294
1295 smagesource ${SMAGENAME} || die "regen: smage2 not found"
1296
1297 if [[ -d ${SOURCEDIR}/${PNAME} ]]
1298 then
1299 echo -e "${COLGREEN}Deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1300 rm -rf ${SOURCEDIR}/${PKGNAME}
1301 fi
1302
1303 download_sources
1304 source_pkg_build ${SMAGENAME}
1305 exit 0
1306 fi
1307
1308 if [ "$1" == "--src-tarball" -a -n "$2" ] || [ "$1" == "-st" -a -n "$2" ]
1309 then
1310 SRCPKGTARBALL="${2}"
1311 USE_SRC_PKG_TARBALL=true
1312
1313 # abort if given file is not a source pkg
1314 [[ ${SRCPKGTARBALL##*.} != ${SRCPKGSUFFIX} ]] && die "${SRCPKGTARBALL} is not a valid src-pkg file."
1315
1316 # set correct SMAGENAME; use the one that the src_pkg provide
1317 # /path/to/SOURCEDIR/PNAME/SMAGENAME
1318 SMAGENAME="${SOURCEDIR}/$(basename ${SRCPKGTARBALL%-*-*})/$(basename ${SRCPKGTARBALL} .${SRCPKGSUFFIX}).${SMAGESUFFIX}"
1319
1320 echo -e "${COLGREEN}Using src-tarball ${COLBLUE}${SRCPKGTARBALL}${COLGREEN} ...${COLDEFAULT}"
1321
1322 [[ ! -d ${SOURCEDIR} ]] && install -d ${SOURCEDIR}
1323
1324 # unpack srctarball
1325 [[ ! -f ${SRCPKGTARBALL} ]] && die "Error: ${SRCPKGTARBALL} does not exist. Aborting."
1326
1327 tar xvjf ${SRCPKGTARBALL} -C ${SOURCEDIR} || die "Error unpackung src-tarball ${SRCPKGTARBALL}"
1328
1329 [[ ! -f ${SMAGENAME} ]] && die "Included smage2 file in src-tarball not found: ${SMAGENAME}"
1330 fi
1331
1332
1333 [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] && die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
1334 [ -z "$(basename ${SMAGENAME} | grep .${SMAGESUFFIX})" ] &&
1335 die "File '$(basename ${SMAGENAME})' is not a sMage v${SMAGEVERSION} file. Aborting."
1336 [ -z "${SOURCEDIR}" ] && die "\$SOURCEDIR not found. Please setup your ${MAGERC} correctly."
1337 [ -z "${SMAGESCRIPTSDIR}" ] && die "\$SMAGESCRIPTSDIR not found. Please setup your ${MAGERC} correctly."
1338 [ -z "${SMAGE2RSYNC}" ] && die "\$SMAGE2RSYNC not found. Please setup your ${MAGERC} correctly."
1339 [ -z "${BINDIR}" ] && die "no BINDIR variable found in ${MAGERC}"
1340 [ -z "${CHOST}" ] && die "no CHOST variable found in ${MAGERC}"
1341 [ -z "${CFLAGS}" ] && die "no CFLAGS variable found in ${MAGERC}"
1342 [ -z "${CXXFLAGS}" ] && die "no CXXFLAGS variable found in ${MAGERC}"
1343
1344 smagesource ${SMAGENAME} || die "source failed"
1345 PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}"
1346 MD5DIR="$(dirname ${SMAGENAME})/md5"
1347 SMAGE_LOG_CMD="tee -a /var/log/smage/${PKGNAME}.log"
1348
1349 xtitle "Compiling ${PKGNAME}"
1350 echo -e "${COLGREEN}Compiling ${PKGNAME}${COLDEFAULT}"
1351
1352 # auto regen mage tree if requested
1353 regen_mage_tree
1354
1355 if [[ ${CREATE_SRC_PKG_TARBALL} = true ]]
1356 then
1357 if [[ -d ${SOURCEDIR}/${PNAME} ]]
1358 then
1359 echo -e "${COLBLUE}===${COLGREEN} deleting old sourcefiles ${COLBLUE}${SOURCEDIR}/${PNAME}${COLGREEN} ...${COLDEFAULT}"
1360 rm -rf ${SOURCEDIR}/${PNAME}
1361 fi
1362 fi
1363
1364 # download sources
1365 [[ ${USE_SRC_PKG_TARBALL} != true ]] && download_sources
1366
1367 # fixes some issues with these functions
1368 export -f src_prepare || die "src_prepare export failed"
1369 export -f src_compile || die "src_compile export failed"
1370 export -f src_check || die "src_check export failed"
1371 export -f src_install || die "src_install export failed"
1372
1373 # fixes some compile issues
1374 export CHOST="${CHOST}" || die "CHOST export failed"
1375 export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
1376 export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
1377 export BINDIR="${BINDIR}" || die "BINDIR export failed"
1378 export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
1379
1380
1381 # setup distcc
1382 # setup for distcc goes *before* ccache, so ccache comes before distcc in path
1383 [[ ${SMAGE_USE_DISTCC} = true ]] && setup_distcc_environment
1384
1385 # setup ccache
1386 [[ ${SMAGE_USE_CCACHE} = true ]] && setup_ccache_environment
1387
1388 # clean up builddir if a previously one exist
1389 if [ -d ${BUILDDIR} ]
1390 then
1391 rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
1392 fi
1393 install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
1394
1395 # clean up srcdir if a previously unpacked one exist
1396 if [ -d ${SRCDIR} ]
1397 then
1398 rm -rf ${SRCDIR}
1399 fi
1400
1401 # clean up bindir if a previous build exist or create a new one
1402 if [ -d ${BINDIR} ]
1403 then
1404 rm -rf ${BINDIR}
1405 fi
1406 install -d ${BINDIR} || die "couldn't create \$BINDIR."
1407
1408 # clean up package temp dir if a previous build exist
1409 if [ -d ${BUILDDIR}/${PKGNAME} ]
1410 then
1411 rm -rf ${BUILDDIR}/${PKGNAME}
1412 fi
1413
1414 # setup build logging
1415 [[ ! -d /var/log/smage ]] && install -d /var/log/smage
1416 echo -e "### Build started on $(date) ###\n" > /var/log/smage/${PKGNAME}.log
1417
1418 src_prepare | ${SMAGE_LOG_CMD}
1419 die_pipestatus 0 "src_prepare failed"
1420 step_by_step $_
1421
1422 src_compile | ${SMAGE_LOG_CMD}
1423 die_pipestatus 0 "src_compile failed"
1424 step_by_step $_
1425
1426 # only run checks if requested
1427 if [[ ${MAGE_CHECK} != true ]]
1428 then
1429 echo "MAGE_CHECK not requested; src_check() will not be run!" | ${SMAGE_LOG_CMD}
1430 step_by_step src_check
1431 else
1432 src_check | ${SMAGE_LOG_CMD}
1433 die_pipestatus 0 "src_check failed"
1434 step_by_step $_
1435 fi
1436
1437 # build several subpackages
1438 if [[ -n ${SPLIT_PACKAGES} ]]
1439 then
1440 # save bindir & pname
1441 split_save_variables
1442 export SAVED_BINDIR="${BINDIR}"
1443 for subpackage in ${SPLIT_PACKAGES}
1444 do
1445 if typeset -f src_install_${subpackage} > /dev/null
1446 then
1447 # export subpackage bindir
1448 export BINDIR="${SAVED_BINDIR}_${subpackage}"
1449 # export PNAME, several internal function and include
1450 # rely on this variable
1451 export PNAME="${subpackage}"
1452
1453 echo
1454 echo -en "${COLBLUE}*** ${COLDEFAULT}"
1455 echo -en " Running ${COLGREEN}split src_install()${COLDEFAULT}"
1456 echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}"
1457 echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..."
1458
1459 src_install_${subpackage} | ${SMAGE_LOG_CMD}
1460 die_pipestatus 0 "src_install_${subpackage} failed"
1461 step_by_step $_
1462 fi
1463 done
1464 # restore bindir & pname
1465 split_restore_variables
1466 # unset all saved smage variables
1467 split_unset_variables
1468 else
1469 src_install | ${SMAGE_LOG_CMD}
1470 die_pipestatus 0 "src_install failed"
1471 step_by_step $_
1472 fi
1473
1474 # compressing doc, info & man files
1475 if [[ -n ${SPLIT_PACKAGES} ]]
1476 then
1477 for subpackage in ${SPLIT_PACKAGES}
1478 do
1479 mcompressdocs ${BINDIR}_${subpackage}
1480 done
1481 else
1482 mcompressdocs ${BINDIR}
1483 fi
1484
1485 if [[ ${SMAGE_STRIP_LIBTOOL} = true ]]
1486 then
1487 if [[ -n ${SPLIT_PACKAGES} ]]
1488 then
1489 for subpackage in ${SPLIT_PACKAGES}
1490 do
1491 echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives for '${subpackage}' ...${COLDEFAULT}"
1492 mstriplibtoolarchive ${BINDIR}_${subpackage}
1493 done
1494 else
1495 echo -e "${COLBLUE}===${COLGREEN} stripping libtool archives ...${COLDEFAULT}"
1496 mstriplibtoolarchive ${BINDIR}
1497 fi
1498 fi
1499
1500 if [[ ${SMAGE_PURGE} = true ]]
1501 then
1502 if [[ -n ${SPLIT_PACKAGES} ]]
1503 then
1504 for subpackage in ${SPLIT_PACKAGES}
1505 do
1506 echo -e "${COLBLUE}===${COLGREEN} purging all purge targets in '${subpackage}' ...${COLDEFAULT}"
1507 mpurgetargets ${BINDIR}_${subpackage}
1508 done
1509 else
1510 echo -e "${COLBLUE}===${COLGREEN} purging all purge targets ...${COLDEFAULT}"
1511 mpurgetargets ${BINDIR}
1512 fi
1513 fi
1514
1515 # stripping all bins and libs
1516 case ${NOSTRIP} in
1517 true|TRUE|yes|y)
1518 echo -e "NOSTRIP=true detected; Package will not be stripped ..."
1519 ;;
1520 *)
1521 if [[ -n ${SPLIT_PACKAGES} ]]
1522 then
1523 for subpackage in ${SPLIT_PACKAGES}
1524 do
1525 echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}"
1526 mstripbins ${BINDIR}_${subpackage}
1527 echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries for '${subpackage}' ...${COLDEFAULT}"
1528 mstriplibs ${BINDIR}_${subpackage}
1529 echo -e "${COLBLUE}===${COLGREEN} stripping static libraries for '${subpackage}' ...${COLDEFAULT}"
1530 mstripstatic ${BINDIR}_${subpackage}
1531 done
1532 else
1533 echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}"
1534 mstripbins ${BINDIR}
1535 echo -e "${COLBLUE}===${COLGREEN} stripping dynamic libraries ...${COLDEFAULT}"
1536 mstriplibs ${BINDIR}
1537 echo -e "${COLBLUE}===${COLGREEN} stripping static libraries ...${COLDEFAULT}"
1538 mstripstatic ${BINDIR}
1539 fi
1540 ;;
1541 esac
1542
1543 # the new buildpkg command
1544 case ${NOPKGBUILD} in
1545 true|TRUE|yes|y)
1546 echo -e "NOPGKBUILD=true detected; Package will not be build ..."
1547 ;;
1548 *)
1549 # build several targets
1550 if [[ -n ${MAGE_TARGETS} ]]
1551 then
1552 for target in ${MAGE_TARGETS}
1553 do
1554 # check if a special target_pkgbuild exists
1555 if typeset -f ${target}_pkgbuild > /dev/null
1556 then
1557 # run it
1558 ${target}_pkgbuild
1559 fi
1560 # now create the target package
1561 ${MLIBDIR}/pkgbuild_dir.sh \
1562 "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \
1563 ${BINDIR} || die "target: ${target} package-build failed"
1564
1565 # build pkg-md5-sum if requested
1566 generate_package_md5sum \
1567 --pcat "${PCATEGORIE}" \
1568 --pname "${PNAME}" \
1569 --pver "${PVER}" \
1570 --pbuild "${PBUILD}" \
1571 --parch "${ARCH}" \
1572 --target "${target}"
1573
1574 echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1575 done
1576
1577 # build several subpackages
1578 elif [[ -n ${SPLIT_PACKAGES} ]]
1579 then
1580 split_save_variables
1581 for subpackage in ${SPLIT_PACKAGES}
1582 do
1583 # get the right variables for the split
1584 export PNAME="${subpackage}"
1585 split_info_${PNAME}
1586
1587 # jump to next one if NOPKGBUILD is set in split_info
1588 case ${NOPKGBUILD} in
1589 true|TRUE|yes|y) continue ;;
1590 esac
1591
1592 # check if an special subpackage_pkgbuild exists
1593 if typeset -f ${PNAME}_pkgbuild > /dev/null
1594 then
1595 # run it
1596 ${PNAME}_pkgbuild
1597 fi
1598 # now create the target package
1599 ${MLIBDIR}/pkgbuild_dir.sh \
1600 "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \
1601 "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed"
1602
1603 # build pkg-md5-sum if requested
1604 generate_package_md5sum \
1605 --pcat "${PCATEGORIE}" \
1606 --pname "${PNAME}" \
1607 --pver "${PVER}" \
1608 --pbuild "${PBUILD}" \
1609 --parch "${ARCH}"
1610
1611 echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1612
1613 # restore smage environment
1614 split_restore_variables
1615 done
1616 # unset all saved smage variables
1617 split_unset_variables
1618
1619 else
1620 ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1621
1622 # build pkg-md5-sum if requested
1623 generate_package_md5sum \
1624 --pcat "${PCATEGORIE}" \
1625 --pname "${PNAME}" \
1626 --pver "${PVER}" \
1627 --pbuild "${PBUILD}" \
1628 --parch "${ARCH}"
1629
1630 echo -e "${COLGREEN}\nPackage ${PKGNAME} successfully builded.\n${COLDEFAULT}"
1631 fi
1632
1633 # build src-pkg-tarball if requested
1634 [[ ${CREATE_SRC_PKG_TARBALL} = true ]] && source_pkg_build ${SMAGENAME}
1635 ;;
1636 esac
1637
1638 if [[ ${SMAGE_BUILD_LOGGING} != false ]]
1639 then
1640 bzip2 -9f /var/log/smage/${PKGNAME}.log
1641 else
1642 [[ -f /var/log/smage/${PKGNAME}.log ]] && rm /var/log/smage/${PKGNAME}.log
1643 fi
1644
1645 # for sure
1646 unset NOPKGBUILD
1647 unset NOSTRIP
1648
1649 xtitleclean

Properties

Name Value
svn:executable *