--- trunk/mage/usr/lib/mage/smage2.sh 2005/08/16 23:23:33 186 +++ trunk/mage/usr/lib/mage/smage2.sh 2005/08/21 21:36:54 200 @@ -4,7 +4,7 @@ # needs pkgbuild_dir (mage) # SMAGE2 -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.21 2005-08-16 23:23:26 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.31 2005-08-21 21:36:54 niro Exp $ #01.10.2004 # added ccache support @@ -230,11 +230,6 @@ return 0 } - -build_mage_script() { - return 0 -} - mconfigure() { if [ -x ./configure ] then @@ -411,6 +406,237 @@ 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}${target}" + 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: +# PNAME name of pkg +# PVER version +# PBUILD revision +# PCATEGORIE categorie of the pkg +# STATE state of pkg stable|unstable|old +# DESCRIPTION va short description (opt) +# HOMEPAGE homepage (opt) +# DEPEND runtime dependencies (opt) +# SDEPEND add. needed deps to build the pkg (opt) +# PROVIDE provides a virtual (opt) +# +# special tags: +# PKGTYPE type of pkg +# INHERITS which functions get included +# SPECIAL_FUNCTIONS special functions wich should also be added +# warning: they get killed before the build starts ! +# +# 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 target + local sym + local depname + + # if MAGE_TREE_DEST not set use BUILDDIR + : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} + + # determinate which suffix this mage file should get, if any + [ -n "$1" ] && target="-$1" + + # name of magefile + magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" + + # destination to magefile + dest="${MAGE_TREE_DEST}/${PCATEGORIE}/${PNAME}${target}/${magefile}" + + # show what we are doing + echo "Generating Mage file:" + echo " ${dest}" + + install -d "$(dirname ${dest})" + # now build the mage file + > ${dest} + + # header + echo '# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.31 2005-08-21 21:36:54 niro Exp $' >> ${dest} + echo >> ${dest} + + # pgkname and state + echo "PKGNAME=\"${PNAME}${target}-${PVER}-\${ARCH}-${PBUILD}\"" >> ${dest} + echo "STATE=\"${STATE}\"" >> ${dest} + echo >> ${dest} + + # description and homepage + echo "DESCRIPTION=\"${DESCRIPTION}\"" >> ${dest} + echo "HOMEPAGE=\"${HOMEPAGE}\"" >> ${dest} + echo >> ${dest} + + # special tags and vars + echo "PKGTYPE=\"${PKGTYPE}\"" >> ${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} + local i + for i in ${INHERITS} + do + echo -n " ${i}" >> ${dest} + done + echo >> ${dest} + fi + echo >> ${dest} + + # deps and provides + 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} + + # add special functions + if [ -n "${SPECIAL_FUNCTIONS}" ] + then + local i + for i in ${SPECIAL_FUNCTIONS} + do + # add to mage (quotes needed !) + typeset -f "${i}" >> ${dest} + # unset to be safe (quotes needed !) + #unset "${i}" <-- later to get every target built + done + echo >> ${dest} + fi + + # pre|post-install|removes + typeset -f preinstall >> ${dest} + echo >> ${dest} + typeset -f postinstall >> ${dest} + echo >> ${dest} + typeset -f preremove >> ${dest} + echo >> ${dest} + typeset -f postremove >> ${dest} + echo >> ${dest} +} + +regen_mage_tree() +{ + local i + + # build them only if requested + if [[ ${REGEN_MAGE_TREE} = true ]] + then + # run it without targets + if [ -z "${MAGE_TARGETS}" ] + then + echo + build_mage_script + echo + 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 + # 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 + unset SPECIAL_FUNCTIONS + for i in ${SPECIAL_VARS} + do + unset "${i}" + done + unset SPECIAL_VARS + unset STATE + unset DESCRIPTION + unset HOMEPAGE + unset PKGTYPE + unset INHERITS + unset DEPEND + unset SDEPEND + unset PROVIDE + unset preinstall + unset postinstall + unset preremove + unset postremove +} + # print out our version showversion echo @@ -422,7 +648,7 @@ exit 1 fi -#updating smage2-scripts +# updating smage2-scripts if [ "$1" == "update" ] then if [ ! -d ${SOURCEDIR} ] @@ -433,7 +659,7 @@ exit 0 fi -#creates md5sums for smages to given dir +# creates md5sums for smages to given dir if [ "$1" == "calcmd5" ] then if [ $# -ge 3 ] @@ -503,7 +729,7 @@ exit 0 fi -#download sources +# download sources if [ "$1" == "download" -a -n "$2" ] then if [ ! -d ${SMAGESCRIPTSDIR} ] @@ -574,15 +800,18 @@ xtitle "Compiling ${PKGNAME}" echo "Compiling ${PKGNAME}" -#download sources +# auto regen mage tree if requested +regen_mage_tree + +# download sources download_sources -#fixes some issues with these functions +# fixes some issues with these functions export -f src_prepare || die "src_prepare export failed" export -f src_compile || die "src_compile export failed" export -f src_install || die "src_install export failed" -#fixes some compile issues +# fixes some compile issues export CHOST="${CHOST}" || die "CHOST export failed" export CFLAGS="${CFLAGS}" || die "CFLAGS export failed" export CXXFLAGS="${CFLAGS}" || die "CXXFLAGS export failed" @@ -590,14 +819,14 @@ export MAKEOPTS="${MAKEOPTS}" || die "MAKEOPTS export failed" -#setup distcc -#distcc mus be setup *before* ccache, as ccache need to be before distcc in path +# setup distcc +# distcc mus be setup *before* ccache, as ccache need to be before distcc in path if [ "${SMAGE_USE_DISTCC}" == "true" ] then setup_distcc_environment fi -#setup ccache +# setup ccache if [ "${SMAGE_USE_CCACHE}" == "true" ] then setup_ccache_environment @@ -618,33 +847,33 @@ #read #debug end -#cleans up build if a previously one exists +# cleans up build if a previously one exists if [ -d ${BUILDDIR} ] then rm -rf ${BUILDDIR}/* || die "couldn't cleanup \$BUILDDIR." fi install -d ${BUILDDIR} || die "couldn't create \$BUILDDIR." -#cleans up srcdir if a previously unpacked one exists +# cleans up srcdir if a previously unpacked one exists if [ -d ${SRCDIR} ] then rm -rf ${SRCDIR} fi -#cleans up bindir if a previous build exists or creates a new one +# cleans up bindir if a previous build exists or creates a new one if [ -d ${BINDIR} ] then rm -rf ${BINDIR} fi install -d ${BINDIR} || die "couldn't create \$BINDIR." -#cleans up package temp dir if a previous build exists +# cleans up package temp dir if a previous build exists if [ -d ${BUILDDIR}/${PKGNAME} ] then rm -rf ${BUILDDIR}/${PKGNAME} fi -#cleans up timestamp if one exists +# cleans up timestamp if one exists if [ -f /var/tmp/timestamp ] then mage rmstamp @@ -655,7 +884,7 @@ src_install || die "src_install failed" -#compressing doc, info & man files +# compressing doc, info & man files echo -e "Compressing man-pages ..." if [ -d ${BUILDDIR}/builded/usr/share/man ] then @@ -681,18 +910,37 @@ ;; esac -#the new buildpkg command +# the new buildpkg command case ${NOPKGBUILD} in true|TRUE|yes|y) echo -e "NOPGKBUILD=true detected; Package will not be build ..." ;; - *) - ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" - echo -e "\nPackage ${PKGNAME} successfully builded.\n" + *) + # build serveral targets + if [ -n "${MAGE_TARGETS}" ] + then + for target in ${MAGE_TARGETS} + do + # check if an special target_pkgbuild exists + if typeset -f ${target}_pkgbuild > /dev/null + then + # run it + ${target}_pkgbuild + fi + # now create the target package + ${MLIBDIR}/pkgbuild_dir.sh \ + "${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD}" \ + ${BINDIR} || die "target: ${target} package-build failed" + echo -e "\nPackage ${PNAME}-${target}-${PVER}-${CHOST%%-*}-${PBUILD} successfully builded.\n" + done + else + ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed" + echo -e "\nPackage ${PKGNAME} successfully builded.\n" + fi ;; esac -#for sure +# for sure unset NOPKGBUILD unset NOSTRIP