--- trunk/mage/usr/lib/mage/smage2.sh 2005/08/19 03:43:56 192 +++ trunk/mage/usr/lib/mage/smage2.sh 2005/08/28 19:23:04 214 @@ -4,7 +4,7 @@ # needs pkgbuild_dir (mage) # SMAGE2 -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.23 2005-08-19 03:43:56 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.36 2005-08-28 19:23:04 niro Exp $ #01.10.2004 # added ccache support @@ -406,6 +406,59 @@ fi } + +# 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 + + # 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 + 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}" +} + # build_mage_script(): helper functions for regen_mage_tree() # generates an mage file with given information in smage file # needs at least: @@ -428,11 +481,13 @@ # # MAGE_TREE_DEST target destination of the generated tree # REGEN_MAGE_TREE set to 'true' to enable this +# +# gets called with build_mage_script target build_mage_script() { local magefile local dest - local suffix + local target local sym local depname @@ -440,13 +495,13 @@ : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} # determinate which suffix this mage file should get, if any - suffix="$1" + [ -n "$1" ] && target="-$1" # name of magefile - magefile="${PNAME}${suffix}-${PVER}-${PBUILD}.mage" + magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" # destination to magefile - dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${suffix}/${magefile}" + dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}" # show what we are doing echo "Generating Mage file:" @@ -457,11 +512,11 @@ > ${dest} # header - echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.23 2005-08-19 03:43:56 niro Exp $' >> ${dest} + echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.36 2005-08-28 19:23:04 niro Exp $' >> ${dest} echo >> ${dest} # pgkname and state - echo "PKGNAME=\"${PNAME}${suffix}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} + echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} echo "STATE=\"${STATE}\"" >> ${dest} echo >> ${dest} @@ -470,8 +525,26 @@ echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} echo >> ${dest} - # special tags + # special tags and vars echo "PKGTYPE=\"${PKGTYPE}\"" >> ${dest} + + # echo MAGE_TARGETS ## note -target is needed ! + echo "MAGE_TARGETS=\"${target}\"" >> ${dest} + echo >> ${dest} + + # add special vars + if [ -n "${SPECIAL_VARS}" ] + then + local i + for i in ${SPECIAL_VARS} + do + # being tricky here :) + echo "${i}=\"$(eval echo \$${i})\"" >> ${dest} + done + echo >> ${dest} + fi + + # add at least all includes if [ -n "${INHERITS}" ] then echo -n "minclude" >> ${dest} @@ -485,8 +558,10 @@ echo >> ${dest} # deps and provides - echo "DEPEND=\"${DEPEND}\"" >> ${dest} - echo "SDEPEND=\"${SDEPEND}\"" >> ${dest} + echo "DEPEND=\"$(fix_mage_deps "${target}" "${DEPEND}")\"" >> ${dest} + echo >> ${dest} + echo "SDEPEND=\"$(fix_mage_deps "${target}" "${SDEPEND}")\"" >> ${dest} + echo >> ${dest} echo "PROVIDE=\"${PROVIDE}\"" >> ${dest} echo >> ${dest} @@ -498,9 +573,11 @@ do # add to mage (quotes needed !) typeset -f "${i}" >> ${dest} + echo >> ${dest} # unset to be safe (quotes needed !) #unset "${i}" <-- later to get every target built done + echo >> ${dest} fi # pre|post-install|removes @@ -521,13 +598,23 @@ # build them only if requested if [[ ${REGEN_MAGE_TREE} = true ]] then - # build for each target an mage file - for i in ${MAGE_TARGETS} - do + # run it without targets + if [ -z "${MAGE_TARGETS}" ] + then echo - build_mage_script "${i}" + build_mage_script echo - done + else + + # build for each target an mage file + # run it with several targets + for i in ${MAGE_TARGETS} + do + echo + build_mage_script "${i}" + echo + done + fi fi # now unset all uneeded vars to be safe @@ -538,6 +625,11 @@ unset "${i}" done unset SPECIAL_FUNCTIONS + for i in ${SPECIAL_VARS} + do + unset "${i}" + done + unset SPECIAL_VARS unset STATE unset DESCRIPTION unset HOMEPAGE @@ -661,6 +753,18 @@ exit 0 fi +# regen-mage-tree +if [ "$1" == "only-regen-tree" -a -n "$2" ] +then + # set correct SMAGENAME + SMAGENAME="$2" + MD5DIR="$(dirname ${SMAGENAME})/md5" + source ${SMAGENAME} || die "regen: smage2 not found" + + regen_mage_tree + exit 0 +fi + if [ ! -e ${MLIBDIR}/pkgbuild_dir.sh ] then die "Error: ${MLIBDIR}/pkgbuild_dir.sh not found. Aborting."