Magellan Linux

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

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

revision 941 by niro, Fri Nov 20 19:41:27 2009 UTC revision 947 by niro, Sat Nov 21 01:44:27 2009 UTC
# Line 75  die() Line 75  die()
75    
76  die_pipestatus()  die_pipestatus()
77  {  {
78   local pos="$1"   # the status change if we do any parameter declarations!!
79   local comment="$2"   # dont do this anymore, keep this in mind!
80     #
81   [ ${PIPESTATUS[${pos}]} -gt 0 ] && die "${comment}"   # local pos="$1"
82     # local comment="$2"
83     #
84     # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}"
85     #
86     [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2"
87  }  }
88    
89  xtitle()  xtitle()
# Line 549  mstripbins() Line 554  mstripbins()
554   find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null   find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
555  }  }
556    
557    mcompressdocs()
558    {
559     local bindir="$@"
560    
561     if [ -d ${bindir}/usr/share/man ]
562     then
563     echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}"
564     ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man
565     fi
566    
567     if [ -d ${bindir}/usr/share/info ]
568     then
569     echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}"
570     ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info
571     fi
572    }
573    
574  sminclude()  sminclude()
575  {  {
576   local i   local i
# Line 664  EOF Line 686  EOF
686  #   INHERITS              which functions get included  #   INHERITS              which functions get included
687  #   SPECIAL_FUNCTIONS     special functions which should also be added  #   SPECIAL_FUNCTIONS     special functions which should also be added
688  #                         warning: they get killed before the build starts !  #                         warning: they get killed before the build starts !
689    #   SPLIT_PACKAGES        names of all subpackages which are splitted from parent
690    #   SPLIT_PACKAGE_BASE    base package name for splitpackages
691    #                         (only in the resulting magefile}
692  #  #
693  #   MAGE_TREE_DEST        target destination of the generated tree  #   MAGE_TREE_DEST        target destination of the generated tree
694  #   REGEN_MAGE_TREE       set to 'true' to enable this  #   REGEN_MAGE_TREE       set to 'true' to enable this
# Line 674  build_mage_script() Line 699  build_mage_script()
699   local magefile   local magefile
700   local dest   local dest
701   local target   local target
702     local split_pkg_base
703   local sym   local sym
704   local depname   local depname
705    
# Line 681  build_mage_script() Line 707  build_mage_script()
707   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
708    
709   # determinate which suffix this mage file should get, if any   # determinate which suffix this mage file should get, if any
710   [ -n "$1" ] && target="-$1"   [[ $1 = --target ]] && shift && target="-$1"
711    
712     # mark package as splitpackage
713     [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
714    
715   # name of magefile   # name of magefile
716   magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"   magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"
# Line 718  build_mage_script() Line 747  build_mage_script()
747   echo "MAGE_TARGETS=\"${target}\"" >> ${dest}   echo "MAGE_TARGETS=\"${target}\"" >> ${dest}
748   echo >> ${dest}   echo >> ${dest}
749    
750     # split package base
751     echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
752     echo >> ${dest}
753    
754   # add special vars   # add special vars
755   if [ -n "${SPECIAL_VARS}" ]   if [ -n "${SPECIAL_VARS}" ]
756   then   then
# Line 785  regen_mage_tree() Line 818  regen_mage_tree()
818   if [[ ${REGEN_MAGE_TREE} = true ]]   if [[ ${REGEN_MAGE_TREE} = true ]]
819   then   then
820   # run it without targets   # run it without targets
821   if [ -z "${MAGE_TARGETS}" ]   if [[ -n ${MAGE_TARGETS} ]]
822   then   then
823     # build for each target a mage file
824     # run it with several targets
825   echo   echo
826   build_mage_script   for i in ${MAGE_TARGETS}
827     do
828     build_mage_script --target "${i}"
829     done
830   echo   echo
  else  
831    
832   # build for each target an mage file   # run it for splitpackages
833     elif [[ -n ${SPLIT_PACKAGES} ]]
834     then
835     local split_pkg_base="${PNAME}"
836     # save smage environment
837     split_save_variables
838     # build for each subpackage a mage file
839   # run it with several targets   # run it with several targets
840   for i in ${MAGE_TARGETS}   echo
841     for i in ${SPLIT_PACKAGES}
842   do   do
843   echo   # get the right variables for the split
844   build_mage_script "${i}"   export PNAME="${i}"
845   echo   split_info_${i}
846     build_mage_script --split-pkg-base "${split_pkg_base}"
847   done   done
848     echo
849     # restore smage environment
850     split_restore_variables
851    
852     else
853     echo
854     build_mage_script
855     echo
856   fi   fi
857   fi   fi
858    
# Line 830  regen_mage_tree() Line 883  regen_mage_tree()
883   unset postremove   unset postremove
884  }  }
885    
886    split_save_variables()
887    {
888     export SAVED_PNAME="${PNAME}"
889     export SAVED_PVER="${PVER}"
890     export SAVED_PBUILD="${PBUILD}"
891     export SAVED_PCATEGORIE="${PCATEGORIE}"
892     export SAVED_DESCRIPTION="${DESCRIPTION}"
893     export SAVED_HOMEPAGE="${HOMEPAGE}"
894     export SAVED_SPECIAL_VARS="${SPECIAL_VARS}"
895     export SAVED_STATE="${STATE}"
896     export SAVED_PKGTYPE="${PKGTYPE}"
897     export SAVED_INHERITS="${INHERITS}"
898     export SAVED_DEPEND="${DEPEND}"
899     export SAVED_SDEPEND="${SDEPEND}"
900     export SAVED_PROVIDE="${PROVIDE}"
901     export SAVED_NOPKGBUILD="${NOPKGBUILD}"
902    
903     # bindir too
904     export SAVED_BINDIR="${BINDIR}"
905    
906     # export the SPLIT_PACKAGE_BASE
907     export SPLIT_PACKAGE_BASE="${SAVED_PNAME}"
908    
909     # functions
910     if [[ ! -z $(typeset -f preinstall) ]]
911     then
912     # rename the old one
913     local saved_preinstall
914     saved_preinstall=SAVED_$(typeset -f preinstall)
915     eval "${saved_preinstall}"
916     export -f SAVED_preinstall
917     fi
918    
919     if [[ ! -z $(typeset -f postinstall) ]]
920     then
921     # rename the old one
922     local saved_postinstall
923     saved_postinstall=SAVED_$(typeset -f postinstall)
924     eval "${saved_postinstall}"
925     export -f SAVED_postinstall
926     fi
927    
928     if [[ ! -z $(typeset -f preremove) ]]
929     then
930     # rename the old one
931     local saved_preremove
932     saved_preremove=SAVED_$(typeset -f preremove)
933     eval "${saved_preremove}"
934     export -f SAVED_preremove
935     fi
936    
937     if [[ ! -z $(typeset -f postremove) ]]
938     then
939     # rename the old one
940     local saved_postremove
941     saved_postremove=SAVED_$(typeset -f postremove)
942     eval "${saved_postremove}"
943     export -f SAVED_postremove
944     fi
945    }
946    
947    split_restore_variables()
948    {
949     export PNAME="${SAVED_PNAME}"
950     export PVER="${SAVED_PVER}"
951     export PBUILD="${SAVED_PBUILD}"
952     export PCATEGORIE="${SAVED_PCATEGORIE}"
953     export DESCRIPTION="${SAVED_DESCRIPTION}"
954     export HOMEPAGE="${SAVED_HOMEPAGE}"
955     export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"
956     export STATE="${SAVED_STATE}"
957     export PKGTYPE="${SAVED_PKGTYPE}"
958     export INHERITS="${SAVED_INHERITS}"
959     export DEPEND="${SAVED_DEPEND}"
960     export SDEPEND="${SAVED_SDEPEND}"
961     export PROVIDE="${SAVED_PROVIDE}"
962     export NOPKGBUILD="${SAVED_NOPKGBUILD}"
963    
964     # bindir too
965     export BINDIR="${SAVED_BINDIR}"
966    
967     # functions
968     if [[ ! -z $(typeset -f SAVED_preinstall) ]]
969     then
970     # rename the old one
971     local saved_preinstall
972     saved_preinstall=$(typeset -f SAVED_preinstall)
973     eval "${saved_preinstall/SAVED_/}"
974     export -f preinstall
975     fi
976    
977     if [[ ! -z $(typeset -f SAVED_postinstall) ]]
978     then
979     # rename the old one
980     local saved_postinstall
981     saved_postinstall=$(typeset -f SAVED_postinstall)
982     eval "${saved_postinstall/SAVED_/}"
983     export -f postinstall
984     fi
985    
986     if [[ ! -z $(typeset -f SAVED_preremove) ]]
987     then
988     # rename the old one
989     local saved_preremove
990     saved_preremove=$(typeset -f SAVED_preremove)
991     eval "${saved_preremove/SAVED_/}"
992     export -f preremove
993     fi
994    
995     if [[ ! -z $(typeset -f SAVED_postremove) ]]
996     then
997     # rename the old one
998     local saved_postremove
999     saved_postremove=$(typeset -f SAVED_postremove)
1000     eval "${saved_postremove/SAVED_/}"
1001     export -f postremove
1002     fi
1003    
1004     # unset saved vars; not needed anymore
1005     unset SAVED_PNAME
1006     unset SAVED_PVER
1007     unset SAVED_PBUILD
1008     unset SAVED_PCATEGORIE
1009     unset SAVED_DESCRIPTION
1010     unset SAVED_HOMEPAGE
1011     unset SAVED_SPECIAL_VARS
1012     unset SAVED_STATE
1013     unset SAVED_PKGTYPE
1014     unset SAVED_INHERITS
1015     unset SAVED_DEPEND
1016     unset SAVED_SDEPEND
1017     unset SAVED_PROVIDE
1018     unset SAVED_BINDIR
1019     unset SAVED_NOPKGBUILD
1020     unset SPLIT_PACKAGE_BASE
1021     unset -f SAVED_preinstall
1022     unset -f SAVED_postinstall
1023     unset -f SAVED_preremove
1024     unset -f SAVED_postremove
1025    }
1026    
1027  export_inherits()  export_inherits()
1028  {  {
1029   local include="$1"   local include="$1"
# Line 953  step_by_step() Line 1147  step_by_step()
1147  {  {
1148   if [[ ${STEP_BY_STEP} = true ]]   if [[ ${STEP_BY_STEP} = true ]]
1149   then   then
1150   echo "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}"   echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}"
1151   echo "Press [enter] to continue"   echo "Press [enter] to continue"
1152   read   read
1153   fi   fi
# Line 1080  then Line 1274  then
1274   regen_mage_tree   regen_mage_tree
1275    
1276   # build several targets   # build several targets
1277   if [ -n "${MAGE_TARGETS}" ]   if [[ -n ${MAGE_TARGETS} ]]
1278   then   then
1279   for target in ${MAGE_TARGETS}   for target in ${MAGE_TARGETS}
1280   do   do
# Line 1093  then Line 1287  then
1287   --parch "${ARCH}" \   --parch "${ARCH}" \
1288   --target "${target}"   --target "${target}"
1289   done   done
1290    
1291     # build several subpackages
1292     elif [[ -n ${SPLIT_PACKAGES} ]]
1293     then
1294     split_save_variables
1295     for subpackage in ${SPLIT_PACKAGE}
1296     do
1297     # get the right variables for the split
1298     export PNAME="${subpackage}"
1299     split_info_${subpackage}
1300     # build md5sum for existing packages
1301     generate_package_md5sum \
1302     --pcat "${PCATEGORIE}" \
1303     --pname "${PNAME}" \
1304     --pver "${PVER}" \
1305     --pbuild "${PBUILD}" \
1306     --parch "${ARCH}"
1307     done
1308     split_restore_variables
1309    
1310   else   else
1311   # build md5sum for existing packages   # build md5sum for existing packages
1312   generate_package_md5sum \   generate_package_md5sum \
# Line 1100  then Line 1314  then
1314   --pname "${PNAME}" \   --pname "${PNAME}" \
1315   --pver "${PVER}" \   --pver "${PVER}" \
1316   --pbuild "${PBUILD}" \   --pbuild "${PBUILD}" \
1317   --parch "${ARCH}" \   --parch "${ARCH}"
  --target "${target}"  
1318   fi   fi
1319    
1320   exit 0   exit 0
# Line 1254  src_compile | ${SMAGE_LOG_CMD} Line 1467  src_compile | ${SMAGE_LOG_CMD}
1467  die_pipestatus 0 "src_compile failed"  die_pipestatus 0 "src_compile failed"
1468  step_by_step $_  step_by_step $_
1469    
1470  src_install | ${SMAGE_LOG_CMD}  # build several subpackages
1471  die_pipestatus 0 "src_install failed"  if [[ -n ${SPLIT_PACKAGES} ]]
1472  step_by_step $_  then
1473     # save bindir & pname
1474     split_save_variables
1475     export SAVED_BINDIR="${BINDIR}"
1476     for subpackage in ${SPLIT_PACKAGES}
1477     do
1478     if typeset -f src_install_${subpackage} > /dev/null
1479     then
1480     # export subpackage bindir
1481     export BINDIR="${SAVED_BINDIR}_${subpackage}"
1482     # export PNAME, several internal function and include
1483     # rely on this variable
1484     export PNAME="${subpackage}"
1485    
1486     echo
1487     echo -en "${COLBLUE}*** ${COLDEFAULT}"
1488     echo -en "  Running ${COLGREEN}split src_install()${COLDEFAULT}"
1489     echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}"
1490     echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..."
1491    
1492     src_install_${subpackage} | ${SMAGE_LOG_CMD}
1493     die_pipestatus 0 "src_install_${subpackage} failed"
1494     step_by_step $_
1495     fi
1496     done
1497     # restore bindir & pname
1498     split_restore_variables
1499    else
1500     src_install | ${SMAGE_LOG_CMD}
1501     die_pipestatus 0 "src_install failed"
1502     step_by_step $_
1503    fi
1504    
1505  # compressing doc, info & man files  # compressing doc, info & man files
1506  if [ -d ${BUILDDIR}/builded/usr/share/man ]  if [[ -n ${SPLIT_PACKAGES} ]]
1507  then  then
1508   echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}"   for subpackage in ${SPLIT_PACKAGE}
1509   ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man   do
1510     mcompressdocs ${BINDIR}_${subpackage}
1511     done
1512    else
1513     mcompressdocs ${BINDIR}
1514  fi  fi
1515    
 if [ -d ${BUILDDIR}/builded/usr/share/info ]  
 then  
  echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}"  
  ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info  
 fi  
1516    
1517  # stripping all bins and libs  # stripping all bins and libs
1518  case ${NOSTRIP} in  case ${NOSTRIP} in
# Line 1278  case ${NOSTRIP} in Line 1520  case ${NOSTRIP} in
1520   echo -e "NOSTRIP=true detected; Package will not be stripped ..."   echo -e "NOSTRIP=true detected; Package will not be stripped ..."
1521   ;;   ;;
1522   *)   *)
1523   echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}"   if [[ -n ${SPLIT_PACKAGES} ]]
1524   mstripbins ${BINDIR}   then
1525   echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}"   for subpackage in ${SPLIT_PACKAGE}
1526   mstriplibs ${BINDIR}   do
1527     echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}"
1528     mstripbins ${BINDIR}_${subpackage}
1529     echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}"
1530     mstriplibs ${BINDIR}_${subpackage}
1531     done
1532     else
1533     echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}"
1534     mstripbins ${BINDIR}
1535     echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}"
1536     mstriplibs ${BINDIR}
1537     fi
1538   ;;   ;;
1539  esac  esac
1540    
# Line 1292  case ${NOPKGBUILD} in Line 1545  case ${NOPKGBUILD} in
1545   ;;   ;;
1546   *)   *)
1547   # build several targets   # build several targets
1548   if [ -n "${MAGE_TARGETS}" ]   if [[ -n ${MAGE_TARGETS} ]]
1549   then   then
1550   for target in ${MAGE_TARGETS}   for target in ${MAGE_TARGETS}
1551   do   do
# Line 1318  case ${NOPKGBUILD} in Line 1571  case ${NOPKGBUILD} in
1571    
1572   echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"   echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1573   done   done
1574    
1575     # build several subpackages
1576     elif [[ -n ${SPLIT_PACKAGES} ]]
1577     then
1578     split_save_variables
1579     for subpackage in ${SPLIT_PACKAGES}
1580     do
1581     # get the right variables for the split
1582     export PNAME="${subpackage}"
1583     split_info_${PNAME}
1584    
1585     # jump to next one if NOPKGBUILD is set in split_info
1586     case ${NOPKGBUILD} in
1587     true|TRUE|yes|y) continue ;;
1588     esac
1589    
1590     # check if an special subpackage_pkgbuild exists
1591     if typeset -f ${PNAME}_pkgbuild > /dev/null
1592     then
1593     # run it
1594     ${PNAME}_pkgbuild
1595     fi
1596     # now create the target package
1597     ${MLIBDIR}/pkgbuild_dir.sh \
1598     "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \
1599     "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed"
1600    
1601     # build pkg-md5-sum if requested
1602     generate_package_md5sum \
1603     --pcat "${PCATEGORIE}" \
1604     --pname "${PNAME}" \
1605     --pver "${PVER}" \
1606     --pbuild "${PBUILD}" \
1607     --parch "${ARCH}"
1608    
1609     echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}"
1610     done
1611     split_restore_variables
1612    
1613   else   else
1614   ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"   ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"
1615    

Legend:
Removed from v.941  
changed lines
  Added in v.947