Magellan Linux

Diff of /branches/mage-next/src/smage2.functions.sh.in

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

trunk/mage/usr/lib/mage/smage2.functions.sh revision 2159 by niro, Wed Aug 14 07:55:29 2013 UTC branches/mage-next/src/smage2.functions.sh.in revision 2843 by niro, Fri Oct 31 14:50:47 2014 UTC
# Line 79  print_distrotag() Line 79  print_distrotag()
79   fi   fi
80  }  }
81    
 showversion()  
 {  
  echo -en "Magellan Source Install v${SMAGEVERSION} "  
  echo -e  "-- Niels Rogalla (niro@magellan-linux.de)"  
 }  
   
 die()  
 {  
  xtitleclean  
  echo -e ${COLRED}"Exited ${BASH_SOURCE} at line no ${BASH_LINENO}."${COLDEFAULT}  
  echo "SMAGE failed: $@"  
  exit 1  
 }  
   
 die_pipestatus()  
 {  
  # the status change if we do any parameter declarations!!  
  # dont do this anymore, keep this in mind!  
  #  
  # local pos="$1"  
  # local comment="$2"  
  #  
  # [ ${PIPESTATUS[${pos}]} -ne 0 ] && die "${comment}"  
  #  
  [ ${PIPESTATUS[$1]} -ne 0 ] && die "$2"  
 }  
   
 xtitle()  
 {  
  if [[ ${TERM} = xterm ]]  
  then  
  echo -ne "\033]0;[sMage: $@]\007"  
  fi  
  return 0  
 }  
   
 xtitleclean()  
 {  
  if [[ ${TERM} = xterm ]]  
  then  
  echo -ne "\033]0;\007"  
  fi  
  return 0  
 }  
   
82  syncsmage2()  syncsmage2()
83  {  {
84   xtitle "Updating smage2-script tree ..."   xtitle "Updating smage2-script tree ..."
# Line 225  download_sources() Line 180  download_sources()
180  }  }
181    
182  # dummy function, used if that does not exist in smage file  # dummy function, used if that does not exist in smage file
183    pkg_setup()
184    {
185     echo "no pkg_setup defined; doing nothing ..."
186     return 0
187    }
188    
189    # dummy function, used if that does not exist in smage file
190  src_prepare()  src_prepare()
191  {  {
192   echo "no src_prepare defined; doing nothing ..."   echo "no src_prepare defined; doing nothing ..."
# Line 318  minstall() Line 280  minstall()
280   sysconfdir=${BINDIR}/etc \   sysconfdir=${BINDIR}/etc \
281   libdir=${BINDIR}/usr/$(mlibdir) \   libdir=${BINDIR}/usr/$(mlibdir) \
282   "$@" install || die "minstall failed"   "$@" install || die "minstall failed"
283          else   else
284                  die "no Makefile found"   die "no Makefile found"
285          fi   fi
286  }  }
287    
288  mmake()  mmake()
# Line 566  sminclude() Line 528  sminclude()
528   then   then
529   for i in $@   for i in $@
530   do   do
531   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
532   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
533   done   done
534   echo   [[ ${SILENT} = 1 ]] || echo
535   fi   fi
536  }  }
537    
# Line 609  marchsrcfile() Line 571  marchsrcfile()
571  marchsrcdir()  marchsrcdir()
572  {  {
573   local retval   local retval
574   if [[ ! -z $(eval echo \$SRCDIR_${ARCH/i*86/x86}) ]]   local var="$1"
575    
576     [[ -z ${var} ]] && var="SRCDIR"
577    
578     if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]
579   then   then
580   eval echo \$SRCDIR_${ARCH/i*86/x86} | tr ';' '\n'   eval echo \$${var}_${ARCH/i*86/x86} | tr ';' '\n'
581   retval=0   retval=0
582   else   else
583   retval=1   retval=1
# Line 623  marchsrcdir() Line 589  marchsrcdir()
589  marchdepend()  marchdepend()
590  {  {
591   local retval   local retval
592     local var="$1"
593    
594     [[ -z ${var} ]] && var="DEPEND"
595    
596   if [[ ! -z $(eval echo \$DEPEND_${ARCH/i*86/x86}) ]]   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]
597   then   then
598   echo "\$(eval echo \\\$DEPEND_\${ARCH/i*86/x86} | tr ';' '\n')"   # evaluate with escape strings for the magefile if called by smage
599     # but do not escape if the smagefile was called by depwalker directly
600     if [[ ${SMAGE_DEPEND} = 1 ]]
601     then
602     eval echo \$${var}_${ARCH/i*86/x86} | tr ';' '\n'
603     else
604     echo "\$(eval echo \\\$${var}_\${ARCH/i*86/x86} | tr ';' '\n')"
605     fi
606   retval=0   retval=0
607   else   else
608   retval=1   retval=1
# Line 638  marchdepend() Line 614  marchdepend()
614  marchsdepend()  marchsdepend()
615  {  {
616   local retval   local retval
617   if [[ ! -z $(eval echo \$SDEPEND_${ARCH/i*86/x86}) ]]   local var="$1"
618    
619     [[ -z ${var} ]] && var="SDEPEND"
620    
621     if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]
622   then   then
623   echo "\$(eval echo \\\$SDEPEND_\${ARCH/i*86/x86} | tr ';' '\n')"   # evaluate with escape strings for the magefile if called by smage
624     # but do not escape if the smagefile was called by depwalker directly
625     if [[ ${SMAGE_DEPEND} = 1 ]]
626     then
627     eval echo \$${var}_${ARCH/i*86/x86} | tr ';' '\n'
628     else
629     echo "\$(eval echo \\\$${var}_\${ARCH/i*86/x86} | tr ';' '\n')"
630     fi
631   retval=0   retval=0
632   else   else
633   retval=1   retval=1
# Line 677  setup_ccache_environment() Line 664  setup_ccache_environment()
664  {  {
665   if [ -x /usr/bin/ccache ]   if [ -x /usr/bin/ccache ]
666   then   then
667   mqueryfeature "icecream" && export CCACHE_PREFIX=icecc   mqueryfeature "icecc" && export CCACHE_PREFIX=icecc
668    
669   echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}"   echo -e "${COLBLUE}---${COLGREEN} Using CCache for compilation ...${COLDEFAULT}"
670   export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"   export PATH=/usr/$(mlibdir)/ccache/bin:${PATH} || die "ccache: could not export new $PATH"
671   fi   fi
672  }  }
673    
 # fixes given dependencies to match a MAGE_TARGET  
 # fix_mage_deps -target s/depend # <-- note -target !  
 fix_mage_deps()  
 {  
  local target="$1"  
  local depend="$2"  
  local NDEPEND  
  local sym dep cat pver pname  
   
  # first of all remove all tabs and duplicate lines  
  if [ -n "${depend}" ]  
  then  
  depend=$(echo "${depend}" | sed 's:\t::g' | sort -u)  
  fi  
   
  # deps and provides are special  
  # they must be fixed to match the target  
   
  # run this only if target and depend is not empty  
  if [ -n "${target}" ] && [ -n "${depend}" ]  
  then  
  # fix DEPEND  
  while read sym dep  
  do  
  # ignore empty lines  
  [[ -z ${dep} ]] && continue  
   
  cat="$(dirname ${dep})"  
  # change if not virtual  
  if [[ ${cat} = virtual ]]  
  then  
  pname="$(basename ${dep})"  
  else  
  # fix pver to target-pver  
  # to get pname-target-pver  
   
  # doing it backwards !  
  pver="${dep##*-}"  
  # full pver  
  pname="$(basename ${dep/-${pver}/})${target}-${pver}"  
  fi  
   
  # do not add empty lines  
  if [ -z "${NDEPEND}" ]  
  then  
  NDEPEND="${sym} ${cat}/${pname}"  
  else  
  NDEPEND="${NDEPEND}  
  ${sym} ${cat}/${pname}"  
  fi  
   
  unset cat pname pver  
  done << EOF  
 ${depend}  
 EOF  
  # set NDEPEND to DEPEND  
  depend="${NDEPEND}"  
  fi  
   
  echo "${depend}"  
 }  
   
674  # build_mage_script(): helper functions for regen_mage_tree()  # build_mage_script(): helper functions for regen_mage_tree()
675  # generates an mage file with given information in smage file  # generates an mage file with given information in smage file
676  # needs at least:  # needs at least:
# Line 779  build_mage_script() Line 704  build_mage_script()
704  {  {
705   local magefile   local magefile
706   local dest   local dest
  local target  
707   local split_pkg_base   local split_pkg_base
708   local sym   local sym
709   local depname   local depname
# Line 787  build_mage_script() Line 711  build_mage_script()
711   # if MAGE_TREE_DEST not set use BUILDDIR   # if MAGE_TREE_DEST not set use BUILDDIR
712   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
713    
  # determinate which suffix this mage file should get, if any  
  [[ $1 = --target ]] && shift && target="-$1"  
   
714   # mark package as splitpackage   # mark package as splitpackage
715   [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"   [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
716    
717   # name of magefile   # name of magefile
718   magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"   magefile="${PNAME}-${PVER}-${PBUILD}.mage"
719    
720   # destination to magefile   # destination to magefile
721   dest="${MAGE_TREE_DEST}/${PCAT}/${PNAME}${target}/${magefile}"   dest="${MAGE_TREE_DEST}/${PCAT}/${PNAME}/${magefile}"
722    
723   # show what we are doing   # show what we are doing
724   echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"   echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
# Line 808  build_mage_script() Line 729  build_mage_script()
729   > ${dest}   > ${dest}
730    
731   # pgkname and state   # pgkname and state
732   echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}$(print_distrotag)-${PBUILD}\"" >> ${dest}   echo "PKGNAME=\"${PNAME}-${PVER}-\${ARCH}$(print_distrotag)-${PBUILD}\"" >> ${dest}
733   echo "STATE=\"${STATE}\"" >> ${dest}   echo "STATE=\"${STATE}\"" >> ${dest}
734    
735   # description and homepage   # description and homepage
# Line 821  build_mage_script() Line 742  build_mage_script()
742   # special tags and vars   # special tags and vars
743   echo "PKGTYPE=\"${PKGTYPE}\""  >> ${dest}   echo "PKGTYPE=\"${PKGTYPE}\""  >> ${dest}
744    
  # echo MAGE_TARGETS ## note -target is needed !  
  echo "MAGE_TARGETS=\"${target}\"" >> ${dest}  
   
745   # split package base   # split package base
746   echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}   echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
747    
# Line 852  build_mage_script() Line 770  build_mage_script()
770   fi   fi
771    
772   # deps and provides   # deps and provides
773   echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}   echo "DEPEND=\"${DEPEND}\"" >> ${dest}
774   echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}   echo "SDEPEND=\"${SDEPEND}\"" >> ${dest}
775   echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}   echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
776    
777   # add special functions   # add special functions
# Line 864  build_mage_script() Line 782  build_mage_script()
782   do   do
783   # add to mage (quotes needed !)   # add to mage (quotes needed !)
784   typeset -f "${i}" >> ${dest}   typeset -f "${i}" >> ${dest}
  # unset to be safe (quotes needed !)  
  #unset "${i}" <-- later to get every target built  
785   done   done
786   fi   fi
787    
# Line 883  regen_mage_tree() Line 799  regen_mage_tree()
799   # build them only if requested   # build them only if requested
800   if mqueryfeature regentree   if mqueryfeature regentree
801   then   then
  # run it without targets  
  if [[ -n ${MAGE_TARGETS} ]]  
  then  
  # build for each target a mage file  
  # run it with several targets  
  echo  
  for subpackage in ${MAGE_TARGETS}  
  do  
  build_mage_script --target "${subpackage}"  
  done  
  echo  
   
802   # run it for splitpackages   # run it for splitpackages
803   elif [[ -n ${SPLIT_PACKAGES} ]]   if [[ -n ${SPLIT_PACKAGES} ]]
804   then   then
805   local split_pkg_base="${PNAME}"   local split_pkg_base="${PNAME}"
806   # save smage environment   # save smage environment
# Line 936  regen_mage_tree() Line 840  regen_mage_tree()
840    
841   # now unset all uneeded vars to be safe   # now unset all uneeded vars to be safe
842   # unset PKGNAME <-- don't do that; smage needs this var   # unset PKGNAME <-- don't do that; smage needs this var
  # unset to be safe (quotes needed !)  
 # for i in ${SPECIAL_FUNCTIONS}  
 # do  
 # unset "${i}"  
 # done  
843   unset SPECIAL_FUNCTIONS   unset SPECIAL_FUNCTIONS
 # for i in ${SPECIAL_VARS}  
 # do  
 # unset "${i}"  
 # done  
844   unset SPECIAL_VARS   unset SPECIAL_VARS
845   unset STATE   unset STATE
846   unset DESCRIPTION   unset DESCRIPTION
# Line 1045  split_restore_variables() Line 940  split_restore_variables()
940   export DESCRIPTION="${SAVED_DESCRIPTION}"   export DESCRIPTION="${SAVED_DESCRIPTION}"
941   export HOMEPAGE="${SAVED_HOMEPAGE}"   export HOMEPAGE="${SAVED_HOMEPAGE}"
942   export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"   export SPECIAL_VARS="${SAVED_SPECIAL_VARS}"
943   export SPECIAL_VARS="${SAVED_SPECIAL_FUNCTIONS}"   export SPECIAL_FUNCTIONS="${SAVED_SPECIAL_FUNCTIONS}"
944   export STATE="${SAVED_STATE}"   export STATE="${SAVED_STATE}"
945   export INHERITS="${SAVED_INHERITS}"   export INHERITS="${SAVED_INHERITS}"
946   export DEPEND="${SAVED_DEPEND}"   export DEPEND="${SAVED_DEPEND}"
# Line 1195  generate_package_md5sum() Line 1090  generate_package_md5sum()
1090   local pver   local pver
1091   local pbuild   local pbuild
1092   local parch   local parch
  local target  
1093   local pkgname   local pkgname
1094    
1095   # very basic getops   # very basic getops
# Line 1207  generate_package_md5sum() Line 1101  generate_package_md5sum()
1101   --pver|-v) shift; pver="$1" ;;   --pver|-v) shift; pver="$1" ;;
1102   --pbuild|-b) shift; pbuild="$1" ;;   --pbuild|-b) shift; pbuild="$1" ;;
1103   --parch|a) shift; parch="$1" ;;   --parch|a) shift; parch="$1" ;;
  --target|t) shift; target="$1" ;;  
1104   esac   esac
1105   shift   shift
1106   done   done
# Line 1223  generate_package_md5sum() Line 1116  generate_package_md5sum()
1116   [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."   [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
1117   [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."   [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
1118    
  # fix target as it may be empty !  
  [ -n "${target}" ] && target="-${target}"  
   
1119   # build pkgname   # build pkgname
1120   pkgname="${pname}${target}-${pver}-${parch}$(print_distrotag)-${pbuild}"   pkgname="${pname}-${pver}-${parch}$(print_distrotag)-${pbuild}"
1121    
1122   # build pkg-md5-sum only if requested   # build pkg-md5-sum only if requested
1123   if mqueryfeature regentree   if mqueryfeature regentree
# Line 1245  generate_package_md5sum() Line 1135  generate_package_md5sum()
1135   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
1136    
1137   # setup md5 dir   # setup md5 dir
1138   dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"   dest="${MAGE_TREE_DEST}/${pcat}/${pname}/md5"
1139   install -d ${dest}   install -d ${dest}
1140    
1141   # gen md5sum   # gen md5sum
# Line 1265  source_pkg_build() Line 1155  source_pkg_build()
1155    
1156   if [[ ! -d ${SOURCEDIR}/${PNAME} ]]   if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
1157   then   then
1158   echo "No SRC_URI defined; src-pkg-tarball not necessary ..."   install -d ${SOURCEDIR}/${PNAME}
  return 0  
1159   fi   fi
1160    
1161   [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly."   [ -z "${SRCPKGDIR}" ] && die "\$SRCPKGDIR not found. Please setup your ${MAGERC} correctly."

Legend:
Removed from v.2159  
changed lines
  Added in v.2843