--- trunk/mage/usr/lib/mage/smage2.sh 2005/07/29 14:28:43 167 +++ trunk/mage/usr/lib/mage/smage2.sh 2005/08/20 15:55:19 196 @@ -4,14 +4,13 @@ # needs pkgbuild_dir (mage) # SMAGE2 -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.15 2005-07-29 14:28:39 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/smage2.sh,v 1.27 2005-08-20 15:55:19 niro Exp $ #01.10.2004 # added ccache support # added distcc support ## setup ## -SMAGEVERSION=0.3.6-r19 PKGSUFFIX="mpk" SMAGENAME="$1" SMAGESUFFIX="smage2" @@ -19,6 +18,10 @@ #SMAGESCRIPTSDIR="/bootstrap/smage2-install-scripts" #SMAGE2RSYNC="rsync://192.168.0.2/smage2-scripts" MLIBDIR=/usr/lib/mage +SMAGEVERSION="$( < ${MLIBDIR}/version)" + +# export default C locale +export LC_ALL=C source /etc/mage.rc @@ -227,11 +230,6 @@ return 0 } - -build_mage_script() { - return 0 -} - mconfigure() { if [ -x ./configure ] then @@ -354,6 +352,20 @@ find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null } +sminclude() { + local i + + if [[ -n "$@" ]] + then + for i in $@ + do + echo "--- Including ${SMAGESCRIPTSDIR}/include/${i}.sminc" + source ${SMAGESCRIPTSDIR}/include/${i}.sminc + done + echo + fi +} + setup_distcc_environment(){ if [ -x /usr/bin/distcc ] then @@ -394,6 +406,233 @@ fi } + +# fixes given dependencies to match a MAGE_TARGET +# fix_mage_deps target s/depend +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})" + # abort on virtual + [[ ${cat} = virtual ]] && continue + + # fix pver to target-pver + # to get pname-target-pver + + # doing it backwards ! + pver="${dep##*-}" + pname=$(basename ${dep/-${pver}/}) + + # do not add empty lines + if [ -z "${NDEPEND}" ] + then + NDEPEND="${sym} ${cat}/${pname}-${target}-${pver}" + else + NDEPEND="${NDEPEND} + ${sym} ${cat}/${pname}-${target}-${pver}" + 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.27 2005-08-20 15:55:19 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} + 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} + + # 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 + + # 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 @@ -405,7 +644,7 @@ exit 1 fi -#updating smage2-scripts +# updating smage2-scripts if [ "$1" == "update" ] then if [ ! -d ${SOURCEDIR} ] @@ -416,7 +655,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 ] @@ -486,10 +725,9 @@ exit 0 fi -#download sources +# download sources if [ "$1" == "download" -a -n "$2" ] then - showversion if [ ! -d ${SMAGESCRIPTSDIR} ] then install -d ${SMAGESCRIPTSDIR} @@ -558,15 +796,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" @@ -574,14 +815,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 @@ -602,33 +843,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 @@ -639,7 +880,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 @@ -665,18 +906,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