Magellan Linux

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

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

revision 2172 by niro, Thu Aug 15 08:56:57 2013 UTC revision 3207 by niro, Mon Aug 21 19:19:15 2023 UTC
# Line 225  download_sources() Line 225  download_sources()
225  }  }
226    
227  # dummy function, used if that does not exist in smage file  # dummy function, used if that does not exist in smage file
228    pkg_setup()
229    {
230     echo "no pkg_setup defined; doing nothing ..."
231     return 0
232    }
233    
234    # dummy function, used if that does not exist in smage file
235  src_prepare()  src_prepare()
236  {  {
237   echo "no src_prepare defined; doing nothing ..."   echo "no src_prepare defined; doing nothing ..."
# Line 254  src_install() Line 261  src_install()
261    
262  mlibdir()  mlibdir()
263  {  {
264   local libdir=lib   local libdir="${ABI_DEFAULT_LIBDIR}"
265   [[ ${ARCH} = x86_64 ]] && libdir=lib64   [[ ${ARCH} = i686 ]] && libdir="${ABI_X86_LIBDIR}"
266     [[ ${ARCH} = x86_64 ]] && libdir="${ABI_X86_64_LIBDIR}"
267     [[ ${MABI} = m32 ]] && libdir="${ABI_X86_LIBDIR}"
268     [[ ${MABI} = m64 ]] && libdir="${ABI_X86_64_LIBDIR}"
269     [[ -n ${ABI_LIBDIR} ]] && libdir="${ABI_LIBDIR}"
270    
271   echo "${libdir}"   echo "${libdir}"
272  }  }
273    
274  mconfigure()  mconfigure()
275  {  {
276     local configure_exec="./configure"
277    
278     if [[ ! -z ${MCONFIGURE_EXEC} ]]
279     then
280     if [ -x ${MCONFIGURE_EXEC} ]
281     then
282     echo -e "${COLBLUE}*** ${COLGREEN}Using '${MCONFIGURE_EXEC}' as configure script${COLDEFAULT}"
283     configure_exec="${MCONFIGURE_EXEC}"
284     else
285     die "MCONFIGURE_EXEC '${MCONFIGURE_EXEC}' not executable"
286     fi
287     fi
288    
289     if [ ! -x ${configure_exec} ]
290     then
291     die "${configure_exec} not executable"
292     fi
293    
294   local myopts   local myopts
295   if [[ ! -z ${CTARGET} ]]   if [[ ! -z ${CTARGET} ]]
296   then   then
297   myopts+=" --target=${CTARGET}"   myopts+=" --target=${CTARGET}"
298   fi   fi
299    
300   if [ -x ./configure ]   # if requested disable-static
301     if [[ ! -z $(${configure_exec} --help | grep -- '--.*able-static') ]]
302   then   then
303   # if requested disable-static   if mqueryfeature '!static'
  if [[ ! -z $(./configure --help | grep -- '--.*able-static') ]]  
304   then   then
305   if mqueryfeature '!static'   myopts+=" --disable-static"
306   then   else
307   myopts+=" --disable-static"   myopts+=" --enable-static"
  else  
  myopts+=" --enable-static"  
  fi  
  fi  
   
  # always enable shared by default but not for waf configure  
  if [[ ! -z $(./configure --help | grep -- '--.*able-shared') ]] &&  
  [[ -z $(./configure --version | grep waf) ]]  
  then  
  myopts+=" --enable-shared"  
308   fi   fi
   
  ./configure \  
  --prefix=/usr \  
  --host=${CHOST} \  
  --build=${CHOST} \  
  --mandir=/usr/share/man \  
  --infodir=/usr/share/info \  
  --datadir=/usr/share \  
  --sysconfdir=/etc \  
  --localstatedir=/var/lib \  
  --libdir=/usr/$(mlibdir) \  
  ${myopts} \  
  "$@" || die "mconfigure failed"  
  else  
  echo "configure is not an executable ..."  
  exit 1  
309   fi   fi
310    
311     # always enable shared by default but not for waf configure
312     if [[ ! -z $(${configure_exec} --help | grep -- '--.*able-shared') ]] &&
313     [[ -z $(${configure_exec} --version | grep waf) ]]
314     then
315     myopts+=" --enable-shared"
316     fi
317    
318     ${configure_exec} \
319     --prefix=/usr \
320     --host=${CHOST} \
321     --build=${CHOST} \
322     --mandir=/usr/share/man \
323     --infodir=/usr/share/info \
324     --datadir=/usr/share \
325     --sysconfdir=/etc \
326     --localstatedir=/var/lib \
327     --libdir=/usr/$(mlibdir) \
328     ${myopts} \
329     "$@" || die "mconfigure failed"
330  }  }
331    
332  minstall()  minstall()
# Line 318  minstall() Line 341  minstall()
341   sysconfdir=${BINDIR}/etc \   sysconfdir=${BINDIR}/etc \
342   libdir=${BINDIR}/usr/$(mlibdir) \   libdir=${BINDIR}/usr/$(mlibdir) \
343   "$@" install || die "minstall failed"   "$@" install || die "minstall failed"
344          else   else
345                  die "no Makefile found"   die "no Makefile found"
346          fi   fi
347  }  }
348    
349  mmake()  mmake()
# Line 384  munpack() Line 407  munpack()
407   popd > /dev/null   popd > /dev/null
408   fi   fi
409   ;;   ;;
410     lz)
411     IFTAR="$(basename $SRCFILE .lz)"
412     IFTAR="${IFTAR##*.}"
413     if [[ ${IFTAR} = tar ]]
414     then
415     tar --no-same-owner --lzip -xvf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tar.lz unpack failed."
416     else
417     pushd ${DEST} > /dev/null
418     lzip -dc ${SOURCEDIR}/${PNAME}/${SRCFILE} > ${DEST}/$(basename ${SRCFILE} .lz) || die ".lz unpack failed."
419     popd > /dev/null
420     fi
421     ;;
422   tbz2|mpks|mpk)   tbz2|mpks|mpk)
423   tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed."   tar --no-same-owner -xvjf ${SOURCEDIR}/${PNAME}/${SRCFILE} -C ${DEST} || die ".tbz2 unpack failed."
424   ;;   ;;
# Line 491  mstriplibs() Line 526  mstriplibs()
526    
527   [[ -z ${stripdir} ]] && stripdir="${BINDIR}"   [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
528   [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug"   [[ -z ${STRIP_DYN_LIB} ]] && STRIP_DYN_LIB="--strip-debug"
529   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
530  }  }
531    
532  mstripbins()  mstripbins()
# Line 500  mstripbins() Line 535  mstripbins()
535    
536   [[ -z ${stripdir} ]] && stripdir="${BINDIR}"   [[ -z ${stripdir} ]] && stripdir="${BINDIR}"
537   [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug"   [[ -z ${STRIP_DYN_BIN} ]] && STRIP_DYN_BIN="--strip-debug"
538   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
539  }  }
540    
541  mstripstatic()  mstripstatic()
# Line 566  sminclude() Line 601  sminclude()
601   then   then
602   for i in $@   for i in $@
603   do   do
604   echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"   [[ ${SILENT} = 1 ]] || echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc"
605   source ${SMAGESCRIPTSDIR}/include/${i}.sminc   source ${SMAGESCRIPTSDIR}/include/${i}.sminc
606   done   done
607   echo   [[ ${SILENT} = 1 ]] || echo
608   fi   fi
609  }  }
610    
# Line 588  march() Line 623  march()
623   return "${retval}"   return "${retval}"
624  }  }
625    
626  marchsrcfile()  marchvariable()
627  {  {
628   local retval   local retval
629   local var="$1"   local var="$1"
630    
631   [[ -z ${var} ]] && var="SRCFILE"   [[ -n ${var} ]] || die "marchvariable(): missing variable"
632    
633   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]   if [[ ! -z $(eval echo \$${var}_${ARCH/i*86/x86}) ]]
634   then   then
# Line 606  marchsrcfile() Line 641  marchsrcfile()
641   return "${retval}"   return "${retval}"
642  }  }
643    
644    marchsrcfile()
645    {
646     local retval
647     local var="$1"
648    
649     [[ -z ${var} ]] && var="SRCFILE"
650    
651     marchvariable "${var}" || die
652    }
653    
654  marchsrcdir()  marchsrcdir()
655  {  {
656   local retval   local retval
657   if [[ ! -z $(eval echo \$SRCDIR_${ARCH/i*86/x86}) ]]   local var="$1"
  then  
  eval echo \$SRCDIR_${ARCH/i*86/x86} | tr ';' '\n'  
  retval=0  
  else  
  retval=1  
  fi  
658    
659   return "${retval}"   [[ -z ${var} ]] && var="SRCDIR"
660    
661     marchvariable "${var}" || die
662  }  }
663    
664  marchdepend()  marchdepend()
665  {  {
666   local retval   local retval
667     local var="$1"
668    
669   if [[ ! -z $(eval echo \$DEPEND_${ARCH/i*86/x86}) ]]   [[ -z ${var} ]] && var="DEPEND"
670    
671     if [[ ! -z $(eval echo \"\$${var}_${ARCH/i*86/x86}\") ]]
672   then   then
673   echo "\$(eval echo \\\$DEPEND_\${ARCH/i*86/x86} | tr ';' '\n')"   # evaluate with escape strings for the magefile if called by smage
674     # but do not escape if the smagefile was called by depwalker directly
675     if [[ ${SMAGE_DEPEND} = 1 ]]
676     then
677     eval echo \"\$${var}_${ARCH/i*86/x86}\" | tr ';' '\n'
678     else
679     echo "\$(eval echo \\\"\\\$${var}_\${ARCH/i*86/x86}\\\" | tr ';' '\n')"
680     fi
681   retval=0   retval=0
682   else   else
683   retval=1   retval=1
# Line 638  marchdepend() Line 689  marchdepend()
689  marchsdepend()  marchsdepend()
690  {  {
691   local retval   local retval
692   if [[ ! -z $(eval echo \$SDEPEND_${ARCH/i*86/x86}) ]]   local var="$1"
693    
694     [[ -z ${var} ]] && var="SDEPEND"
695    
696     if [[ ! -z $(eval echo \"\$${var}_${ARCH/i*86/x86}\") ]]
697   then   then
698   echo "\$(eval echo \\\$SDEPEND_\${ARCH/i*86/x86} | tr ';' '\n')"   # evaluate with escape strings for the magefile if called by smage
699     # but do not escape if the smagefile was called by depwalker directly
700     if [[ ${SMAGE_DEPEND} = 1 ]]
701     then
702     eval echo \"\$${var}_${ARCH/i*86/x86}\" | tr ';' '\n'
703     else
704     echo "\$(eval echo \\\"\\\$${var}_\${ARCH/i*86/x86}\\\" | tr ';' '\n')"
705     fi
706   retval=0   retval=0
707   else   else
708   retval=1   retval=1
# Line 684  setup_ccache_environment() Line 746  setup_ccache_environment()
746   fi   fi
747  }  }
748    
 # 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}"  
 }  
   
749  # build_mage_script(): helper functions for regen_mage_tree()  # build_mage_script(): helper functions for regen_mage_tree()
750  # generates an mage file with given information in smage file  # generates an mage file with given information in smage file
751  # needs at least:  # needs at least:
# Line 779  build_mage_script() Line 779  build_mage_script()
779  {  {
780   local magefile   local magefile
781   local dest   local dest
  local target  
782   local split_pkg_base   local split_pkg_base
783   local sym   local sym
784   local depname   local depname
# Line 787  build_mage_script() Line 786  build_mage_script()
786   # if MAGE_TREE_DEST not set use BUILDDIR   # if MAGE_TREE_DEST not set use BUILDDIR
787   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
788    
  # determinate which suffix this mage file should get, if any  
  [[ $1 = --target ]] && shift && target="-$1"  
   
789   # mark package as splitpackage   # mark package as splitpackage
790   [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"   [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1"
791    
792   # name of magefile   # name of magefile
793   magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage"   magefile="${PNAME}-${PVER}-${PBUILD}.mage"
794    
795   # destination to magefile   # destination to magefile
796   dest="${MAGE_TREE_DEST}/${PCAT}/${PNAME}${target}/${magefile}"   dest="${MAGE_TREE_DEST}/${PCAT}/${PNAME}/${magefile}"
797    
798   # show what we are doing   # show what we are doing
799   echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"   echo -e "${COLBLUE}===${COLGREEN} generating mage file:${COLDEFAULT}"
# Line 808  build_mage_script() Line 804  build_mage_script()
804   > ${dest}   > ${dest}
805    
806   # pgkname and state   # pgkname and state
807   echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}$(print_distrotag)-${PBUILD}\"" >> ${dest}   echo "PKGNAME=\"${PNAME}-${PVER}-\${ARCH}$(print_distrotag)-${PBUILD}\"" >> ${dest}
808   echo "STATE=\"${STATE}\"" >> ${dest}   echo "STATE=\"${STATE}\"" >> ${dest}
809    
810   # description and homepage   # description and homepage
# Line 821  build_mage_script() Line 817  build_mage_script()
817   # special tags and vars   # special tags and vars
818   echo "PKGTYPE=\"${PKGTYPE}\""  >> ${dest}   echo "PKGTYPE=\"${PKGTYPE}\""  >> ${dest}
819    
  # echo MAGE_TARGETS ## note -target is needed !  
  echo "MAGE_TARGETS=\"${target}\"" >> ${dest}  
   
820   # split package base   # split package base
821   echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}   echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest}
822    
# Line 834  build_mage_script() Line 827  build_mage_script()
827   for i in ${SPECIAL_VARS}   for i in ${SPECIAL_VARS}
828   do   do
829   # being tricky here :)   # being tricky here :)
830   echo "${i}=\"$(eval echo \$${i})\"" >> ${dest}   echo "${i}=\"$(eval echo \"\$${i}\")\"" >> ${dest}
831   done   done
832   fi   fi
833    
# Line 852  build_mage_script() Line 845  build_mage_script()
845   fi   fi
846    
847   # deps and provides   # deps and provides
848   echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest}   echo "DEPEND=\"${DEPEND}\"" >> ${dest}
849   echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest}   echo "SDEPEND=\"${SDEPEND}\"" >> ${dest}
850   echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}   echo "PROVIDE=\"${PROVIDE}\"" >> ${dest}
851    
852   # add special functions   # add special functions
# Line 864  build_mage_script() Line 857  build_mage_script()
857   do   do
858   # add to mage (quotes needed !)   # add to mage (quotes needed !)
859   typeset -f "${i}" >> ${dest}   typeset -f "${i}" >> ${dest}
  # unset to be safe (quotes needed !)  
  #unset "${i}" <-- later to get every target built  
860   done   done
861   fi   fi
862    
# Line 883  regen_mage_tree() Line 874  regen_mage_tree()
874   # build them only if requested   # build them only if requested
875   if mqueryfeature regentree   if mqueryfeature regentree
876   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  
   
877   # run it for splitpackages   # run it for splitpackages
878   elif [[ -n ${SPLIT_PACKAGES} ]]   if [[ -n ${SPLIT_PACKAGES} ]]
879   then   then
880   local split_pkg_base="${PNAME}"   local split_pkg_base="${PNAME}"
881   # save smage environment   # save smage environment
# Line 936  regen_mage_tree() Line 915  regen_mage_tree()
915    
916   # now unset all uneeded vars to be safe   # now unset all uneeded vars to be safe
917   # 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  
918   unset SPECIAL_FUNCTIONS   unset SPECIAL_FUNCTIONS
 # for i in ${SPECIAL_VARS}  
 # do  
 # unset "${i}"  
 # done  
919   unset SPECIAL_VARS   unset SPECIAL_VARS
920   unset STATE   unset STATE
921   unset DESCRIPTION   unset DESCRIPTION
# Line 1195  generate_package_md5sum() Line 1165  generate_package_md5sum()
1165   local pver   local pver
1166   local pbuild   local pbuild
1167   local parch   local parch
  local target  
1168   local pkgname   local pkgname
1169    
1170   # very basic getops   # very basic getops
# Line 1207  generate_package_md5sum() Line 1176  generate_package_md5sum()
1176   --pver|-v) shift; pver="$1" ;;   --pver|-v) shift; pver="$1" ;;
1177   --pbuild|-b) shift; pbuild="$1" ;;   --pbuild|-b) shift; pbuild="$1" ;;
1178   --parch|a) shift; parch="$1" ;;   --parch|a) shift; parch="$1" ;;
  --target|t) shift; target="$1" ;;  
1179   esac   esac
1180   shift   shift
1181   done   done
# Line 1223  generate_package_md5sum() Line 1191  generate_package_md5sum()
1191   [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."   [ -z "${PKGDIR}" ] && die "generate_package_md5sum() \$PKGDIR not set."
1192   [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."   [ -z "${PKGSUFFIX}" ] && die "generate_package_md5sum() \$PKGSUFFIX not set."
1193    
  # fix target as it may be empty !  
  [ -n "${target}" ] && target="-${target}"  
   
1194   # build pkgname   # build pkgname
1195   pkgname="${pname}${target}-${pver}-${parch}$(print_distrotag)-${pbuild}"   pkgname="${pname}-${pver}-${parch}$(print_distrotag)-${pbuild}"
1196    
1197   # build pkg-md5-sum only if requested   # build pkg-md5-sum only if requested
1198   if mqueryfeature regentree   if mqueryfeature regentree
# Line 1245  generate_package_md5sum() Line 1210  generate_package_md5sum()
1210   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}   : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree}
1211    
1212   # setup md5 dir   # setup md5 dir
1213   dest="${MAGE_TREE_DEST}/${pcat}/${pname}${target}/md5"   dest="${MAGE_TREE_DEST}/${pcat}/${pname}/md5"
1214   install -d ${dest}   install -d ${dest}
1215    
1216   # gen md5sum   # gen md5sum
# Line 1257  generate_package_md5sum() Line 1222  generate_package_md5sum()
1222    
1223  source_pkg_build()  source_pkg_build()
1224  {  {
  if [[ ${PKGTYPE} = virtual ]]  
  then  
  echo "Virtual package detected; src-pkg-tarball not necessary ..."  
  return 0  
  fi  
   
1225   if [[ ! -d ${SOURCEDIR}/${PNAME} ]]   if [[ ! -d ${SOURCEDIR}/${PNAME} ]]
1226   then   then
1227   echo "No SRC_URI defined; src-pkg-tarball not necessary ..."   install -d ${SOURCEDIR}/${PNAME}
  return 0  
1228   fi   fi
1229    
1230   [ -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.2172  
changed lines
  Added in v.3207