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 2362 by niro, Mon Jan 6 12:47:23 2014 UTC branches/mage-next/src/smage2.functions.sh.in revision 3082 by niro, Tue May 22 14:12:41 2018 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 491  mstriplibs() Line 453  mstriplibs()
453    
454   [[ -z ${stripdir} ]] && stripdir="${BINDIR}"   [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
455   [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug"   [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug"
456   find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null   find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "[shared object|pie executable]" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_LIB} 2> /dev/null
457  }  }
458    
459  mstripbins()  mstripbins()
# Line 500  mstripbins() Line 462  mstripbins()
462    
463   [[ -z ${stripdir} ]] && stripdir="${BINDIR}"   [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
464   [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug"   [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug"
465   find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null   find ${stripdir} ! -type d | xargs --no-run-if-empty file | grep -v "pie executable" | grep "executable" | grep ELF | cut -f 1 -d : | xargs --no-run-if-empty strip ${STRIP_DYN_BIN} 2> /dev/null
466  }  }
467    
468  mstripstatic()  mstripstatic()
# 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 588  march() Line 550  march()
550   return "${retval}"   return "${retval}"
551  }  }
552    
553  marchsrcfile()  marchvariable()
554  {  {
555   local retval   local retval
556   local var="$1"   local var="$1"
557    
558   [[ -z ${var} ]] && var="SRCFILE"   [[ -n ${var} ]] || die "marchvariable(): missing variable"
559    
560   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]
561   then   then
# Line 606  marchsrcfile() Line 568  marchsrcfile()
568   return "${retval}"   return "${retval}"
569  }  }
570    
571    marchsrcfile()
572    {
573     local retval
574     local var="$1"
575    
576     [[ -z ${var} ]] && var="SRCFILE"
577    
578     marchvariable "${var}" || die
579    }
580    
581  marchsrcdir()  marchsrcdir()
582  {  {
583   local retval   local retval
# Line 613  marchsrcdir() Line 585  marchsrcdir()
585    
586   [[ -z ${var} ]] && var="SRCDIR"   [[ -z ${var} ]] && var="SRCDIR"
587    
588   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]   marchvariable "${var}" || die
  then  
  eval echo \$${var}_${ARCH/i*86/x86} | tr ';' '\n'  
  retval=0  
  else  
  retval=1  
  fi  
   
  return "${retval}"  
589  }  }
590    
591  marchdepend()  marchdepend()
# Line 633  marchdepend() Line 597  marchdepend()
597    
598   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]
599   then   then
600   echo "\$(eval echo \\\$${var}_\${ARCH/i*86/x86} | tr ';' '\n')"   # evaluate with escape strings for the magefile if called by smage
601     # but do not escape if the smagefile was called by depwalker directly
602     if [[ ${SMAGE_DEPEND} = 1 ]]
603     then
604     eval echo \$${var}_${ARCH/i*86/x86} | tr ';' '\n'
605     else
606     echo "\$(eval echo \\\$${var}_\${ARCH/i*86/x86} | tr ';' '\n')"
607     fi
608   retval=0   retval=0
609   else   else
610   retval=1   retval=1
# Line 651  marchsdepend() Line 622  marchsdepend()
622    
623   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]
624   then   then
625   echo "\$(eval echo \\\$${var}_\${ARCH/i*86/x86} | tr ';' '\n')"   # evaluate with escape strings for the magefile if called by smage
626     # but do not escape if the smagefile was called by depwalker directly
627     if [[ ${SMAGE_DEPEND} = 1 ]]
628     then
629     eval echo \$${var}_${ARCH/i*86/x86} | tr ';' '\n'
630     else
631     echo "\$(eval echo \\\$${var}_\${ARCH/i*86/x86} | tr ';' '\n')"
632     fi
633   retval=0   retval=0
634   else   else
635   retval=1   retval=1
# Line 695  setup_ccache_environment() Line 673  setup_ccache_environment()
673   fi   fi
674  }  }
675    
 # 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}"  
 }  
   
676  # build_mage_script(): helper functions for regen_mage_tree()  # build_mage_script(): helper functions for regen_mage_tree()
677  # generates an mage file with given information in smage file  # generates an mage file with given information in smage file
678  # needs at least:  # needs at least:
# Line 790  build_mage_script() Line 706  build_mage_script()
706  {  {
707   local magefile   local magefile
708   local dest   local dest
  local target  
709   local split_pkg_base   local split_pkg_base
710   local sym   local sym
711   local depname   local depname
# Line 798  build_mage_script() Line 713  build_mage_script()
713   # if MAGE_TREE_DEST not set use BUILDDIR   # if MAGE_TREE_DEST not set use BUILDDIR
714   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
715    
  # determinate which suffix this mage file should get, if any  
  [[ $1 = --target ]] && shift && target="-$1"  
   
716   # mark package as splitpackage   # mark package as splitpackage
717   [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"   [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
718    
719   # name of magefile   # name of magefile
720   magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"   magefile="${PNAME}-${PVER}-${PBUILD}.mage"
721    
722   # destination to magefile   # destination to magefile
723   dest="${MAGE_TREE_DEST}/${PCAT}/${PNAME}${target}/${magefile}"   dest="${MAGE_TREE_DEST}/${PCAT}/${PNAME}/${magefile}"
724    
725   # show what we are doing   # show what we are doing
726   echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"   echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
# Line 819  build_mage_script() Line 731  build_mage_script()
731   > ${dest}   > ${dest}
732    
733   # pgkname and state   # pgkname and state
734   echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}$(print_distrotag)-${PBUILD}\"" >> ${dest}   echo "PKGNAME=\"${PNAME}-${PVER}-\${ARCH}$(print_distrotag)-${PBUILD}\"" >> ${dest}
735   echo "STATE=\"${STATE}\"" >> ${dest}   echo "STATE=\"${STATE}\"" >> ${dest}
736    
737   # description and homepage   # description and homepage
# Line 832  build_mage_script() Line 744  build_mage_script()
744   # special tags and vars   # special tags and vars
745   echo "PKGTYPE=\"${PKGTYPE}\""  >> ${dest}   echo "PKGTYPE=\"${PKGTYPE}\""  >> ${dest}
746    
  # echo MAGE_TARGETS ## note -target is needed !  
  echo "MAGE_TARGETS=\"${target}\"" >> ${dest}  
   
747   # split package base   # split package base
748   echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}   echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
749    
# Line 863  build_mage_script() Line 772  build_mage_script()
772   fi   fi
773    
774   # deps and provides   # deps and provides
775   echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}   echo "DEPEND=\"${DEPEND}\"" >> ${dest}
776   echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}   echo "SDEPEND=\"${SDEPEND}\"" >> ${dest}
777   echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}   echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
778    
779   # add special functions   # add special functions
# Line 875  build_mage_script() Line 784  build_mage_script()
784   do   do
785   # add to mage (quotes needed !)   # add to mage (quotes needed !)
786   typeset -f "${i}" >> ${dest}   typeset -f "${i}" >> ${dest}
  # unset to be safe (quotes needed !)  
  #unset "${i}" <-- later to get every target built  
787   done   done
788   fi   fi
789    
# Line 894  regen_mage_tree() Line 801  regen_mage_tree()
801   # build them only if requested   # build them only if requested
802   if mqueryfeature regentree   if mqueryfeature regentree
803   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  
   
804   # run it for splitpackages   # run it for splitpackages
805   elif [[ -n ${SPLIT_PACKAGES} ]]   if [[ -n ${SPLIT_PACKAGES} ]]
806   then   then
807   local split_pkg_base="${PNAME}"   local split_pkg_base="${PNAME}"
808   # save smage environment   # save smage environment
# Line 947  regen_mage_tree() Line 842  regen_mage_tree()
842    
843   # now unset all uneeded vars to be safe   # now unset all uneeded vars to be safe
844   # 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  
845   unset SPECIAL_FUNCTIONS   unset SPECIAL_FUNCTIONS
 # for i in ${SPECIAL_VARS}  
 # do  
 # unset "${i}"  
 # done  
846   unset SPECIAL_VARS   unset SPECIAL_VARS
847   unset STATE   unset STATE
848   unset DESCRIPTION   unset DESCRIPTION
# Line 1206  generate_package_md5sum() Line 1092  generate_package_md5sum()
1092   local pver   local pver
1093   local pbuild   local pbuild
1094   local parch   local parch
  local target  
1095   local pkgname   local pkgname
1096    
1097   # very basic getops   # very basic getops
# Line 1218  generate_package_md5sum() Line 1103  generate_package_md5sum()
1103   --pver|-v) shift; pver="$1" ;;   --pver|-v) shift; pver="$1" ;;
1104   --pbuild|-b) shift; pbuild="$1" ;;   --pbuild|-b) shift; pbuild="$1" ;;
1105   --parch|a) shift; parch="$1" ;;   --parch|a) shift; parch="$1" ;;
  --target|t) shift; target="$1" ;;  
1106   esac   esac
1107   shift   shift
1108   done   done
# Line 1234  generate_package_md5sum() Line 1118  generate_package_md5sum()
1118   [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."   [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
1119   [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."   [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
1120    
  # fix target as it may be empty !  
  [ -n "${target}" ] && target="-${target}"  
   
1121   # build pkgname   # build pkgname
1122   pkgname="${pname}${target}-${pver}-${parch}$(print_distrotag)-${pbuild}"   pkgname="${pname}-${pver}-${parch}$(print_distrotag)-${pbuild}"
1123    
1124   # build pkg-md5-sum only if requested   # build pkg-md5-sum only if requested
1125   if mqueryfeature regentree   if mqueryfeature regentree
# Line 1256  generate_package_md5sum() Line 1137  generate_package_md5sum()
1137   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
1138    
1139   # setup md5 dir   # setup md5 dir
1140   dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"   dest="${MAGE_TREE_DEST}/${pcat}/${pname}/md5"
1141   install -d ${dest}   install -d ${dest}
1142    
1143   # gen md5sum   # gen md5sum
# Line 1268  generate_package_md5sum() Line 1149  generate_package_md5sum()
1149    
1150  source_pkg_build()  source_pkg_build()
1151  {  {
  if [[ ${PKGTYPE} = virtual ]]  
  then  
  echo "Virtual package detected; src-pkg-tarball not necessary ..."  
  return 0  
  fi  
   
1152   if [[ ! -d ${SOURCEDIR}/${PNAME} ]]   if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
1153   then   then
1154   echo "No SRC_URI defined; src-pkg-tarball not necessary ..."   install -d ${SOURCEDIR}/${PNAME}
  return 0  
1155   fi   fi
1156    
1157   [ -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.2362  
changed lines
  Added in v.3082