4 |
# needs pkgbuild_dir (mage) |
# needs pkgbuild_dir (mage) |
5 |
|
|
6 |
# SMAGE2 |
# SMAGE2 |
7 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.18 2005-07-31 14:47:55 niro Exp $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.30 2005-08-21 21:23:48 niro Exp $ |
8 |
|
|
9 |
#01.10.2004 |
#01.10.2004 |
10 |
# added ccache support |
# added ccache support |
11 |
# added distcc support |
# added distcc support |
12 |
|
|
13 |
## setup ## |
## setup ## |
|
SMAGEVERSION=0.3.7-r1 |
|
14 |
PKGSUFFIX="mpk" |
PKGSUFFIX="mpk" |
15 |
SMAGENAME="$1" |
SMAGENAME="$1" |
16 |
SMAGESUFFIX="smage2" |
SMAGESUFFIX="smage2" |
18 |
#SMAGESCRIPTSDIR="/bootstrap/smage2-install-scripts" |
#SMAGESCRIPTSDIR="/bootstrap/smage2-install-scripts" |
19 |
#SMAGE2RSYNC="rsync://192.168.0.2/smage2-scripts" |
#SMAGE2RSYNC="rsync://192.168.0.2/smage2-scripts" |
20 |
MLIBDIR=/usr/lib/mage |
MLIBDIR=/usr/lib/mage |
21 |
|
SMAGEVERSION="$( < ${MLIBDIR}/version)" |
22 |
|
|
23 |
# export default C locale |
# export default C locale |
24 |
export LC_ALL=C |
export LC_ALL=C |
230 |
return 0 |
return 0 |
231 |
} |
} |
232 |
|
|
|
|
|
|
build_mage_script() { |
|
|
return 0 |
|
|
} |
|
|
|
|
233 |
mconfigure() { |
mconfigure() { |
234 |
if [ -x ./configure ] |
if [ -x ./configure ] |
235 |
then |
then |
355 |
sminclude() { |
sminclude() { |
356 |
local i |
local i |
357 |
|
|
358 |
if [ -n "$@" ] |
if [[ -n "$@" ]] |
359 |
then |
then |
360 |
for i in $@ |
for i in $@ |
361 |
do |
do |
362 |
echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" |
363 |
source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
source ${SMAGESCRIPTSDIR}/include/${i}.sminc |
364 |
done |
done |
365 |
|
echo |
366 |
fi |
fi |
367 |
} |
} |
368 |
|
|
406 |
fi |
fi |
407 |
} |
} |
408 |
|
|
409 |
|
|
410 |
|
# fixes given dependencies to match a MAGE_TARGET |
411 |
|
# fix_mage_deps -target s/depend # <-- note -target ! |
412 |
|
fix_mage_deps() { |
413 |
|
local target="$1" |
414 |
|
local depend="$2" |
415 |
|
local NDEPEND |
416 |
|
local sym dep cat pver pname |
417 |
|
|
418 |
|
# deps and provides are special |
419 |
|
# they must be fixed to match the target |
420 |
|
|
421 |
|
# run this only if target and depend is not empty |
422 |
|
if [ -n "${target}" ] && [ -n "${depend}" ] |
423 |
|
then |
424 |
|
# fix DEPEND |
425 |
|
while read sym dep |
426 |
|
do |
427 |
|
cat="$(dirname ${dep})" |
428 |
|
# change if not virtual |
429 |
|
if [[ ${cat} != virtual ]] |
430 |
|
then |
431 |
|
# fix pver to target-pver |
432 |
|
# to get pname-target-pver |
433 |
|
|
434 |
|
# doing it backwards ! |
435 |
|
pver="${dep##*-}" |
436 |
|
pname=$(basename ${dep/-${pver}/}) |
437 |
|
fi |
438 |
|
|
439 |
|
# do not add empty lines |
440 |
|
if [ -z "${NDEPEND}" ] |
441 |
|
then |
442 |
|
NDEPEND="${sym} ${cat}/${pname}${target}-${pver}" |
443 |
|
else |
444 |
|
NDEPEND="${NDEPEND} |
445 |
|
${sym} ${cat}/${pname}${target}-${pver}" |
446 |
|
fi |
447 |
|
|
448 |
|
unset cat pname pver |
449 |
|
done << EOF |
450 |
|
${depend} |
451 |
|
EOF |
452 |
|
# set NDEPEND to DEPEND |
453 |
|
depend="${NDEPEND}" |
454 |
|
fi |
455 |
|
|
456 |
|
echo "${depend}" |
457 |
|
} |
458 |
|
|
459 |
|
# build_mage_script(): helper functions for regen_mage_tree() |
460 |
|
# generates an mage file with given information in smage file |
461 |
|
# needs at least: |
462 |
|
# PNAME name of pkg |
463 |
|
# PVER version |
464 |
|
# PBUILD revision |
465 |
|
# PCATEGORIE categorie of the pkg |
466 |
|
# STATE state of pkg stable|unstable|old |
467 |
|
# DESCRIPTION va short description (opt) |
468 |
|
# HOMEPAGE homepage (opt) |
469 |
|
# DEPEND runtime dependencies (opt) |
470 |
|
# SDEPEND add. needed deps to build the pkg (opt) |
471 |
|
# PROVIDE provides a virtual (opt) |
472 |
|
# |
473 |
|
# special tags: |
474 |
|
# PKGTYPE type of pkg |
475 |
|
# INHERITS which functions get included |
476 |
|
# SPECIAL_FUNCTIONS special functions wich should also be added |
477 |
|
# warning: they get killed before the build starts ! |
478 |
|
# |
479 |
|
# MAGE_TREE_DEST target destination of the generated tree |
480 |
|
# REGEN_MAGE_TREE set to 'true' to enable this |
481 |
|
# |
482 |
|
# gets called with build_mage_script target |
483 |
|
build_mage_script() |
484 |
|
{ |
485 |
|
local magefile |
486 |
|
local dest |
487 |
|
local target |
488 |
|
local sym |
489 |
|
local depname |
490 |
|
|
491 |
|
# if MAGE_TREE_DEST not set use BUILDDIR |
492 |
|
: ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} |
493 |
|
|
494 |
|
# determinate which suffix this mage file should get, if any |
495 |
|
[ -n "$1" ] && target="-$1" |
496 |
|
|
497 |
|
# name of magefile |
498 |
|
magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" |
499 |
|
|
500 |
|
# destination to magefile |
501 |
|
dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}" |
502 |
|
|
503 |
|
# show what we are doing |
504 |
|
echo "Generating Mage file:" |
505 |
|
echo " ${dest}" |
506 |
|
|
507 |
|
install -d "$(dirname ${dest})" |
508 |
|
# now build the mage file |
509 |
|
> ${dest} |
510 |
|
|
511 |
|
# header |
512 |
|
echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.30 2005-08-21 21:23:48 niro Exp $' >> ${dest} |
513 |
|
echo >> ${dest} |
514 |
|
|
515 |
|
# pgkname and state |
516 |
|
echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} |
517 |
|
echo "STATE=\"${STATE}\"" >> ${dest} |
518 |
|
echo >> ${dest} |
519 |
|
|
520 |
|
# description and homepage |
521 |
|
echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest} |
522 |
|
echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} |
523 |
|
echo >> ${dest} |
524 |
|
|
525 |
|
# special tags and vars |
526 |
|
echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest} |
527 |
|
# add special vars |
528 |
|
if [ -n "${SPECIAL_VARS}" ] |
529 |
|
then |
530 |
|
local i |
531 |
|
for i in ${SPECIAL_VARS} |
532 |
|
do |
533 |
|
# being tricky here :) |
534 |
|
echo "${i}=\"$(eval echo \$${i})\"" >> ${dest} |
535 |
|
done |
536 |
|
echo >> ${dest} |
537 |
|
fi |
538 |
|
# add at least all includes |
539 |
|
if [ -n "${INHERITS}" ] |
540 |
|
then |
541 |
|
echo -n "minclude" >> ${dest} |
542 |
|
local i |
543 |
|
for i in ${INHERITS} |
544 |
|
do |
545 |
|
echo -n " ${i}" >> ${dest} |
546 |
|
done |
547 |
|
echo >> ${dest} |
548 |
|
fi |
549 |
|
echo >> ${dest} |
550 |
|
|
551 |
|
# deps and provides |
552 |
|
echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest} |
553 |
|
echo >> ${dest} |
554 |
|
echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest} |
555 |
|
echo >> ${dest} |
556 |
|
echo "PROVIDE=\"${PROVIDE}\"" >> ${dest} |
557 |
|
echo >> ${dest} |
558 |
|
|
559 |
|
# add special functions |
560 |
|
if [ -n "${SPECIAL_FUNCTIONS}" ] |
561 |
|
then |
562 |
|
local i |
563 |
|
for i in ${SPECIAL_FUNCTIONS} |
564 |
|
do |
565 |
|
# add to mage (quotes needed !) |
566 |
|
typeset -f "${i}" >> ${dest} |
567 |
|
# unset to be safe (quotes needed !) |
568 |
|
#unset "${i}" <-- later to get every target built |
569 |
|
done |
570 |
|
echo >> ${dest} |
571 |
|
fi |
572 |
|
|
573 |
|
# pre|post-install|removes |
574 |
|
typeset -f preinstall >> ${dest} |
575 |
|
echo >> ${dest} |
576 |
|
typeset -f postinstall >> ${dest} |
577 |
|
echo >> ${dest} |
578 |
|
typeset -f preremove >> ${dest} |
579 |
|
echo >> ${dest} |
580 |
|
typeset -f postremove >> ${dest} |
581 |
|
echo >> ${dest} |
582 |
|
} |
583 |
|
|
584 |
|
regen_mage_tree() |
585 |
|
{ |
586 |
|
local i |
587 |
|
|
588 |
|
# build them only if requested |
589 |
|
if [[ ${REGEN_MAGE_TREE} = true ]] |
590 |
|
then |
591 |
|
# run it without targets |
592 |
|
if [ -z "${MAGE_TARGETS}" ] |
593 |
|
then |
594 |
|
echo |
595 |
|
build_mage_script |
596 |
|
echo |
597 |
|
else |
598 |
|
|
599 |
|
# build for each target an mage file |
600 |
|
# run it with several targets |
601 |
|
for i in ${MAGE_TARGETS} |
602 |
|
do |
603 |
|
echo |
604 |
|
build_mage_script "${i}" |
605 |
|
echo |
606 |
|
done |
607 |
|
fi |
608 |
|
fi |
609 |
|
|
610 |
|
# now unset all uneeded vars to be safe |
611 |
|
# unset PKGNAME <-- don't do that; smage needs this var |
612 |
|
# unset to be safe (quotes needed !) |
613 |
|
for i in ${SPECIAL_FUNCTIONS} |
614 |
|
do |
615 |
|
unset "${i}" |
616 |
|
done |
617 |
|
unset SPECIAL_FUNCTIONS |
618 |
|
for i in ${SPECIAL_VARS} |
619 |
|
do |
620 |
|
unset "${i}" |
621 |
|
done |
622 |
|
unset SPECIAL_VARS |
623 |
|
unset STATE |
624 |
|
unset DESCRIPTION |
625 |
|
unset HOMEPAGE |
626 |
|
unset PKGTYPE |
627 |
|
unset INHERITS |
628 |
|
unset DEPEND |
629 |
|
unset SDEPEND |
630 |
|
unset PROVIDE |
631 |
|
unset preinstall |
632 |
|
unset postinstall |
633 |
|
unset preremove |
634 |
|
unset postremove |
635 |
|
} |
636 |
|
|
637 |
# print out our version |
# print out our version |
638 |
showversion |
showversion |
639 |
echo |
echo |
645 |
exit 1 |
exit 1 |
646 |
fi |
fi |
647 |
|
|
648 |
#updating smage2-scripts |
# updating smage2-scripts |
649 |
if [ "$1" == "update" ] |
if [ "$1" == "update" ] |
650 |
then |
then |
651 |
if [ ! -d ${SOURCEDIR} ] |
if [ ! -d ${SOURCEDIR} ] |
656 |
exit 0 |
exit 0 |
657 |
fi |
fi |
658 |
|
|
659 |
#creates md5sums for smages to given dir |
# creates md5sums for smages to given dir |
660 |
if [ "$1" == "calcmd5" ] |
if [ "$1" == "calcmd5" ] |
661 |
then |
then |
662 |
if [ $# -ge 3 ] |
if [ $# -ge 3 ] |
726 |
exit 0 |
exit 0 |
727 |
fi |
fi |
728 |
|
|
729 |
#download sources |
# download sources |
730 |
if [ "$1" == "download" -a -n "$2" ] |
if [ "$1" == "download" -a -n "$2" ] |
731 |
then |
then |
732 |
if [ ! -d ${SMAGESCRIPTSDIR} ] |
if [ ! -d ${SMAGESCRIPTSDIR} ] |
797 |
xtitle "Compiling ${PKGNAME}" |
xtitle "Compiling ${PKGNAME}" |
798 |
echo "Compiling ${PKGNAME}" |
echo "Compiling ${PKGNAME}" |
799 |
|
|
800 |
#download sources |
# auto regen mage tree if requested |
801 |
|
regen_mage_tree |
802 |
|
|
803 |
|
# download sources |
804 |
download_sources |
download_sources |
805 |
|
|
806 |
#fixes some issues with these functions |
# fixes some issues with these functions |
807 |
export -f src_prepare || die "src_prepare export failed" |
export -f src_prepare || die "src_prepare export failed" |
808 |
export -f src_compile || die "src_compile export failed" |
export -f src_compile || die "src_compile export failed" |
809 |
export -f src_install || die "src_install export failed" |
export -f src_install || die "src_install export failed" |
810 |
|
|
811 |
#fixes some compile issues |
# fixes some compile issues |
812 |
export CHOST="${CHOST}" || die "CHOST export failed" |
export CHOST="${CHOST}" || die "CHOST export failed" |
813 |
export CFLAGS="${CFLAGS}" || die "CFLAGS export failed" |
export CFLAGS="${CFLAGS}" || die "CFLAGS export failed" |
814 |
export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" |
export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" |
816 |
export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed" |
export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed" |
817 |
|
|
818 |
|
|
819 |
#setup distcc |
# setup distcc |
820 |
#distcc mus be setup *before* ccache, as ccache need to be before distcc in path |
# distcc mus be setup *before* ccache, as ccache need to be before distcc in path |
821 |
if [ "${SMAGE_USE_DISTCC}" == "true" ] |
if [ "${SMAGE_USE_DISTCC}" == "true" ] |
822 |
then |
then |
823 |
setup_distcc_environment |
setup_distcc_environment |
824 |
fi |
fi |
825 |
|
|
826 |
#setup ccache |
# setup ccache |
827 |
if [ "${SMAGE_USE_CCACHE}" == "true" ] |
if [ "${SMAGE_USE_CCACHE}" == "true" ] |
828 |
then |
then |
829 |
setup_ccache_environment |
setup_ccache_environment |
844 |
#read |
#read |
845 |
#debug end |
#debug end |
846 |
|
|
847 |
#cleans up build if a previously one exists |
# cleans up build if a previously one exists |
848 |
if [ -d ${BUILDDIR} ] |
if [ -d ${BUILDDIR} ] |
849 |
then |
then |
850 |
rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." |
rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." |
851 |
fi |
fi |
852 |
install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." |
install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." |
853 |
|
|
854 |
#cleans up srcdir if a previously unpacked one exists |
# cleans up srcdir if a previously unpacked one exists |
855 |
if [ -d ${SRCDIR} ] |
if [ -d ${SRCDIR} ] |
856 |
then |
then |
857 |
rm -rf ${SRCDIR} |
rm -rf ${SRCDIR} |
858 |
fi |
fi |
859 |
|
|
860 |
#cleans up bindir if a previous build exists or creates a new one |
# cleans up bindir if a previous build exists or creates a new one |
861 |
if [ -d ${BINDIR} ] |
if [ -d ${BINDIR} ] |
862 |
then |
then |
863 |
rm -rf ${BINDIR} |
rm -rf ${BINDIR} |
864 |
fi |
fi |
865 |
install -d ${BINDIR} || die "couldn't create \$BINDIR." |
install -d ${BINDIR} || die "couldn't create \$BINDIR." |
866 |
|
|
867 |
#cleans up package temp dir if a previous build exists |
# cleans up package temp dir if a previous build exists |
868 |
if [ -d ${BUILDDIR}/${PKGNAME} ] |
if [ -d ${BUILDDIR}/${PKGNAME} ] |
869 |
then |
then |
870 |
rm -rf ${BUILDDIR}/${PKGNAME} |
rm -rf ${BUILDDIR}/${PKGNAME} |
871 |
fi |
fi |
872 |
|
|
873 |
#cleans up timestamp if one exists |
# cleans up timestamp if one exists |
874 |
if [ -f /var/tmp/timestamp ] |
if [ -f /var/tmp/timestamp ] |
875 |
then |
then |
876 |
mage rmstamp |
mage rmstamp |
881 |
src_install || die "src_install failed" |
src_install || die "src_install failed" |
882 |
|
|
883 |
|
|
884 |
#compressing doc, info & man files |
# compressing doc, info & man files |
885 |
echo -e "Compressing man-pages ..." |
echo -e "Compressing man-pages ..." |
886 |
if [ -d ${BUILDDIR}/builded/usr/share/man ] |
if [ -d ${BUILDDIR}/builded/usr/share/man ] |
887 |
then |
then |
907 |
;; |
;; |
908 |
esac |
esac |
909 |
|
|
910 |
#the new buildpkg command |
# the new buildpkg command |
911 |
case ${NOPKGBUILD} in |
case ${NOPKGBUILD} in |
912 |
true|TRUE|yes|y) |
true|TRUE|yes|y) |
913 |
echo -e "NOPGKBUILD=true detected; Package will not be build ..." |
echo -e "NOPGKBUILD=true detected; Package will not be build ..." |
914 |
;; |
;; |
915 |
*) |
*) |
916 |
${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" |
# build serveral targets |
917 |
echo -e "\nPackage ${PKGNAME} successfully builded.\n" |
if [ -n "${MAGE_TARGETS}" ] |
918 |
|
then |
919 |
|
for target in ${MAGE_TARGETS} |
920 |
|
do |
921 |
|
# check if an special target_pkgbuild exists |
922 |
|
if typeset -f ${target}_pkgbuild > /dev/null |
923 |
|
then |
924 |
|
# run it |
925 |
|
${target}_pkgbuild |
926 |
|
fi |
927 |
|
# now create the target package |
928 |
|
${MLIBDIR}/pkgbuild_dir.sh \ |
929 |
|
"${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD}" \ |
930 |
|
${BINDIR} || die "target: ${target} package-build failed" |
931 |
|
echo -e "\nPackage ${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD} successfully builded.\n" |
932 |
|
done |
933 |
|
else |
934 |
|
${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" |
935 |
|
echo -e "\nPackage ${PKGNAME} successfully builded.\n" |
936 |
|
fi |
937 |
;; |
;; |
938 |
esac |
esac |
939 |
|
|
940 |
#for sure |
# for sure |
941 |
unset NOPKGBUILD |
unset NOPKGBUILD |
942 |
unset NOSTRIP |
unset NOSTRIP |
943 |
|
|