Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 191 by niro, Fri Aug 19 02:24:12 2005 UTC revision 256 by niro, Mon Oct 3 21:02:31 2005 UTC
# Line 4  Line 4 
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.22 2005-08-19 02:24:12 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.39 2005-10-03 21:02:31 niro Exp $
8    
9  #01.10.2004  #01.10.2004
10  # added ccache support  # added ccache support
# Line 230  src_install() { Line 230  src_install() {
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
# Line 411  setup_ccache_environment(){ Line 406  setup_ccache_environment(){
406   fi   fi
407  }  }
408    
409  # alx_create_mage_file: helper functions for regen_mage_tree()  
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     pname="$(basename ${dep})"
432     else
433     # fix pver to target-pver
434     # to get pname-target-pver
435    
436     # doing it backwards !
437     pver="${dep##*-}"
438     # full pver
439     pname="$(basename ${dep/-${pver}/})${target}-${pver}"
440     fi
441    
442     # do not add empty lines
443     if [ -z "${NDEPEND}" ]
444     then
445     NDEPEND="${sym} ${cat}/${pname}"
446     else
447     NDEPEND="${NDEPEND}
448     ${sym} ${cat}/${pname}"
449     fi
450    
451     unset cat pname pver
452     done << EOF
453    ${depend}
454    EOF
455     # set NDEPEND to DEPEND
456     depend="${NDEPEND}"
457     fi
458    
459     echo "${depend}"
460    }
461    
462    # build_mage_script(): helper functions for regen_mage_tree()
463  # generates an mage file with given information in smage file  # generates an mage file with given information in smage file
464  # needs at least:  # needs at least:
465  #   PNAME                 name of pkg  #   PNAME                 name of pkg
# Line 433  setup_ccache_environment(){ Line 481  setup_ccache_environment(){
481  #  #
482  #   MAGE_TREE_DEST        target destination of the generated tree  #   MAGE_TREE_DEST        target destination of the generated tree
483  #   REGEN_MAGE_TREE       set to 'true' to enable this  #   REGEN_MAGE_TREE       set to 'true' to enable this
484  alx_create_mage_file()  #
485    # gets called with build_mage_script target
486    build_mage_script()
487  {  {
488   local magefile   local magefile
489   local dest   local dest
490   local suffix   local target
491   local sym   local sym
492   local depname   local depname
493    
# Line 445  alx_create_mage_file() Line 495  alx_create_mage_file()
495   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
496    
497   # determinate which suffix this mage file should get, if any   # determinate which suffix this mage file should get, if any
498   suffix="$1"   [ -n "$1" ] && target="-$1"
499    
500   # name of magefile   # name of magefile
501   magefile="${PNAME}${suffix}-${PVER}-${PBUILD}.mage"   magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
502    
503   # destination to magefile   # destination to magefile
504   dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${suffix}/${magefile}"   dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}"
505    
506   # show what we are doing   # show what we are doing
507   echo "Generating Mage file:"   echo "Generating Mage file:"
# Line 462  alx_create_mage_file() Line 512  alx_create_mage_file()
512   > ${dest}   > ${dest}
513    
514   # header   # header
515   echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.22 2005-08-19 02:24:12 niro Exp $' >> ${dest}   echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.39 2005-10-03 21:02:31 niro Exp $' >> ${dest}
516   echo  >> ${dest}   echo  >> ${dest}
517    
518   # pgkname and state   # pgkname and state
519   echo "PKGNAME=\"${PNAME}${suffix}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}   echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest}
520   echo "STATE=\"${STATE}\"" >> ${dest}   echo "STATE=\"${STATE}\"" >> ${dest}
521   echo >> ${dest}   echo >> ${dest}
522    
# Line 475  alx_create_mage_file() Line 525  alx_create_mage_file()
525   echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}   echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest}
526   echo >> ${dest}   echo >> ${dest}
527    
528   # special tags   # special tags and vars
529   echo "PKGTYPE=\"${PKGTYPE}\""  >> ${dest}   echo "PKGTYPE=\"${PKGTYPE}\""  >> ${dest}
530    
531     # echo MAGE_TARGETS ## note -target is needed !
532     echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
533     echo >> ${dest}
534    
535     # add special vars
536     if [ -n "${SPECIAL_VARS}" ]
537     then
538     local i
539     for i in ${SPECIAL_VARS}
540     do
541     # being tricky here :)
542     echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}
543     done
544     echo  >> ${dest}
545     fi
546    
547     # add at least all includes
548   if [ -n "${INHERITS}" ]   if [ -n "${INHERITS}" ]
549   then   then
550   echo -n "minclude"  >> ${dest}   echo -n "minclude"  >> ${dest}
# Line 490  alx_create_mage_file() Line 558  alx_create_mage_file()
558   echo >> ${dest}   echo >> ${dest}
559    
560   # deps and provides   # deps and provides
561   echo "DEPEND=\"${DEPEND}\"" >> ${dest}   echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}
562   echo "SDEPEND=\"${SDEPEND}\"" >> ${dest}   echo >> ${dest}
563     echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}
564     echo >> ${dest}
565   echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}   echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
566   echo >> ${dest}   echo >> ${dest}
567    
# Line 503  alx_create_mage_file() Line 573  alx_create_mage_file()
573   do   do
574   # add to mage (quotes needed !)   # add to mage (quotes needed !)
575   typeset -f "${i}" >> ${dest}   typeset -f "${i}" >> ${dest}
576     echo >> ${dest}
577   # unset to be safe (quotes needed !)   # unset to be safe (quotes needed !)
578   unset "${i}"   #unset "${i}" <-- later to get every target built
579   done   done
580     echo  >> ${dest}
581   fi   fi
582    
583   # pre|post-install|removes   # pre|post-install|removes
# Line 526  regen_mage_tree() Line 598  regen_mage_tree()
598   # build them only if requested   # build them only if requested
599   if [[ ${REGEN_MAGE_TREE} = true ]]   if [[ ${REGEN_MAGE_TREE} = true ]]
600   then   then
601   # build for each target an mage file   # run it without targets
602   for i in ${MAGE_TARGETS}   if [ -z "${MAGE_TARGETS}" ]
603   do   then
604   echo   echo
605   alx_create_mage_file "${i}"   build_mage_script
606   echo   echo
607   done   else
608    
609     # build for each target an mage file
610     # run it with several targets
611     for i in ${MAGE_TARGETS}
612     do
613     echo
614     build_mage_script "${i}"
615     echo
616     done
617     fi
618   fi   fi
619    
620   # now unset all uneeded vars to be safe   # now unset all uneeded vars to be safe
621   unset PKGNAME   # unset PKGNAME <-- don't do that; smage needs this var
622     # unset to be safe (quotes needed !)
623     for i in ${SPECIAL_FUNCTIONS}
624     do
625     unset "${i}"
626     done
627     unset SPECIAL_FUNCTIONS
628     for i in ${SPECIAL_VARS}
629     do
630     unset "${i}"
631     done
632     unset SPECIAL_VARS
633   unset STATE   unset STATE
634   unset DESCRIPTION   unset DESCRIPTION
635   unset HOMEPAGE   unset HOMEPAGE
# Line 545  regen_mage_tree() Line 638  regen_mage_tree()
638   unset DEPEND   unset DEPEND
639   unset SDEPEND   unset SDEPEND
640   unset PROVIDE   unset PROVIDE
  unset SPECIAL_FUNCTIONS  
641   unset preinstall   unset preinstall
642   unset postinstall   unset postinstall
643   unset preremove   unset preremove
644   unset postremove   unset postremove
645  }  }
646    
647    export_inherits()
648    {
649     local include="$1"
650     shift
651    
652     while [ "$1" ]
653     do
654     local functions="$1"
655    
656     # sanity checks
657     [ -z "${include}" ] && die "export_inherits(): \$include not given."
658     [ -z "${functions}" ] && die "export_inherits(): \$functions not given."
659    
660     eval "${functions}() { ${include}_${functions} ; }"
661    
662     # debug
663     [[ ${MAGEDEBUG} = on ]] && typeset -f "${functions}"
664    
665     shift
666     done
667    }
668    
669    generate_package_md5sum()
670    {
671     local dest
672     local pcat
673     local pname
674     local pver
675     local pbuild
676     local parch
677     local target
678     local pkgname
679    
680     # very basic getops
681     for i in $*
682     do
683     case $1 in
684     --pcat|-c) shift; pcat="$1" ;;
685     --pname|-n) shift; pname="$1" ;;
686     --pver|-v) shift; pver="$1" ;;
687     --pbuild|-b) shift; pbuild="$1" ;;
688     --parch|a) shift; parch="$1" ;;
689     --target|t) shift; target="$1" ;;
690     esac
691     shift
692     done
693    
694     # sanity checks; abort if not given
695     [ -z "${pcat}" ] && die "generate_package_md5sum() \$pcat not given."
696     [ -z "${pname}" ] && die "generate_package_md5sum() \$pname not given."
697     [ -z "${pver}" ] && die "generate_package_md5sum() \$pver not given."
698     [ -z "${pbuild}" ] && die "generate_package_md5sum() \$pbuild not given."
699     [ -z "${parch}" ] && die "generate_package_md5sum() \$parch not given."
700    
701     # check needed global vars
702     [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
703     [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
704    
705     # fix target as it may be empty !
706     [ -n "${target}" ] && target="-${target}"
707    
708     # build pkgname
709     pkgname="${pname}${target}-${pver}-${parch}-${pbuild}"
710    
711     # build pkg-md5-sum only if requested
712     if [[ ${REGEN_MAGE_TREE} = true ]]
713     then
714     echo -n "Generating a md5sum for ${pkgname}.${PKGSUFFIX} ... "
715    
716     # abort if not exist
717     if [ ! -f ${PKGDIR}/${pkgname}.${PKGSUFFIX} ]
718     then
719     echo "! exists"
720     return 0
721     fi
722    
723     # if MAGE_TREE_DEST not set use BUILDDIR
724     : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
725    
726     # setup md5 dir
727     dest="${MAGE_TREE_DEST}/${pcat}/${pname}/md5"
728     install -d ${dest}
729    
730     # gen md5sum
731     ( cd ${PKGDIR}; md5sum "${pkgname}.${PKGSUFFIX}" ) \
732     > ${dest}/${pkgname}.md5
733     echo "done"
734     fi
735    }
736    
737  # print out our version  # print out our version
738  showversion  showversion
739  echo  echo
# Line 563  then Line 745  then
745   exit 1   exit 1
746  fi  fi
747    
748  #updating smage2-scripts  # updating smage2-scripts
749  if [ "$1" == "update" ]  if [ "$1" == "update" ]
750  then  then
751   if [ ! -d ${SOURCEDIR} ]   if [ ! -d ${SOURCEDIR} ]
# Line 574  then Line 756  then
756   exit 0   exit 0
757  fi  fi
758    
759  #creates md5sums for smages to given dir  # creates md5sums for smages to given dir
760  if [ "$1" == "calcmd5" ]  if [ "$1" == "calcmd5" ]
761  then  then
762   if [ $# -ge 3 ]   if [ $# -ge 3 ]
# Line 644  then Line 826  then
826   exit 0   exit 0
827  fi  fi
828    
829  #download sources  # download sources
830  if [ "$1" == "download" -a -n "$2" ]  if [ "$1" == "download" -a -n "$2" ]
831  then  then
832   if [ ! -d ${SMAGESCRIPTSDIR} ]   if [ ! -d ${SMAGESCRIPTSDIR} ]
# Line 661  then Line 843  then
843   exit 0   exit 0
844  fi  fi
845    
846    # regen-mage-tree
847    if [ "$1" == "only-regen-tree" -a -n "$2" ]
848    then
849     # set correct SMAGENAME
850     SMAGENAME="$2"
851     MD5DIR="$(dirname ${SMAGENAME})/md5"
852     source ${SMAGENAME} || die "regen: smage2 not found"
853    
854     regen_mage_tree
855    
856     # build md5sum for existing packages
857     generate_package_md5sum \
858     --pcat "${PCATEGORIE}" \
859     --pname "${PNAME}" \
860     --pver "${PVER}" \
861     --pbuild "${PBUILD}" \
862     --parch "${ARCH}" \
863     --target "${target}"
864    
865     exit 0
866    fi
867    
868  if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ]  if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ]
869  then  then
870   die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."   die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."
# Line 709  fi Line 913  fi
913    
914    
915  source ${SMAGENAME} || die "source failed"  source ${SMAGENAME} || die "source failed"
916  PKGNAME="${PNAME}-${PVER}-${CHOST%%-*}-${PBUILD}"  PKGNAME="${PNAME}-${PVER}-${ARCH}-${PBUILD}"
917  MD5DIR="$(dirname ${SMAGENAME})/md5"  MD5DIR="$(dirname ${SMAGENAME})/md5"
918    
919  xtitle "Compiling ${PKGNAME}"  xtitle "Compiling ${PKGNAME}"
# Line 718  echo "Compiling ${PKGNAME}" Line 922  echo "Compiling ${PKGNAME}"
922  # auto regen mage tree if requested  # auto regen mage tree if requested
923  regen_mage_tree  regen_mage_tree
924    
925  #download sources  # download sources
926  download_sources  download_sources
927    
928  #fixes some issues with these functions  # fixes some issues with these functions
929  export -f src_prepare || die "src_prepare export failed"  export -f src_prepare || die "src_prepare export failed"
930  export -f src_compile || die "src_compile export failed"  export -f src_compile || die "src_compile export failed"
931  export -f src_install || die "src_install export failed"  export -f src_install || die "src_install export failed"
932    
933  #fixes some compile issues  # fixes some compile issues
934  export CHOST="${CHOST}" || die "CHOST export failed"  export CHOST="${CHOST}" || die "CHOST export failed"
935  export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"  export CFLAGS="${CFLAGS}" || die "CFLAGS export failed"
936  export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"  export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed"
# Line 734  export BINDIR="${BINDIR}" || die "BINDIR Line 938  export BINDIR="${BINDIR}" || die "BINDIR
938  export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"  export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed"
939    
940    
941  #setup distcc  # setup distcc
942  #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
943  if [ "${SMAGE_USE_DISTCC}" == "true" ]  if [ "${SMAGE_USE_DISTCC}" == "true" ]
944  then  then
945   setup_distcc_environment   setup_distcc_environment
946  fi  fi
947    
948  #setup ccache  # setup ccache
949  if [ "${SMAGE_USE_CCACHE}" == "true" ]  if [ "${SMAGE_USE_CCACHE}" == "true" ]
950  then  then
951   setup_ccache_environment   setup_ccache_environment
# Line 762  sleep 1 Line 966  sleep 1
966  #read  #read
967  #debug end  #debug end
968    
969  #cleans up build if a previously one exists  # cleans up build if a previously one exists
970  if [ -d ${BUILDDIR} ]  if [ -d ${BUILDDIR} ]
971  then  then
972   rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."   rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR."
973  fi  fi
974  install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."  install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR."
975    
976  #cleans up srcdir if a previously unpacked one exists  # cleans up srcdir if a previously unpacked one exists
977  if [ -d ${SRCDIR} ]  if [ -d ${SRCDIR} ]
978  then  then
979   rm -rf ${SRCDIR}   rm -rf ${SRCDIR}
980  fi  fi
981    
982  #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
983  if [ -d ${BINDIR} ]  if [ -d ${BINDIR} ]
984  then  then
985   rm -rf ${BINDIR}   rm -rf ${BINDIR}
986  fi  fi
987  install -d ${BINDIR} || die "couldn't create \$BINDIR."  install -d ${BINDIR} || die "couldn't create \$BINDIR."
988    
989  #cleans up package temp dir if a previous build exists  # cleans up package temp dir if a previous build exists
990  if [ -d ${BUILDDIR}/${PKGNAME} ]  if [ -d ${BUILDDIR}/${PKGNAME} ]
991  then  then
992   rm -rf ${BUILDDIR}/${PKGNAME}   rm -rf ${BUILDDIR}/${PKGNAME}
993  fi  fi
994    
995  #cleans up timestamp if one exists  # cleans up timestamp if one exists
996  if [ -f /var/tmp/timestamp ]  if [ -f /var/tmp/timestamp ]
997  then  then
998   mage rmstamp   mage rmstamp
# Line 799  src_compile || die "src_compile failed" Line 1003  src_compile || die "src_compile failed"
1003  src_install || die "src_install failed"  src_install || die "src_install failed"
1004    
1005    
1006  #compressing doc, info & man files  # compressing doc, info & man files
1007  echo -e "Compressing man-pages ..."  echo -e "Compressing man-pages ..."
1008  if [ -d ${BUILDDIR}/builded/usr/share/man ]  if [ -d ${BUILDDIR}/builded/usr/share/man ]
1009  then  then
# Line 825  case ${NOSTRIP} in Line 1029  case ${NOSTRIP} in
1029   ;;   ;;
1030  esac  esac
1031    
1032  #the new buildpkg command  # the new buildpkg command
1033  case ${NOPKGBUILD} in  case ${NOPKGBUILD} in
1034   true|TRUE|yes|y)   true|TRUE|yes|y)
1035   echo -e "NOPGKBUILD=true detected; Package will not be build ..."   echo -e "NOPGKBUILD=true detected; Package will not be build ..."
1036   ;;   ;;
1037   *)   *)
1038   ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"   # build serveral targets
1039   echo -e "\nPackage ${PKGNAME} successfully builded.\n"   if [ -n "${MAGE_TARGETS}" ]
1040     then
1041     for target in ${MAGE_TARGETS}
1042     do
1043     # check if an special target_pkgbuild exists
1044     if typeset -f ${target}_pkgbuild > /dev/null
1045     then
1046     # run it
1047     ${target}_pkgbuild
1048     fi
1049     # now create the target package
1050     ${MLIBDIR}/pkgbuild_dir.sh \
1051     "${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD}" \
1052     ${BINDIR} || die "target: ${target} package-build failed"
1053    
1054     # build pkg-md5-sum if requested
1055     generate_package_md5sum \
1056     --pcat "${PCATEGORIE}" \
1057     --pname "${PNAME}" \
1058     --pver "${PVER}" \
1059     --pbuild "${PBUILD}" \
1060     --parch "${ARCH}" \
1061     --target "${target}"
1062    
1063     echo -e "\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n"
1064     done
1065     else
1066     ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1067    
1068     # build pkg-md5-sum if requested
1069     generate_package_md5sum \
1070     --pcat "${PCATEGORIE}" \
1071     --pname "${PNAME}" \
1072     --pver "${PVER}" \
1073     --pbuild "${PBUILD}" \
1074     --parch "${ARCH}"
1075    
1076     echo -e "\nPackage ${PKGNAME} successfully builded.\n"
1077     fi
1078   ;;   ;;
1079  esac  esac
1080    
1081  #for sure  # for sure
1082  unset NOPKGBUILD  unset NOPKGBUILD
1083  unset NOSTRIP  unset NOSTRIP
1084    

Legend:
Removed from v.191  
changed lines
  Added in v.256