--- trunk/mage/usr/lib/mage/smage2.sh 2009/11/20 19:41:27 941 +++ trunk/mage/usr/lib/mage/smage2.sh 2010/06/28 17:47:38 1081 @@ -75,10 +75,15 @@ die_pipestatus() { - local pos="$1" - local comment="$2" - - [ ${PIPESTATUS[${pos}]} -gt 0 ] && die "${comment}" + # 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() @@ -525,11 +530,15 @@ install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "creating doc dirs." fi + local i for i in ${docfiles} do - cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs." - install -m 0644 ${SRCDIR}/${i}.gz \ - ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs." + if [ -f ${i} ] + then + cat ${i} | gzip -9c > ${i}.gz || die "gzipping docs." + install -m 0644 ${SRCDIR}/${i}.gz \ + ${BINDIR}/usr/share/doc/${PNAME}-${PVER} || die "coping docs." + fi done } @@ -549,6 +558,23 @@ find ${stripdir} | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null } +mcompressdocs() +{ + local bindir="$@" + + if [ -d ${bindir}/usr/share/man ] + then + echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}" + ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/man + fi + + if [ -d ${bindir}/usr/share/info ] + then + echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}" + ${MLIBDIR}/compressdoc -g -9 ${bindir}/usr/share/info + fi +} + sminclude() { local i @@ -664,6 +690,9 @@ # INHERITS which functions get included # SPECIAL_FUNCTIONS special functions which should also be added # warning: they get killed before the build starts ! +# SPLIT_PACKAGES names of all subpackages which are splitted from parent +# SPLIT_PACKAGE_BASE base package name for splitpackages +# (only in the resulting magefile} # # MAGE_TREE_DEST target destination of the generated tree # REGEN_MAGE_TREE set to 'true' to enable this @@ -674,6 +703,7 @@ local magefile local dest local target + local split_pkg_base local sym local depname @@ -681,7 +711,10 @@ : ${MAGE_TREE_DEST=${BUILDDIR}/mage-tree} # determinate which suffix this mage file should get, if any - [ -n "$1" ] && target="-$1" + [[ $1 = --target ]] && shift && target="-$1" + + # mark package as splitpackage + [[ $1 = --split-pkg-base ]] && shift && split_pkg_base="$1" # name of magefile magefile="${PNAME}${target}-${PVER}-${PBUILD}.mage" @@ -718,6 +751,10 @@ echo "MAGE_TARGETS=\"${target}\"" >> ${dest} echo >> ${dest} + # split package base + echo "SPLIT_PACKAGE_BASE=\"${split_pkg_base}\"" >> ${dest} + echo >> ${dest} + # add special vars if [ -n "${SPECIAL_VARS}" ] then @@ -785,21 +822,43 @@ if [[ ${REGEN_MAGE_TREE} = true ]] then # run it without targets - if [ -z "${MAGE_TARGETS}" ] + if [[ -n ${MAGE_TARGETS} ]] then + # build for each target a mage file + # run it with several targets echo - build_mage_script + for i in ${MAGE_TARGETS} + do + build_mage_script --target "${i}" + done echo - else - # build for each target an mage file + # run it for splitpackages + elif [[ -n ${SPLIT_PACKAGES} ]] + then + local split_pkg_base="${PNAME}" + # save smage environment + split_save_variables + # build for each subpackage a mage file # run it with several targets - for i in ${MAGE_TARGETS} + echo + for i in ${SPLIT_PACKAGES} do - echo - build_mage_script "${i}" - echo + # get the right variables for the split + export PNAME="${i}" + split_info_${i} + build_mage_script --split-pkg-base "${split_pkg_base}" + # restore smage environment + split_restore_variables done + echo + # unset all saved smage variables + split_unset_variables + + else + echo + build_mage_script + echo fi fi @@ -830,6 +889,150 @@ unset postremove } +split_save_variables() +{ + export SAVED_PNAME="${PNAME}" + export SAVED_PVER="${PVER}" + export SAVED_PBUILD="${PBUILD}" + export SAVED_PCATEGORIE="${PCATEGORIE}" + export SAVED_DESCRIPTION="${DESCRIPTION}" + export SAVED_HOMEPAGE="${HOMEPAGE}" + export SAVED_SPECIAL_VARS="${SPECIAL_VARS}" + export SAVED_STATE="${STATE}" + export SAVED_PKGTYPE="${PKGTYPE}" + export SAVED_INHERITS="${INHERITS}" + export SAVED_DEPEND="${DEPEND}" + export SAVED_SDEPEND="${SDEPEND}" + export SAVED_PROVIDE="${PROVIDE}" + export SAVED_NOPKGBUILD="${NOPKGBUILD}" + + # bindir too + export SAVED_BINDIR="${BINDIR}" + + # export the SPLIT_PACKAGE_BASE + export SPLIT_PACKAGE_BASE="${SAVED_PNAME}" + + # functions + if [[ ! -z $(typeset -f preinstall) ]] + then + # rename the old one + local saved_preinstall + saved_preinstall=SAVED_$(typeset -f preinstall) + eval "${saved_preinstall}" + export -f SAVED_preinstall + fi + + if [[ ! -z $(typeset -f postinstall) ]] + then + # rename the old one + local saved_postinstall + saved_postinstall=SAVED_$(typeset -f postinstall) + eval "${saved_postinstall}" + export -f SAVED_postinstall + fi + + if [[ ! -z $(typeset -f preremove) ]] + then + # rename the old one + local saved_preremove + saved_preremove=SAVED_$(typeset -f preremove) + eval "${saved_preremove}" + export -f SAVED_preremove + fi + + if [[ ! -z $(typeset -f postremove) ]] + then + # rename the old one + local saved_postremove + saved_postremove=SAVED_$(typeset -f postremove) + eval "${saved_postremove}" + export -f SAVED_postremove + fi +} + +split_restore_variables() +{ + export PNAME="${SAVED_PNAME}" + export PVER="${SAVED_PVER}" + export PBUILD="${SAVED_PBUILD}" + export PCATEGORIE="${SAVED_PCATEGORIE}" + export DESCRIPTION="${SAVED_DESCRIPTION}" + export HOMEPAGE="${SAVED_HOMEPAGE}" + export SPECIAL_VARS="${SAVED_SPECIAL_VARS}" + export STATE="${SAVED_STATE}" + export PKGTYPE="${SAVED_PKGTYPE}" + export INHERITS="${SAVED_INHERITS}" + export DEPEND="${SAVED_DEPEND}" + export SDEPEND="${SAVED_SDEPEND}" + export PROVIDE="${SAVED_PROVIDE}" + export NOPKGBUILD="${SAVED_NOPKGBUILD}" + + # bindir too + export BINDIR="${SAVED_BINDIR}" + + # functions + if [[ ! -z $(typeset -f SAVED_preinstall) ]] + then + # rename the old one + local saved_preinstall + saved_preinstall=$(typeset -f SAVED_preinstall) + eval "${saved_preinstall/SAVED_/}" + export -f preinstall + fi + + if [[ ! -z $(typeset -f SAVED_postinstall) ]] + then + # rename the old one + local saved_postinstall + saved_postinstall=$(typeset -f SAVED_postinstall) + eval "${saved_postinstall/SAVED_/}" + export -f postinstall + fi + + if [[ ! -z $(typeset -f SAVED_preremove) ]] + then + # rename the old one + local saved_preremove + saved_preremove=$(typeset -f SAVED_preremove) + eval "${saved_preremove/SAVED_/}" + export -f preremove + fi + + if [[ ! -z $(typeset -f SAVED_postremove) ]] + then + # rename the old one + local saved_postremove + saved_postremove=$(typeset -f SAVED_postremove) + eval "${saved_postremove/SAVED_/}" + export -f postremove + fi +} + +split_unset_variables() +{ + # unset saved vars; not needed anymore + unset SAVED_PNAME + unset SAVED_PVER + unset SAVED_PBUILD + unset SAVED_PCATEGORIE + unset SAVED_DESCRIPTION + unset SAVED_HOMEPAGE + unset SAVED_SPECIAL_VARS + unset SAVED_STATE + unset SAVED_PKGTYPE + unset SAVED_INHERITS + unset SAVED_DEPEND + unset SAVED_SDEPEND + unset SAVED_PROVIDE + unset SAVED_BINDIR + unset SAVED_NOPKGBUILD + unset SPLIT_PACKAGE_BASE + unset -f SAVED_preinstall + unset -f SAVED_postinstall + unset -f SAVED_preremove + unset -f SAVED_postremove +} + export_inherits() { local include="$1" @@ -953,7 +1156,7 @@ { if [[ ${STEP_BY_STEP} = true ]] then - echo "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}" + echo -e "${COLRED}Step-by-step enabled! Paused after $1.${COLDEFAULT}" echo "Press [enter] to continue" read fi @@ -1080,7 +1283,7 @@ regen_mage_tree # build several targets - if [ -n "${MAGE_TARGETS}" ] + if [[ -n ${MAGE_TARGETS} ]] then for target in ${MAGE_TARGETS} do @@ -1093,6 +1296,29 @@ --parch "${ARCH}" \ --target "${target}" done + + # build several subpackages + elif [[ -n ${SPLIT_PACKAGES} ]] + then + split_save_variables + for subpackage in ${SPLIT_PACKAGES} + do + # get the right variables for the split + export PNAME="${subpackage}" + split_info_${subpackage} + # build md5sum for existing packages + generate_package_md5sum \ + --pcat "${PCATEGORIE}" \ + --pname "${PNAME}" \ + --pver "${PVER}" \ + --pbuild "${PBUILD}" \ + --parch "${ARCH}" + # restore smage environment + split_restore_variables + done + # unset all saved smage variables + split_unset_variables + else # build md5sum for existing packages generate_package_md5sum \ @@ -1100,8 +1326,7 @@ --pname "${PNAME}" \ --pver "${PVER}" \ --pbuild "${PBUILD}" \ - --parch "${ARCH}" \ - --target "${target}" + --parch "${ARCH}" fi exit 0 @@ -1254,23 +1479,54 @@ die_pipestatus 0 "src_compile failed" step_by_step $_ -src_install | ${SMAGE_LOG_CMD} -die_pipestatus 0 "src_install failed" -step_by_step $_ +# build several subpackages +if [[ -n ${SPLIT_PACKAGES} ]] +then + # save bindir & pname + split_save_variables + export SAVED_BINDIR="${BINDIR}" + for subpackage in ${SPLIT_PACKAGES} + do + if typeset -f src_install_${subpackage} > /dev/null + then + # export subpackage bindir + export BINDIR="${SAVED_BINDIR}_${subpackage}" + # export PNAME, several internal function and include + # rely on this variable + export PNAME="${subpackage}" + echo + echo -en "${COLBLUE}*** ${COLDEFAULT}" + echo -en " Running ${COLGREEN}split src_install()${COLDEFAULT}" + echo -en " for subpkg: ${COLBLUE}${PNAME}${COLDEFAULT}" + echo -e " - basepkg: ${COLBLUE}${SPLIT_PACKAGE_BASE}${COLDEFAULT} ..." + + src_install_${subpackage} | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_install_${subpackage} failed" + step_by_step $_ + fi + done + # restore bindir & pname + split_restore_variables + # unset all saved smage variables + split_unset_variables +else + src_install | ${SMAGE_LOG_CMD} + die_pipestatus 0 "src_install failed" + step_by_step $_ +fi # compressing doc, info & man files -if [ -d ${BUILDDIR}/builded/usr/share/man ] +if [[ -n ${SPLIT_PACKAGES} ]] then - echo -e "${COLBLUE}===${COLGREEN} compressing man-pages ...${COLDEFAULT}" - ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/man + for subpackage in ${SPLIT_PACKAGES} + do + mcompressdocs ${BINDIR}_${subpackage} + done +else + mcompressdocs ${BINDIR} fi -if [ -d ${BUILDDIR}/builded/usr/share/info ] -then - echo -e "${COLBLUE}===${COLGREEN} compressing info-pages ...${COLDEFAULT}" - ${MLIBDIR}/compressdoc -g -9 ${BUILDDIR}/builded/usr/share/info -fi # stripping all bins and libs case ${NOSTRIP} in @@ -1278,10 +1534,21 @@ echo -e "NOSTRIP=true detected; Package will not be stripped ..." ;; *) - echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" - mstripbins ${BINDIR} - echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}" - mstriplibs ${BINDIR} + if [[ -n ${SPLIT_PACKAGES} ]] + then + for subpackage in ${SPLIT_PACKAGES} + do + echo -e "${COLBLUE}===${COLGREEN} stripping binaries for '${subpackage}' ...${COLDEFAULT}" + mstripbins ${BINDIR}_${subpackage} + echo -e "${COLBLUE}===${COLGREEN} stripping libraries for '${subpackage}' ...${COLDEFAULT}" + mstriplibs ${BINDIR}_${subpackage} + done + else + echo -e "${COLBLUE}===${COLGREEN} stripping binaries ...${COLDEFAULT}" + mstripbins ${BINDIR} + echo -e "${COLBLUE}===${COLGREEN} stripping libraries ...${COLDEFAULT}" + mstriplibs ${BINDIR} + fi ;; esac @@ -1292,7 +1559,7 @@ ;; *) # build several targets - if [ -n "${MAGE_TARGETS}" ] + if [[ -n ${MAGE_TARGETS} ]] then for target in ${MAGE_TARGETS} do @@ -1318,6 +1585,49 @@ echo -e "${COLGREEN}\nPackage ${PNAME}-${target}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" done + + # build several subpackages + elif [[ -n ${SPLIT_PACKAGES} ]] + then + split_save_variables + for subpackage in ${SPLIT_PACKAGES} + do + # get the right variables for the split + export PNAME="${subpackage}" + split_info_${PNAME} + + # jump to next one if NOPKGBUILD is set in split_info + case ${NOPKGBUILD} in + true|TRUE|yes|y) continue ;; + esac + + # check if an special subpackage_pkgbuild exists + if typeset -f ${PNAME}_pkgbuild > /dev/null + then + # run it + ${PNAME}_pkgbuild + fi + # now create the target package + ${MLIBDIR}/pkgbuild_dir.sh \ + "${PNAME}-${PVER}-${ARCH}-${PBUILD}" \ + "${BINDIR}_${PNAME}" || die "split_package: ${PNAME} package-build failed" + + # build pkg-md5-sum if requested + generate_package_md5sum \ + --pcat "${PCATEGORIE}" \ + --pname "${PNAME}" \ + --pver "${PVER}" \ + --pbuild "${PBUILD}" \ + --parch "${ARCH}" + + echo -e "${COLGREEN}\nPackage ${PNAME}-${PVER}-${ARCH}-${PBUILD} successfully builded.\n${COLDEFAULT}" + + # restore smage environment + split_restore_variables + done + # unset all saved smage variables + split_unset_variables + else ${MLIBDIR}/pkgbuild_dir.sh ${PKGNAME} ${BINDIR} || die "package-build failed"